Use for loops to do something with every value in a vector/list or to do something a certain number of times
for (identifier in vector/list){
do something
}
for (identifier in 1:somenumber){
do something
}
Use if else statements to only do something if one criteria (or more) is fulfilled
if (value1 == value2){
do this
}
else if (value1 < value3){
do this
}
else {
do something else
}
library(obdc)
con <- dbConnect(odbc(), Driver = "SQL Server", Server = e.g "PSADS004", Database = e.g. "TrailBlazer", trusted_connection = TRUE)
Note: you must connect to a database first
result <- dbGetQuery(conn = con, statement = "SELECT * FROM table1...")
mean(df$column) #Returns the mean
median(df$column) #Returns the median
sd(df$column) #Returns the standard deviation
quantile(df$column) #Returns the 0, 25th, 50th, 100th quantiles
summary(df) #Returns summary stats for all
#columns in df
library(psych)
describeBy(df, group) #Returns statistics by group
The group argument should be a factor
Use functions to repeat common actions and to help compartmentalise your code
function_name <- function(argument_1, argument_2, ...){
do something
return(return_value)
}