[R] return()

Thomas Lumley tlumley at u.washington.edu
Wed Feb 27 17:39:52 CET 2002


On Wed, 27 Feb 2002, christian schulz wrote:

> Hi,
> i get only one value, but expect ncol values  - what's wrong ?

You only compute one value for y and then return it. The assignment to y
is outside the loop, but in any case it would overwrite the previous value

> test <- function(){
>        for (i in 1:ncol(configData))
>        x <- subset(configData, Q71 == 1 & configData[,i] ==1 , select =
> configData[,i])
>        y <- (dim(x)[1]/dim(configData)[1])*100
>        return(y) }

My guess is that you mean something like
 test <- function(){
	y<-numeric(ncol(configData))
        for (i in 1:ncol(configData)){
          x <- subset(configData, Q71 == 1 & configData[,i] ==1 , select = configData[,i])
          y[i] <- (dim(x)[1]/dim(configData)[1])*100
        }
        return(y) }



     -thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list