R Programming LAB
R Programming LAB
R Programming LAB
PAGE
S.NO. DATE CONTENT SIGNATURE
NO.
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP3:To create a addition function for default values and perform the
arithmetic calculations for input user.
STEP5:Select the program and run the program or source the program.
print("Welcome to R programming")
a=4
b=5
print(a+b)
a=as.integer(a)
b=as.integer(b)
print(a+b)
print(a-b)
print(a*b)
print(a/b)
OUTPUT:
RESULT:
Thus, the program was executed successfully and the output was verified.
EXNO:2 IMPLEMENATION OF VECTOR DATA OBJECTS
DATE: OPERATIONS
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP5:Select the program and run the program or source the program.
#Combining vector
a = c(1, 2, 3, 4)
b = c("Apple", "Banana", "Orange", "Avocado")
c(a,b)
#Arithmetic vector
c = c (2)
d = c (1)
c+d
#Logical and numeric index
s = c("Apple", "Banana")
L = c(FALSE, TRUE)
s[L]
s[15]
#Duplicate and range index
s = c("Orange", "Avocado", "Jack fruit", "Watermelon", "Dragon fruit")
s[c(2,3,5,3)]
s[1:3]
#Out-of-order index
s[c(2, 1, 3)]
#Named vectors
v=c("Apple","Banana")
names(v)=c('First','Second')
print(v)
OUTPUT:
RESULT:
Thus, the program was executed successfully and the output was verified.
EXNO:3 IMPLEMENTATION OF MATRIX,ARRAY AND
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP3:To perform the all type of data types like array, matrix and factor.
STEP5:Select the program and run the program or source the program.
#Matrix
M = matrix( c('a','a','b','c','b','a'), nrow = 2, ncol = 3, byrow = TRUE)
print(M)
#Factor
apple_colors <- c('green','green','yellow','red','red','red','green')
factor_apple <- factor(apple_colors)
print(factor_apple)
print(nlevels(factor_apple))
#Array
a <- array(c('green','yellow'),dim = c(3,3,2))
print(a)
OUTPUT:
RESULT:
Thus, the program was executed successfully and the output was verified.
EXNO:4 IMPLEMENATION AND USE OF DATA FRAMES IN R
DATE:
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP5:Select the program and run the program or source the program.
#Adding column
newDf = cbind(data, Department=c("IT","IT","IT","Operation","Finance"))
print(newDf)
RESULT:
Thus, the program was executed successfully and the output was verified
EXNO:5 CREATE SAMPLE(DUMMY) DATA IN R AND PERFORM DATA
DATE: MANIPULATION WITH R
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP5:Select the program and run the program or source the program.
RESULT:
Thus, the program was executed successfully and the output was verified
EXNO:6 STUDY AND IMPLEMETATION OF VARIOUS CONTROL STURUCTURE
DATE: IN R
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP3:If conditions are in the looping statement, perform a various operations or process.
STEP5:Select the program and run the program or source the program.
#Using letters
x <- letters[4:10]
for(i in x){
print(i)
}
x=1
# Print 1 to 5
while(x <= 5){
print(x)
x=x+1
}
OUTPUT:
RESULT:
Thus, the program was executed successfully and the output was verified
EXNO:7 DATA MANIPULATION WITH DPLYR PACKAGE
DATE:
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP3:To import a dataset in R and perform various methos with use dplyr package.
STEP5:Select the program and run the program or source the program.
RESULT:
Thus, the program was executed successfully and the output was verified
EXNO:8 DATA MANIPULATION WITH DATA.TABLE PACKAGE
DATE:
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP3:To import a dataset in data manipulation and perform various methos with use data.table.
STEP5:Select the program and run the program or source the program.
RESULT:
Thus, the program was executed successfully and the output was verified
EXNO:9 STUDY AND IMPLEMENTATION OF DATA VISUALIZATION
DATE: WITH GGPLOT2
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP3:To import a dataset in R and perform various methos with use tidyverse and ggplot2.
STEP5:Select the program and run the program or source the program.
library(tidyverse)
colnames(sampledataset)
sampledataset %>%
ggplot(aes(x = Salary, y = `Yearly Turnover`))+
geom_line()+
labs(
title = "Measuring the monthly turnover",
y ="Basic pay"
)
OUTPUT:
> colnames(sampledataset)
[1] "Name" "Age" "Gender" "Phone number" "Yearly Turnover"
[6] "Basic pay" "Salary"
RESULT:
Thus, the program was executed successfully and the output was verified.
EXNO:10
DATE: STUDY AND IMPLEMENTATION OF DATA TRANSPOSE
OPERATION IN R
AIM:
ALGORITHM:
STEP1:Open R studio.
STEP5:Select the program and run the program or source the program.
library(data.table)
df <- data.frame(Name = c("karthi", "Deva", "Vidhya", "Arun", "Dhiya"),
Age = c(22, 15, 45, 34,10),
salary= c(11000, 12000, 13000, 14000, 15000))
row.names(df) <- c('One', 'Two', 'Three', 'Four', 'Five')
print(df)
df_t <- transpose(df)
rownames(df_t) <- colnames(df)
colnames(df_t) <- rownames(df)
print(df_t)
OUTPUT:
RESULT:
Thus, the program was executed successfully and the output was verified