Skip to content
Back to formatted view

Raw Message

Message-ID: <CAM_vjumEo+MGgkVas7KYCoN3CEfswGrsrE1rG=4tD+HS5SnGGw@mail.gmail.com>
Date: 2015-05-30T11:51:53Z
From: Sarah Goslee
Subject: lapply function
In-Reply-To: <CABUTPBm-UVm7wdz+u0Cv_-bd=uJP0D7ueC9T_cLKJTxHGHu9cQ@mail.gmail.com>

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]]