문제

I want to print a head of a file in R. I know how to use read.table and other input methods supported by R. I just want to know R alternatives to unix command cat or head that reads in a file and print some of them.

Thank you,

SangChul

도움이 되었습니까?

해결책

read.table() takes an nrows argument for just this purpose:

read.table(header=TRUE, text="
    a b
    1 2
    3 4
    ", nrows=1)
#   a b
# 1 1 2

If you are instead reading in (possibly less structured) files with readLines(), you can use its n argument instead:

readLines(textConnection("a b
1 2 3 4 some other things
last"), n=1)
# [1] "a b"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top