[R] converting code into a function - seperating a data frame with n columns into n individual vectors

From: r user <ruser2006_at_yahoo.com>
Date: Fri 05 May 2006 - 10:16:44 EST


I have many very large dataframes with 20 columns each.

In order to conserve memory, I wish to separate the data frame into 20 vectors, each named the name of the dataframe followed by .1,.2,.3….20.

(For example purposes, one data frame is named
“testa”.)

e.g. testa.1, testa.2, testa.3

I have written the code to do this (see below). I am trying to convert this into a function that I can reuse. Suggestions are appreciated.

(I am not sure if this is the best way to approach the
problem, but I do think it will work. FYI, I really do need all the data, so selecting subset of the data is not a good option.)

Here is the code I’ve been using:

load('c:/testa.r')

testa.1<-testa[ , 1]
testa.2<-testa[ , 2]
testa.3<-testa[ , 3]
testa.4<-testa[ , 4]
testa.5<-testa[ , 5]
testa.6<-testa[ , 6]
testa.7<-testa[ , 7]
testa.8<-testa[ , 8]
testa.9<-testa[ , 9]
testa.10<-testa[ , 10]
testa.11<-testa[ , 11]
testa.12<-testa[ , 12]
testa.13<-testa[ , 13]
testa.14<-testa[ , 14]
testa.15<-testa[ , 15]
testa.16<-testa[ , 16]
testa.17<-testa[ , 17]
testa.18<-testa[ , 18]
testa.19<-testa[ , 19]
testa.20<-testa[ , 20]

rm(testa)
gc()

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri May 05 10:21:26 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 05 May 2006 - 12:10:03 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.