Clean column names in R with clean_names()

Поділитися
Вставка
  • Опубліковано 1 лют 2025

КОМЕНТАРІ • 12

  • @jenniferahakes
    @jenniferahakes 2 роки тому

    Thank you so much for showing the important step of saving the dataframe anew. I have been cleaning names but then would click on the dataframe in the Environment and couldn't figure out why the changes weren't showing up.

  • @sloperspinches3122
    @sloperspinches3122 4 роки тому

    Simple and effective. It definitively saves me a lot of time when cleaning data. Thank you for sharing.

  • @nerdygirl53
    @nerdygirl53 2 роки тому

    thank you so so much i've been stuck on this for a while now

  • @jitendarreddy98
    @jitendarreddy98 4 роки тому

    Great Tip, saves lot of time in cleaning column names. Thank you so much.

  • @franky2803
    @franky2803 3 роки тому

    That keyboard sound is underrated.

  • @tomhenry-datasciencewithr6047
    @tomhenry-datasciencewithr6047  4 роки тому +1

    What's **your** favorite function in R that's underrated?

  • @GayathriMahendran
    @GayathriMahendran Рік тому

    Very helpful. Thank you for this.

  • @mohammadsaifuddin1009
    @mohammadsaifuddin1009 2 роки тому +1

    Hi, I just want to clean "CQ22." from following data. Is it possible?
    CQ22.Allergy
    CQ22._Chest_Pain
    CQ22._Cough
    CQ22._Hair_Loss
    CQ22._Irritable_Mood

    • @tomhenry-datasciencewithr6047
      @tomhenry-datasciencewithr6047  2 роки тому

      Yes, the way I would do it is using a regular expression like this:
      data %>% rename_all(. %>% str_replace_all("^CQ22[._]*", ""))
      which matches ^ start of string, CQ22, and any number of . or _ afterwards
      ........ or even ....
      data %>% rename_all(. %>% str_replace_all("^[^._]*[._]*", ""))
      if all the columns have the same format, which matches ^ start of the string, [^._]* any number of NON - '_ or .' characters, and [._]* any number of '_ or .' characters ....
      and replaces them with the empty string.
      (And then I would pass to janitor::clean_names(), e.g.
      data %>% rename_all(. %>% str_replace_all("^[^._]*[._]*", "")) %>% janitor::clean_names()
      but up to you!)

  • @daviddhaese83
    @daviddhaese83 3 роки тому

    Simple but useful!