Sheet
Sheet
Sheet
if(year %% 4 ==0 ){
}else{
print(paste(year,"is a leap"))
}else{
while(num >0){
sum =sum+num
num =num -1
}
print(paste("the sum is",sum))
}
With formula
num = as.integer(readline(prompt = "Enter a number: "))
if(num < 0) {
print("Enter a positive number")
} else {
sum = (num * (num + 1)) / 2
print(paste("The sum is", sum))
}
3) Marks A B C D
mydata = data.frame(enr_no =seq(1,20,by=2),
marks = sample(100:200,10,TRUE),
Names = LETTERS[1:10])
mydata$grades =ifelse(mydata$marks>150,"A",ifelse(mydata$marks>130,"B",
ifelse(mydata$marks>120,"c","D")
))
mydata
4.Calculator
6. searching between 1 to 50
lst <-list(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50)
srch <- 20
check <-function(x){
if(x %in% lst){
print("The number is in the list")
}
else{
print("The number is not present in the list")
}
}
7.store marks and of any 3 sub and find max min ave
mar <-list(science = c(20,34,66,44,23,53,34,56,22,13),
Maths = c(34,53,12,34,21,52,13,63,52,24),
EVS = c(78,98,57,43,54,67,89,24,23,12))
DF <- data.frame(mar)
9.matrix operation
m1 = matrix(1:9,nrow = 3,ncol =3)
m2 = matrix(10:18,nrow = 3,ncol =3)
print("Matrix-1:")
print(m1)
print("Matrix-2:")
print(m2)
result = m1 + m2
print("Result of addition")
print(result)
result = m1 - m2
print('Result of Subtraction')
print(result)
print('Result of Mulitiplication')
result = m1*m2
print(result)
print('Result of Division')
result = m1 / m2
print(result)
print('Traspose of Matrices')
result = t(m1)
print(result)
result = t(m2)
print(result)
10.list operations
list_data = list("computation","PHP",c(5,7,9,11),TRUE,125.17,75.83)
print("Data of the list")
print(list_data)
list_data2 = list(c("Red","Green","Black"),
matrix(c(1,3,5,7,9,11),nrow =2),
list("USCI"),"4th element")
print("List:")
print(list_data2)
print("Update the second element of the list:")
list_data2[2] = "R programming"
print("New list:")
print(list_data2)
print(list_data2[4])