forked from Himanshu091190/IIT_Madara_ML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyscript3.R
123 lines (83 loc) · 3.19 KB
/
myscript3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Get and print current working directory.
print(getwd())
MyData <- read.csv(file="C:/Users/lenovo/Documents/data.csv", header=TRUE, sep=",")
print(MyData)
print(is.data.frame(MyData))
print(ncol(MyData))
print(nrow(MyData))
# Get the max salary from data frame.
sal <- max(MyData$salary)
print(sal)
# Get the person detail having max salary.
retval <- subset(MyData, salary == max(salary))
print(retval)
# Get all people working in IT Department
retval <- subset( MyData, dept == "IT")
print(retval)
# Detail of people working in IT and Salary > 600
info <- subset(MyData, salary > 600 & dept == "IT")
print(info)
# People who joined on or after 2014
retval <- subset(MyData, as.Date(start_date) > as.Date("2014-01-01"))
print(retval)
# Writing to CSV File
retval <- subset(MyData, as.Date(start_date) > as.Date("2014-01-01"))
# Write filtered data into a new file.
write.csv(retval,"output.csv")
newdata <- read.csv("output.csv")
print(newdata)
################################################################### CHARTS AND GRAPHS ##################################################
#The basic syntax for creating a pie-chart using the R is ???
#pie(x, labels, radius, main, col, clockwise)
#Following is the description of the parameters used ???
#x is a vector containing the numeric values used in the pie chart.
#labels is used to give description to the slices.
#radius indicates the radius of the circle of the pie chart.(value between ???1 and +1).
#main indicates the title of the chart.
#col indicates the color palette.
#clockwise is a logical value indicating if the slices are drawn clockwise or anti clockwise.
###################################################################
# Create data for the graph.
x <- c(21, 62, 10, 53)
labels <- c("London", "New York", "Singapore", "Mumbai")
# Give the chart file a name.
png(file = "city.jpg")
# Plot the chart.
pie(x,labels)
# Save the file.
dev.off()
###############################
# Create data for the graph.
x <- c(21, 62, 10, 53)
labels <- c("London", "New York", "Singapore", "Mumbai")
# Give the chart file a name.
png(file = "city_title_colours.jpg")
# Plot the chart with title and rainbow color pallet.
pie(x, labels, main = "City pie chart", col = rainbow(length(x)))
# Save the file.
dev.off()
###############################
# Create data for the graph.
x <- c(21, 62, 10,53)
labels <- c("London","New York","Singapore","Mumbai")
piepercent<- round(100*x/sum(x), 1)
# Give the chart file a name.
png(file = "city_percentage_legends.jpg")
# Plot the chart.
pie(x, labels = piepercent, main = "City pie chart",col = rainbow(length(x)))
legend("topright", c("London","New York","Singapore","Mumbai"), cex = 0.8,
fill = rainbow(length(x)))
# Save the file.
dev.off()
#################################
# Get the library.
library(plotrix)
# Create data for the graph.
x <- c(21, 62, 10,53)
lbl <- c("London","New York","Singapore","Mumbai")
# Give the chart file a name.
png(file = "3d_pie_chart.jpg")
# Plot the chart.
pie3D(x,labels = lbl,explode = 0.1, main = "Pie Chart of Countries ")
# Save the file.
dev.off()