R-programming -Final Lab Manual-2022 (1)
R-programming -Final Lab Manual-2022 (1)
(ADDITION,SUBTRACTION, MULTIPLICATION)
AIM:
ALGORITHM:
AIM:
ALGORITHM:
AIM:
ALGORITHM:
PROGRAM:
In the drive E create a directory “Sample”
In the note pad type the data shown in k1.csv
setwd("E:\\Sample")
getwd()
sample = read.csv("k1.csv")
data <- read.csv("k1.csv")
head(sample)
# Create a data frame.
barplot(data$salary,main="SALARY",
ylab='salary',
xlab ="name",
col="blue",
horiz=FALSE,beside=TRUE)
hist(data$salary)
colnames<-c(data$name)
colnames
rowname<-c(data$sa)
OUTPUT:
RESULT:
EX NO:4 Random Number Generator In R.
AIM:
ALGORITHM:
PROGRAM:
df <- data.frame("Serial_number" = 1:5, "Age" = c(20, 21, 17, 23,
19), "Name" = c("raja","ramu", "ravi", "raghu", "rajesh"))
# Sort by age ascending order
newdataAsc <- df[order(df$Age),]
newdataAsc
# sorting is descending order
> newdataDsc> newdataDsc <- df[order(-df$Age),] > newdataAsc
OUTPUT:
RESULT:
EX NO:5 Calculating Mean, Median,
Standard Deviation, Variance For
A Given Set Of Data
AIM:
ALGORITHM:
PROGRAM:
setwd("E:\\Sample")
getwd()
sample2 = read.csv("k5.csv")
data <- read.csv("k5.csv")
data
mean(data$x)
median(data$x)
sd(data$x)
var(data$x)
#mediam absolute variance
mad(data$x)
max(data$x)
min(data$x)
sum(data$x)
length(data$x)
OUTPUT:
RESULT:
EX NO:6 Factorial Using Recursive
Function
AIM:
ALGORITHM:
PROGRAM:
rec_fac <- function(x){
if(x==0 || x==1){
return(1)
} else {
return(x*rec_fac(x-1))
}
}
var = readline();
var = as.integer(var)
print(var)
x<-var
f<-rec_fac(x)
t1<-c("factorial",x,"is",f )
t1
OUTPUT:
RESULT:
EX NO:7 Factorial Using Recursive
Function
AIM:
ALGORITHM:
PROGRAM:
In the drive E create a directory “Sample”
In the note pad type the data shown in k3.csv
(I am attaching the k3.csv file for your kind perusal)
setwd("E:\\Sample")
getwd()
sample1 = read.csv("k3.csv")
data <- read.csv("k3.csv")
head(sample1)
# Create a data frame.
RESULT:
EX NO:8 Plot the Graph for Normal
Distribution
AIM:
ALGORITHM:
PROGRAM:
# Create a sequence of numbers between -5 and 5 incrementing it
by 0.2.
x <- seq(-5, 5, by = .1)
# The mean here is 1.0 and standard deviation as 0.
y <- dnorm(x, mean =0, sd = 1)
#Plot the Graph
plot(x,y)
OUTPUT:
RESULT:
EX NO:9 Time Series Graph For A Given Set
Of Data
AIM:
ALGORITHM:
PROGRAM:
sales_ice <- c(450, 613, 466, 205.7,571.0, 622.0, 851.4, 621.4,875.3,
979.7, 927.5,14.45)
sales_cooldrink <- c(550, 713, 566, 687.2,110, 120, 72.4,
814.4,423.5, 98.7, 741.4,345.3)
combined.sales <- matrix(c(sales_ice,sales_cooldrink),nrow = 12)
sales.timeseries <- ts(combined.sales,start = c(2021,1),frequency =
12)
plot(sales.timeseries, main = "Showing ice cream – cooldrink sales")
print(sales.timeseries)
OUTPUT:
RESULT:
EX NO:10 Hypothesis Testing Using R
Programming
AIM:
ALGORITHM:
PROGRAM:
x <- sample(c(1:100),size=20,replace=TRUE)
y <- sample(c(1:100),size=20,replace=TRUE)
t1<- c("value of variable x")
t1
x
t2<- c("value of variable y")
y
t3<-c("t test ")
t3
t.test(x,y)
t4<-c("Correlation between x and y")
t4
cor(x,y)
t5<-c("covarience")
t5
cov(x,y)
OUTPUT:
RESULT: