Skip to content

Instantly share code, notes, and snippets.

@tenkabuto
Last active August 5, 2017 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenkabuto/17934131842d837d81d7a103b47eee37 to your computer and use it in GitHub Desktop.
Save tenkabuto/17934131842d837d81d7a103b47eee37 to your computer and use it in GitHub Desktop.
Crosstab (contingency table) to Dataframe
# Read in CSV file that's formatted as a Crosstab (empty top left cell, top row contains column names and first column contains row names)
# `header = T` pulls column names from first row
# `row.names = 1` pulls row names from first column, so starts from 1, not 0
b2009 <- read.csv("20092009 Beer - CrossTab.csv", header = T, row.names = 1)
table <- as.table(as.matrix(b2009))
test <- data.frame(table)
# Add names to Columns, starting from leftmost column
colnames(test) <- c("Beer","Judge","Rating")
test[1:37,]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment