【发布时间】:2017-10-11 13:17:48
【问题描述】:
这是我的数据:
dataset <- c("h", "H", "homme", "masculin", "f", "femme", "épouse")
如何替换向量的文本值,例如:
- “femme”->“f”
- “épouse”->“f”
- “Homme”->“h”
- “男性”->“h”
我对“femme”的尝试 -> “f”
test_out <- sapply(dataset, switch,
"f"="femme")
test_out
预期结果:
"h" "h" "h" "masculin" "f" "f" "f"
【问题讨论】:
标签: r