I must have missed something simple, but still, i don't know what. I obtained my basic data as follows:
x <- sprintf("SELECT m_id,sale_date,YEAR(sale_date) AS sale_year,WEEK(sale_date) AS sale_week,return_type,0.0001 + DATEDIFF(return_date,sale_date) AS elapsed_time FROM `merchants2`.`risk_input` WHERE DATEDIFF(return_date,sale_date) IS NOT NULL") moreinfo <- dbGetQuery(con, x) I then made the data frame I want to use as follows: fun_m_id <- function(df) if (length(df$elapsed_time) > 5) { rv = fitdist(df$elapsed_time,"exp") rv$mid = df$m_id[1] rv } aaa <- lapply(split(moreinfo,list(moreinfo$m_id),drop = TRUE), fun_m_id) m_id_default_res <- do.call(rbind, aaa) At this point, each row in m_id_default_res corresponds to one data.frame produced by fitdist. When I print it, I get the output I expected. However, I need to store only some of it into my DB. And then, because fitdist produces a data frame that includes a lot of info I don't need to store in the DB, I tried making a new data.frame containing only the info I need as follows: ndf = data.frame() for (i in 1:length(m_id_default_res[,1])) { ndf$mid[i] = m_id_default_res$mid[i] ndf$estimate[i] = m_id_default_res$estimate[i] ndf$sd[i] = m_id_default_res$sd[i] ndf$n[i] = m_id_default_res[i] ndf$loglik[i] = m_id_default_res$loglik[i] ndf$aic[i] = m_id_default_res$aic[i] ndf$bic[i] = m_id_default_res$bic[i] ndf$chisq[i] = m_id_default_res$chisq[i] ndf$chisqpvalue[i] = m_id_default_res$chisqpvalue[i] ndf$chisqdf[i] = m_id_default_res$chisqdf[i] } ndf And I get the following error: Error in `$<-.data.frame`(`*tmp*`, "n", value = list(0.114752782316094)) : replacement has 1 rows, data has 0 I need to either get rid of the columns in m_id_default_res that I don't need, or I need to copy only those columns I need to a new data.frame. How do I do this. Obviously, doing an element-wise copy, at least as I tried to do it, doesn't work. Thanks, Ted [[alternative HTML version deleted]] ______________________________________________ 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.