I'm working with the ToothGrowth data:
library(datasets)
data(ToothGrowth)
Here I have three columns, lenght, supplement and dosis. I want to a add a fourth column with a categorical variable that depends on the dosis amount, like for example if dosis = 0.5, then "D5", if dosis = 1, then "D1", I tried the following:
data(ToothGrowth)
df_TD <- ToothGrowth
dosiscatg <- NULL
for(i in 1:nrow(df_TD)) {
  if df_TD$dose==0.5 {
    dosiscatg <- c(dosiscatg, "D0.5")
  } else if df_TD$dose==1 {
    dosiscatg <- c(dosiscatg, "D1")
  } else if df_TD$dose==2 {
    dosiscatg <- c(dosiscatg, "D2")
  }
}
But I keep getting an error with the brackets "{}", also I don't know if that code is correct.
 
     
     
     
    