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
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
.
Try tihs:
data2 <- head(data2, -10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With