我有两个数据帧每列名删除特殊符号data.frame列的值
df1
:
name
@one2
!iftwo
there_2_go
come&go
df1 = structure(list(name = c("@one2", "!iftwo", "there_2_go", "come&go")),.Names = c("name"), row.names = c(NA, -4L), class = "data.frame")
df2
:
name
One2
IfTwo#
there-2-go
come.go
df2 = structure(list(name = c("One2", "IfTwo#", "there-2-go", "come.go")),.Names = c("name"), row.names = c(NA, -4L), class = "data.frame")
我们比较这两个不平等的数据帧由于使用%in%
的特殊符号而非常麻烦。使用stringR
删除特殊符号可能会有用。但究竟如何,我们可以使用stringR
功能与%in%
并显示它们之间的不匹配
已经做了mutate()
全部转换成小写toLower()
如下
df1<-mutate(df1,name=tolower(df1$name))
df2<-mutate(df2,name=tolower(df2$name))
比较的电流输出:
df2[!(df2 %in% df1),]
[1] "one2" "iftwo#" "there-2-go" "come.go"
预期输出基本上与内容相同,但带有特殊符号:
df2[!(df2 %in% df1),]
character(0)
问题:我们如何忽略框架
你错误地附上'df'而不是两次DF和DF2?你的预期输出是什么? – Sotos
哦,这是一个错误,而从R控制台复制到堆栈流 – Anurodh
这是现在纠正@Sotos – Anurodh