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 <sohai...@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]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to