0

Okay so my problem is that I want to import a csv file (that is separeted by commas, so R reads it as a dataframe).

The first column is called "Animals", and below there is "crocodile", "elephant" etc. Here I want to replace names of the animals to be either "reptile" or "mammal".

How do I do this?

Thank you a lot in advance

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

You need to make a reproducible code. A reproducible example allows someone else to recreate your problem by just copying and pasting R code. Btw if I understand correctly try this:

 library(dplyr)
    
 your_df = read.csv("the file path", sep = ",") %>% 
           mutate(Animals = case_when(Animals == "crocodile" ~ "reptile",
                                      Animals == "elephant" ~ "mammal",
                                      T ~ as.character(Animals)))

  

Where "the file path" is your csv file path like "D:/Users/YourUser/Desktop/my_file.csv"
Victor
  • 142
  • 6