On Jun 29, 2014, at 5:46 AM, Brian Willis wrote:
I am trying to incrementally add rows to an empty data frame. The
data has 7
columns, the last 6 are numeric.
For the first columns I would like to include a text identifier,
called
‘Case’ like Andrew, Burt, Charlie etc. that is also output to a data
frame –
this is where I am having the problem
The identifiers are being input from file which automatically
assigns them
to a data frame
Code:
Inp_dat<- read.csv("/File/Input data.csv")
out_put<-data.frame(Case=character(), StdL=numeric(), StdPP=numeric(),
StdSE=numeric(), L=numeric(), MRPP=numeric(), MRSE=numeric(),
stringsAsFactors=FALSE)
for(i in 1:4)
{
if (i==1) b<-Andrew # these assignments do not appear to ever get
used.
if (i==2) b<-Burt
if (i==3) b<-Charlie
if (i==4) b<-Dave
pr <- Inp_dat$p[i]
SE_pr <- Inp_dat$SE[i]
r<- Inp_dat$r[i]
n<- Inp_dat$n[i]
Case<- levels(Inp_dat$Case)[i])
# Since the question involves failure of this step, there woudn't
appear to be much we could say unless you provided teh output of
levels(Inp_dat$Case).
…
out_put[i,]<-data.frame(Case, stdL, stdPP, stdSE, L, PP, PP_SE)
The values stdL through PP_SE seem to come from someplace else.
}
out_put
Case StdL StdPP StdSE L
MRPP MRSE
1 1 19.466823 0.16432300 0.03137456 26.002294 0.2080145
0.03804692
2 1 2.334130 0.22566939 0.08962662 5.095703 0.3888451
0.08399101
3 1 2.588678 0.05502765 0.00454159 42.058326 0.4861511
0.02128030
4 1 7.857898 0.18457822 0.04372297 4.705487 0.1193687
0.01921609
Unfortunately the Case column loses the labels Andrew, Burt …
If you were thinking that the values Andrew and Burt would come from
that loop then it's unclear whay tha twould be so since the value of
"b" is never used after it is defined.
I’ve tried always to keep these, but are clearly doing something
wrong. Can
anyone help?
David Winsemius, MD
Alameda, CA, USA
______________________________________________
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.