R File 6th Sem
R File 6th Sem
1
OUTPUT:
2
PROGRAM 2:
Write a R program to compare two data frames to find the row(s) in first
data frame that are not present in second data frame.
df_90 = data.frame(
"item" = c("item1", "item2", "item3"),
"Jan_sale" = c(12, 14, 12),
"Feb_sale" = c(11, 12, 15),
"Mar_sale" = c(12, 14, 15)
)
df_91 = data.frame(
"item" = c("item1", "item2", "item3"),
"Jan_sale" = c(12, 14, 12),
"Feb_sale" = c(11, 12, 15),
"Mar_sale" = c(12, 15, 18)
)
print("Original Dataframes:")
print(df_90)
print(df_91)
print("Row(s) in first data frame that are not present in
second data frame:")
print(setdiff(df_90,df_91))
3
OUTPUT:
4
PROGRAM 3;
Write a R program to access the element at 3rd column and 2nd row,
only the 3rd row and only the 4th column of a given matrix.
5
OUTPUT:
PROGRAM 4:
6
Write a R program to create two 2x3 matrix and add, subtract, multiply
and divide the matrixes.
result = m1 + m2
print("Result of addition")
print(result)
result = m1 - m2
print("Result of subtraction")
print(result)
result = m1 * m2
print("Result of multiplication")
print(result)
result = m1 / m2
print("Result of division:")
print(result)
OUTPUT:
7
PROGRAM 5:
8
Write a R program to sort a Vector in ascending and descending order.
OUTPUT:
9
PROGRAM 6:
OUTPUT:
11
PROGRAM 7:
12
print_factors = function(n) {
print(paste("The factors of",n,"are:"))
for(i in 1:n) {
if((n %% i) == 0) {
print(i)
}
}
}
print_factors(4)
print_factors(7)
print_factors(12)
OUTPUT:
13
PROGRAM 8:
14
Write a R program to get the first 10 Fibonacci numbers.
15
OUTPUT:
16
PROGRAM 9:
# defining vector
png(file = "barplot.png")
# plotting vector
col.axis = "darkgreen",
col.lab = "darkgreen")
dev.off()
17
OUTPUT:
18
PROGRAM 10:
Write a R program to make a chart using piechart3D.
library(plotrix)
png(file = "piechart3d.png")
dev.off()
19
OUTPUT:
20