There are several ways to do this.
Note: For future use and finding friends here, please always provide a reproducible example.
example data
df <- data.frame(Name = c("Ind1","Ind2","Ind3","Ind4","Ind5"), Sex = c(1,2,1,2,2))
df2<- data.frame(Code = c(1,2), Label = c("Male","Female"))
label by position
You can use the index of a vector element to "overwrite" it with another vector of "labels".
The following stores the result in a new column. Obviously, you can overwrite your Sex column with the result.
df$Sex2 <- df2$Label[df$Sex]
joining
The other more general way to do this is to join your data frames.
library(dplyr) # for pipe and left_join()
df <- df %>%
left_join(df2
, by = c("Sex"="Code") # define columns for the join
)
This creates the Label column which you need to further process.
Example output:
df
Name Sex Label Sex2
1 Ind1 1 Male Male
2 Ind2 2 Female Female
3 Ind3 1 Male Male
4 Ind4 2 Female Female
5 Ind5 2 Female Female