Rp
1) Program to illustrate if else
{
a<-c(1,2,3)
b<-c(4,5,6)
if(length(a)==length(b))
{
print("same")
}else{
print("not Same")
}
}
2) Program to illustrate for loop and stop condition
{
for(i in 1:10)
{
print(paste("i=",i))
if(i==5)
{
stop("iteration stopped on condition at i=5")
}
}
}
4) Program to Implement t test
groupA<-c(18,21,24,27,30)
groupB<-c(17,20,23,26,29)
res_ttest<-t.test(groupA,groupB)
res_ttest
5) Programe to write the t apply and s apply functions
values<-c(42,55,38,65,49,72,53,66,41,58)
groups<-factor(c("A","B","A","B","A","B","A","B","A","B"))
mean_by_tapply<-tapply(values, groups, mean)
mean_by_sapply<-sapply(unique(groups),function(group){
mean(values[groups==group])
})
print(mean_by_sapply)
9) Write a Program for graphic funciotns like plot his line chartp pie scatter etc
# Plot
plot(c(1, 2), c(3, 4))
# Histogram
v <- c(12, 24, 16, 38, 21, 13, 55, 17, 39, 10, 60)
hist(v, xlab = "marks", ylab = "frequency", main = "Histogram")
# Line chart
V <- c(13, 22, 28, 7, 31)
plot(V, type = "o", col = "purple", xlab = "Month", ylab = "temperature", main = "Line chart")
# Pie chart
Peoples <- c(23, 56, 20, 63)
city <- c("Mumbai", "Pune", "Chennai", "Bengaluru")
pie(Peoples, labels = city, main = "City Pie Chart", col = rainbow(length(Peoples)))
legend("topright", c("Mumbai", "Pune", "Chennai", "Bengaluru"), cex = 0.5, fill = rainbow(length(Peoples)))
# Box plot
boxplot(mpg ~ cyl, data = mtcars, main = "Mileage Data Boxplot", ylab = "Miles per Gallon (mpg)", xlab = "Number of Cylinders", col = "orange")
# Scatter plot
data <- mtcars[c('wt', 'mpg')]
plot(data$wt, d
ata$mpg, xlab = "Weight", ylab = "Mileage", main = "Weight vs Mileage")
10) Program for with any data set containg dataframe objects and emplyee manipulating and analysing data
df <- data.frame(
name = c("amiya", "raj", "ashish"),
program_language = c("R", "python", "java"),
age = c(22, 25, 45)
)
cat("Before adding the rows\n")
print(df)
mytbl <- df
new_row <- data.frame(
name = "sandeep",
program_language = "C",
age = 20
)
newdf <- rbind(mytbl, new_row)
cat("After adding the row\n")
print(newdf)
11) Program to crate a application of linear regration in multivariant context for predictive purpuse
{
bp<-c(150,140,180,135,142)
age<-c(48,43,52,36,40)
cat("correlation between bp and age is",cor(bp,age))
model<-lm(bp~age)
summary(model)
}
12) Programe to Find mean mod and median
a=c(8,10,4,6,23,5,9,8,5,4,8,7,8)
print(paste("the mean of vector is",mean(a)))
print(paste("the median of vector is",median(a)))
mode=names(sort(-table(a))[1])
print(paste("the mod of vector is",mode))
8)
{
output_file_path<-"C:\file\out.txt"
data<-"hello this is a test"
paste("written successfully",writeLines((data,output_file_path)))
paste("file read data is",readLines("C:\file\out.txt"))
}
Comments
Post a Comment