大家好:
这里想要询问循环资料“选择性输出”的做法。
有一份资料,我要比对它的字段两两是否相同。
【单笔测试】
> 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"
感谢~