da=read.table("m-ibm6708.txt",header=T) #<== Load data with header
#<== Check dimension of the data (row = sample size, col = variables)
###############502 rows, col 1 = date, col 2 = ibm, col 3 = sprtn
#<== Print out the first 6 rows of the data object "da".
printrows <- da[1:6]
printrows
打印行不起作用。我尝试了很多东西。我认为它可能会使用 cbind。 da 是一张大表,但我只需要显示前 6 行。
最佳答案
正如 jdharrison 所说,head(da,6)
将起作用 - 或者您可以使用索引打印前 6 行 da[1:6,]
当使用索引符号时,请记住它是 [rows,columns]
,如果您有 data.frame
或 matrix
,则必须包含逗号> - 即前六行的 [1:6,]
或前六列的 [,1:6]
。
关于r - 如何从 R Studio 中的 read.table 打印一定数量的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25655525/