gpt4 book ai didi

r - R如何将级别之一更改为NA

转载 作者:行者123 更新时间:2023-12-03 20:25:18 24 4
gpt4 key购买 nike

我有一个数据集,其列之一具有因子水平"a" "b" "c" "NotPerformed"。如何将所有"NotPerformed"因素更改为NA?

最佳答案

将级别设置为NA:

x <- factor(c("a", "b", "c", "NotPerformed"))
x
## [1] a b c NotPerformed
## Levels: a b c NotPerformed
levels(x)[levels(x)=='NotPerformed'] <- NA
x
## [1] a b c <NA>
## Levels: a b c


请注意,因子级别已删除。

关于r - R如何将级别之一更改为NA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25354964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com