[英]How to display phone numbers in SQL that contain two and only two '0s'?
[英]How do I limit results to only those data frame rows and columns that contain 0s?
我正在R中进行近似的字符串匹配。我对这种技术并不熟悉,但是因为我想找到实例,其中我的x字符串与我的y字符串的部分完全匹配,所以我只对Levenshtein分数0感兴趣(这是正确的吗?接近?)。
子集结果最方便的方法是什么? 因为我有大约1万列和1000行,所以我不确定是否有任何方法可以有效地可视化结果。 对于这个问题缺乏技巧,我深表歉意。 我只是缺乏经验。
使用Mark的数据,这是一种使用apply
建立索引的方法:
rows <- apply(my.data, 1, function(x) any(!x))
cols <- apply(my.data, 2, function(x) any(!x))
my.data[rows, cols]
## V2 V3 V4
## 1 0 2 1
## 3 1 1 0
## 5 0 0 0
这将保留所有包含零的行和列。
set.seed(2234)
my.data <- as.data.frame(matrix(sample(0:2,20,replace=TRUE), nrow=5))
my.data
aa <- unique(which(my.data==0,arr.ind=TRUE)[,1])
bb <- unique(which(my.data==0,arr.ind=TRUE)[,2])
my.data2 <- my.data[sort(aa),sort(bb)]
my.data2
> my.data
V1 V2 V3 V4
1 2 0 2 1
2 2 2 1 2
3 2 1 1 0
4 2 2 2 1
5 1 0 0 0
> my.data2
V2 V3 V4
1 0 2 1
3 1 1 0
5 0 0 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.