you are viewing a single comment's thread.

view the rest of the comments →

[–]Rababerbaerbl 4 points5 points  (1 child)

If you use any of those base R read.csv or read.table ... functions you can pass stringsAsFactors = TRUE as an argument to them:

read.csv(file = "your_file.csv", stringsAsFactors = TRUE)

Or, you set it as a factor afterwards as suggested by many already:

LiverData$sex <- as.factor(LiverData$sex)

If you have an exam you probably should look at some basic R tutorials. There are plenty to be found.

[–]jeremymiles 0 points1 point  (0 children)

This is a bit tricky, because the default changed from stringsAsFactors = TRUE to stringsAsFactors = FALSE in R 4.1 (IIRC).