# [R] For Loop Help

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

```Hi,
I guess you need to change the parentheses from:

ts=sum(t(m.sham),pick.a[count])
#to

ts=sum(t(m.sham,pick.a[count]))

#similarly for tc:

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
}
A.K.

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
https://stat.ethz.ch/mailman/listinfo/r-help