Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I have a data frame like this

User     OS
A        Windows
A        Linux
B        MacOS
C        Linux
C        FreeBSD
C        Windows
D        Windows  

What I want to do is plot two types of statistics.

  1. The share of users with different number of OSs. So, it would be the fraction of the users with 1 OS, with OS etc.
  2. The share of users with only one OS and more than one OS.

For this I tried using tapply(OS, User, unique). But don't know how to go about plotting the results.

I was wondering if this is the right way and what more would I need to do to to get the plots I wanted.

share|improve this question
if it's really about programming in R, there are quite some plot people on stackoverflow.com that can help you out as well. – Joris Meys Nov 26 '10 at 16:20

1 Answer

up vote 4 down vote accepted

You could try something like

> df <- data.frame(User=sample(LETTERS[1:10], 100, rep=T), 
                   OS=sample(c("Win","Lin","Mac"), 100, rep=T))
> (res <- with(df, tapply(OS, User, function(x) length(unique(x)))))
A B C D E F G H I J 
2 3 3 3 3 3 3 3 3 3 
> barplot(table(res)) # for counts
> barplot(table(ifelse(res==1, "1", "2+")))

Replace table() by prop.table() if you want proportions instead of counts, as suggested by @Chase in a comment to your preceding question.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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