"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

April 09, 2016

Day #14 - R Working Tips

#Tip #1 - R - Case Sensitive
#Tip #2 - R - Data Stored in memory
#Tip #3 - Assigning variables
var2 <-3
var2
var2 <-"Test"
var2
#Tip #4 - Working with Dates
#Convert character to date using as.Date function
as.Date('2016-04-16')
#Tip #5 - Function to remove non available values (Missing Data)
na.rm = TRUE
#Test for Missing Data
is.na(VariableName)
#Tip #6
#Vectors - Basic Data Structures One Dimensional Arrays
#Created using c command
a_vector <- c(1,2,3,4,5)
a_vector
#Index starts with 1
a_vector[1]
b_vector <- c("Apple","Orange","Banana")
b_vector
b_vector[2]
#Negate - Ignore particular value, Return everything except 1
b_vector[-1]
#Tip #7 - Vector Operations
v1 <- c(2,3,4)
v2 <- c(10,11,12)
v1+v2
#Tip #8 - Lists
#Can hold different data types
emp_details_1 <- list(01,'Siva','India')
emp_details_1
emp_details_2 <- list(02,'TOM','USA')
emp_details_2
#Tip #9 - Data Frame (Store Rows and Columns)
#Row bind
df1 = rbind(emp_details_1,emp_details_2)
df1
#Column bind
df2 = cbind(v1,v2)
df2
#Tip #10 - Empty vector and append elements
a <- vector(mode="numeric", length=0)
b <- vector(mode="numeric", length=0)
a <- c(a,1)
b <- c(b,2)
a
b
#Tip #11 - Merge function - merge based on particular column
#Tip #12 - Factors
# R automatically recognizes
#as.factor converts into factor
#classification uses factors
gender <- c("Male","Female")
gender_cf <- as.factor(gender)
gender_cf
#Matrix Basics
xx <- matrix(c(0.4, 0.6, 0.3, 0.7))
xx
xx <- matrix(c(0.4, 0.6, 0.3, 0.7), nrow=2)
xx
xx <- matrix(c(0.4, 0.6, 0.3, 0.7), nrow=2)
xx <- t(xx)
xx
xx %*% xx
view raw RBasics.R hosted with ❤ by GitHub
Happy Learning!!!

No comments: