Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a matrix into a dataframe

Tags:

r

This a generic question, let' say I have:

matrix=replicate(5, rnorm(10))

I want a data.frame with 3 columns: row number, column number, matrix value.

like image 311
user3083324 Avatar asked Sep 13 '25 09:09

user3083324


1 Answers

What you are looking for is melt inside library(reshape)

melt(matrix)

edit: use reshape2 instead.

like image 138
Vlo Avatar answered Sep 15 '25 22:09

Vlo