[R] adding list to data.frame iteratively

2010-09-08 Thread raje...@cse.iitm.ac.in

Hi,

I have a preallocated dataframe to which I have to add a list whose vectors 
will become rows in the dataframe. This is done iteratively. How can I do this?
I'm dealing with very large numbers...list of 1000 vectors to a dataframe of 
20 iteratively

for e.g.
my list is as follows

ll-list(c(1,2,3),c(2,3,4))

I have to add this to a dataframe
dd-data.frame(matrix(nrow=10,ncol=3))

so that I get
1 2 3
2 3 4
etc.
[[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.


Re: [R] adding list to data.frame iteratively

2010-09-08 Thread fishkbob

 ll-list(c(1,2,3),c(2,3,4)) 
 ll
[[1]]
[1] 1 2 3

[[2]]
[1] 2 3 4

 dd-data.frame(matrix(nrow=10,ncol=3)) 
 dd
   X1 X2 X3
1  NA NA NA
2  NA NA NA
3  NA NA NA
4  NA NA NA
5  NA NA NA
6  NA NA NA
7  NA NA NA
8  NA NA NA
9  NA NA NA
10 NA NA NA
 dd[1,]-ll[[1]]
 dd
 X1   X2   X3
1 123
2  NA NA NA
3  NA NA NA
4  NA NA NA
5  NA NA NA
6  NA NA NA
7  NA NA NA
8  NA NA NA
9  NA NA NA
10 NA NA NA
 dd[2,]-ll[[2]]
 dd
 X1   X2   X3
1 123
2 234
3  NA NA NA
4  NA NA NA
5  NA NA NA
6  NA NA NA
7  NA NA NA
8  NA NA NA
9  NA NA NA
10 NA NA NA

you could easily put this into a for loop such that
dd[i,]-ll[[i]]
-- 
View this message in context: 
http://r.789695.n4.nabble.com/adding-list-to-data-frame-iteratively-tp2531124p2532154.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] adding list to data.frame iteratively

2010-09-08 Thread Joshua Wiley
Hi,

This is not exactly the same, but there was a recent thread on
rbind()ing dataframes from a list:

http://r.789695.n4.nabble.com/Please-explain-do-call-in-this-context-or-critique-to-stack-this-list-faster-td2526908.html

Given that, I wonder if this would work for you:

ll - list(c(1,2,3),c(2,3,4))
dd - data.frame(matrix(nrow=10,ncol=3))
# rbind() each element of the list together into a data frame
temp - as.data.frame(do.call(rbind, ll), stringsAsFactors = FALSE)
# assign that dataframe to whichever rows of dd you want
dd[1:2, ] - temp
# print to screen
dd

Just a thought,

Josh

On Tue, Sep 7, 2010 at 11:17 PM, raje...@cse.iitm.ac.in
raje...@cse.iitm.ac.in wrote:

 Hi,

 I have a preallocated dataframe to which I have to add a list whose vectors 
 will become rows in the dataframe. This is done iteratively. How can I do 
 this?
 I'm dealing with very large numbers...list of 1000 vectors to a dataframe of 
 20 iteratively

 for e.g.
 my list is as follows

 ll-list(c(1,2,3),c(2,3,4))

 I have to add this to a dataframe
 dd-data.frame(matrix(nrow=10,ncol=3))

 so that I get
 1 2 3
 2 3 4
 etc.
        [[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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


Re: [R] adding list to data.frame iteratively

2010-09-08 Thread Hadley Wickham
Why don't you read the answers to your stackoverflow question?
http://stackoverflow.com/questions/3665885/adding-a-list-of-vectors-to-a-data-frame-in-r/3667753

Hadley

On Wed, Sep 8, 2010 at 1:17 AM, raje...@cse.iitm.ac.in
raje...@cse.iitm.ac.in wrote:

 Hi,

 I have a preallocated dataframe to which I have to add a list whose vectors 
 will become rows in the dataframe. This is done iteratively. How can I do 
 this?
 I'm dealing with very large numbers...list of 1000 vectors to a dataframe of 
 20 iteratively

 for e.g.
 my list is as follows

 ll-list(c(1,2,3),c(2,3,4))

 I have to add this to a dataframe
 dd-data.frame(matrix(nrow=10,ncol=3))

 so that I get
 1 2 3
 2 3 4
 etc.
        [[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.




-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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