Hi, 

 

I want to create a dataframe where one of the columns does not hold
individual elements, but a vector instead. 

For example, imagine the following dataframe without any vectors as elements
. . . 

 

ex

            X1         X2

1          5          15

2          7          12

3          9          14

 

If I have a pre-existing dataframe, then setting an element in the dataframe
to a vector is easy. That is, 

ex[1,2]<-c(45,98,78)

 

ex1

            X1         X2

1          5          45,98,78

2          7          12

3          9          14

 

I could also set each element in a column to a vector. That is, 

ex$X2<-list(c(45,98,78))

 

ex2

            X1         X2

1          5          45,98,78

2          7          45,98,78

3          9          45,98,78

 

However, if my dataframe does not already exist, then I cannot create a
dataframe with vectors using the following syntax:

 

data.frame(x1=list(c(5,6,7),c(8,9,10)))

 

What I want:

 

ex3

            X1         

1          5,6,7

2          8,9,10

 

What I get:

 

  x1.c.5..6..7. x1.c.8..9..10.

1             5              8

2             6              9

3             7             10

 

R seems to pull out each element in each list component and treat them as
separate elements in the dataframe. 

Is there syntax to get R to treat a component of a list as valid entry into
a single element in a dataframe without the dataframe already existing?

 

Thanks, 
Steve Lacey

 I can simply set any element or column to the 


        [[alternative HTML version deleted]]

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

Reply via email to