#EDA with R #Mean internet_usage <- c(22, 0, 7, 12, 5, 33, 14, 8, 0, 9) internet_usage mean(internet_usage) internet_usage <- c(22, 0, 7, 12, 5, NA, 33, 14, 8, NA, 0, 9) mean(internet_usage, na.rm = TRUE) #Median median(internet_usage) #Measures of Variance A <- c(49, 33, 37, 63, 48, 54, 62, 52, 64, 71, 68) min(A) max(A) which.min(A) which.max(A) print(max(A) - min (A)) range(A) print(range(A)[2] - range(A)[1]) x <- c(3, 4, 5, 6, 7, 8, 10, 10, 11, 12, 14, 14, 14, 15, 16, 17, 21, 25, 27, 32) quantile(x, 0.80, type = 7) quantile(x, 0.25, type = 7) quantile(x, 0.50, type = 7) quantile(x, 0.75, type = 7) summary(x) irq = function(x) (quantile(x,0.75) - quantile(x,0.25)) irq(x) #Variance courses = c(6, 2, 1, 9, 17, 4, 3, 2, 1, 5, 11, 4, 3, 1, 2, 2, 5, 4, 3, 6) var(courses) sum((courses - mean(courses))^2 / (length(courses)-1)) #Standard Deviation sd(courses) sqrt(var(courses)) #Ορίζουμε δική μας std = function(x) sqrt(var(x)) std(courses) #Visualizing quantitative data m = c("car", "car", "bus", "metro", "metro", "car", "metro", "metro", "foot", "car", "foot", "bus", "bus", "metro", "metro", "car", "car", "car", "metro", "car") table(m) prop.table(table(m)) barplot(table(m)) barplot(prop.table(table(m))) pie(table(m)) pie(prop.table(table(m)), col=c("purple", "green", "red", "blue")) g = c(rep("M",8),rep("F",12)) g mg = table(m,g) mg barplot(mg) barplot(mg, xlim = c(0,2), xlab="Gender", legent = levels(m), col = 1:4) x = c(10, 10, 5, 9, 7, 6, 8, 6, 5, 8, 10, 7, 7, 8, 5, 6, 4, 7, 9, 7, 4, 8, 10, 10, 7, 4, 9, 5, 8, 9) table(x) prop.table(table(x)) hist(x) hist(x, nclass=3) w = c(1950, 2090, 2700, 3350, 4200, 3720, 4400, 2980, 3850, 4550, + 3050, 2350, 1850, 2820, 3670, 2950, 3750, 1850, 2420, 3150, + 4450, 3120, 3660, 3070, 3550, 2020, 3500, 2500, 3780, 3940, + 3000, 3470, 3920, 3100, 2400, 2900, 2650, 3450, 3650, 4020, + 3540, 2800, 2850, 4450, 1950, 3020, 2800, 3500, 1480, 4495, + 2850, 3100, 2250, 3300, 4100, 3220, 3600, 2130, 4020, 4075) hist(w) hist(w, nclass = 4) hist(w, breaks = seq(from = 1000, to=5000, by=300)) hist(w) rug(jitter(w)) boxplot(w, horizontal = T)