I have likert scale data. I want to display them in an easy (for none-R-users) reading way. Important is that it need to be plain text on the console. No graphics or things like the likert
package offers. It not have to be a table()
but it should look like a table - no matter what magic R construct is behind it.
This table is just for a first view when beginning with exploring the dataset.
This is the example data
> set.seed(0)
> lik <- sample(c(0:3, NA), 150, replace=TRUE)
> lik <- factor(lik, levels=0:3, labels=c('no', 'maybe no', 'maybe yes', 'yes'))
> tn <- table(lik, useNA="always")
> tn
lik
no maybe no maybe yes yes <NA>
22 33 34 37 24
I "nice" table could look like this
no maybe no maybe yes yes <NA>
n 24 34 37 29 26
% 36 51 55.5 43.5 39
Please pay attention here on the fact that 37
and 29
are displayed without digits!
If I would use rbind()
here there are digits. See what I tried so far
> tp <- sapply(tn, function(x) { sum(tn) / 100 * x })
> rbind(tn, tp)
no maybe no maybe yes yes <NA>
tn 22 33.0 34 37.0 24
tp 33 49.5 51 55.5 36
A problem with this is, how to set the row names (e.g. tn
-< n
) and how to prevent to printing the numbers in the first row with digits.
I am fully open for suggestion about how likert data could be display nice and easy (in the meaning of: readable for non-R-users e.g. SPSS-users) in plain text.