R Useful Stuff
R Useful Stuff
#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
#---------------------------------------------------------------
Anything regarding strings following formulas:
gsub, sub, strsplit, grep, grepl
#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
Optimizing R code Course
microbenchmark function(test several stuff together and see which takes longer)
system.time function to check how much time it takes to compute something
Never grow vectors!
Profvis function to see where the bottlenecks are in your code
Parallel programming - this one seems useless to me for now. Will look into it
little later.
#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
Writing to specific row and column in R. Use package openxlsx, function writeData()
#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
library(rMouse) for controlling mouse and clicking stuff on keyboard. Can be
powerful if used right.
#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
combn function for all combinations of numbers. combn(Numbers,9)
9 specifies how many elements it should select
#----------------------------------------------------------------------------------
-----------------------------------------
6.paste for concatenating vectors and paste0 for sep = "" by default.
2nd Section
1. library(stringr)
4. str_sub is the same as Mid in SQL. first argument is a string, second argument
is the position and third is
the number of strings to go after. For example:
String <- c("Hello World!")
str_sub(String,1,-2) this will return: "Hello World" without exclamation mark
6. str_count is the function for counting how many times does the pattern repeat.
7. str_subset is the function to get the strings that match the pattern.
8. str_length gives you the length of all the strings in a vector, while length
gives you the length of the vector.
Example: Vector <- c("Hel","asdasd","dewfewf","ffqwfqw"). length(Vector) output:4
str_length(Vector) Output: 3, 6, 7, 7
#----------------------------------------------------------------------------------
--------
names(as.list(.GlobalEnv)), this gets names from the Global Environment
useful for lapply function and like.
#----------------------------------------------------------------------------------
--------
Send email via gmail
send.mail(from="[email protected]",
to= "[email protected]",
subject= "test" ,
body="ტესტ",
encoding = "utf-8",
html=T,
smtp=list(host.name = "smtp.gmail.com",
port = 465,
user.name = "[email protected]",
passwd = "hehexdkyskid12",
ssl = T),
authenticate=T,
attach.files = paste0("C:\\Users\\TBCBank\\Desktop\\New Folder\\"...)
)