1. Generate a vector of Serial Numbers or Item Numbers using R

# i.e. Item1, Item2, Item3, Item4, Item5, Item6 etc.
1:6
seq(1,6)

paste("Item", 1:6, sep = "")
item_num <- paste("Item", 1:6, sep = "")
class(item_num)

data.frame(item_num)

paste("Item", seq(1,6), sep = "")

head(mtcars)

#Summary
1:6
seq(1:6)
paste("SerialNum", 1:6, sep="")

2. Change the Column Names of a Data Frame using R

head(mtcars)

#Col1, Col2 .... Coln

m <- mtcars

dim(m)

col_name <- paste("Col", 1:11, sep = "")

head(m)
names(m) <- col_name
head(m)

#Change the Row Names to Row1, Row2, Row3 .... Row32

dim(m)

row_names <- paste("Row", 1:32, sep = "")

rownames(m) <- row_names
head(m)
tail(m)

#Summary
dim(m)
names(m) <- paste("Col", 1:11, sep = "") #Column Names
rownames(m) <- paste("Row", 1:32, sep = "") #Row Names

3. Find match between two vectors using R

#R3 - Find match between two vectors

a <-c('a','b','c','d','e','f','g')
b <-c("e", "f", "g", "h", "i", "j")

a %in% b
a[a %in% b]

a <-list('a','b','c','d','e','f','g')
b <-list("e", "f", "g", "h", "i", "j")

a %in% b
a[a %in% b]

4. Find mismatch between two vectors using R

# 4. Find mismatch between two vectors using R

x <-c('a','b','c','d','e','f','g')
y <-c("e", "f", "g", "h", "i", "j")  #Both single and double quotes can be used

#Item in x which are not in y
x[!(x %in% y)]
setdiff(x,y)

#Items in y which are not in x
y[!(y %in% x)]
setdiff(y,x)