假设我使用gsub函数,希望从字符串中删除以下符号(=,+,-),并用下划线替换。
当我尝试使用加号(+)时,有人能描述一下发生了什么吗?
test<- "sandwich=bread-mustard+ketchup"
# [1] "sandwich=bread-mustard+ketchup"
test<-gsub("-","_",test)
# [1] "sandwich=bread_mustard+ketchup"
test<-gsub("=","_",test)
# [1] "sandwich_bread_mustard+ketchup"
test<-gsub("+","_",test)
#[1] "_s_a_n_d_w_i_c_h___b_r_e_a_d___m_u_s_t_a_r_d_+_k_e_t_c_h_u_p_"
fixed = TRUE
设为真或者在加号前使用转义符。 - Jotagsub("[+]", "_", test)
- alexwhitworth