Reputation: 789
I've got the following code:
isNoun <- as.factor(isNoun)
isVerb <- as.factor(isVerb)
labels <- as.factor(labels)
alles <- matrix(c(isNoun, isVerb, length,labels), nrow=388,ncol=4)
alles_df <- as.data.frame(alles)
summary(alles_df)
> summary(alles_df)
V1 V2 V3 V4
Min. :0.0000 Min. :0.00000 Min. : 3.000 Min. :0.0000
1st Qu.:1.0000 1st Qu.:0.00000 1st Qu.: 5.000 1st Qu.:0.0000
Median :1.0000 Median :0.00000 Median : 6.500 Median :0.0000
Mean :0.9098 Mean :0.01546 Mean : 7.193 Mean :0.2938
3rd Qu.:1.0000 3rd Qu.:0.00000 3rd Qu.: 9.000 3rd Qu.:1.0000
Max. :1.0000 Max. :1.00000 Max. :18.000 Max. :1.0000
where isVerb, isNoun and labels are codes as 0 (= no) and 1 (=yes). Now I would like to treat these three variables as categorical variables, so I would like to get a frequency table of isNoun, isVerb and labels, instead of a mean. I've tried this with the function as.factor(isNoun), but it didn't work.
Upvotes: 0
Views: 304
Reputation: 8488
The problem is that you first create a matrix, whose elements must be of the same type, and then you convert to data frame. You have to create the data frame from the beginning:
alles <- data.frame(isNoun = as.factor(isNoun),
isVerb = as.factor(isVerb),
length,
labels = as.factor(labels))
Upvotes: 2