-2
$\begingroup$

Say I have this data

User 1  User 2  Duration
5       2       7-11 months
5       5       Less than 1 month
5       5       4-6 months
5       5       4-6 months
5       4       4-6 months
5       5       2 years
4       6       1 year
4       4       4-6 months
4       8       7-11 months
4       4       2 years
3       3       Less than 1 month
3       3       7-11 months
3       3       1-3 months

To sum the variable, for example, if I want to calculate user1 within 4-6 months, I did that. Now I want to display all the individual values like

       4-6 months  7-11 months  1-3 months
User1    values      values       values
User2    values      values       values

How do I get this kind of output?

Till now I have used this

df %>% group_by(Duration) %>% summarise(count=sum(User1, na.rm = TRUE)) %>% filter(Duration=="4-6 months")
$\endgroup$
  • $\begingroup$ You'll get more eyeballs on this question if you take it to stackoverflow.com where it is also on-topic. $\endgroup$ – Spacedman Aug 25 '17 at 16:45
0
$\begingroup$

Check out the xtabs() function. Here are some examples:

https://www.rdocumentation.org/packages/stats/versions/3.4.1/topics/xtabs

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.