-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable_Function.R
More file actions
48 lines (38 loc) · 1.28 KB
/
Table_Function.R
File metadata and controls
48 lines (38 loc) · 1.28 KB
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
44
45
46
47
48
#Data frame creation
Gender <- c("Female","Female","Male","Male")
Restaurant <- c("Yes","No","Yes","No")
Count <- c(220, 780, 400, 600)
DiningSurvey <- data.frame(Gender, Restaurant, Count)
DiningSurvey
#Compare gender & Restaurant
table(DiningSurvey$Gender)
table(DiningSurvey$Restaurant)
#Summarize Data
table(DiningSurvey$Count>650)
#Finding NA values
DiningSurvey$Restaurant <- c("Yes", "No", "Yes", NA)
table(DiningSurvey$Restaurant,useNA = "always")
table(is.na(DiningSurvey$Gender))
#Exclude gender Male
table(DiningSurvey$Gender, exclude = "Male")
#margin.table() Data summed over Sections
RentalUnits <- matrix(c(45,37,34,10,15,12,24,18,19),ncol=3,byrow=TRUE)
colnames(RentalUnits) <- c("Section1","Section2","Section3")
rownames(RentalUnits) <- c("Rented","Vacant","Reserved")
RentalUnits <- as.table(RentalUnits)
margin.table(RentalUnits,margin = 2)
#tables of proportions
prop.table(RentalUnits)
prop.table(RentalUnits, margin = 1)
prop.table(RentalUnits, margin = 2)
#Summarize the table
ftable(RentalUnits)
#Chi-Square Test of Independence
summary(object = RentalUnits)
#list frequencies
as.data.frame(RentalUnits)
#creates arbitrary margins
addmargins(RentalUnits)
addmargins(RentalUnits, 1) #Columnwise
addmargins(RentalUnits, 2) #Rowwise
addmargins(prop.table(RentalUnits,2)) #Proportion