Hi,

I have defined a function, and I want to apply this function for different values of i, yet, when I use a for command, it only
executes the function for the first value of i.


My functions are long, but here is an example. The problem is if I run the following code:

tab<-function(data,x){
a.length<-length(data[,x])
return(a.length)
}

sum<-function(data,x){
b.sum<-sum(data[,x])
return(b.sum)
}

final <- function(data,c){
    if(is.factor(data[,x])==TRUE){
    tab(data,x)
  } else{
    sum(data,c)}
  }


Then try to run: for (i in 1:10){ final(data,i) }

I get only the output for function for when i=1, and not for each value.

Thanks in advance,
Jenn


Jennifer A. Emond, MS Statistician Department of Biostatistics, UCSD 9500 Gilman Drive M/C 0949 La Jolla, CA 92093-0949 (858) 622-5877 [EMAIL PROTECTED]

______________________________________________
[EMAIL PROTECTED] 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

Reply via email to