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
DF <- data.frame(Pr = runif(100, min = 0, max = 1), | |
Index = 1:100) | |
DF$rand<- runif(100, 0, 1) | |
DF$samp<- 1 | |
DF[ DF$rand > (1- DF$Pr) & DF$rand < DF$Pr, "samp"] <- 2 | |
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("dygraphs") | |
library("lubridate") | |
library("xts") | |
months <- data.frame(month = 1:12, year_1 = 401:412, year _2 = 501:512) | |
test$month<- paste("2000-", test$month, "-01") | |
test$month<- ymd(test$month) | |
dygraph(xts(test[, 2:3], test$month )) |
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
# Tidy directed network | |
library(dplyr) | |
df <- data_frame( Var_1 = c("x", "y", "z", "z"), | |
Var_2 = c("y", "z", "x", "y"), | |
Weight= 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
library(dplyr) | |
library(ggplot2) | |
library(microbenchmark) | |
x1 <- bind_rows(lapply(1:10, function(x)iris)) | |
x2 <-data.frame();for(i in 1:10){x2<-rbind(x2,iris)} | |
all.equal(x1, x2) | |
f1 <- function(vector){ | |
bind_rows(lapply(vector, function(x)iris)) | |
} |
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(DiagrammeR) | |
files <- list.files(recursive = TRUE) | |
file_df <- data_frame(files = files, | |
type = tools::file_ext(files)) | |
file_df <- filter(file_df, type != "") | |
file_df$shape <- ifelse(file_df$type %in% c("R", "Rmd"), "circle", "square") | |
dependencies <- data_frame( |
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(ggplot2) | |
df <- mtcars %>% | |
group_by(cyl) %>% | |
mutate(n = 1: n()) | |
ggplot(df, aes(x = cyl, y = n)) + geom_point() |
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(purrr) | |
library(dplyr) | |
library(microbenchmark) | |
list <- map(1:1000, function(x) rep("a", 100)) | |
f1 <- function(list){ | |
reduce(list, c) | |
} |
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
classify <- function(value, function_char){ | |
fun <- get(paste0("as.", function_char)) | |
fun(value) | |
} | |
mtcars_char[] <- map(mtcars_char, as.character) | |
map(mtcars_char, class) | |
mtcars_char[] <- map2(mtcars_char, | |
map_chr(mtcars, class), | |
~classify(.x, .y)) |
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(stacksurveyr) | |
library(dplyr) | |
library(tidyr) | |
library(purrr) | |
library(stringr) | |
library(ggplot2) | |
library(forcats) | |
df <- stack_survey %>% | |
select(respondent_id, gender, tech_do) %>% |
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
`%d%` <- function(vars, list){ | |
for(i in vars){ | |
assign(i, list[[i]], envir = .GlobalEnv) | |
} | |
} | |
c("mpg", "cyl") %d% mtcars | |
test_list = list(cars = mtcars, | |
numbers = 1:500, |
OlderNewer