0
votes

Here's the problem

With this data table

dt <- data.table( Type=c("E", "E", "B", "B","B","B","C",NA), ID=c(1,2,3,4,5,6,7,6), Frequency=c(17, 6, 3,8, 12,8,9,10))

The summarytools package frequency function gives the following result:

summarytools::freq(dt,weights=dt$Frequency)

. Freq % Valid % Valid Cum. % Total % Total Cum.


    B   31.00     49.21          49.21     42.47          42.47
    C    9.00     14.29          63.49     12.33          54.79
    E   23.00     36.51         100.00     31.51          86.30
 <NA>   10.00                              13.70         100.00
Total   73.00    100.00         100.00    100.00         100.00

This takes weights in account and also entire data table but

is not able to give me percentages which include the #NA counts

(Only gives valid percentage counts)

The function 'freq' from package 'questionr' gives that. See additional "%" column, before "val%" column

questionr::freq(dt$Type)

. n % val%

B 4 50.0 57.1
C 1 12.5 14.3
E 2 25.0 28.6
NA 1 12.5 NA
4 rows

But this second function does not accept

1.weights (column Frequency in my example)

2.Entire data table ( rather than specifying individual columns)

Maybe a better function is out there or even some deft lines of code to add "%" functionality in the first function? Thanks!

1
I get a more complex result (a list with three elements) from the first code. Furthermore there is a colum: "% Total" which appears to already have what you are requesting. Perhaps you are using an out-of-date version of the package?IRTFM
Thanks you are correct. Please post as answer and I will accept.DashingQuark

1 Answers

1
votes

I get a more complex result (a list with three elements) from the first code. Furthermore there is a column: "% Total" which appears to already have what you are requesting. Perhaps you are using an out-of-date version of the package?