5
Suppose I have the date frame iris
, present in the memory of R:
head(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
Suppose I also have a data frame called flores
, with the following structure:
flores <- data.frame(Especies=c("setosa", "virginica", "versicolor"),
Nome=c("Flor 1", "Flor 2", "Flor 3"))
Especies Nome
1 setosa Flor 1
2 virginica Flor 2
3 versicolor Flor 3
I would like to replace the occurrences of iris$Species
by flores$Nome
. I mean, I’d like every occurrence of setosa
in iris$Species
be replaced by Flor 1
; each occurrence of virginica
in iris$Species
be replaced by Flor 2
; and each occurrence of versicolor
in iris$Species
be replaced by Flor 3
.
Use something like if
or ifelse
It’s out of the question, because the data set I’m working with has thousands of occurrences of different species. It would be impossible to type in all the options I have to work with.