Created
June 26, 2018 06:25
-
-
Save moodymudskipper/3fc9aeb517a3a0435a690e0f9e06ac05 to your computer and use it in GitHub Desktop.
RStudio snippets
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
######### machine learning ########## | |
snippet _hclust | |
model <- hclust(dist(iris[-5]), method="complete") # define model | |
predicted <- cutree(model,k=3) # cut tree (get cluster membership) | |
plot(model) # plot dendogram | |
plot(iris$Sepal.Length, iris$Sepal.Width, col = predicted) # result by 2 variables | |
plot(iris$Sepal.Length, iris$Sepal.Width, col = iris$Species) | |
######### misc ########## | |
# paste clipboard content without the annoying indentation | |
snippet p | |
`r paste(readClipboard(),collapse="\n")` | |
# commented last value | |
snippet lv | |
`r paste("#",capture.output(.Last.value),collapse="\n")` | |
# read.table from text | |
snippet so | |
df <- read.table(header=${1:TRUE},stringsAsFactors=${2:FALSE},text="${3:table}") | |
######### tidyverse ########## | |
snippet libt | |
library(tidyverse) | |
snippet ggp | |
ggplot(${1:data},aes(${2:...})) + | |
geom_${3:...}() | |
# main data wrangling functions by ~alphabetical order | |
snippet ar | |
%>% | |
arrange(${1:...}) | |
snippet bc | |
%>% | |
bind_cols(${1:...}) | |
snippet br | |
%>% | |
bind_rows(${1:...}) | |
snippet co | |
%>% | |
count(${1:...}) | |
snippet col | |
%>% | |
collect() | |
snippet di | |
%>% | |
distinct() | |
snippet fi | |
%>% | |
filter(${1:...}) | |
snippet fj | |
%>% | |
full_join(${1:...}) | |
snippet ij | |
%>% | |
inner_join(${1:...}) | |
snippet lj | |
%>% | |
left_join(${1:...}) | |
snippet rj | |
%>% | |
right_join(${1:...}) | |
snippet sj | |
%>% | |
semi_join(${1:...}) | |
snippet gbs | |
${1:data} %>% | |
group_by(${2:...}) %>% | |
summarize(${3:...}) | |
snippet gb | |
%>% | |
group_by(${1:...}) | |
snippet mu | |
%>% | |
mutate(${1:...}) | |
snippet re | |
%>% | |
rename(${1:...}) | |
snippet rw | |
%>% | |
rowwise(${1:...}) | |
snippet se | |
%>% | |
select(${1:...}) | |
snippet sl | |
%>% | |
slice(${1:...}) | |
snippet su | |
%>% | |
summarize${1:_at}(${2:...}) | |
######### default snippets ########## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment