Group a dinamic number of vectors in a data.frame

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Group a dinamic number of vectors in a data.frame

Daniele Medri-2
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Group a dinamic number of vectors in a data.frame

Uwe Ligges
Daniele Medri wrote:

> 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.

For example:

   lab <- paste("N", seq(along=abc), sep="")
   D <- data.frame(lapply(lab, get))
   names(D) <- lab

Uwe Ligges



> Cheers

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html