All the sources indicate that the character variables name
and gender
in this data frame from startSalary.csv are to be categorized as factors.
name salary gender
Anne 75000 F
David 70000 M
Cindy 55000 F
Mark 65000 M
Patrick 64000 M
When I read it as follows:
df1 <- read.csv("startSalary.csv")
str(df1)
data.frame': 5 obs. of 3 variables:
$ name : chr "Anne" "David" "Cindy" "Mark" ...
$ salary: int 75000 70000 55000 65000 64000
$ gender: chr "F" "M" "F" "M" ...
R categorizes these variables as characters, not the default categorization as factor. I know I could read the data as
df2 <- read.csv("startSalary.csv",stringsAsFactors = TRUE)
for R to categorize them as factors.
Why my R codes are not categorizing them as factors, which is the default?
I have not used any options()
function. Have I done a global change in defaults without knowing about it?
Thanks.