[R] Populate data frame for meta-analysis

Jim Lemon drjimlemon at gmail.com
Tue Jul 28 13:52:33 CEST 2015


Hi Jerry,
Try this:

jl.df<-read.table(text="ID,score,success,failure
study1,1,35,85
study1,2,46,83
study2,1,78,246
study2,2,45,96",
sep=",",
header=TRUE)

nrows<-dim(jl.df)[1]
jlexp.df<-data.frame()
for(row in 1:nrows) {
 success_rows<-data.frame(ID=rep(jl.df$ID[row],jl.df$success[row]),
  score=rep(jl.df$score[row],jl.df$success[row]),
  outcome=rep("success",jl.df$success[row]))
 failure_rows<-data.frame(ID=rep(jl.df$ID[row],jl.df$failure[row]),
  score=rep(jl.df$score[row],jl.df$failure[row]),
  outcome=rep("failure",jl.df$failure[row]))
 jlexp.df<-rbind(jlexp.df,success_rows,failure_rows)
}

Jim


On Tue, Jul 28, 2015 at 2:06 PM, Jerry <josephlockhart at hotmail.com> wrote:
>
>
> I am trying to model an existing meta-analysis to examine alternative
> hypotheses (e.g., doing a random-effects analysis), as well as re-sampling
> techniques. There are over 2,000 subjects, but the data is fairly simple: a
> binary outcome, success or failure, linked with a score (0-10) on a
> structured assessment. I have the frequencies of success or failure for each
> score, nested within each study. I am looking for a easier way to create the
> dataset rather than keying it in, or using the rep function multiple times.
>
> I would like each row to look something like this: Study_ID,
> Test_Result[0-10], Outcome[0 or 1]
>
> For example, let's say I just had two studies and two test levels (1 or 2):
> study 1 has 35 successes, and 85 failures for score of "1"; for a score of
> "2," 46 successes and 83 failures. In study 2, for a score of "1" there are
> 78 successes, 246 failures; for a score of "2," 45 successes and 96
> failures.
>
> Using just the frequencies provided, how could I most easily create a data
> frame with the several hundred lines of data?
> Thanks in advance,
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Populate-data-frame-for-meta-analysis-tp4710450.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list