[R] lapply function
    Sarah Goslee 
    sarah.goslee at gmail.com
       
    Sat May 30 13:51:53 CEST 2015
    
    
  
You need the vectorizes ifelse() instead of if().
Also watch out for order of operations in the last line, and there is
already a base R function named scale(). And spelling of arguments, of
course.
On Saturday, May 30, 2015, Sohail Khan <sohail13 at gmail.com> wrote:
> Hi R Gurus,
>
> I am writing a simple function that take a numeric vector column from a
> data frame and scales the vector column with certain criteria.  I would
> then pass this function to a list of dataframes by lappy.
>
> Question is how do I write a function that works on a numeric vector.  My
> function as is, seems to work on the first element of the vector.
>
> I.E.
> scale
> function(x,mn,max){
> if (x==min(x)) 0
>
> if (x==max(x)) 10
> else x=max-min/10
> }
>
> where x is the numeric column of the dataframe.
>
> Thank you.
>
>
>
-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org
	[[alternative HTML version deleted]]
    
    
More information about the R-help
mailing list