Created
April 4, 2017 16:05
-
-
Save Awuor87/a95eb8aa377dc51f5a54e0756bfd6376 to your computer and use it in GitHub Desktop.
Sample Code for Crosstabs in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
crosstab<- read.csv("CrossTab_Example.csv", header= TRUE) | |
View(crosstab) | |
accountsize<- table(crosstab[,2]) # accountsize | |
dimnames(accountsize)<- list(c("small", "medium","large")) | |
dim(crosstab) # check the data has expected number of rows and columns | |
library(gmodels) | |
cbc.df<- read.csv("http://goo.gl/5xQObB") | |
View(cbc.df) | |
#create a cross table | |
CrossTable(cbc.df[,6], cbc.df[,9], dnn=c("cargo","choice")) | |
# to find the relationship between cargo and price | |
CrossTable(cbc.df[,6],cbc.df[,9], chisq = TRUE, expected = TRUE, dnn=c("cargo", "choice")) | |
# to find the relationship between seat and choice | |
CrossTable(cbc.df[,5],cbc.df[,9], chisq = TRUE, expected = TRUE, dnn=c("seat", "choice")) | |
# load the Hmisc package | |
library(Hmisc) | |
seat= cbc.df[,5] | |
choice=cbc.df[,9] | |
rcorr(cbind(seat, choice), type = c("pearson", "spearman")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment