[R] create many variables at one time~
Greg Snow
Greg.Snow at imail.org
Thu Jun 5 04:54:15 CEST 2008
An easy and good way to make a bunch of variables is to store them in a list. For example:
> mylist <- replicate(100, sample(1:100, 10), simplify=FALSE)
> id <- paste('id.',1:100, sep='')
> names(mylist) <- id
> sapply(mylist, median)
id.1 id.2 id.3 id.4 id.5 id.6 id.7 id.8 id.9 id.10 id.11
23.0 66.0 58.0 42.5 66.5 42.0 52.0 41.0 64.0 55.0 73.5
id.12 id.13 id.14 id.15 id.16 id.17 id.18 id.19 id.20 id.21 id.22
57.0 64.0 62.0 45.0 32.5 44.5 54.5 70.5 57.0 72.5 41.0
id.23 id.24 id.25 id.26 id.27 id.28 id.29 id.30 id.31 id.32 id.33
43.0 44.5 48.5 71.0 68.5 33.5 44.5 62.5 58.5 40.0 47.0
id.34 id.35 id.36 id.37 id.38 id.39 id.40 id.41 id.42 id.43 id.44
45.5 33.5 62.0 69.0 60.5 22.0 69.0 36.0 43.0 64.5 42.5
id.45 id.46 id.47 id.48 id.49 id.50 id.51 id.52 id.53 id.54 id.55
46.0 49.5 47.5 44.5 66.5 65.0 61.0 43.5 39.0 50.0 49.0
id.56 id.57 id.58 id.59 id.60 id.61 id.62 id.63 id.64 id.65 id.66
56.0 31.0 45.5 37.0 68.0 39.5 69.5 47.0 66.0 56.5 55.5
id.67 id.68 id.69 id.70 id.71 id.72 id.73 id.74 id.75 id.76 id.77
42.0 30.5 49.5 32.0 59.5 33.5 38.0 51.0 74.0 39.5 42.0
id.78 id.79 id.80 id.81 id.82 id.83 id.84 id.85 id.86 id.87 id.88
35.0 55.5 51.0 31.5 44.0 41.5 32.5 60.5 58.5 41.5 39.5
id.89 id.90 id.91 id.92 id.93 id.94 id.95 id.96 id.97 id.98 id.99
46.0 51.0 60.0 51.5 43.5 65.5 42.5 38.0 43.0 46.0 53.5
id.100
41.0
>
Now what do you want to do with all of those variables?
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Manli Yan [manliyanrhelp at gmail.com]
Sent: Wednesday, June 04, 2008 4:52 PM
To: r-help at r-project.org
Subject: [R] create many variables at one time~
I need to create 100 variable ,whose name is id.1,id.2~~~~id.100
then I need to let a vector say id<-c(id.1,id.2....id.100)
any easy way to do this?
thanks a lot~
[[alternative HTML version deleted]]
______________________________________________
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