[R] Ifelse statement on a factor level data frame

Patrick Burns pburns at pburns.seanet.com
Sun Sep 28 12:40:04 CEST 2014


I believe you are in Circle 8.2.7 of
The R Inferno.

http://www.burns-stat.com/documents/books/the-r-inferno/

Pat

On 28/09/2014 05:49, Kate Ignatius wrote:
> Quick question:
>
> I am running the following code on some variables that are factors:
>
> dbpmn$IID1new <- ifelse(as.character(dbpmn[,2]) ==
> as.character(dbpmn[,(21)]), dbpmn[,20], '')
>
> Instead of returning some value it gives me this:
>
> c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
>
> Playing around with the code, gives me some kind of variation to it.
> Is there some way to get me what I want.  The variable that its
> suppose to give back is a bunch of sampleIDs.
>
> Thanks!
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>

-- 
Patrick Burns
pburns at pburns.seanet.com
twitter: @burnsstat @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of:
  'Impatient R'
  'The R Inferno'
  'Tao Te Programming')



More information about the R-help mailing list