I would like to be able to scan a csv file row by row in R and exclude the rows that contain the word “target”.
The problem is that the data comes from different places and the word “target” can come up in a number of different columns in the data frame.
So I need a line in a function that will look for this string, and if it is not present, then append that row to a new data frame (that I will then write out as a new csv).
Any and all help gratefully recieved.
Andrie’s comment is probably the way most users would approach this, but if you want to do this at the reading in stage, you can try this:
Read in your csv using
readLinesand make any lines that have the text target blank:Use
read.tableto converttempto adata.frame. Since all lines that have the text target are now blank, the defaultblank.lines.skip=TRUEinread.tableshould correctly read in the rest of your data as adata.frame.