我要从 Python 转到 R,我想比较我通常使用 dict
做的两件事:
dict_one = {'a': 1, 'b': 2, 'c': 3}
dict_two = {'a': 1, 'b': 2, 'c': 4}
for key1, value1 in dict_one.items():
if dict_two[key1] != value1:
print(key1) #prints c
有没有类似的R?我制作了两个命名列表
list_one <- list(a = 1, b = 2, c = 3)
list_two <- list(a = 1, b = 2, c = 4)
我试过这样的东西,但它没有输出我要找的东西。
> list_one %in% list_two
[1] TRUE TRUE TRUE #looking for TRUE TRUE FALSE
最佳答案
您可以这样做(这将考虑您的列表中可能的不同排序):
> unlist(list_two[names(list_one)])!=unlist(list_one)
a b c
FALSE FALSE TRUE
关于python - 比较 R 中等效的键值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43241162/