Neil Skjodt
2004-Mar-19 14:49 UTC
[R] for loop or Hmisc library trap.rule function syntax error
Hello: I am new R user stumped why the R code after this paragraph generates "Error: syntax error" messages after each of the last 2 lines. I have tried searching the manuals, Hmisc documentation, contributed manuals, help archives, and Internet. I am running R 1.7.1 under Windows 2000 (I will upgrade when my imminent OS upgrade happens). My data was successfully entered and displayed as data.df whose first row is column labels, whose subsequent rows are separate subject results, whose 2nd to 7th columns are numeric control results (for observations at 0, 30, 60, 90, 120, and 180 min), and whose 8th to 13th columns are numeric treatment results. I am trying to enter the control and test area under the curve values from the Hmisc trap.rule function into "control" and "test" for hypothesis testing. I tried posting this last PM, but my message seems to have been lost. I apologize if this appears as a duplicate message. Thanks. Neil ... control = c(); test = c(); for (subj in 1:11) { rownum = subj+1 # add one to subject as first row is column labels control(subj)=trap.rule(c(0,30,60,90,120,180),c(data.df(subj,2:7)) test(subj)=trap.rule(c(0,30,60,90,120,180),c(data.df(subj,8:13)) } ...
Frank E Harrell Jr
2004-Mar-19 14:50 UTC
[R] for loop or Hmisc library trap.rule function syntax error
On Fri, 19 Mar 2004 07:49:26 -0700 Neil Skjodt <neil.skjodt at ualberta.ca> wrote:> Hello: > > I am new R user stumped why the R code after this paragraph generates > "Error: syntax error" messages after each of the last 2 lines. I have > tried searching the manuals, Hmisc documentation, contributed manuals, > help archives, and Internet. I am running R 1.7.1 under Windows 2000 (I > will upgrade when my imminent OS upgrade happens). My data was > successfully entered and displayed as data.df whose first row is column > labels, whose subsequent rows are separate subject results, whose 2nd to > 7th columns are numeric control results (for observations at 0, 30, 60, > 90, 120, and 180 min), and whose 8th to 13th columns are numeric > treatment results. I am trying to enter the control and test area under > the curve values from the Hmisc trap.rule function into "control" and > "test" for hypothesis testing. I tried posting this last PM, but my > message seems to have been lost. I apologize if this appears as a > duplicate message. Thanks. Neil > > ... > control = c(); > test = c();You need to spend time with the manuals. Remove ; from end of line, set aside vectors of full length, use [ ] for subscripting and subsetting; remove rownum; recognize that first row should not be "column labels". Frank Harrell> > for (subj in 1:11) { > > rownum = subj+1 # add one to subject as first row is column labels > control(subj)=trap.rule(c(0,30,60,90,120,180),c(data.df(subj,2:7)) > test(subj)=trap.rule(c(0,30,60,90,120,180),c(data.df(subj,8:13)) > }--- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
Prof Brian Ripley
2004-Mar-19 15:11 UTC
[R] for loop or Hmisc library trap.rule function syntax error
Try counting parentheses: they don't match. A good editor (e.g. R mode in Emacs) would make this instantly obvious. I doubt if data.df(subj,2:7) is what you want, either: perhaps data.df[subj, 2:7]. There is much more in that vain. On Fri, 19 Mar 2004, Neil Skjodt wrote:> Hello: > > I am new R user stumped why the R code after this paragraph generates "Error: > syntax error" messages after each of the last 2 lines. I have tried searching > the manuals, Hmisc documentation, contributed manuals, help archives, and > Internet. I am running R 1.7.1 under Windows 2000 (I will upgrade when my > imminent OS upgrade happens). My data was successfully entered and displayed > as data.df whose first row is column labels, whose subsequent rows are > separate subject results, whose 2nd to 7th columns are numeric control results > (for observations at 0, 30, 60, 90, 120, and 180 min), and whose 8th to 13th > columns are numeric treatment results. I am trying to enter the control and > test area under the curve values from the Hmisc trap.rule function into > "control" and "test" for hypothesis testing. I tried posting this last PM, but > my message seems to have been lost. I apologize if this appears as a duplicate > message. Thanks. Neil > > ... > control = c(); > test = c(); > > for (subj in 1:11) { > > rownum = subj+1 # add one to subject as first row is column labels > control(subj)=trap.rule(c(0,30,60,90,120,180),c(data.df(subj,2:7)) > test(subj)=trap.rule(c(0,30,60,90,120,180),c(data.df(subj,8:13)) > } > ... > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595