我有以下r中數據幀查找最大值和最小值爲偶數和奇數
ID numbers
1 12
2 4
3 13
4 8
5 9
6 4
我想找到最大和最小的奇數和偶數列數和標記,
ID numbers Tag
1 12 Largest even
2 4 Smallest even
3 13 Largest odd
4 8
5 9 Smallest odd
6 4 Smallest even
我試着做下列
df$tag <- ifelse(which.max(df$numbers %% 2 == 0),"Largest even",
ifelse(which.min(df$numbers %% 2 == 0),"Smallest even",
ifelse(which.max(df$numbers %% 2 != 0),"Largest odd",
ifelse(which.min(df$numbers %% 2 != 0),"Smallest odd",
它不工作,我想要的方式。
會發生什麼事時,只有1偶數? – zx8754
在我的情況下,它不會發生。我至少會有兩個偶數或奇數。 – Neil