[R] adding list to data.frame iteratively
fishkbob
fishkbob at gmail.com
Thu Sep 9 00:53:38 CEST 2010
> 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 1 2 3
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 1 2 3
2 2 3 4
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.
More information about the R-help
mailing list