Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R data - Changing my data frame (converting columns into rows and vice versa)

Tags:

r

rows

So I have created a data frame in R with this output called 'data'

But I want to convert my data frame to something like the one below

How would I go about doing this?

like image 478
Gladdys Gotherin Avatar asked Apr 08 '13 06:04

Gladdys Gotherin


2 Answers

To transpose in R use the function t():

t(data)

like image 82
jmanelsg Avatar answered Oct 22 '22 06:10

jmanelsg


t(data) returns a matrix.

To convert it to a data.frame from the matrix, wrap the output withas.data.frame()`.

like image 33
Yap Avatar answered Oct 22 '22 05:10

Yap