Module #9 Assignment
#1
# Create the data frame
assignment_data <- data.frame(
Country = c("France", "Spain", "Germany", "Spain", "Germany", "France", "Spain", "France", "Germany", "France"),
age = c(44, 27, 30, 38, 40, 35, 52, 48, 45, 37),
salary = c(6000, 5000, 7000, 4000, 8000, 6000, 5000, 7000, 4000, 8000),
Purchased = c("No", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "No", "Yes")
)
# Create a table
simple_table <- data.frame(
Country = assignment_data$Country,
age = assignment_data$age,
salary = assignment_data$salary,
Purchased = assignment_data$Purchased
)
# Print the table
print(simple_table)
#2
# Load the mtcars dataset
data(mtcars)
# Create a contingency table
assignment9 <- table(mtcars$gear, mtcars$cyl, dnn = c("gears", "cylinders"))
# Print the contingency table
print(assignment9)
#2.1
# Add margins to the table
table_with_margins <- addmargins(assignment9)
# Print the table with margins
print(table_with_margins)
#2.2
# Calculate proportional weights
proportional_weights <- prop.tables(assignment9)
# Print the proportional weights
print(proportional_weights)
#2.3
# Calculate row proportions
row_proportions <- prop.table(assignment9, margin = 1)
# Print the row proportions
print(row_proportions)
Comments
Post a Comment