What is the recommended way to read a csv file and convert the content of a two-way table with one predictable category variable for rows and one category variable for columns into a dataframe?
In the example below the row category variable has values R1
and R2
, and the column category variable has values C1
and C2
.
> system('cat twt.csv')
,C1,C2
R1,1,2
R2,3,4
> data.frame(as.table(as.matrix(read.csv('twt.csv',row.names=1))))
Var1 Var2 Freq
1 R1 C1 1
2 R2 C1 3
3 R1 C2 2
4 R2 C2 4
I believe there are better ways than this.