Home > Back-end >  How to remove "year olds" from each row of a Dataset?
How to remove "year olds" from each row of a Dataset?

Time:10-25

As in the image below, how would I remove each of the 'year olds' from the second column?

Image of Dataset

CodePudding user response:

df$age5txt <- gsub(" year olds", "", df$age5txt)

where df is your dataset

CodePudding user response:

Using trimws

df$age5txt <- trimws(df$age5txt, whitespace = "\\s year olds")
  •  Tags:  
  • r
  • Related