Hi, I am running the following script for a different (much larger data frame): DF = data.frame(read.table(textConnection(" A B C D E 1 1 a 1999 1 0 2 1 b 1999 0 1 3 1 c 1999 0 1 4 1 d 1999 1 0 5 2 c 2001 1 0 6 2 d 2001 0 1 7 3 a 2004 0 1 8 3 b 2004 0 1 9 3 d 2004 0 1 10 4 b 2001 1 0 11 4 c 2001 1 0 12 4 d 2001 0 1"),head=TRUE,stringsAsFactors=FALSE)) DF<-DF[order(DF$B,DF$C),]#order by developer_id and year f<- function(x) { unlist(lapply(x, FUN = function(z) cumsum(z) - z)) } DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:5)],DF$B, FUN = f)) I get the following error: Error in `[<-.data.frame`(`*tmp*`, i, , value = integer(0)) : replacement has 0 items, need 37597770 In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf The dimensions of the data frame are (50000,108), so the last line of the script becomes: DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:108)],DF$B, FUN = f)) Any idea how to solve this problem? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Error-tp3324531p3324531.html Sent from the R help mailing list archive at Nabble.com.
Works fine on my machine:> DFA B C D E 1 1 a 1999 0 0 2 1 b 1999 0 0 3 1 c 1999 0 0 4 1 d 1999 0 0 5 2 c 2001 0 1 6 2 d 2001 1 0 7 3 a 2004 1 0 8 3 b 2004 0 1 9 3 d 2004 1 1 10 4 b 2001 0 2 11 4 c 2001 1 1 12 4 d 2001 1 2 here's my session info:> sessionInfo()R version 2.12.1 (2010-12-16) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] phyloch_1.4.48 XML_3.2-0 colorspace_1.0-1 phangorn_1.3-1 ape_2.6-2 [6] quadprog_1.5-3 plyr_1.4 loaded via a namespace (and not attached): [1] gee_4.13-16 grid_2.12.1 lattice_0.19-17 nlme_3.1-97 tools_2.12.1 On Friday, February 25, 2011 at 8:31 AM, mathijsdevaan wrote:> Hi, I am running the following script for a different (much larger data > frame): > > DF = data.frame(read.table(textConnection(" A B C D E > 1 1 a 1999 1 0 > 2 1 b 1999 0 1 > 3 1 c 1999 0 1 > 4 1 d 1999 1 0 > 5 2 c 2001 1 0 > 6 2 d 2001 0 1 > 7 3 a 2004 0 1 > 8 3 b 2004 0 1 > 9 3 d 2004 0 1 > 10 4 b 2001 1 0 > 11 4 c 2001 1 0 > 12 4 d 2001 0 1"),head=TRUE,stringsAsFactors=FALSE)) > DF<-DF[order(DF$B,DF$C),]#order by developer_id and year > f<- function(x) > { > unlist(lapply(x, FUN = function(z) cumsum(z) - z)) > } > DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:5)],DF$B, FUN = f)) > > I get the following error: > > Error in `[<-.data.frame`(`*tmp*`, i, , value = integer(0)) : > replacement has 0 items, need 37597770 > In addition: Warning message: > In max(i) : no non-missing arguments to max; returning -Inf > > The dimensions of the data frame are (50000,108), so the last line of the > script becomes: > > DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:108)],DF$B, FUN = f)) > > Any idea how to solve this problem? Thanks! > > > -- > View this message in context: http://r.789695.n4.nabble.com/Error-tp3324531p3324531.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. >[[alternative HTML version deleted]]
Sorry for being unclear: the example works fine on my machine too. However, with the much larger dataset (dim(50000,108)) I get the reported error. Mathijs On Fri, Feb 25, 2011 at 3:56 PM, Scott Chamberlain < scttchamberlain4@gmail.com> wrote:> Works fine on my machine: > > DF > A B C D E > 1 1 a 1999 0 0 > 2 1 b 1999 0 0 > 3 1 c 1999 0 0 > 4 1 d 1999 0 0 > 5 2 c 2001 0 1 > 6 2 d 2001 1 0 > 7 3 a 2004 1 0 > 8 3 b 2004 0 1 > 9 3 d 2004 1 1 > 10 4 b 2001 0 2 > 11 4 c 2001 1 1 > 12 4 d 2001 1 2 > > > here's my session info: > > > sessionInfo() > R version 2.12.1 (2010-12-16) > Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) > > locale: > [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] phyloch_1.4.48 XML_3.2-0 colorspace_1.0-1 phangorn_1.3-1 > ape_2.6-2 > [6] quadprog_1.5-3 plyr_1.4 > > loaded via a namespace (and not attached): > [1] gee_4.13-16 grid_2.12.1 lattice_0.19-17 nlme_3.1-97 > tools_2.12.1 > > On Friday, February 25, 2011 at 8:31 AM, mathijsdevaan wrote: > > > Hi, I am running the following script for a different (much larger data > frame): > > DF = data.frame(read.table(textConnection(" A B C D E > 1 1 a 1999 1 0 > 2 1 b 1999 0 1 > 3 1 c 1999 0 1 > 4 1 d 1999 1 0 > 5 2 c 2001 1 0 > 6 2 d 2001 0 1 > 7 3 a 2004 0 1 > 8 3 b 2004 0 1 > 9 3 d 2004 0 1 > 10 4 b 2001 1 0 > 11 4 c 2001 1 0 > 12 4 d 2001 0 1"),head=TRUE,stringsAsFactors=FALSE)) > DF<-DF[order(DF$B,DF$C),]#order by developer_id and year > f<- function(x) > { > unlist(lapply(x, FUN = function(z) cumsum(z) - z)) > } > DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:5)],DF$B, FUN = f)) > > I get the following error: > > Error in `[<-.data.frame`(`*tmp*`, i, , value = integer(0)) : > replacement has 0 items, need 37597770 > In addition: Warning message: > In max(i) : no non-missing arguments to max; returning -Inf > > The dimensions of the data frame are (50000,108), so the last line of the > script becomes: > > DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:108)],DF$B, FUN = f)) > > Any idea how to solve this problem? Thanks! > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Error-tp3324531p3324531.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. > > >[[alternative HTML version deleted]]
Hi, I don't get any error... DF <- cbind(DF[,c(1:3)],ave(DF[, c(4:5)],DF$B, FUN = f)) DF A B C D E 1 1 a 1999 0 0 7 3 a 2004 1 0 2 1 b 1999 0 0 10 4 b 2001 0 1 8 3 b 2004 1 1 3 1 c 1999 0 0 5 2 c 2001 0 1 11 4 c 2001 1 1 4 1 d 1999 0 0 6 2 d 2001 1 0 12 4 d 2001 1 1 9 3 d 2004 1 2 Ivan Le 2/25/2011 15:31, mathijsdevaan a ?crit :> Hi, I am running the following script for a different (much larger data > frame): > > DF = data.frame(read.table(textConnection(" A B C D E > 1 1 a 1999 1 0 > 2 1 b 1999 0 1 > 3 1 c 1999 0 1 > 4 1 d 1999 1 0 > 5 2 c 2001 1 0 > 6 2 d 2001 0 1 > 7 3 a 2004 0 1 > 8 3 b 2004 0 1 > 9 3 d 2004 0 1 > 10 4 b 2001 1 0 > 11 4 c 2001 1 0 > 12 4 d 2001 0 1"),head=TRUE,stringsAsFactors=FALSE)) > DF<-DF[order(DF$B,DF$C),]#order by developer_id and year > f<- function(x) > { > unlist(lapply(x, FUN = function(z) cumsum(z) - z)) > } > DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:5)],DF$B, FUN = f)) > > I get the following error: > > Error in `[<-.data.frame`(`*tmp*`, i, , value = integer(0)) : > replacement has 0 items, need 37597770 > In addition: Warning message: > In max(i) : no non-missing arguments to max; returning -Inf > > The dimensions of the data frame are (50000,108), so the last line of the > script becomes: > > DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:108)],DF$B, FUN = f)) > > Any idea how to solve this problem? Thanks! > >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
Does it work for FUN=mean? If yes, you need to print out the results of f before you return them to find the anomalous value. BTW "Error" is not a very good subject line. I don't see many posts from people reporting how well things are going :) -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of mathijsdevaan Sent: Friday, February 25, 2011 9:31 AM To: r-help at r-project.org Subject: [R] Error Hi, I am running the following script for a different (much larger data frame): DF = data.frame(read.table(textConnection(" A B C D E 1 1 a 1999 1 0 2 1 b 1999 0 1 3 1 c 1999 0 1 4 1 d 1999 1 0 5 2 c 2001 1 0 6 2 d 2001 0 1 7 3 a 2004 0 1 8 3 b 2004 0 1 9 3 d 2004 0 1 10 4 b 2001 1 0 11 4 c 2001 1 0 12 4 d 2001 0 1"),head=TRUE,stringsAsFactors=FALSE)) DF<-DF[order(DF$B,DF$C),]#order by developer_id and year f<- function(x) { unlist(lapply(x, FUN = function(z) cumsum(z) - z)) } DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:5)],DF$B, FUN = f)) I get the following error: Error in `[<-.data.frame`(`*tmp*`, i, , value = integer(0)) : replacement has 0 items, need 37597770 In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf The dimensions of the data frame are (50000,108), so the last line of the script becomes: DF<-cbind(DF[,c(1:3)],ave(DF[, c(4:108)],DF$B, FUN = f)) Any idea how to solve this problem? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Error-tp3324531p3324531.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at 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. message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited.