edX Course on R (2019)
? - help for that function
Eg: ? sqrt
Assignment: = and <-
vect = c(1, 2, 3)
vect1 = c('A', 'E', 'I')
sequ = seq(0, 100, 2) or c(seq(0, 100, 2))
| | |
| end diff
start
-
sqrt(number or sequence) - gives square root for each element of the vector.
Eg: sqrt(100) or sqrt(sequence)
-
abs(number or sequence) - gives the absolute value.
-
mean(vector) - Find the mean of a vector.
Eg: mean(vect1) mean(df$col)
-
sd(vector) - Find the standard deviation. Same as mean
-
seq(start, end, incr) - creates a vector from start to end with each element differing by incr (similar to np.arange)
-
min(vector) - returns the minimum value
-
max(vector) - returns the max of a vector
-
str(df) - Display the structure of an R object
-
summary(df) - Display the summary of an R object
-
ls() - list of variables
-
read.csv(filename) - Read filename
-
write.csv(filename) - Write to filename
-
rm(var_name) or remove(var_name) - remove a variable or a list of variables (comma separated)
-
which.min(vector) - return the index of the minimum value.
-
which.max(vector) - return the index of the max value.
-
rbind(df1, df2) and cbind(df1, df2) - combine to vectors or dataframes row-wise/column-wise.
-
View(df, title(optional)) - Invoke a spreadsheet-style data viewer on a matrix-like R object.
-
plot(x, y, xlab, ylab) - Plots a graph for x and y (which are R objects) and sets the x-label as xlab and y-label as ylab.
-
nrow(x) - no. of rows in x
-
ncol(x) - no. of columns in x
-
hist(df$col) - plot a histogram
-
table(df$col_1, (optional)df$col_2...) - table uses the cross-classifying factors to build a contingency table of the counts at each combination of factor levels. Length should be same.
-
names(df) - to get or set the name of an object.
Eg: names(x) names(x) <- value
-
tapply(df$col_1, df$col_2, op, (optional)na.rm = T): To remove na values, pass na.rm = T or TRUE a. Split the data by col_2 b. Perform operation on col_1
-
subset(DataFrame, condition) - truncates the dataframe to the given condition
Eg: df_europe = subset(df, Region == "Europe")
-
match(x, table) - return a vector of indices where x is first found in table
Eg: match('Africa', df$Region) | | | vector vector/value
df$new_col = c(1, 2, 3) - Appends this vector to an already existing dataframe df.
Eg: vect = df$col > mean(df$col, na.rm = T)
vect contains True of False based on the condition.
vect = as.numeric(df$col > mean(df$col, na.rm = T))
now vect contains binary values.