view raw
FKG FKG - 9 months ago 57
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?


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.