I need to replace some string values in my data set with 0, which I would like to do by
df$colName[df$colName == "< LOD"] <- 0
If I apply this to one column it works perfectly fine but I would like to use it in a for loop, since I have over 300 columns, so I tried this:
aa()
for (i in 1:ncol(df)) {
aa <- df$i[df$i == "< LOD"] <- 0
}
this gives me the Error in in `$<-.data.frame`(`*tmp*`, "i", value = numeric(0)) :
replacement has 0 rows, data has 22
(my data has 22 rows).
Now I already read that it is some kind of problem that I first need to define a data frame, which I am not sure how to do it in this example. any help would be very much appreciated!