So i know you can skip columns with read.table by providing a NULL to colClasses vector, but this is usually only helpful if you know how many columns are in your table.
What if I want to skip first 2 columns of table but read all the rest (which I know are numeric). Something like:
colClasses = c(NULL,NULL,rep("numeric", k))
except I don't know what k is. What would be best way to handle this?
If you use the default white-space separation on a file named "fil.txt" then use this
colClasses = c(NULL,NULL,rep("numeric", count.fields("fil.txt")[1] -2 ))
If you use a different separator then something like
colClasses = c(NULL,NULL,rep("numeric", count.fields("fil.txt", sep=",")[1] -2 ))
跳过前两列的简单方法:
data <- read.table("dataname.csv", header = TRUE, sep = ",")[,-c(1,2)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.