[R] For Subset or Reshaping the Table

hadley wickham h.wickham at gmail.com
Fri Feb 15 14:23:50 CET 2008


On Thu, Feb 14, 2008 at 7:53 PM, dinesh kumar <barupal at gmail.com> wrote:
> Hi  R users
>  I am a new user in the field of R.
>  I want to subset or reshape a data.frame.
>  For example I have a matrix like
>
>    A  B  C  D  E  F  G
>  a  1  2  3   4  5   6  7
>  b  4  6  8   9  5   5  6
>  c  3  4  4   4  3   3  6
>  d  1  2  4   6  8   8  9
>  e  5  6  7   8  9   2  3
>
>  I want to reshape the matrix in this format
>
>  Row  Col  Value
>  a       D     4
>  a       E     5
>  a       F     6
>  .        .      ..
>  e       E     9
>
>  I want only the  pair which pass a threshold for example >3.

library(reshape)
molten <- melt(mymatrix)
subset(molten, value > 3)

You can learn more about the reshape package at http://had.co.nz/reshape

Hadley


-- 
http://had.co.nz/



More information about the R-help mailing list