RSTUDIO
RSTUDIO
AbdulKalamTechnicalUniversity,Lucknow,UttarPradesh
PRACTICAL FILE
SEMESTER-1
INPUT:
a <- 7.5
b <- 2
OUTPUT:
INPUT:
OUTPUT:
INPUT:
a <- c(7.5, 3, 5)
b <- c(2, 7, 0)
print ( a<b ) # less than
OUTPUT:
INPUT:
OUTPUT:
INPUT:
# R program to illustrate
# application of for loop
OUTPUT:
INPUT:
# R program to demonstrate the use of while loop
val = 1
OUTPUT:
INPUT:
# R Scripts For User-Defined Functions
vec1
OUTPUT:
OUTPUT:
Learn how to organize and modify data in R using data frames and dplyr
OUTPUT:
library(dplyr)
# create a data frame
stats <- data.frame(player=c('A', 'B', 'C', 'D', 'A', 'A'),
runs=c(100, 200, 408, 19, 56, 100),
wickets=c(17, 20, NA, 5, 2, 17))
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
INPUT:
# import dplyr package
library(dplyr)
# summarize method
summarize(stats, sum(runs), mean(runs))
Output:
INPUT:
OUTPUT:
INPUT:
INPUT:
# Loading package
library(dplyr)
OUTPUT:
INPUT:
# Data Layer
ggplot(data = mtcars)
OUTPUT:
INPUT:
# Aesthetic Layer
ggplot(data = mtcars, aes(x = hp, y = mpg, col = disp))
OUTPUT:
INPUT:
# Geometric layer
ggplot(data = mtcars,
aes(x = hp, y = mpg, col = disp)) + geom_point()
INPUT:
# Facet Layer
p <- ggplot(data = mtcars,
aes(x = hp, y = mpg,
shape = factor(cyl))) + geom_point()
# Statistics layer
ggplot(data = mtcars, aes(x = hp, y = mpg)) +
geom_point() +
stat_smooth(method = lm, col = "red")
OUTPUT:
INPUT:
# Coordinates layer: Control plot dimensions
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_point() +
stat_smooth(method = lm, col = "red") +
scale_y_continuous("mpg", limits = c(2, 35),
expand = c(0, 0)) +
scale_x_continuous("wt", limits = c(0, 25),
expand = c(0, 0)) + coord_equal()
OUTPUT:
INPUT:
# Add coord_cartesian() to proper zoom in
ggplot(data = mtcars, aes(x = wt, y = hp, col = am)) +
geom_point() + geom_smooth() +
coord_cartesian(xlim = c(3, 6))
OUTPUT:
INPUT:
# Theme layer
ggplot(data = mtcars, aes(x = hp, y = mpg)) +
geom_point() + facet_grid(. ~ cyl) +
theme(plot.background = element_rect(
fill = "black", colour = "gray"))
OUTPUT:
Learn the basics of aggregate functions in R with dplyr, Which let us
calculate quantities that describe groups of data
.R Script Using aggregate function to summarize in one variable and
Group by one variable.
INPUT:
# create the dataframe with 4 columns
data = data.frame(subjects=c("java", "python", "java",
"java", "php", "php"),
id=c(1, 2, 3, 4, 5, 6),
names=c("manoj", "sai", "mounika",
"durga", "deepika", "roshan"),
marks=c(89, 89, 76, 89, 90, 67))
OUTPUT:
INPUT: Multiple Value
# create the dataframe with 4 columns
data = data.frame(subjects=c("java", "python", "java",
"java", "php", "php"),
id=c(1, 2, 3, 4, 5, 6),
names=c("manoj", "sai", "mounika",
"durga", "deepika", "roshan"),
marks=c(89, 89, 76, 89, 90, 67))
OUTPUT:
INPUT: Multiple Value and Group by one variable
# create the dataframe with 4 columns
data = data.frame(subjects=c("java", "python", "java",
"java", "php", "php"),
id=c(1, 2, 3, 4, 5, 6),
names=c("manoj", "sai", "mounika",
"durga", "deepika", "roshan"),
marks=c(89, 89, 76, 89, 90, 67))
OUTPUT:
INPUT: Multiple value and Group by multiple variable
# create the dataframe with 4 columns
data = data.frame(subjects=c("java", "python", "java",
"java", "php", "php"),
id=c(1, 2, 3, 4, 5, 6),
names=c("manoj", "sai", "mounika",
"durga", "deepika", "roshan"),
marks=c(89, 89, 76, 89, 90, 67))
OUTPUT:
Learn the basics of joining tables together in R with dplyr
R script for Inner Join
INPUT: R Script for inner join
# load the library
library("dplyr")
OUTPUT:
INPUT: R Script for Left Join
# load the library
library("dplyr")
gfg2<-data.frame(ID=c(4:8))
OUTPUT:
INPUT: Right Join
# load the library
library("dplyr")
# create dataframes
gfg1<-data.frame(ID=c(1:5))
gfg2<-data.frame(ID=c(4:8))
OUTPUT:
INPUT: Full Join
# load library
library("dplyr")
# create dataframe
gfg1<-data.frame(ID=c(1:5))
gfg2<-data.frame(ID=c(4:8))
OUTPUT:
INPUT: Semi Join
# load the library
library("dplyr")
# perform semijoin
semi_join(gfg1,gfg2, by = "ID")
OUTPUT:
INPUT: Anti Join
# load the library
library("dplyr")
OUTPUT:
Learn to Use R Or manually Calculate the Mean, median, and mode of
real-world datasets
.R Script for importing data using read.CSV
INPUT:
OUTPUT:
INPUT:R Script for importing data using read.csv and find mean,
median, and mode value
OUTPUT:
INPUT:
# R program to illustrate
# Descriptive Analysis
OUTPUT:
INPUT:
# Import the data using read.csv()
myData = read.csv("CardioGoodFitness.csv",
stringsAsFactors=F)
mode = function(){
return(sort(-table(myData$Age))[1])
}
mode()
OUTPUT:
INPUT:
# R program to illustrate
# Descriptive Analysis
OUTPUT: