Snippets Collections
mutate(var_name = str_replace(var_name, "Q", "q"))
mutate(r_varname = ifelse(p_varname > 0.05, "-", r_varname))
install.packages("tidyverse")
library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) + 
       geom_point() +
       labs(x = bquote('x axis'~(Å^2)), y = "y axis") +
       #or
       #labs(x = bquote('x axis'~(ring(A)^2)), y = "y axis") 
       theme_bw()
theme(strip.background = element_rect(colour = "black", fill = "white"))
library(tidyverse)
library(purrr)
library(zoo)

data %>% 
  group_by(group_name) %>% 
  nest() %>% 
  mutate(data = pmap(list(data),
                     ~ mutate(.x,
                              r_mean = lag(rollmean(x = var_name, k = 7, fill = NA, align = "right")))
                     )
  ) %>% 
  unnest(cols = data)
try(log("not a number"), silent = TRUE)
print("errors can't stop me")
library(ggplot2)
library("ggpubr")
theme_set(
  theme_bw() +
    theme(legend.position = "top")
  )
#Outlier Removal Function
remove_outliers <- function(dataframe, column, na.rm = TRUE) {
  Q1 <- quantile(column, .25)
  Q3 <- quantile(column, .75)
  IQR <- IQR(column)
  dataframe <- subset(dataframe, column> (Q1 - 1.5*IQR) & column< (Q3 + 1.5*IQR))
}

#Not looping
df_1 <-remove_outliers(df_1,df_1$Column1)

#Loop through a list of column names
for(i in Column_List){
  df_1 <- remove_outliers(df_1, df_1[[i]])
}  
# Account
statement <- read.csv("statement.csv", stringsAsFactors = F, sep = ";")

# Get rid of irrelevant columns
statement <- statement[2:13]

# Statement money flows
rahavoog <- statement[statement$Reatüüp == 20,]
rahavoog$Summa <- as.numeric(gsub(",", ".", rahavoog$Summa))

str_order(
  x,
  decreasing = FALSE,
  na_last = TRUE,
  locale = "en",
  numeric = FALSE,
  ...
)
  
# Examples 
  
  str_order(letters)
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26
str_sort(letters)
#>  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
#> [20] "t" "u" "v" "w" "x" "y" "z"

str_order(letters, locale = "haw")
#>  [1]  1  5  9 15 21  2  3  4  6  7  8 10 11 12 13 14 16 17 18 19 20 22 23 24 25
#> [26] 26
str_sort(letters, locale = "haw")
#>  [1] "a" "e" "i" "o" "u" "b" "c" "d" "f" "g" "h" "j" "k" "l" "m" "n" "p" "q" "r"
#> [20] "s" "t" "v" "w" "x" "y" "z"

x <- c("100a10", "100a5", "2b", "2a")
str_sort(x)
#> [1] "100a10" "100a5"  "2a"     "2b"    
str_sort(x, numeric = TRUE)
#> [1] "2a"     "2b"     "100a5"  "100a10"
dir <- "directory of archives"

directories <- as.list(file.path(dir, list.files(dir, pattern = ".*.csv")))

dataframes <- map(directories , rio::import)

dataset <- plyr::ldply(dataframes, data.frame)
var <- "mpg"
#Doesn't work
mtcars$var
#These both work, but note that what they return is different
# the first is a vector, the second is a data.frame
mtcars[[var]]
mtcars[var]
# make data frame 
a <- data.frame( x =  c(1,2,3,4)) 
b <- data.frame( y =  c(1,2,3,4,5,6))
subset(b, !(y %in% a$x)) #Pulls values from frame b that are not in frame a
library(tidyverse)

df$column <- df$column str_to_title(df$column) #Standardize caps

#Two options 
df$column <- str_replace(df$column, "old", "new") #Option 1, uses str_replace
df$column <- gsub("old", "new", df$column) #Option 2, uses str_replace  
x <- data$variable_xaxis
y <- data$variable_yaxis

plot(x, y, main = "Main title",
     xlab = "X axis title", ylab = "Y axis title",
     pch = 19, frame = FALSE)
abline(lm(y ~ x, data = mtcars), col = "blue")
g <- ggplot(data_set, aes(x-variable, y-variable) 

g + geom_point()
qplot(x-coordinate, y-coordinate, data=data_frame, geom = c("point", "smooth")
x <- data$variable_xaxis
y <- data$variable_yaxis

plot(x, y, main = "Main title",
     xlab = "X axis title", ylab = "Y axis title",
     pch = 19, frame = FALSE)
abline(lm(y ~ x, data = mtcars), col = "blue")
star

Mon Apr 26 2021 17:39:49 GMT+0000 (UTC)

#r
star

Fri Apr 23 2021 20:35:43 GMT+0000 (UTC) https://stackoverflow.com/questions/66630759/model-formula-for-two-way-interactions-between-one-set-of-variables-and-another/66630789#66630789

#r
star

Mon Apr 12 2021 03:38:09 GMT+0000 (UTC) https://www.tidyverse.org/

#r
star

Thu Mar 25 2021 16:57:42 GMT+0000 (UTC)

#r
star

Wed Mar 24 2021 22:17:16 GMT+0000 (UTC)

#r
star

Wed Mar 24 2021 14:24:49 GMT+0000 (UTC)

#r
star

Wed Mar 24 2021 14:22:53 GMT+0000 (UTC)

#r
star

Sun Mar 21 2021 10:33:11 GMT+0000 (UTC) https://www.datanovia.com/en/lessons/combine-multiple-ggplots-into-a-figure/

#r
star

Mon Mar 15 2021 05:12:08 GMT+0000 (UTC) https://stringr.tidyverse.org/reference/str_order.html

#r
star

Fri Mar 12 2021 19:23:49 GMT+0000 (UTC)

#r
star

Thu Mar 11 2021 14:57:05 GMT+0000 (UTC) https://stackoverflow.com/questions/18222286/dynamically-select-data-frame-columns-using-and-a-character-value

#r
star

Sun Mar 07 2021 02:05:35 GMT+0000 (UTC) https://stackoverflow.com/questions/5812478/how-i-can-select-rows-from-a-dataframe-that-do-not-match

#r
star

Sun Mar 07 2021 02:01:46 GMT+0000 (UTC)

#r
star

Fri Mar 05 2021 12:52:40 GMT+0000 (UTC)

#r
star

Sun Sep 27 2020 20:07:34 GMT+0000 (UTC)

#r
star

Sun Sep 27 2020 14:58:51 GMT+0000 (UTC)

#r
star

Sun Sep 13 2020 17:36:11 GMT+0000 (UTC)

#r

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension