如何在data.frame中永久禁用stringsAsFactors = TRUE? [英] How to disable stringsAsFactors=TRUE in data.frame permanently?

查看:732
本文介绍了如何在data.frame中永久禁用stringsAsFactors = TRUE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

见标题。坦白说,我一直都在手忙着做调整。

See title. Frankly I am a bit sick of manually doing the adjustment all the time.

这应该是一个简单的问题,但我不知道如何解决它。谢谢。

This should be a simple question, but I just can't figure out how to fix it. Thanks.

推荐答案

开始设置 options(stringsAsFactors = FALSE)您的R会话,或您的.RProfile。

Set options(stringsAsFactors = FALSE) at the beginning of your R session, or in your .RProfile.

由于下面的评论可能会建议, stringsAsFactors 有点在R社区内有争议的话题。你觉得这个默认值有多烦恼可能有点依赖于你花多少时间来使用R来适应许多标准统计模型( lm glm 等)。许多模型拟合和相关功能都是使用因子数据类型构建的。

As the comments below may suggest, stringsAsFactors is a bit of a controversial topic within the R community. How irritating you find this default value may depend somewhat on how much time you spend using R to fit many "standard" statistical models (lm, glm, etc). Many of those model fitting and related functions are built around using the factor data type.

如果您花费大部分时间进行其他更通用类型的数据分析,您可能会发现这种默认值更为恼人。

If you spend most of your time doing other more "generic" types of data analysis, you might find this default more irritating.

由于以下原因,全局设置 stringsAsFactors = FALSE 是被广泛认为的危险:在共享代码时可能会引起严重的混乱。事实上,即使你主要单独工作,如果您坚持使用 stringsAsFactors = FALSE 来运行R,那么参与像StackOverflow这样的在线社区可能会很棘手:您对某个问题的回答可能无效对于OP,或者您可能无法复制别人看到的错误!

It is widely considered dangerous to globally set stringsAsFactors = FALSE for the reasons mentioned below: it can cause significant confusion when sharing code. Indeed, even if you work mainly alone, participating in online communities like StackOverflow can be tricky if you insist on running R with stringsAsFactors = FALSE: your answer to a question may not work for the OP, or you may not be able to replicate errors others are seeing!

当然,每个人都可以自己选择如何最好地管理这些风险。

Of course, everyone can make their own choices about how best to manage these risks for themselves.

这篇关于如何在data.frame中永久禁用stringsAsFactors = TRUE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆