Quick Intro to R
Also see, The BigData Landscape
x <- “Hello World”;
print(x)
#vector
v <- c(1, 2, 3)
print(v)
#sequence
s <- 1:5
print(s)
#matrix
m <- matrix(data = 1:6, nrow = 2, ncol = 3)
#array
a <- array(data = 1:8, dim = c(2, 2, 2))
print(a)
#list heterogenous
l <- list(TRUE, 123L, 2.3, “abc”)
#creating a factor
categories <- c(“Male”, “Female”, “Male”, “Male”)
factor <- factor(categories)
print(factor)
print(levels(factor))
print(unclass(factor))
#Creating Data Frame – for working with tabular data
df <- data.frame(Name = c(“Cat”, “Dog”, “Cow”, “Pig”), HowMany = c(5, 10, 15, 20), IsPet = c(TRUE, TRUE, FALSE, FALSE))
print(df)
print(2:4,)
print(df$IsPet == TRUE,)
print(df$Name %in% c(“Cat”, “Cow”))
#Vectorized language
print(c(1, 2, 3) + c(3, 4, 5))
#Installing packages
install.packages(“dplyr”)
#Loading Packages
library(“dplyr”)
#Help ?
? data.frame
#Named versus Ordered Args
m <- matrix(data = 1:6, nrow = 2, ncol = 3)
n <- matrix(1:6, 2, 3)
m == n
identical(m, n)
Leave a Reply