Created
July 21, 2016 09:17
-
-
Save jaehyeon-kim/a64ae3357c3b9e28a63f02d0e1c8d5e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(magrittr) | |
set.seed(1237) | |
set_df <- function() { | |
data.frame(MRN = sample(1:5, 10, replace = TRUE), source = sample(letters[1:20], 10), value = sample(1:10, 10)) | |
} | |
df1 <- set_df() | |
df2 <- set_df() | |
bind_rows(df1, df2) %>% | |
group_by(MRN) %>% | |
summarise(total_value = sum(value), | |
sources = paste(source, collapse = "_"), | |
values = paste(value, collapse = "_")) | |
#Source: local data frame [5 x 4] | |
# | |
#MRN total_value sources values | |
#(int) (int) (chr) (chr) | |
#1 1 33 d_g_i_t_b_s 8_1_9_9_4_2 | |
#2 2 16 c_e_h_c 5_2_1_8 | |
#3 3 5 k 5 | |
#4 4 14 t_l 4_10 | |
#5 5 42 q_l_m_o_p_j_e 7_10_3_6_6_7_3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment