R Turning a list into a matrix when the list contains objects of "different size" -


i've seen couple of questions turning matrices lists (not clear why want that) reverse operation i've been unable find.

basically, following

# ind.dum = data frame 29 observations , 2635 variables (i in 1:ncol(ind.dum)) tmp[[i]]<-which(rollapply(ind.dum[,i],4,identical,c(1,0,0,0),by.column=t)) 

i got list of 2635 objects, of contain 1 value, bust 7. i'd need convert matrix 2635 rows , many columns necessary fit every value in separate cells (with 0 values rest).

i tried coerce measures know (as.data.frame, as.matrix ...) , option define new matrix maximum dimensions nothing works.

m<-matrix(0,nrow=2635,ncol=7) tmp_m<-structure(tmp,dim=dim(m)) error in structure(tmp,dim=dim(m))dims [product 18445] not match length of object [2635] 

i'm sure there's quick fix i'm hoping can me it. btw, values in tmp list's objects numeric, although "integer(0)" , i.e. when pattern c(1,0,0,0) not found in columns of original ind.dum matrix.

not sure if there way use unlist without losing information values belong same row...

desired output matrix or dataframe 2635 rows , 7 columns , looking this

12 0 0 0 0 0 0 8 14 0 0 0 0 0  0  0 0 0 0 0 0  1  4 8 12 0 0 0  ... 

the values refer years in specific pattern started. need able able use information tie problem earlier problem described before (see this link).

try example:

do.call(rbind,lapply(ll,                function(x)                  if(length(x)==1)c(x,rep(0,6))                else x)) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -