How to acess a column in R: We have the dataset survey_data We will be looking at satisfaction scores:
So, we will extract the Satisfaction column”
The code we will use ius as follows:
sati<-survey_data$Satisfaction
mean(sati)
[1] 6.75
median(sati)
[1] 7
hr_ages <- survey_data$Age[survey_data$Department == "HR"]
mean(hr_ages)
[1] 30
age_satisfaction_matrix <- as.matrix(survey_data[, c("Age", "Satisfaction")])
mean(age_satisfaction_matrix)
[1] 20.35
department_matrix <- as.matrix(aggregate(Satisfaction ~ Department,data = survey_data,FUN = mean))
department_matrix
Department Satisfaction
[1,] "Finance" "6.4"
[2,] "HR" "7.8"
[3,] "IT" "6.4"
[4,] "Marketing" "6.4"
transpose_matrix<- t(department_matrix)
data.frame(survey_data)
dim(survey_data)
[1] 20 5
filtered_data <- subset(survey_data, Age >= 30 & Age <= 40)
mean(filtered_data$Age)
[1] 34.55556
hist(survey_data$Age)
hist(survey_data$Satisfaction)
boxplot(Satisfaction ~ Department, data = survey_data)
boxplot(Age~Gender, data= survey_data)
Q1 <- quantile(survey_data$Satisfaction, 0.25, na.rm = TRUE)
Q3 <- quantile(survey_data$Satisfaction, 0.75, na.rm = TRUE)
IQR_value <- IQR(survey_data$Satisfaction, na.rm = TRUE)
lower_bound <- Q1 - 1.5 * IQR_value
upper_bound <- Q3 + 1.5 * IQR_value
outliers <- survey_data[lower_bound, upper_bound]