aggregate - R Error in Ave and Memory Size -


i have problems in r.

i aggregate column "product.family" in data frame , aggregated value should written specific row. have many data frames in list , should work each of them. here example:

    x <- data.frame("product.family"=c("family1","family2","family3","family1","family1","family3","family2"),                 "value"=c(2,3,3.5,2.8,1.7,3.8,2.2)) dflist<-list(rep(x,7))  match <- function(df) {   df$avg.product.family <- ave(df$value,df$product.family,fun=mean) } dflist_new <- lapply(dflist, match) 

i error

 error in split.default(x, g) : first argument must vector  

does know problem is?

my other problem is, calculate raises between values. there many na´s , can´t post minimal example here because error

    error: cannot allocate vector of size 183 kb in addition: warning messages: 1: in data.frame(..., check.names = false) :   reached total allocation of 16326mb: see help(memory.size) 2: in data.frame(..., check.names = false) :   reached total allocation of 16326mb: see help(memory.size) 3: in data.frame(..., check.names = false) :   reached total allocation of 16326mb: see help(memory.size) 

occurs when have big data frames. idea create vector without na´s every row , calculate change in percent between first , last value. code:

    idc2 <- function(x) {   xx <- x[!is.na(x)]   ch=(xx[length(xx)]-xx[1])/xx[1] } i.d.crease2 <- function(df) {   d <- as.matrix(df[,-c(1:12)])   cbind(df, t(apply(d, 1, idc2))) } dflist_neu2 <- lapply(dflist2, i.d.crease2) 

may there smarter solution, runs without errors?


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -