Module # 9


Module #9 Assignment 

Question 1: Creating a Simple Table


```R

# 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, 7000, 6000, 8000, 5000, 7000),

  Purchased = c("No", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "No", "Yes")

)


# Create a simple table

simple_table <- as.table(assignment_data)


# Print the simple table

print(simple_table)

```


Question 2: Generating a Contingency Table and Adding Margins


```R

# Load the mtcars dataset (if not already loaded)

data(mtcars)


# Generate a contingency table for gear and cyl columns

assignment9 <- table(mtcars$gear, mtcars$cyl, dnn = c("gears", "cylinders"))


# Add margin totals for rows and columns

table_with_margins <- addmargins(assignment9)


# Print the table with margins

print(table_with_margins)

```


Question 2.2: Adding Proportional Weights


```R

# Generate a proportional table

prop_table <- prop.table(assignment9)


# Print the proportional table

print(prop_table)

```


Question 2.3: Adding Row Proportions


```R

# Generate row proportions

row_prop_table <- prop.table(assignment9, margin = 1)


# Print the row proportions

print(row_prop_table)

```

Comments