[R] subset in a matrix

Henrique Dallazuanna wwwhsd at gmail.com
Tue Feb 9 21:19:20 CET 2010


Try this:

z[z[,1] < 0,]

On Tue, Feb 9, 2010 at 6:12 PM, DonDiego <jorge.nieves at moorecap.com> wrote:
>
> Hi,
>
> I have a matrix of data values like the example bellow. I would like to
> extract a subset of the matrix for the values where the first column is
> negative.  I am using the subset function. However, I am getting an error
> message that the conditional variable doe snot exist.  For some reason, the
> subset operation only works if I transform the matrix to a data set using
> as.data.set(). The help indicates that the subset function can be applied to
> matrixes and data sets. I am wondering if anyone has seen a similar problem
> before. am I using the correct syntax?
>
>
>
> n = 15
> m = 5
>
> cnames = paste("x",1:m,sep="")
> rnames = 1:n
>
> z = matrix(rnorm(n*m),n,m,dimnames =list(rnames,cnames))
>
>
> Thanks,
>
> Jorge
>
>
>
>
> test = subset(z,x1 < 0, select = c(cnames))
>
> --
> View this message in context: http://n4.nabble.com/subset-in-a-matrix-tp1474958p1474958.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list