i have loop stores in list 1 date , 1 value after computations. create two-column table (date,value) when extract values list can't preserve date format:
n <- 5 x <- factor(1:3,levels=1:3,labels=c('a','b','c')) dates <- as.date(c('2000-01-01','2001-01-01','2002-01-01')) mylist <- list() (i in 1:n) { #some operations mylist[[i]] <- list(sample(dates,1),as.numeric(sample(x,1))) } z <- do.call(cbind,mylist)
you need change data structure 1 can hold different data types (i.e. data frame) , rbind
them together:
for (i in 1:n) { #some operations mylist[[i]] <- data.frame(sample(dates,1),as.numeric(sample(x,1))) } z <- do.call(rbind,mylist)
the problem in code cbind
operation coerced list
matrix
(which default behavior of rbind
/cbind
) can hold 1 data type.
Comments
Post a Comment