dcast(res, factoroneid ~ factortwoid)
Works for me.
سؤال
I am a bit confused on how to use dcast function even after reading the documentation. I am trying to dcast a molten dataframe as below
> head(res)
factoroneid factortwoid val
1 1 1 5.8223670800
2 1 2 -1.3314644000
3 1 3 0.7206910120
4 1 4 0.0762039224
5 1 5 2.7409736300
6 1 6 0.0896606575
res contains 1st column and 2nd column as indices. I need to use 1st column data as row number and 2nd column data as column number and generate a matrix with value from 3rd column. I am trying something like this but the data doesn't look correct.
temp <- dcast(res, factoroneid + factortwoid ~ val)
expected output should be:
1 2 3 4 ...
1 5.82 -1.33 0.72 0.076 ...
2
3
4
.
.
Could you please suggest?
المحلول
dcast(res, factoroneid ~ factortwoid)
Works for me.