FKG FKG - 1 year ago 165
R Question

How to save data with selected variables in R?

Let's say I have data with 1000 variables. The dataset is a

and I read it using:
mydata<- read.csv2("dataset.csv", header=TRUE, sep=";")

How do I save
with selected variables? I usually use
write.csv2(mydata, "~/Desktop/newdata.csv")
-- is it possible to select certain variable within
? If not, what are the other options?

Answer Source

You can try this:

write.csv(dataframename[,c("a","b")], file="~/Desktop/newdata.csv",row.names=FALSE)

dataframename[rows,cols] select rows and columns of a data frame.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download