In R, I need to read in a tab delimited text file, but only the rows where column 1 (strings) equals a specific string. I've been told I can do this using the with()
function, but have not been able to accomplish it. I can do this in 2 statements, but I need to do it in 1 using with()
.
Here's how I've done it using the two statements:
dF <- read.table(file, header=TRUE, sep="\t", na='-999')
dF <- subset(dF,dF$C1=="value")[,-1]
Since I'm filtering on column 1, I'm also going to remove it in the new data frame.
Is this possible to do in one with()
function? If so, can I also display the results in the same expression? Would indexing help? I can't figure out how to make indexing work for this.
Thank you in advance!