[R] Help with R: functions

From: Pryseley Assam <assampryseley_at_yahoo.com>
Date: Tue 31 Jan 2006 - 00:14:14 EST

Hello R-users    

  I am new to R and trying to write some functions. I have problems writing functions that takes a data set as an arguement and uses variables in the data. I illustrate my problem with a small example below:    

   sample data   #------------------

  dats<- data.frame(cbind(visual24,visual52))   remove(visual24, visual52)    

  # first code

  st <-function(data,x,y){



  This code works fine, but with such a code the data as an arguement to the funtion is not necessary.   However, i wish to write a function that reads the variables from the data directly.   I tried using the function below but it does not work.    

  # second code


  st <-function(data,x,y){


  I wish to inquire if any one has an idea of what i need to adjust in the function so that it works.   I believe that the referencing $x or $y in the function is not doing the correct thing.    

  Better still, will it be a problem if i code the functions as in the first code above?   I mean given that they will be used to create a library    

  Best regards

        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jan 31 00:21:47 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:14 EST