Skip to content

Instantly share code, notes, and snippets.

@ndricca
Created June 27, 2018 08:29
Show Gist options
  • Save ndricca/95dca0530e4a1be6ab5be52b7753e8a5 to your computer and use it in GitHub Desktop.
Save ndricca/95dca0530e4a1be6ab5be52b7753e8a5 to your computer and use it in GitHub Desktop.
dplyr conteggio e proporzione in riga per grouppi
rm(list = ls())
library(dplyr)
df <- data_frame(y = rnorm(10,2),
x1 = as.factor(rbinom(10,1,0.5)),
x2 = as.factor(rep(letters[1:2],5)))
df
df %>%
add_count() %>%
add_count(x1) %>%
mutate(prop = nn/n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment