case-when

Can dplyr package be used for conditional mutating?

穿精又带淫゛_ 提交于 2019-11-26 01:42:48
问题 Can the mutate be used when the mutation is conditional (depending on the values of certain column values)? This example helps showing what I mean. structure(list(a = c(1, 3, 4, 6, 3, 2, 5, 1), b = c(1, 3, 4, 2, 6, 7, 2, 6), c = c(6, 3, 6, 5, 3, 6, 5, 3), d = c(6, 2, 4, 5, 3, 7, 2, 6), e = c(1, 2, 4, 5, 6, 7, 6, 3), f = c(2, 3, 4, 2, 2, 7, 5, 2)), .Names = c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"), row.names = c(NA, 8L), class = \"data.frame\") a b c d e f 1 1 1 6 6 1 2 2 3 3 3 2 2 3 3 4 4