Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Date - anything regarding dates:

Run ?strptime in console

#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
#---------------------------------------------------------------
Anything regarding strings following formulas:
gsub, sub, strsplit, grep, grepl

#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------

Extract numbers from a string:


Vector <- c("SummedCollaterals20200131", "SummedCollaterals20200331",
"SummedCollaterals20190131","SummedCollaterals20190331",
"SummedCollaterals20190430","SummedCollaterals20190531")
library(tidyr)
extract_numeric(Vector)

#----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
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

#----------------------------------------------------------------------------------
-----------------------------------------

Stringr R code Course


1st Section
1. Use escape(\) when you want to write special characters in string like brackets
or
some kind of emojis. Much more to learn!
When you use escape and want to write the string with symbols that require escape
symbol, then you should use writeLines() function

2. When used \n starts a new paragraph in a string. Example: writeLines("This is


a \n new paragraph") when printed will look like ->
This is a
new paragraph

3.?Quotes help page for \n and other useful stuff

4. Converting numbers from 1000000 to 1,000,000 use the code: format(Variable,


big.mark = ",")

5.formatC is better than format

6.paste for concatenating vectors and paste0 for sep = "" by default.

2nd Section
1. library(stringr)

2. str_c is same as paste0

3. str_length to return the length of the string

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

5. str_detect is the function for detecting strings, same as grepl.

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

9. str_replace_all, replace pattern string with replacement. works like this:


str_replace_all - > str_replace_all(Vector, pattern = "&", replacement = "and")

#----------------------------------------------------------------------------------
--------
names(as.list(.GlobalEnv)), this gets names from the Global Environment
useful for lapply function and like.

#----------------------------------------------------------------------------------
--------
Send email via gmail

send.mail(from="isali17@freeuni.edu.ge",
to= "nbech17@freeuni.edu.ge",
subject= "test" ,
body="ტესტ",
encoding = "utf-8",
html=T,
smtp=list(host.name = "smtp.gmail.com",
port = 465,
user.name = "isali17@freeuni.edu.ge",
passwd = "hehexdkyskid12",
ssl = T),
authenticate=T,
attach.files = paste0("C:\\Users\\TBCBank\\Desktop\\New Folder\\"...)
)

You might also like