lundi 27 avril 2020

Fill in empty values in column of dataframe by condition

I have the followin dataframe. Now I want to fill in the empty values in "product" by determining the value of the code 44 and 90. 44 should be "shirt" and 90 "sweater".

What's the best way to do this? With a for loop?

data = data.frame("code" = c(44,78,21,90,100,44,90), "product" = c("","hat","shoe","","umbrella","",""))
> data
  code  product
1   44         
2   78      hat
3   21     shoe
4   90         
5  100 umbrella
6   44         
7   90      

Aucun commentaire:

Enregistrer un commentaire