我试图用R中的一个空格(“”)替换单元格,但是由于某种原因,它不起作用。我的载体是这样的:
[1] "SICREDI N/NE" "SICOOB CREDIMINAS" "UNICRED SC/PR"
[4] " " " " "CRESOL SC/RS"
我尝试使用,CENTRAL<-gsub("\\\b \\\b", NA,CENTRAL)
但随后返回:
[1] NA NA NA NA NA
[6] "CRESOL SC/RS" NA NA NA NA
您的单词中有空格,因此gsub将插入一个NA,这将导致整个条目中的NA值。您可以这样做:
vec <- c("words with spaces", "word with spaces", " ", " ", "not", "here")
vec
[1] "words with spaces"
[2] "word with spaces"
[3] " "
[4] " "
[5] "not"
[6] "here"
vec[vec==" "]
[1] " " " "
vec[vec==" "] <- NA
vec
[1] "words with spaces"
[2] "word with spaces"
[3] NA
[4] NA
[5] "not"
[6] "here"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句