R Record
R Record
R Record
Program:
name=readline(prompt="Enter name of student:")
sub_1=as.integer(readline(prompt="Enter marks of sub_1"))
sub_2=as.integer(readline(prompt="Enter marks of sub_2"))
sub_3=as.integer(readline(prompt="Enter marks of sub_3"))
sub_4=as.integer(readline(prompt="Enter marks of sub_4"))
sub_5=as.integer(readline(prompt="Enter marks of sub_5"))
student_marks=(sub_1+sub_2+sub_3+sub_4+sub_5)
cat(“Total marks obtained:”,student_marks)
if (student_marks<1000 && student_marks>800){
print("Grade A+")
}else if (student_marks<800 && student_marks>700){
print("Grade A ")
}else if (student_marks<700 && student_marks>500){
print("Grade B+")
}else if (student_marks<500 && student_marks>400){
print("Grade B")
}else if (student_marks<400 && student_marks>150){
print("Grade C")
}else{
print("Grade D")
}
Output:
Enter name of student: Aman
Enter marks of sub_1:187
Enter marks of sub_2:176
Enter marks of sub_3:169
Enter marks of sub_4:180
Enter marks of sub_5:199
Total marks obtained:911
Grade A+
4. Write a program to make a simple calculator that can add, subtract,
multiple and divide using switch case.
Program:
a=as.integer(readline(prompt="Enter the value of a:"))
b=as.integer(readline(prompt="Enter the value of b:"))
operator=readline(prompt="Enter the operator(+,-,*,/):")
calc=switch(choice,
"+"=cat("Adiition of two numbers is:",a+b),
"-"=cat("Subtraction of two numbers is:",a-b),
"*"=cat("Muliplication of two numbers is:",a*b),
"/"=cat("Division of two numbers is:",a/b))
print(calc)
Output:
Enter the value of a: 8
Enter the value of b: 4
Enter the operator(+,-,*,/): +
Adiition of two numbers is: 12
tail()- is used to view the lastr few rows of the data frame
>>tail(data)
Output:
5. Rani 22 Female
6. Rayan 21 Male
7. Uma 19 Female
8. Rahul 23 Male
9. Hiba 21 Female
Program:
a=c(95,120,117,99,110,107,125,98,85,127,105,114,103,112,92,101,122,120)
#This module computes the mean
mean_of_a=mean(a)
cat("Mean of the sample is:",round(mean_of_a,2))
#This module computes the median
median_of_a=median(a)
cat("Median of the sample is:",round(median_of_a,2))
#This module computes the mode
mode_of_a=table(a)
print(mode_of_a)
mode1=names(mode_of_a[(mode_of_a==max(mode_of_a))])
cat("Mode of the sample is:",mode1)
#This module computes the standard deviation
sd_dev=sd(a)
cat("Standard deviation of the sample is:", round(sd_dev,2))
#This module computes the coefficient of variation
co_var=(sd_dev/mean_of_a)*100
cat("Co-effecient of variation of sample is:",round(co_var,2))
#This module computes the range
range_of_a=range(a)
cat("Range of sample is:",range_of_a)
Output:
Mean of the sample is: 108.44
Median of the sample is: 108.5
85 92 95 98 99 101 103 105 107 110 112 114 117 120 122 125 127
1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1
Mode of the sample is: 120
Standard deviation of the sample is: 12.09
Co-effecient of variation of sample is: 11.15
Range of sample is: 85 127
10.Write the program to print males and females for the following data using
dataframe and draw the boxplot giving colour , title and calculate summary
of the data.
48,49,49,30,57,59,78,79
Program:
dat1=c(48,49,49,30,57,59,78,79)
male=rep("Male",5)
female=rep(“Female",3)
gender=c(male,female)
print(gender)
#creating the data frame
data_frame=data.frame("Data"=dat1,"Gender"=gender)
print(data_frame)
#This module is to create boxplot for the data
boxplot(data~gender,data=data_frame,col=c("pink","green"),main="boxp
-lot of males anf females",xlab="gender",ylab="sample data")
#To calculate the summary of the data
summary_of_data=summary(data_frame)
print(summary_of_data)
Output:
"Male" "Male" "Male" "Male" "Male" "Female" "Female" "Female"
Dataframe is:
Data Gender
1 48 Male
2 49 Male
3 49 Male
4 30 Male
5 57 Male
6 59 Female
7 78 Female
8 79 Female
Summary of the data is:
Data Gender
Min. :30.00 Length:8
1st Qu.:48.75 Class :character
Median :53.00 Mode :character
Mean :56.12
3rd Qu.:63.75
Max. :79.00
11.Sorting the following data and draw the histogram for the same.
0.799,2.147,2.147,3.643,3.429,4.180
Program:
data5=c(0.799,2.147,2.147,3.643,3.429,4.180)
sort_of_data=sort(c(0.799,2.147,2.147,3.643,3.429,4.180))
cat("The sorted data is:",sort_of_data)
#To draw the histogram
histogram=hist(data5,col="blue",main="Histogram",xlab="X-
axis",ylab="Y-axis")
Output:
The sorted data is: 0.799 2.147 2.147 3.429 3.643 4.18
Histogram: