Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 列中的字符串操作_R_Dplyr_Stringr - Fatal编程技术网

R 列中的字符串操作

R 列中的字符串操作,r,dplyr,stringr,R,Dplyr,Stringr,考虑data.frame,我们可以这样说: df <- data_frame(id = c(1, 1, 2, 2), n = c("100+", "50+", "30+", "40+")) 必须有一种正确的方法为带有dplyr的列应用str_replace()函数。您需要传递要在其上执行替换的列,然后转义加号 library(dplyr) library(stringr) df %>% mutate(n = str_replace(n, "\\+","")) 完美的谢谢 l

考虑data.frame,我们可以这样说:

df <- data_frame(id = c(1, 1, 2, 2), n = c("100+", "50+", "30+", "40+"))

必须有一种正确的方法为带有dplyr的列应用
str_replace()
函数。

您需要传递要在其上执行替换的列,然后转义加号

library(dplyr)
library(stringr)

df %>%
  mutate(n = str_replace(n, "\\+",""))

完美的谢谢
library(dplyr)
library(stringr)

df %>%
  mutate(n = str_replace(n, "\\+",""))