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.
The argument 'stringsAsFactors' is an argument to the 'data. frame()' function in R. It is a logical that indicates whether strings in a data frame should be treated as factor variables or as just plain strings. The argument also appears in 'read.
Please note that stringsAsFactors = FALSE is the default specification of the data. frame function, in case you are using R version 4.0 or newer. In older versions, the default specification was stringsAsFactors = TRUE. logical: should character vectors be converted to factors?
Set options(stringsAsFactors = FALSE)
at the beginning of your R session, or in your .RProfile.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With