You can also change the column names to something else en mass:

colnames(dat) <- paste("X",1:100,sep="")

I next tried constructing the X<n> names inside data.frame, but failed using the paste function. The help page for data.frame has a paragraph that begins "How the names of the data frame are created is complex..."

At least the following will result in names of the form X.1, X.2 ...

dat <- data.frame( X = replicate(100, rnorm(10)) )

--
David Winsemius
On Mar 4, 2009, at 4:44 PM, Kingsford Jones wrote:

On Wed, Mar 4, 2009 at 2:34 PM, Manli Yan <manliyanrh...@gmail.com> wrote:
 Hi:
 I need to create many variables at one time,how to do this in R?
 for eg ,X1,X2.......X100?

It depends what you want.  If you want 100 random normal variables of
length 10, stored in a data.frame with names V1, V2, ..., V100 try

dat <- as.data.frame(replicate(100, rnorm(10)))


hth,
Kingsford Jones


 Thanks~

       [[alternative HTML version deleted]]

______________________________________________
R-help@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.


______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to