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
#### Analyse ngrams #### | |
ngram_analyser <- function(text,count_col, n = 2){ | |
tibble(text = text, line = length(text)) -> ori_tb | |
ori_tb %>% | |
tidytext::unnest_tokens(output = phrase, input = text, token = "ngrams", n = n) %>% | |
count(phrase, sort = TRUE) %>% | |
rename(!!sym(count_col):="n") -> ngram_df | |
return(ngram_df) |
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
Sub AnalysisTableFormatter() | |
Dim WS As Excel.Worksheet | |
Dim row_n As Long | |
CurrentWorkbook = ThisWorkbook.FullName | |
For Each WS In ThisWorkbook.Worksheets | |
WS.Activate | |
Columns("A:A").ColumnWidth = 16 | |
Columns("B:B").ColumnWidth = 18 |
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
mt_analyse <- function(df,sample,weight){ | |
df %>% | |
group_by(Week_Date) %>% | |
filter(Sample==sample) %>% | |
mutate_at(vars(X7_Days,X28_Days),~./sum(.)) %>% # Calculate weights | |
mutate_at(vars(Score,Fam_Score,Familiar,Per_Love,Per_Pos,Per_Hate,Per_Burn),list(~.*.data[[weight]])) %>% | |
summarise_at(vars(Score,Fam_Score,Familiar,Per_Love,Per_Pos,Per_Hate,Per_Burn),~sum(.)) | |
} | |
cell_adder <- function(df1, df2, key){ |
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(tidyverse) | |
tinsmen <- c("Andis", | |
"Sterer", | |
"Cliff", | |
"Ken", | |
"Ocean", | |
"Newton", | |
"Brandon", | |
"Jaf", | |
"K Ko", |
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(tidyverse) | |
tibble(c1 = c("B", "A", "C"), | |
c2 = c(2, 4, 3)) -> tb | |
tb %>% | |
slice(match(c1, c("C", "B", "A"))) |
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
Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace '\(','_' } | |
Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace ' ','' } | |
Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace '\)','' } | |
# Another example | |
Get-ChildItem *.Rmd | Rename-Item -NewName { $_.Name -replace 'rajar','digit' } |
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
## Create n number of columns returning the row-wise ranks of values in selected columns | |
tibble(a = c(200, 300, 100, 150), | |
b = c(400, 120, 600, 700), | |
c = c(500, 100, 200, 300)) %>% | |
mutate(ranks = select(., a, b, c) %>% | |
apply(1, function(x){ | |
x %>% | |
order() %>% | |
paste(collapse = ";") |
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(plotly) | |
library(quantmod) | |
getSymbols("AAPL",src='yahoo') | |
# basic example of ohlc charts | |
df <- data.frame(Date=index(AAPL),coredata(AAPL)) | |
df <- tail(df, 30) | |
p <- df %>% |
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(tidyverse) | |
tibble(x1 = c("a", "b", "c"), | |
x2 = c("v", "x", "y"), | |
x3 = c("w", "u", "u")) %>% | |
map(~as_tibble(table(.))) |
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
@echo off | |
set /p host=Please enter host address: | |
set logfile=Log_%host%.log | |
echo Target Host = %host% >%logfile% | |
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping) | |
:Ping | |
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do ( | |
echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile% |