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
https://sebastiansauer.github.io/dplyr_filter/ |
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
To remove a local branch from your machine: | |
``` | |
git branch -d {the_local_branch} (use -D instead to force deletion without checking merged status) | |
``` | |
To remove a remote branch from the server: | |
``` | |
git push origin --delete {the_remote_branch} |
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
Using, e.g., summarise_each, we can plug in ANY function and apply it to all groups!! | |
E.g., getting a boxplot table, by grouping according to a factor, and calculating the moments: | |
Data <- tbl_df ( Factors (str) | FactorValues (dbl) ) | |
BoxMoments <- Data %>% | |
group_by(Factors) %>% | |
summarise_each( funs( Min = min, Max = max, Mean = mean, Median = median, N = n(), | |
LowHinge = boxplot.stats(.)[[1]][2], | |
UpHinge = boxplot.stats(.)[[1]][4] |
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
# using dplyr finctions in non-interactive mode | |
# examples | |
library(plyr) | |
library(dplyr) | |
d1 = data_frame(x = seq(1,20),y = rep(1:10,2),z = rep(1:5,4)) | |
head(d1) | |
#### single table verbs #### |
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
tmydf = setNames(data.frame(t(mydf[,-1])), mydf[,1]) |
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
# ======= MAP pb ============ | |
# Setup | |
N <- 5 | |
pb <- vector(mode = "list",N); for (iP in 1:N) {pb[[iP]] <- progress_estimated(nrow(VCV))} | |
# In MAPPED function | |
add argument: | |
, .pb=NULL |
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
# =============== Filter =================== | |
# You need to use interp (from the lazyeval package) to substitute which_colum by the symbol v1 (and not the string "v1"), as explained in this vignette. | |
filter_criteria <- interp(~ which_column == 1, which_column = as.name("v1")) | |
df %>% filter_(filter_criteria) | |
# OR | |
df %>% filter_(paste0("is.na(`","ABL SJ Equity","`)")) | |
# =============== Mutate =================== | |
mutate_call = lazyeval::interp(~ a + b, a = as.name(col1), b = as.name(col2)) |
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(RColorBrewer) | |
# Function for plotting colors side-by-side | |
pal <- function(col, border = "light gray", ...){ | |
n <- length(col) | |
plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1), | |
axes = FALSE, xlab = "", ylab = "", ...) | |
rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border) | |
} |