Aswin Seshadri
Aswin Seshadri

Reputation: 1

How to summarize a dataframe columns in R?

I am trying to create a summarized table in R from the following data frame but i am not able to do so..

Col A    Col B    Col C
1        4         1 
2        4         2 
1        5         3
2        5         4
df1 <- data.frame(Col_A = c(1, 2, 1, 2),
                  Col_B = c(4, 4, 5, 5),
                  Col_C = c(1, 2, 3, 4))

Basically, i would like the summary to be like this,

                     Col B 
                4           5

       1        1           3
Col A
       2        2           4

Upvotes: 0

Views: 61

Answers (1)

akrun
akrun

Reputation: 886938

We can use xtabs

xtabs(`Col C` ~ `Col A` + `Col B`, df1)

Upvotes: 3

Related Questions