I am attempting to write code to find all "ND" values in a large data frame named "Master" and reassign them as 0. I tried this:
library(tidyverse)
library(readr)
#VSS
Master1 <- Master %>%
mutate(VSS = ifelse(str_detect(
string=VSS,
pattern="ND"
),
parse_number(gsub(
pattern = "ND",
replacement ="", x = 0, parse_number(VSS)
))))
but I wind up with this error message:
# Error in ifelse(str_detect(string = VSS, pattern = "ND"), parse_number(gsub(pattern = "ND", : argument "no" is missing, with no default
If there is a better method to search all columns in the dataframe at once and replace them, that would be preferred.
Data Example: (Master)
TDS TSS VSS TKN DOC TOC DON Chla
10 2.2 3.5 ND 10 2.2 3.5 ND
14 2.5 3.75 0.01 14 2.5 3.75 0.01
ND N/A 5 0.2 ND N/A 5 0.2
10 2.2 3.5 ND 10 2.2 3.5 ND
14 2.5 3.75 0.01 14 2.5 3.75 0.01
ND N/A 5 0.2 ND N/A 5 0.2
14 2.5 3.75 0.01 14 2.5 3.75 0.01
ND N/A 5 0.2 ND N/A 5 0.2
10 2.2 3.5 ND 10 2.2 3.5 ND
14 2.5 3.75 0.01 14 2.5 3.75 0.01
ND N/A 5 0.2 ND N/A 5 0.2
*Please note that I want to maintain N/As, which I will change to blanks later