作者paranoia5201 (社会黑暗、行路难)
看板R_Language
标题[问题] all.equal()不用印出所有资讯
时间Sat Apr 27 11:26:13 2019
大家好:
这里想要询问回圈资料「选择性输出」的做法。
有一份资料,我要比对它的栏位两两是否相同。
【单笔测试】
> m <- all.equal(list.d2[1, ], list.d2[2, ])
> m
[1] "Attributes: < Component “row.names”: Mean relative difference: 1 >"
[2] "Component “phone.4”: 1 string mismatch"
由於笔数繁多,所以我写了一个回圈来重复执行:
> for(i in seq(1, 5, by = 2)){
+ match <- all.equal(list.d2[i, ], list.d2[i+1, ])
+ print(i)
+ print(match)
+ }
[1] 1
[1] "Attributes: < Component “row.names”: Mean relative difference: 1 >"
[2] "Component “phone.4”: 1 string mismatch"
[1] 3
[1] "Attributes: < Component “row.names”: Mean relative difference:
0.3333333 >"
[1] 5
[1] "Attributes: < Component “row.names”: Mean relative difference: 0.2 >"
这里是想请问:我要如何让这回圈只列印有不一致的资讯,而其他不用显示?
【理想结果】
[1] 1
[2] "Component “phone.4”: 1 string mismatch"
感谢~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.194.164.43
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1556335575.A.92D.html
1F:→ andrew43: 不明白为什麽只有第一次的比较被你视为不一致 04/27 22:15
2F:推 TOOYA: print(c(i,match[2])) ? 04/30 14:57
3F:→ TOOYA: print(i);print(match[2]) ? 04/30 14:58
4F:→ paranoia5201: 原来可以这样选!感谢楼上赐教。 04/30 22:53