簡體   English   中英

在文本之前和之后從R中的數據框中刪除特殊字符

[英]Remove special character from data frame in R before and after text

我有以下數據框

1   +PAL+PEA+ + + + 

我想刪除文字前后的“ +”,並得到類似

1   PAL+PEA 

嘗試

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM