To transpose a dataframe in R, you can use the t()
function or the transpose()
function from the data.table
package.
Here's an example of using the t()
function to transpose a dataframe:
main.r56 chars3 lines
This will return:
main.r68 chars5 lines
If you're working with larger datasets in R, you may want to use the transpose()
function from the data.table
package for improved performance. Here's an example:
main.r91 chars4 lines
This will also return:
main.r48 chars5 lines
Note that when using transpose()
from data.table
, you must first convert your dataframe to a data.table object using the setDT()
function.
gistlibby LogSnag