R programming
R programming
Programs List:
1) Write a R-Program for to compute mean, median, minimum, maximum, variance, standard
deviation, skewness and quantities (Q1, Q2, Q3)
2) Write an R Program that includes variables, constants, and data types.
3) Write an R Program that include different operators, control structures, default values for
arguments, returning complex objects.
4) Write a R Program for calculating cumulative sums and products, minima, maxima
and calculus.
5) Write a R-Program for finding stationary distribution of markov chains.
6) Write a R Program that include linear algebra operations on vectors and matrices.
7) Write a R Program for any visual representation of an object with creating graphs using
graphic functions: Hist(), Linechart(), Pie()
8) Write a R Program for any visual representation of an object with creating graphs using
graphic functions: Plot(), Box plot(), Scatter plots()
9) Write R Program for any dataset containing data frame objects, indexing and subs
setting data frames and employ manipulating and analyzing data.
10) Write a Program to create any application of linear regression in multivariate context for
predictive purpose.
Lab-1:
Lab-2:
Write an R Program that includes variables, constants, and data types.
# Constants
PI <- 3.14159
GREETING <- "Hello World!"
# Variables
age <- 30
name <- "Alice"
height <- 165.5
is_student<- TRUE
# Printing constants and variables
cat("Constants:\n")
cat("PI:", PI, "\n")
cat("GREETING:", GREETING, "\n\n")
cat("Variables:\n")
cat("Name:", name, "\n")
cat("Age:", age, "\n")
cat("Height:", height,"cm\n")
cat("Is Student:", is_student, "\n")
#Checking datatypes
cat("\n Data Types:\ n")
cat("Name is of type:", class(name), "\n")
cat("Age is of type:", class(age), "\n")
cat("Height is of type:", class(height), "\n")
cat("Is Student is of type:", class(is_student),"\n")
Lab-3:
Write an R Program that include different operators, control structures, default values for
arguments, returning complex objects
Lab-4:
Write a R Program for calculating cumulative sums and products, minima, maxima and
calculus.
#Cumulative product
cumulative_product <- cumprod(data)
cat("CumulativeProduct:\n")
cat(cumulative_product,"\n\n")
Lab-5:
Write a R-Program for finding stationary distribution of markov chains
library (Matrix)
Lab-6:
Write a R Program that include linear algebra operations on vectors and matrices
#Create vectors
vec1 <- c(1, 2, 3)
vec2 <- c(4, 5, 6)
#Vector algebra
sum<- vec1 + vec2
diff <- vec1 - vec2
prod<- sum(vec1 * vec2)
#Create matrices
mat1 <- matrix(1:6, nrow = 2,ncol=2,byrow=T)
print(mat1)
#Matrix algebra
msum<- mat1 + mat2
msub<- mat1-mat2
mmul<- mat1 %*% mat2
Prepared By: K C Silpa, Asst. Professor. Dept. of BCA Page 9
R Programming Lab Manual VVFGC, Tumkur
Lab-7:
Write a R Program for any visual representation of an object with creating graphs
using graphic functions: Hist(), Linechart(), Pie()
Par(“mar”)
Par(mar=c(1,1,1,1))
#Sample data
data <- c(10, 15, 20, 25, 30, 35, 40, 45, 50, 55)
categories <- c("A", "B", "C", "D", "E")
#Create a histogram
hist(data, col = "green", main = "Histogram ", xlab = "Values", ylab = "Frequency")
Lab-8:
Write a R Program for any visual representation of an object with creating graphs
using graphic functions: Plot(), Box plot(), Scatter plots()
x<-c(1,2,3,4,5)
y<-c(2,3,5,7,8)
#Create a scatter plot using plot()
plot(x,y,main="Scatter Plot using plot()",xlab="X-AxisLabel",ylab="Y-
AxisLabel",col="blue",pch=16)
y<-2*x+rnorm(50)
plot(x,y,col="blue",xlab="XValues",ylab="YValues",main="Scatterplot")
#dev.off()
Write R Program for any dataset containing data frame objects, indexing and sub setting
data frames and employ manipulating and analyzing data.
Write a Program to create any application of linear regression in multivariate context for
predictive purpose.
T1<-c(15,17,8,19,20, 12, 13, 15, 15, 16)
T2<-c(13,15,15,16,15,17,10,19,20,13)
T3<-c(16,15,15, 16, 18, 17, 10, 19,20,11)
Finalexam<-c(70,65,65,75,85,50,40,90,87,60)
result<-1m(Finalexam~T1+T2+T3)
print(result)
install.packages("car")
avplots (result)