Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

One way to do this is to use rxSummary() to compute the group sums and then calculate the group percentages from these categorical counts.

 

Here is a simple example that shows how to do this:

df <- data.frame(g = c('1', '0', '1', '0'), a=c(1, 2, 3, 4)) 
sums.within.g <- rxSummary(a ~ g, data = df, summaryStats = "Sum") 
sums.within.g <- sums.within.g$categorical[[1]][,3]

numRows <- length(unique(df$g)) 
totSum <- cumsum(sums.within.g) 
totSum <- totSum[length(totSum)] 
df.percentages <- sums.within.g / totSum 
names(df.percentages) <- levels(df$g)

> df.percentages 
 0 1 
0.6 0.4

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×