Reputation: 3082
i knew that there is options skip
for read.csv()
I knew how to do for skip first 10 rows as follow:
data2<-read.csv("book4.csv", skip=10, header=T)
How about for skipping last 10 rows?
My approach is
data2 <- data2[1:(dim(data2)[1]-10),]
Is there any alternative way?
Thanks
Upvotes: 10
Views: 13246
Reputation: 25736
As @Thomas suggested you can combine readLines
and read.csv
, e.g.:
df <- read.csv(text=paste0(head(readLines("file.csv"), -10), collapse="\n"))
But I am not sure that this approach is better than your data2 <- data2[1:(dim(data2)[1]-10),]
. It would be the better approach if your last 10 lines are in a different format and break read.csv
.
Upvotes: 12