Importing data Files of Other
Software and Redirecting Output
First step:
>getwd()
>
(To know where is R software located in computer)
Second step:
>setwd
>setwd(“E/Rcourse/”)
(To change work location of directory)
Third step
Save file in CSV format in new work location ( In Rcourse -E drive)
Calculation in R by importing data in CSV
format
Mean
Median
SD
Correlation
Regression
Calculation of MEAN
>setwd(“E/Rcourse/”)
>data<-read.csv(“file name.csv")
>data
(incomplete data)
>data<-read.csv(“file name.csv", header=FALSE)
(complete data with proper heading)
>data
(give comments to each column by using # key)
> #V1 EMPLOYEE NUMBERS
> #V2 NUMBERS OF HOURS WORKED
> #V3 TOTAL REMUNERATIONS
> #V4 NUMBER OF DAYS ABSENT
Check data column wise
> data[,1]
> data[,2]
> data[,3]
> data[,4]
Find out mean
> mean(data[,1])
> mean(data[,2])
> mean(data[,3])
> mean(data[,4])
Calculation of MEDIAN
>median(data[,1])
>median(data[,2])
> median(data[,3])
> median(data[,4])
Calculation of SD
>sd(data[,1])
>sd(data[,2])
> sd(data[,3])
> sd(data[,4])
Absolute and relative frequencies:
Absolute frequency: Actual frequency
Relative frequency: Proportion
Data on gender:
M,F,F,M,F,M,M,F,F,M
1,2,2,1,2,1,1,2,2,1
Absolute frequency:
Total Male:5
Total Female:5
Relative Frequency:
Total male/Total persons= 05/10= 0.5
Total Female/Total persons= 05/10= 0.5
> gender<-c(1,2,1,1,2,1,2,1,2,1,2)
> gender
[1] 1 2 1 1 2 1 2 1 2 1 2
> table(gender)
gender
1 2
6 5
> table(gender)/length(gender)
gender
1 2
0.5454545 0.4545455
Graphics and Plots
> gender<-c(1,2,1,2,1,2,2,1,2,1,1)
> gender
[1] 1 2 1 2 1 2 2 1 2 1 1
> table(gender)
gender
1 2
6 5
> barplot(table(gender))
> barplot(gender)
> barplot(table(gender))
>barplot(table(gender)/length(gender))
Pie diagram
>pie(table(gender))
Histogram
> hist(gender)
Correlation
> cor(c(100,200,300,400),c(100,200,300,400))
[1] 1
Graph
> cor(c(1,2,3,4,5,6,7,8),c(1,2,3,4,5,6,7,8))
[1] 1
> plot(c(1,2,3,4,5,6,7,8),c(1,2,3,4,5,6,7,8))
> scatter.smooth(c(1,2,3,4,5,6,7,8),c(1,2,3,4,5,6,7,8))

Lecture 9 ba 9 r software