Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 R 中有一个列,如下所示:
won <- c("\001", rep("\\0",3), "\001") won \001 \\0 \\0 \\0 \\0 \001
有两个可能的值,\0 或 \001
我想知道最有效的方法是将这些值更改为 0(对于 \0)和 1(对于 \001)。我确定 gsub() 是一种选择,但不清楚是否可以更改两个单独的字符串值。
对于这种特定情况:
2 - nchar(won)
这是另一种选择:
ifelse(won == "\001", 1, 0)