0 votes
1 view
in R Programming by (11.5k points)

I am new to R programming and I have imported a CSV file. I would like to change the variable value for symbol column. If the value is "DEF" then "NEW1". If the value is "GHI" then "NEW2". I tried the below code but, I am getting a warning message and I checked the dataframe contains "NA" after changing.

df$symbol[df$symbol == "DEF"] <- "NEW1"
df$symbol[df$symbol == "GHI"] <- "NEW2"

Warning message:

In `[<-.factor`(`*tmp*`, df$symbol == "DEF",  :
  invalid factor level, NA generated

1 Answer

0 votes
by (31.4k points)

I would suggest you to simply try this :

df$symbol <- as.character(df$symbol)

df$symbol[df$symbol == "DEF"] <-"NEW1"

Welcome to Intellipaat Community. Get your technical queries answered by top developers !