Reputation: 175
So I have read in data using readLine()
I'm needing to apply a function to every line in the list except for example lets say the lines before line 15 and after like 30.
How am I meant to cut this data out of my original text data?
I was thinking of maybe indexing the data I need like data[15]
to data[30]
and then using lapply()
on the data within these bounds. I also thought about just deleting (or ignoring) the data lines unto line 15 and after line 30 but I have no idea where to start.
Upvotes: 2
Views: 53
Reputation: 19015
If you want to keep only lines 15-30, it's simply:
# write something to a text file
nrow(iris)
write.table(iris, 'temp.txt', row.names=FALSE, quote=FALSE)
some_txt <- readLines(file('temp.txt'))[15:30]
length(some_txt)
If you want to keep everything except those lines then it's some_txt <- readLines(file('temp.txt'))[-(15:30)]
. We're a little confused which subset you're looking for.
Upvotes: 1