-
Notifications
You must be signed in to change notification settings - Fork 0
/
UFO Data.R
43 lines (35 loc) · 1.11 KB
/
UFO Data.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
setwd('~/R practice')
install.packages('janitor')
library(janitor)
library(ggplot2)
library(lubridate)
#Downloading the dataset
UFO <- read.csv("~/Downloads/UFO.csv")
#Exploring the dataset
summary(UFO)
#Cleaning the dataset
table(is.na(UFO))
table(UFO=='')
UFO[UFO==""] <- NA
UFO <- na.omit(UFO)
UFO$datetime <- as.character(UFO$datetime)
UFO$datetime <- dmy_hm(UFO$datetime)
str(UFO$datetime)
UFO <- na.omit(UFO)
UFO$months <- month(UFO$datetime)
UFO$months <- as.character(UFO$months)
UFO$seasons[UFO$months == c(12, 11, 1)] <- 'Winter'
UFO$seasons[UFO$months == c(8, 9, 10)] <- 'Autumn'
UFO$seasons[UFO$months == c(5, 6, 7)] <- 'Summer'
UFO$seasons[UFO$months == c(2, 3, 4)] <- 'Spring'
UFO$seasons[1] <- 'Autumn'
UFO$seasons[nrow(UFO)] <- 'Autumn'
UFO$seasons <- na.locf(UFO$seasons)
table(UFO$seasons)
sort(table(UFO$state), decreasing = TRUE)
head(sort(table(UFO$city), decreasing = TRUE))
head(sort(table(UFO$datetime), decreasing = TRUE))
head(sort(table(UFO$date.posted), decreasing = TRUE))
UFO$duration..seconds. <- as.numeric(UFO$duration..seconds.)
summary(UFO$duration..seconds.)
summary(UFO$duration..hours.min.)