Convert table to data frame in R