Reputation: 5173
I have x = 1,2,3,4 which is my categorical variable but when I use summary() it automatically thinks that this is discrete : so I would get something like this
Min : 1st Qu.: Median :
But what I want is to give me just the frequency for this variable within the summary()
1: 2: 3: 4:
Thank you
Upvotes: 3
Views: 15784
Reputation: 10478
> x <- seq(1:10)
> summary(as.factor(x))
1 2 3 4 5 6 7 8 9 10
1 1 1 1 1 1 1 1 1 1
Or, if you want to permanently assign x as categorical variable in a dataframe named mydata, do this before the summary()
call:
mydata$x <- factor(mydata$x)
(Spending an hour or two with any of the many books or online intros to R and typing out the examples is a smart investment and saves a lot of time.)
Upvotes: 9