[R-sig-eco] Problem in Search and Association Loop
Alexandre F. Souza
alexsouza.cb.ufrn.br at gmail.com
Sat Sep 5 02:34:06 CEST 2015
Dear friends,
I am writing a loop to compare scientific plant names from one data frame
in a second data frame containing a smaller set of potentially different
plant names, and then to copy the associated abundances of the sp already
present in the first database, and add the new species to the bottom.
I am receiving, however, an error message saying that factor levels are
different. Can someone give me a hint on what can be happening?
Here you have the code
The base dataframe
> base
family genus epithet abundance
1 Burseraceae Coccoloba cf. cordifolia 224
2 Anacardiaceae Tapirira guianensis 112
3 Euphorbiaceae Pogonophora schomburgkiana 146
4 Anacardiaceae Thyrsodium spruceanum 115
5 Apocynaceae Himatanthus phagedaenicus 47
6 Sapotaceae Pouteria coriacea 71
7 Malpighiaceae Byrsonima sericea 25
8 Polygonaceae Coccoloba cf. cordifolia 29
9 Burseraceae Protium heptaphyllum 37
The new data data.frame
> new.data
genus sp.new abundance
1 Coccoloba cf. cordifolia 29
2 Protium heptaphyllum 37
3 Bowdichia virgilioides 15
4 Sclerolobium densiflorum 15
5 Ocotea glomerata 16
The Output table
output= matrix(nrow = 10, ncol = 3)
colnames(output) = c("genus", "epithet", "abundance")
output
for (i in 1:nrow(base)){
for (j in 1:nrow(new.data)){
if ((base[i,2] == new.data[j,1]) & (base[i,3] == new.data[j,2])){
output[i,1] = base[i,2]
output[i,2] = base[i,3]
output[i,3] = new.data[j,2]
}
}
}
This is just the beginning of the code I plan. I stopped due to the error
message.
Thank you very much in advance,
Alexandre
--
Dr. Alexandre F. Souza
Professor Adjunto III
Universidade Federal do Rio Grande do Norte
CB, Departamento de Ecologia
Campus Universitário - Lagoa Nova
59072-970 - Natal, RN - Brasil
lattes: lattes.cnpq.br/7844758818522706
http://www.docente.ufrn.br/alexsouza
[[alternative HTML version deleted]]
More information about the R-sig-ecology
mailing list