[R] I need help making a data.fame comprised of selected columns of an original data frame.
Steve Lianoglou
mailinglist.honeypot at gmail.com
Fri Jul 16 18:04:31 CEST 2010
Hi,
First: it's kind of hard to play along w/o some reproducible data. To
that end, you can paste into an email the output of:
dput(moreinfo)
If there are lots of rows in `moreinfo`, just give us the first ~10-20
dput(head(moreinfo, 20))
Anyway:
<snip>
> 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]
> }
Forget the for loop. How about:
ndf <- m_id_default[, c('mid, 'estimate', 'sd', 'loglik', 'aic',
'bic', 'chisq', 'chisqpvalue', 'chisqdf')
Having just written that, I see something strange in your for loop.
Specifically this line:
> ndf$n[i] = m_id_default_res[i]
m_id_default_res is a data.frame, right? Why don't you try to see what
`m_id_default_res[1]` returns.
I'm not sure that that's what your error message is coming from, but I
foresee this to be a problem anyway, if I follow your "build up" code
correctly.
Hope that helps,
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the R-help
mailing list