[R] Group a dinamic number of vectors in a data.frame
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.be
Mon Feb 20 16:40:16 CET 2006
one way is:
N1 <- rnorm(4)
N2 <- rnorm(4)
N3 <- rnorm(4)
N4 <- rnorm(4)
X1 <- LETTERS[1:4]
###################
nams <- c(paste("N", 1:4, sep = ""), "X1")
dat <- data.frame(lapply(nams, get))
names(dat) <- nams
dat
# check also
sapply(dat, data.class)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Daniele Medri" <dmedri at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, February 20, 2006 4:26 PM
Subject: [R] Group a dinamic number of vectors in a data.frame
> Hi all,
>
> I need to create a data.frame from a variable number of vectors.
> The number of these vectors could change so I need a dinamic way to
> group all in a data.frame. The number is length(abc).
>
> e.g. vectors in my workspace
>
> N1 <-c(1,2,3,4)
> N2 <-c(1,2,3,4)
> N3 <-c(1,2,3,4)
> abc <-c(1,2,3)
>
> the data.frame I want to create:
>
> tcm <-data.frame(OneVector, TwoVector, paste("N",1:length(abc)))
>
> Obviously :) if I am here this approach doesn't work, so any kind of
> tip
> is welcome.
>
> Cheers
> --
> Daniele Medri
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list