我有一个包含 1 列地址的 csv 文件。它具有以下值:
A <- structure(list(Address = structure(1:3, .Label = c("&2340 P St",
"&5656 N St", "456 B Street"), class = "factor")), .Names = "Address",
row.names = c(NA, 3L), class = "data.frame")
A
## Address
## 1 &2340 P St
## 2 &5656 N St
## 3 456 B Street
我需要清理数据——如果有“&”,则删除所有字符(或用空格替换)。我在我的 2.csv 文件中期待这个结果:
## Address
## 1 456 B Street
这是代码:
A <-read.csv("U:/161/1.csv", header=T,sep=",")
B<-gsub("&", " ", A$ADDRESS1, ignore.case = TRUE)
write.table(B, file = "U:/161/2.csv", sep = ","
, col.names = NA, qmethod = "double")
它只删除“&”。如何删除地址的其余部分?