1

I am doing this research using RStudio that can generate/tabulate labels that will also show 0 counts. I am using the 'cro and 'calc_cro function in RStudio.

My sample codes:

S4 <- cro(data$S4, list(total(), data$S3A_1, data$User, data$S4, data$S8rev, data$S5rev))

and

S9 <- calc_cro(data, mrset(S9_1 %to% S9_993_1),list(total(), S3A_1, User, S4, S8rev, S5rev))

For example, S4 is a variable code for size, i.e. (1 - Small, 2 - Medium, 3 - Large).

Moreover, sample survey results show only small and large respondents. My codes results will be more like this:

Size Total Male Female ...
Small 15 8 7 ...
Large 15 8 7 ...

Can someone help me to modify my codes that are using to show also labels with 0 counts like this:

Size Total Male Female ...
Small 15 8 7 ...
Medium 0 0 0 ...
Large 15 8 7 ...

I am thinking right now that this is not possible because R can't determine the range of the labels (in my example 1-3, how would it know that it is 1 to 3 and doesn't have 4,5,..., x number of labels).

However, there are still thoughts in my head saying if I can define/include the range in my codes, would it be possible to make this work?

Here's my dput...

structure(list(RespID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 
28, 29, 30), S4 = c(1, 3, 3, 3, 3, 3, 3, 1, 3, 1, 1, 1, 3, 3, 
1, 3, 1, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1), Gender = c(1, 
1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 
2, 1, 2, 1, 1, 2, 2, 2), Area = c(2, 2, 2, 4, 1, 1, 3, 4, 1, 
1, 1, 4, 2, 3, 1, 3, 3, 1, 3, 4, 1, 3, 3, 4, 4, 3, 1, 1, 4, 1
)), row.names = c(NA, -30L), class = c("tbl_df", "tbl", "data.frame"
))

With data labels:

S4 = {1 - Small, 2 - Medium, 3 - Large} 
Gender = {1 - Male, 2 - Female}
Area = {1 - North, 2 - East, 3 - South, 4 - North}
EibwenVBA
  • 37
  • 6
  • Please show a sample reproducible example with `dput` – akrun Jan 15 '21 at 05:16
  • Sorry, what is ```dput```? – EibwenVBA Jan 15 '21 at 05:33
  • If you do `dput(data)` there will be an output on the console which you can copy/paste and edit in your post. It gives the structure of your data. If the data is really big, take the `dput(head(data))` Your post have only code and the output got. If we have the structure of data, it is easier to debug – akrun Jan 15 '21 at 05:35
  • Hi and welcome to Stack Overflow! You may want to read our community guidelines on [how to make a great R reproducible example](https://stackoverflow.com/a/5963610/6574038) ;) – jay.sf Jan 15 '21 at 05:45
  • Apologies, but I am new in here. I've already edited and insert my dput. Thanks! – EibwenVBA Jan 15 '21 at 06:04
  • Can you please put your question in simple terms? I am not getting from which you are using `cro` and `calc-cro` – AnilGoyal Jan 15 '21 at 06:32
  • I am using ```cro``` for single-answered question and ```calc_cro``` for multiple response question. – EibwenVBA Jan 15 '21 at 06:39
  • @EibwenVBA They meant from which package the functions stem from, please add `library`. – jay.sf Jan 15 '21 at 07:01
  • @jay.sf sorry, it came from the package ```expss``` – EibwenVBA Jan 15 '21 at 07:17

1 Answers1

0

I think you just misunderstood function usage, try

library("expss")
S4 <- cro(data$S4, col_vars=list("S3A_1", "User", "S4", "S8rev", "S5rev"))
S4
# |         |              | S3A_1 | User | S4 | S8rev | S5rev |
# | ------- | ------------ | ----- | ---- | -- | ----- | ----- |
# | data$S4 |            1 |    15 |   15 | 15 |    15 |    15 |
# |         |            3 |    15 |   15 | 15 |    15 |    15 |
# |         | #Total cases |    30 |   30 | 30 |    30 |    30 |

I'm not very sure, though, what you're actually asking.

jay.sf
  • 60,139
  • 8
  • 53
  • 110