[英]Remove special character from data frame in R before and after text
I have the following data frame 我有以下数据框
1 +PAL+PEA+ + + +
I want to remove the '+' before and after the text and get something like 我想删除文字前后的“ +”,并得到类似
1 PAL+PEA
Try 尝试
gsub('^[+]*|[+ ]*$', '', str1)
#[1] "PAL+PEA"
str1 <- '+PAL+PEA+ + + +'
regmatches(str1,gregexpr("[aA-zZ]+[+]{1}[aA-zZ]+",str1))
[[1]]
[1] "PAL+PEA"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.