简体   繁体   English

我在 R 中有一个因子列。 我正在尝试删除它,但我不断收到错误消息。 如何删除 R 中的因子列?

[英]I have a factor columns in R. I am trying to delete it but I keep getting errors messages. How do I delete a factor column in R?

My data frame df has has a factor column.我的数据框df有一个因子列。 The column is just filled with "yes" and "no" values.该列仅填充了“是”和“否”值。 I used the following formula:我使用了以下公式:

* df$column <- NULL* * df$column <- NULL*

However I get the following messages;但是我收到以下消息;

Warning message: In Ops.factor(df$Embarked, NULL): '<' not meaningful for factors警告消息:在 Ops.factor(df$Embarked, NULL): '<' 对因素没有意义

& &

logical(0)逻辑(0)

Can someone advise what formula to use instead of the one I used please?有人可以建议使用什么公式代替我使用的公式吗?

library(dplyr)
df <- select(df, -column)

It should work.它应该工作。

df <-
    data.frame(fac = factor(sample(
        c("yes", "no"), size = 10, replace = TRUE
    )), ind = 1:10)
df$fac <- NULL
# column is removed

Check if NULL is valid, not being overwritten by something else.检查NULL是否有效,没有被其他东西覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在R中删除空间多边形数据框中的因子水平? - How do I delete factor levels in a spatialpolygonsdataframe in R? 我想在R中的因子和数值变量中找到缺失值的数量。我该怎么做? - I want to find the number of missing values in the factor and numerical variables in R. How do I do that? R:为什么在将列转换为因数后仍不能得到类型或类的“因数”? - R: Why am I not getting type or class “factor” after converting columns to factor? 在 R 中使用 glm function 时出现因子错误 - I am getting factor error while using glm function in R 我正在尝试使用 R 获取矩阵中列的乘积。 我究竟做错了什么? - I'm trying to take the product of the columns in a matrix using R. What am I doing wrong? 运行因子加载后,如何在 r 中的 pca 分析中保持 id 变量? - How do I keep id variable in pca analysis in r after running factor loadings? 如何使用R计算因子得分? - How can I calculate factor scores with R? 我想使用R中库glmnet中的cv.glmnet。我的变量之一是类型为weekday的字符表示。 我怎样才能做到这一点? - I want to use cv.glmnet from library glmnet in R. One of my variables is a character representation of weekday, of type factor. How can I do this? 如何迭代 R 中因子的水平? - How can I iterate the levels of a factor in R? 如何删除R中的一个因子水平? - how do I remove one factor level in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM