# [R] Nested for loop help please.

arun smartpink111 at yahoo.com
Sun Jan 12 00:01:43 CET 2014

```

Hi,
I guess you need to replace t() with t.control() or t.sham()
output <-vector()
for(count in 1:length(pick.a)){
for(count1 in 1:length(pick.d)){
ts1 = sum(t.sham(m.sham,pick.a[count],pick.d[count1]))
tc1 <- sum(t.control(m.control,pick.a[count]))
output= c(output,ts1/tc1)
}
}
m1 <- matrix(output,200,100)
dim(m1)
# 200 100
A.K.

On Saturday, January 11, 2014 3:20 PM, Mathew Nagendran <mathew.nagendran at mail.utoronto.ca> wrote:
Hi all I am relatively new to R. I am trying to create a nested for loop but i keep getting an error message (unused argument). Can someone help me find out where I am goign wrong?

> 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.control=function(m, a){(1-exp(-a*m))}
> t.sham=function(m, a, d){(1-exp(-a*(1-d)*m))}
>
> t.ratio=function(ts, tc){(ts/tc)}
>
> pick.a=seq(0.01,2,by=0.01) #set of a values defined
> pick.d=seq(0.01,1,by=0.01) #set of d values defined
>
> output=array(NA,c(length(pick.a), length(pick.d))) #define array for Ts/Tc ratios. a values (0.01-2) in column 1 and d values (0.01-1) in the other columns.
>
> for(count in 1:length(pick.a)){
+ for(count in 1:length(pick.d)){
+ ts=sum(t(m.sham,pick.a[count],pick.d[count]))
+ tc=sum(t(m.control,pick.a[count]))
+ output[count,2]= (ts/tc)
+ }
+ print(output)
+ }
Error in t(m.sham, pick.a[count], pick.d[count]) :
unused argument(s) (pick.a[count], pick.d[count])

[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help