SML Practicals All
SML Practicals All
Practical No 2
Write Program to-
i. Demonstrate use of the R-Number
>a = 12
> class(a)
[1] "numeric"
> b = 12L
> class(b)
[1] "integer"
> c = 2+3i
> class(c)
[1] "complex"
Practical No 3
c. Find the dimensions of the data set and view the names of the variables.
Hint: Use dim( ) and names( ) function.
# Find the dimensions of the mtcars dataset
dim(mtcars)
# Find the name of each row in the first column of the mtcars dataset
rownames(mtcars)
Practical No 4
Write a program to-
a. Find the lowest or highest value in a data set.
Hint: Use min( ) and max( ) functions.
b. Find the index position of the max and min value in the table.
Hint: use which.max( ) and which.min( ) functions.
# Find the index position of the max value in the mpg column
which.max(mtcars$mpg)
# Find the index position of the min value in the mpg column
which.min(mtcars$mpg)
Practical No 5
Write programs to calculate Measures of Central tendency.
a. Import data into R.
SML
# Load the mtcars dataset
data(mtcars)
b. Calculate the Mean (Average value) of a variable from the given data
set.
c. Find the Median (Mid-Point value) of the variable from the given data
set.
d. Calculate the mode for the variable from the given data set.( by sorting
the column of the dataframe and by using the ‘modest’ package).
e. Calculate the Percentile of the variable from the given data set.
Practical No 6
Write programs to-
a. Print Original Data Frame, Modified Frequency Table, Cumulative
Frequency Table, Relative Frequency Table.
Practical No 7
Write programs to calculate-Variance, Standard Deviation, Range, Mean
Deviation for the given data.
# Load the mtcars dataset
data(mtcars)
Practical No 8
Write Programs to graphically represent mode and median of the given data.
a. Draw Histogram for the given data.
Practical No 9
Write a Program to calculate Skewness for the given data.
# Load the mtcars dataset
data(mtcars)
SML
# Calculate the skewness of the mpg variable
skewness_mpg <- (sum((mtcars$mpg - mean(mtcars$mpg))^3) /
length(mtcars$mpg)) / (sd(mtcars$mpg))^3
print(paste("Skewness of mpg:", skewness_mpg))
Practical No 10
Write a Program to draw a scatterplot for two variables for the given dataset.
# Load the mtcars dataset
data(mtcars)
b. Compute correlation in R.
Practical No 12
abline(linear_regression_mpg_wt)
SML
Practical No 14
num_spades <- 13
total_cards <- 52
Practical No 18
# Define probabilities
pRain <- 0.20
SML
pCloudy <- 0.40
pCloudyRain <- 0.85
Practical No 19
return(y_new)
}
SML
# Define the x and y values
x <- c(0, 1, 2, 3, 4)
y <- c(1, 2, 5, 10, 17)
Practical No 20
return(y_new)
}
# Define the x and y values
x <- c(0, 1, 2, 3, 4)
y <- c(1, 2, 5, 10, 17)
Practical No 21
return(y_new)
}
Practical No 24
Practical No 25
Practical No 26