-2

I took out single factor subset from a.df, which has 38 levels in field 'Rh_spps' but in new subject, when I check levels, it gives whole list, while there is only one level here area detail code

rr.lepp<-a.df[a.df$Rh_spps=="R. lepidotum",] 
head(rr.lepp)
         Rh_spps     dataset   lat  long   AP MAT
337 R. lepidotum Ole & Inger 28.50 84.30  420  25
338 R. lepidotum Ole & Inger 28.10 85.30 1445 119
339 R. lepidotum Ole & Inger 27.90 86.20 2186 124
340 R. lepidotum Ole & Inger 28.40 84.85  439  57

levels(rr.lepp$Rh_spps)
[1] "R."                "R. adenogynum" 
..
..
37] "R. virgatum"       "R. wallichii"

count(rr.lepp$Rh_spps)
             x freq
1 R. lepidotum  432
dim(rr.lepp)
[1] 432   6
count(rr.lepp$Rh_spps)
             x freq
1 R. lepidotum  432

as you see, there are only 432 rows and single species (factor) but the levels result 38 (as in original df)

Q. how do I move the levels thanking you

MKS
  • 13
  • 1
  • 4

1 Answers1

1

Either:

  1. Remove the levels before you begin, ala a.df$Rh_spps <- as.character(a.df$Rh_spps); or

  2. Refactor after extraction, such as rr.lepp$Rh_spps <- factor(rr.lepp$Rh_spps).

r2evans
  • 141,215
  • 6
  • 77
  • 149