[R] For Loop Help

arun smartpink111 at yahoo.com
Sun Jan 5 22:34:46 CET 2014

I guess you need to change the parentheses from:



#similarly for tc:

 for(count in 1:length(pick.a)){
output[count,2] <- (ts-tc)/ts

On Sunday, January 5, 2014 3:47 PM, Mathew Nagendran <mathew.nagendran at mail.utoronto.ca> wrote:
I'm relatively new to R. I'm trying to for loop but I keep getting an error message. Can anyone hint at what I am doing wrong please?

> m.control=c(1.45,9.40,9.96,4.2,1.86,0.2)
> m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09)
> t=function(m, a){(1-exp(-a*m))} #t function defined
> d=function(ts, tc){(ts-tc)/ts} #d function defined
> pick.a=seq(0.01,2,by=0.01) #set of a values defined
> output=cbind(pick.a,d=rep(NA,length(pick.a))) #define array containing a values in column 1 and d values (outputs) in column 2
> for(count in 1:length(pick.a)){
+ ts=sum(t(m.sham),pick.a[count])
+ tc=sum(t(m.control),pick.a[count])
+ output[count,2]=(ts-tc)/ts
+ }
Error in -a : 'a' is missing

    [[alternative HTML version deleted]]

R-help at r-project.org mailing list
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