r user
2006-May-05 00:16 UTC
[R] converting code into a function - seperating a data frame with n columns into n individual vectors
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()
Gabor Grothendieck
2006-May-05 01:39 UTC
[R] converting code into a function - seperating a data frame with n columns into n individual vectors
On 5/4/06, r user <ruser2006 at yahoo.com> wrote:> I have many very large dataframes with 20 columns > each. > > In order to conserve memory, I wish to separate theI don't think that that will save any memory.> iris2 <- iris > gc()used (Mb) gc trigger (Mb) max used (Mb) Ncells 169178 4.6 350000 9.4 350000 9.4 Vcells 63343 0.5 786432 6.0 290042 2.3> for(i in 1:ncol(iris)) assign(paste("iris", i, sep = "."), iris2[,i]) > rm(iris2) > gc()used (Mb) gc trigger (Mb) max used (Mb) Ncells 169961 4.6 350000 9.4 350000 9.4 Vcells 64101 0.5 786432 6.0 290042 2.3