Professional Documents
Culture Documents
FDP Indoglobal Group of Colleges: 27 April To 1 May R Programming Language Assignment Submission
FDP Indoglobal Group of Colleges: 27 April To 1 May R Programming Language Assignment Submission
R Programming Language
Assignment Submission
harish.pamnani@poornima.edu.in
Feedback of FDP
At first, want to say a big thanks to organizing committee who arrange
this FDP. This gives an immense pleasure to learner, provides a platform
to learn many other things apart from just R language. There were number
of different session which assign a new directions to participants likewise
IBM computing session by Dr. Mani Madukar.
Suggestion from my side are that
1. This would be better if you provide a feedback form to participants
where you can ask questions about sessions.
2. A Proper road map should give to participants, like wise number of
video lecture could be divide into number of days.
Assignments
> log2(2^5)
[1] 5
> log(exp(1)*exp(2))
[1] 3
Explore the Help tab in RStudio: Change the labels, title, etc.
> help(title)
> help("labels")
Check whether plyr package is installed on your machine. If yes, load it.
library(plyr)
1. Find out how to calculate median - using Help button and web search.
help(median)
# Create a vector.
x <- c(12,7,3,4.2,18,2,54,-21,8,-5)
# Find Mean.
result.median <- median(x)
print(result.median)
name<-c("Mahi","Saurav","Azahar","Patudi","Sunny")
name
name<-c("Mahi","Saurav","Azahar","Patudi","Sunny","Dravid")
name
played=c(23,45,56,67,78)
played
won=c(11,23,34,45,56)
lost<-c(11,22,12,23,34)
y=c(12,34,23,45,12,15)
capatin<-data.frame(name,played,won,lost,y)
lost<-c(11,22,12,23,34,22)
capatin<-data.frame(name,played,won,lost,y)
played=c(23,45,56,67,78,33)
capatin<-data.frame(name,played,won,lost,y)
won=c(11,23,34,45,56,44)
capatin<-data.frame(name,played,won,lost,y)
view(captain)
View(captain)
View(capatin)
capatin$name
ratio=capatin$won/capatin$played
> ratio
[1] 0.4782609 0.5111111 0.6071429 0.6716418 0.7179487
[6] 1.3333333
> ratio=(capatin$won/capatin$played)*100
> ratio
[1] 47.82609 51.11111 60.71429 67.16418 71.79487
[6] 133.33333
3. Take the help of R for all the commands shown in this tutorial.
st=read.csv("CO3-4-5.csv")
st=st[1:12,]
View(st)
load("matrices.R")
Create a new folder on your computer and make it your working directory.
Step1 Click on files plate..left side of R Studio
Step 2 Click on Folder—Working R Dirctory
Step 3 Click on More
Step 4 Choose set as Working Directory
vect3
mat1<-matrix(vect3,nrow = 4,ncol = 3,byrow=TRUE)
mat1
vect3
mat1<-matrix(vect3,nrow = 4,ncol = 3,byrow=TRUE)
mat1
Using built-in dataset iris, implement all the functions we have learnt in this tutorial.
library(XML)
rm(list=ls())
student=read.csv("Iris.csv")
subdata<-student[1:12,]
student1<-subdata
student1
summary(student1)
class(student1)
typeof(student1)
head(student1,2)
tail(student1,2)
str
str(student1)
student2=read.csv("Iris.csv")
View(student2)
MergeData<-merge(student1,student2,by="Student.Name")
View(MergeData)
xmldata<-xm
xmldata<-xmlToDataFrame("student2.xml")
View(xmldata)
Data types and Factors – Assignment
Using built-in dataset iris, Irs_out the categorical variables.
rm(list=ls())
st1=read.csv("Iris.csv")
View(st1)
st1<-st1[1:12,]
st1
str(st1)
2. Can you _nd a variable which is categorical, but R reads as numeric? If yes, change
it to categorical.
st1=read.csv("Iriscsv")
View(st1)
st1<-st1[1:12,]
st1
str(st1)
print(st1$Sepal_name)
st1$Total<-factor(st1$categorical)
str(st1)
levels(st1$Total)
st=read.csv("Iris.csv")
st<-st[1:12,]
data=st[1:3,c("Sepal-width”,”petal-width)]
mat1=as.matrix(data)
mat1
myvector=c(1:5)
lst=list(st,mat1,myvector)
Plotting Histograms and Pie Chart - Assignment
1. Read the _le moviesData.csv. Create a histogram of the object named imdb num
votes
2. in this _le.Create a pie chart of the object mpaa rating.
3. Save both the plots.
rm(list=ls())
st=read.csv("moviesData.csv")
st<-st[1:12,]
View(st)
rm(list=ls())
st=read.csv("CO3-4-5.csv")
st<-st[1:12,]
hist(st$Total,main="Student Marks",
xlab = "Total MArks",xlim = c(0,18),
col="blue",breaks = 2)
generalCount<-table(st$Total)
View(generalCount)
pie(generalCount)
rm(list=ls())
st=read.csv("moviesData.csv")
st<-st[1:10,]
View(st)
barplot(st$Total,ylab = "Total",
xlab = "Total Marks",col="Blue",
ylim = c(0,10),main = "Total Marks")
library("ggplot2")
rm(list = ls() )
movies <-
read.csv("C:\\Users\\Harish\\Documents\\R_Working_Directory\\moviesData.csv"
)
View(movies)
ggplot(data=movies,mapping=aes(x=mpaa_rating))+
geom_point()
geom_bar()
Data Manipulation using dplyr Package - Assignment
1. Consider the built-in data set mtcars. Find the cars with hp greater than 100 and
cyl equal to 3.
2. Arrange the mtcars data set based on mpg variable.
library(dplyr)
rm(list = ls() )
1. Use the built-in data set airquality. Using select function, select the variables
Ozone,Wind, and Temp in this data set.
2. Use the built-in data set mtcars. Rename the variables mpg and cyl with
MilesPerGallonvand Cylinder, respectively.
MoviesTGI<-select(movies,title,genre,imdb_rating)
View(MoviesTGI)
Use the built-in data set iris. Using the pipe operator, group the owers by their
Species.
Summarise the grouped data by the mean of Sepal.Length and Sepal.Width.
library(datasets)
data(iris)
summary(iris)
iris %>% group_by(Species) %>% summarize_all(funs(mean))
1. Use the built-in data set iris. Find the Species, in which Sepal.Length is greater
than Petal.Length.
2. Count all such Species.
dim(iris)
Functions in R - Assignment
1. Create a function which computes combination of two numbers.
2. Create a function which takes a natural number as an argument, and prints
Fibonacci series. For example, consider fibonacci(5). It should print the _rst 5
elements of Fibonacci series, i.e. 1, 1, 2, 3, 5.
combinations(3,2,letters[1:3])
combinations(3,2,letters[1:3],repeats=TRUE)