dimanche 21 mars 2021

Altering the Characters of a Dataframe in R

I have a column in an R Dataframe that has values of the form 21, 2021, 18, 2019, and so on. Basically, the value 21 is the same as the value 2021 because the column contains values for years. I am trying to write code in R which replaces all the instances of years that have a length of 2 and replaces them with a "20" appended in the beginning. For example, "18" should turn into "2018". Can someone suggest what code should be used to achieve this? I am thinking of using the ifelse command but I am not sure what the exact syntax should be.

Aucun commentaire:

Enregistrer un commentaire