Hello everyone, I have a data set like this:
> head( fish_transect) ID_TRANSECT ID_PROJECT DE_ZONE DE_LOCALITY DE_SECTOR MES 1 42 MB Tarragona Creixell Control I 9 2 42 MB Tarragona Creixell Control I 9 3 42 MB Tarragona Creixell Control I 9 4 42 MB Tarragona Creixell Control I 9 5 42 MB Tarragona Creixell Control I 9 6 42 MB Tarragona Creixell Control I 9 ID_SPECIES WEIGHT SIZE N FAMILIA 1 Spondyliosoma cantharus 15.64 10 1 Sparidae 2 Symphodus melanocercus 11.21 10 1 Labridae 3 Diplodus vulgaris 30.20 10 2 Sparidae 4 Diplodus vulgaris 52.24 12 2 Sparidae 5 Diplodus sargus 221.41 14 5 Sparidae 6 Diplodus annularis 3.47 6 1 Sparidae The table function of the column FAMILIA gives: Apogonidae Atherinidae Blennidae Blenniidae Bothidae 216 1 406 2 11 Carangidae Centracanthidae Congridae Gadidae Gobidae 25 4 21 2 214 Haemulidae Labridae Mugilidae Mullidae Muraenidae 25 6381 10 965 45 Myliobatidae Sciaenidae Scombridae Scorpaenidae Serranidae 2 159 1 512 2127 Sparidae Sphyraenidae Synodontidae Torpedinidae Trachinidae 6196 5 1 1 1 Tripterygidae 135 I want to add a new column "familia2" where those families with low number of individuals are listed as "other", that is, for these families Atherinidae Blenniidae Bothidae Carangidae Centracanthidae 1 2 11 25 4 Congridae Gadidae Haemulidae Mugilidae Muraenidae 21 2 25 10 45 Myliobatidae Scombridae Sphyraenidae Synodontidae Torpedinidae 2 1 5 1 1 Trachinidae 1 I want them in column "familia2" to be named "others" I've been trying to do a loop telling R to write "others" when the sum of FAMILIA was less than 50, but it didn't work because FAMILIA is a factor, and there isn't a "count" function (or I didn't find it). I also tried other options like the "match" function, "level" function, etc. I know I can do it manually typing by myself the names of the 16 families but I want to learn a way to do where I don't need to type the names. Thanks in advance! Lucia -- View this message in context: http://r.789695.n4.nabble.com/count-of-factors-tp3224791p3224791.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.