Lets say I have a file like this:
a b c d
2 3 4 5
9 8 7 4
5 7 8 4
I would like to export column a
and c
but nothing else.
Can I do a version of write.csv
or write.table
e.g. write.csv(myobject$a && myobject$b, file="outfile.csv")
This should work
write.csv(myobject[,c("a","b")], file="outfile.csv",row.names=FALSE)
The brackets in myobject[rows,cols]
select rows and columns of a data frame or matrix. If the rows argument is left empty, all rows are returned; and similarly for the "cols". A vector can be used to select multiple rows or columns. In this case, we're selecting all rows (because that part is blank) and columns "a" and "b".
The row.names=FALSE
option prevents rownames from being printed. In some cases, you might want to keep them, of course.
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