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"
```

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to