dobero
dobero

Reputation: 71

compute with the values in table() function

I am new to R and stuck in computing the proportions of two values.

I got to this point with using the table() function

table(data$subscriptions, data$pickup)

The subscriptions data is divided into casual and registered users per station. Basically, I want to compute the proportion of casual users per station.

Should I be using tapply() to solve this?

tab

Thankful for any help!

Upvotes: 0

Views: 47

Answers (1)

Karolis Koncevičius
Karolis Koncevičius

Reputation: 9656

There is a function prop.table() that is called on the table to turn counts into proportions. So in your case try something like this:

tab <- table(data$subscriptions, data$pickup)
prop.table(tab, 2)

Where 2 is a margin on which the proportions will be calculated. 2 means columns in your case.

Also see help(prop.table)

Upvotes: 3

Related Questions