[R] for loop or Hmisc library trap.rule function syntax error

Frank E Harrell Jr feh3k at spamcop.net
Fri Mar 19 15:50:19 CET 2004


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




More information about the R-help mailing list