Arif AH
Arif AH

Reputation: 25

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

Upvotes: 1

Views: 976

Answers (1)

Elias
Elias

Reputation: 736

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

Let me know if it worked :)

Upvotes: 1

Related Questions