It is easy to extract data from the rows and columns of a data frame but there are situations where the data frame needs to be in a format that is different from the format in which it was received.
Data Reshaping in R is about changing the way data is organized into rows and columns.
Joining columns and rows in a data frame is achieved by 2 functions:
rbind (Combines vector, matrix or data frame by rows)

cbind (Combines vector, matrix or data frame by columns)

To convert the rows into columns and columns into rows (essentially flipping the data frame) - use the t() function in R.

The t function is used to create the transpose, after which as.data.frame is used to convert the result into a data frame.
 
        
McGill Libraries • Questions? Ask us!
Privacy notice