I have association matrix file that looks like this (4 rows and 3 columns) .
test=read.table("test.csv", sep=",", header=T) head(test) LosAngeles SanDiego Seattle 1 2 3 A 1 0.1 0.2 0.2 B 2 0.2 0.4 0.2 C 3 0.3 0.5 0.3 D 4 0.2 0.5 0.1 What I want to is reshape this matrix file into data frame. The result should look something like this (12(= 4 * 3) rows and 3 columns):
RowNum ColumnNum Value 1 1 0.1 2 1 0.2 3 1 0.3 4 1 0.2 1 2 0.2 2 2 0.4 3 2 0.5 4 2 0.5 1 3 0.2 2 3 0.2 3 3 0.3 4 3 0.1 That is, if my matrix file has 100 rows and 90 columns. I want to make new data frame file that contains 9000 (= 100 * 90) rows and 3 columns.
I've tried to use reshape package but but I do not seem to be able to get it right. Any suggestions how to solve this problem?
as.data.frame(as.table(test))from (stackoverflow.com/questions/15885111/…)dput(head(test))?meltin thereshape2package could help (qualify this with i am a bit unsure of your data format - doesn't look like 4 rows / 3 columns)