我有一个包含三列和很多行的数据框。其中一列包含 80803 和 9995 之类的数字。我想用 0 替换此列中的特定数字 80803 和 9995。
假设我的数据框名为 df。我尝试使用 gsub 函数,如 gsub(80803,0,df)。但是错误显示了哪些状态pattern has length > 1 and only the first element will be used。
这是我的 df 的示例。只是有更多的行。
a <- c(85.42, 80.80, 78.56 , 70.40)
b <- c(110, 80803, 9995, 50)
c <- c(3, 4 , 7, 5)
df <- data.frame(a, b, c)
df
a b c
1 85.42 110 3
2 80.80 80803 4
3 78.56 9995 7
4 70.40 50 5
Run Code Online (Sandbox Code Playgroud)
这就是我希望我的 df 的样子。
df
a b c
1 85.42 110 3
2 80.80 0 4
3 78.56 0 7
4 70.40 50 5
Run Code Online (Sandbox Code Playgroud)