Reshape three column data frame to matrix (“long” to “wide” format) [duplicate]
问题 This question already has answers here : How to reshape data from long to wide format (11 answers) Closed 28 days ago . I have a data.frame that looks like this. x a 1 x b 2 x c 3 y a 3 y b 3 y c 2 I want this in matrix form so I can feed it to heatmap to make a plot. The result should look something like: a b c x 1 2 3 y 3 3 2 I have tried cast from the reshape package and I have tried writing a manual function to do this but I do not seem to be able to get it right. 回答1: There are many ways