Re: [R] lapply, sapply

2008-08-02 Thread baptiste auguie
It seems to me that the reshape package should do the job, library(reshape) # note that you need to fix the method to melt lists in the current version ( passing ... to the method for data.frames, as discussed here last week) cast(data=melt(dat), fun.aggregate = function(.x) rle(.x)$length[

Re: [R] lapply, sapply

2008-08-02 Thread jim holtman
### Example Data dat <-list() set.seed(1) dat[[1]] <- data.frame(matrix( rbinom(40, 1, .8),nrow=5)) dat[[2]] <- data.frame(matrix( rbinom(40, 1, .8),nrow=5)) Code x<-sapply(dat,"[",3)#Extracting the vector y<-lapply(x,rle) #Counting the sequences which is returned as a list z<-sapp

[R] lapply, sapply

2008-08-02 Thread [EMAIL PROTECTED]
Hello everybody, I have problem with a lapply command, which rather proves that I don't fully understand it. I want to extract from a list that consists of dataframes, the length of the first sequences from a given variable (its part of a simulation exercises). Below is code which does the job, b