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 不适合它:如何将数据帧的一列中低于 X 的所有值更改为 0,以及将 X 和所有大于 X 的值更改为 1?
ifelse函数完全符合您的要求。如果您的数据框被调用d,并且列被调用d$column:
d
d$column
d$column = ifelse(d$column < X, 0, 1)