You can work with levels of factor:

levels(DF$SOCIAL_STATUS)[DF$MALE > 4 & DF$SOCIAL_STATUS == "B"] <- "C"

On Wed, Jun 24, 2009 at 1:34 PM, Mark Na <mtb...@gmail.com> wrote:

> Hi R-helpers,
>
> Please see the below R output.
> The problem is that after running the ifelse statement, data$SOCIAL_STATUS
> is converted from a factor to a character.
>
> Is there some way I can avoid this conversion?
>
> Thanks in advance, Mark Na
>
>
> > str(data)
> 'data.frame': 2100 obs. of  11 variables:
> $ DATE           : Factor w/ 5 levels "4-Jun-09","7-May-09",..: 1 1 1 1 1 1
> 1 1 1 1 ...
> $ POND_ID        : Factor w/ 113 levels "10","18","19",..: 8 8 8 8 8 8 8 8
> 8
> 8 ...
> $ STATUS         : num  1 1 1 1 1 1 1 1 1 1 ...
> $ SPECIES        : Factor w/ 25 levels "AGWT","AMCO",..: 10 10 7 7 3 5 5 5
> 5
> 2 ...
> $ SOCIAL_STATUS  : Factor w/ 8 levels "A","B","D","E",..: 4 1 4 1 4 4 4 4 1
> 6 ...
> $ COUNT_OF_GROUPS: num  1 1 1 1 1 3 3 3 1 2 ...
> $ MALE           : num  1 1 1 1 1 1 1 1 1 0 ...
> $ FEMALE         : num  1 0 1 0 1 1 1 1 0 0 ...
> $ NOSEX          : num  0 0 0 0 0 0 0 0 0 2 ...
> $ UPLAND         : num  0 0 0 0 0 0 0 0 0 0 ...
> $ TAG            : num  0 0 0 0 0 0 0 0 0 0 ...
>
> > data$SOCIAL_STATUS<-ifelse(data$SOCIAL_STATUS=="B" & data$MALE>4, "C",
> data$SOCIAL_STATUS)
>
> > str(data)
> 'data.frame': 2100 obs. of  11 variables:
> $ DATE           : Factor w/ 5 levels "4-Jun-09","7-May-09",..: 1 1 1 1 1 1
> 1 1 1 1 ...
> $ POND_ID        : Factor w/ 113 levels "10","18","19",..: 8 8 8 8 8 8 8 8
> 8
> 8 ...
> $ STATUS         : num  1 1 1 1 1 1 1 1 1 1 ...
> $ SPECIES        : Factor w/ 25 levels "AGWT","AMCO",..: 10 10 7 7 3 5 5 5
> 5
> 2 ...
> $ SOCIAL_STATUS  : chr  "4" "1" "4" "1" ...
> $ COUNT_OF_GROUPS: num  1 1 1 1 1 3 3 3 1 2 ...
> $ MALE           : num  1 1 1 1 1 1 1 1 1 0 ...
> $ FEMALE         : num  1 0 1 0 1 1 1 1 0 0 ...
> $ NOSEX          : num  0 0 0 0 0 0 0 0 0 2 ...
> $ UPLAND         : num  0 0 0 0 0 0 0 0 0 0 ...
> $ TAG            : num  0 0 0 0 0 0 0 0 0 0 ...
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to