Search code examples
rdataframesummaryfactors

Categorical variables are not properly summarized when running the summary() function on Data Frame


df <- read.csv("student-mat.csv", sep = ";")

head(df)

The Data

Now when I run summary(df)

Expected Output

My Output

Why don't I get the proper descriptive summary for categorical variables / factors (e.g. A count for the two genders under the "sex" factor).

Background Information:

Operating System: macOS High Sierra Version 10.13.6

RStudio Version 1.3.959


Solution

  • You need to define your variables as a factor. E.g df$sex <- as.factor(df$sex)

    Let me know if it worked :)