[R] Calling Dynamic Variables names

Petr PIKAL petr.pikal at precheza.cz
Thu Mar 29 12:11:54 CEST 2012


Hi

First of all you shall change your dataset structure to list. It will help 
you in future.


> 
> HI,
> 
> Need help in calling the dynamic variables 
> 
> I have 2 datasets . FIrst one(mdata) is having the metadata and second
> one(dataset) has got the data. 
> 
> sample 
> *mdata *
> Variable (header)
> 
> attribute1
> attribute2
> attribute3
> attribute4
> 
> *dataset *
> 
> attribute1     attribute2     attribute3    attribute4 
> 
> 1                             3                    34               12
> 3                             45                  1                  09
> 34                           22                  12               12
> 56                           6                     16              77
> ......................
> so i have written a forloop 
> 
> 
> code :  i want to find the mean for each attribites
> 
> for( i in mdata$vairable)
> {
>   print (mean(dataset$i)    # wants to call i value

In cycle you shall use different kind of subsetting.

print (mean(dataset[,i]))

Regards
Petr


> }
> 
> 
> please help in regard.
> 
> THanks,
> Santosh
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Calling-
> Dynamic-Variables-names-tp4514820p4514820.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list