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


