1 minute read

set.seed()

Using this function, the reproducible results can be retrieved for the later use.

set.seed(7)
#create data frame
df <- data.frame(var1 = rnorm(10),
                 var2 = rnorm(10),
                 var3 = rnorm(10))
#
#
#
set.seed(7)
#create second data frame
df2 <- data.frame(var1 = rnorm(10),
                  var2 = rnorm(10),
                  var3 = rnorm(10))

#view data frame
df2 # it should be same as first dataframe
error in plot.new() : figure margins too large
# Solution 1 : Increaing size of the Plot Panel
plot(1:30)

# Solution 2 : Par()
par(mar = c(1, 1, 1, 1))

# Solution 3 :  
dev.off()
Plot

Scatter Plot

# Scatter Plot
pairs(college[, 2:10])
attach()

It makes the columns be accessible with using variable names.

attach(iris)
head(Sepal.Width)
fix()

It enables to change the object that is assigned into the function parameters.

f <- function(a, b) {+ a + b}
$

It extracts the subset from the data frame or list.

boxplot(college$Outstate ~ college$Elite, college, ylab = "out of state tuition", xlab = "Private College(private=1, non-private=0)")
Data.frame

It creates data frames, tightly coupled collections of variables which share many of the properties of matrices and of lists, used as the fundamental data structure by most of R’s modeling software.

Data_Frame <- data.frame (
  Players = c("Tom", "Smith", "Kevin"),
  Duration = c(60, 30, 45)
)

# There are three ways to access the column
Data_Frame[1]
Data_Frame[["Players"]]
Data_Frame$Players
Elite=rep("No",nrow(college))
Elite[college$Top10perc >50]="Yes"
Elite=as.factor(Elite)
college=data.frame(college,Elite)
rep()

It replicates elements following the configuration defined by each, times, len.

x <- letters[1:3]        # Creating vector
x                        # "a" "b" "c"

rep(x, each = 4)         # Apply rep with each argument
# "a" "a" "a" "a" b" "b" "b" "b" "c" "c" "c" "c"

Categories:

Updated:

Leave a comment