[R] Want to create empty vectors inside a empty data frame

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Dec 27 17:21:54 CET 2008


Yes, you can add empty vectors, if you really need (I doubt you need):


  cat_record_mean_dfs <- data.frame()
  cat_record_mean_dfs[[paste("recmeanC", 1, sep="")]] <- numeric(0)

Best,
Uwe Ligges



Moumita Das wrote:
> Hi All,
> I want to create empty vectors inside an empty data frame.The name of the
> vectors has to come dynamically.
> 
> For example if record_mean is my empty data frame,and i have say 4
> categories,the category names for record mean data frame has to
> recmeanC1,recmeanC2,recmeanC3,recmeanC4,which will be dynamically created
> and which will again be inserted in my data frame's as column values.Each of
> these should be also vectors later.Because later i want to use the cbind
> function.
> 
> I wanted to do this:--
> record_mean<-cbind(recmeanC1,recmeanC2,recmeanC3,recmeanC4)
> 
> 
> where:--
> record_mean=>is my initially created empty data frame------------------[i
> can create this]
> recmeanC1,recmeanC2,recmeanC3,recmeanC4=>the names i generate
> dynamically,according to the categories i have [Caregories is again
> collection of items...........[Able to do this]
> recmeanC1=>this and others (like recmeanC2,recmeanC3,recmeanC4)=>should be
> all vectors having the means of each records set item mean for a particular
> category.....[]
> 
> Say i have 2 categories:--
> Category1 say has==>i1,i2(say i have 10 records,i.e i1,i2 pair values)
> Category2 say has==>i3,i4(10 records )
> recmeanC1=>means of each i1,i2 value per record for category 1 as vector (i
> keep adding rows of means ,using rbind)
> recmeanC2=>means of each i3,i4 value per record for category 1 as vector
> 
> 
> what i did was:--
> cat_record_mean_dfs<-data.frame(r_m=NULL)
>                 #Preparing the number of categories mean storage dfs
>                 for(catno in 1:catnam_dataset_data_size[1])
>                 {
>                     cat_record_mean<-paste("recmeanC",1:catno,sep="")
>                     cat_mean_vector<-as.vector(cat_record_mean)
>                     #str(cat_mean_vector)
>                     print(cat_mean_vector)
>                     #cat_record_mean_dfs<-c(cat_record_mean)
>                     #print("each category mean storage place")
>                     #print(cat_record_mean_dfs)
> 
> #cat_record_mean_dfs<-rbind(cat_record_mean_dfs,data.frame(cat_record_mean=NULL))
> # adding rows to the empty data frame
> 
>                 }
> 
> Bottomline is ,can empty vectors be created inside an empty data frame?
> 
>



More information about the R-help mailing list