[R] Select dataframe row containing a digit
Luigi Marongiu
m@rong|u@|u|g| @end|ng |rom gm@||@com
Wed Nov 30 13:40:50 CET 2022
Hello,
I have a data frame where some lines containing strings including digits.
How do I select those rows and change their values?
In essence, I have a data frame with different values assigned to the
column "val". I am formatting everything to either "POS" and "NEG",
but values entered as number should get the value "NUM".
How do I change such values?
--
Best regards,
Luigi
```
df = data.frame(id = runif(10, 1, 100),
val = c("", "POs", "Pos", "P", "Y",
"13.6", "Neg", "N", "0.5", "58.4"),
stringsAsFactors = FALSE)
df$val[df$val == ""] = NA
df$val[df$val == "POs"] = "POS"
df$val[df$val == "Pos"] = "POS"
df$val[df$val == "P"] = "POS"
df$val[df$val == "Y"] = "POS"
df$val[df$val == "Neg"] = "NEG"
df$val[df$val == "N"] = "NEG"
```
More information about the R-help
mailing list