Re: [R] deleting lines and row small than a value

From: jim holtman <jholtman_at_gmail.com>
Date: Thu, 24 May 2007 13:44:57 -0400

I am not sure what your matrix looks like, but here is some code that will check each row and then delete those rows with any value < .7:

> set.seed(1)
> data <- matrix(runif(100,0,10), 10)
> data

           [,1]     [,2]      [,3]     [,4]      [,5]      [,6]
[,7]     [,8]     [,9]     [,10]

 [1,] 2.6550866 2.059746 9.3470523 4.820801 8.2094629 4.7761962 9.1287592 3.390729 4.346595 2.3962942
 [2,] 3.7212390 1.765568 2.1214252 5.995658 6.4706019 8.6120948 2.9360337 8.394404 7.125147 0.5893438
 [3,] 5.7285336 6.870228 6.5167377 4.935413 7.8293276 4.3809711 4.5906573 3.466835 3.999944 6.4228826
 [4,] 9.0820779 3.841037 1.2555510 1.862176 5.5303631 2.4479728 3.3239467 3.337749 3.253522 8.7626921
 [5,] 2.0168193 7.698414 2.6722067 8.273733 5.2971958 0.7067905 6.5087047 4.763512 7.570871 7.7891468
 [6,] 8.9838968 4.976992 3.8611409 6.684667 7.8935623 0.9946616 2.5801678 8.921983 2.026923 7.9730883
 [7,] 9.4467527 7.176185 0.1339033 7.942399 0.2333120 3.1627171 4.7854525 8.643395 7.111212 4.5527445
 [8,] 6.6079779 9.919061 3.8238796 1.079436 4.7723007 5.1863426 7.6631067 3.899895 1.216919 4.1008408
 [9,] 6.2911404 3.800352 8.6969085 7.237109 7.3231374 6.6200508 0.8424691 7.773207 2.454885 8.1087024
[10,] 0.6178627 7.774452 3.4034900 4.112744 6.9273156 4.0683019 8.7532133 9.606180 1.433044 6.0493329
> less.7 <- apply(data, 1, function(x) any(x < .7))
> less.7

 [1] FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE
> data[!less.7,]
         [,1]     [,2]     [,3]     [,4]     [,5]      [,6]      [,7]
[,8]     [,9]    [,10]

[1,] 2.655087 2.059746 9.347052 4.820801 8.209463 4.7761962 9.1287592 3.390729 4.346595 2.396294
[2,] 5.728534 6.870228 6.516738 4.935413 7.829328 4.3809711 4.5906573 3.466835 3.999944 6.422883
[3,] 9.082078 3.841037 1.255551 1.862176 5.530363 2.4479728 3.3239467 3.337749 3.253522 8.762692
[4,] 2.016819 7.698414 2.672207 8.273733 5.297196 0.7067905 6.5087047 4.763512 7.570871 7.789147
[5,] 8.983897 4.976992 3.861141 6.684667 7.893562 0.9946616 2.5801678 8.921983 2.026923 7.973088
[6,] 6.607978 9.919061 3.823880 1.079436 4.772301 5.1863426 7.6631067 3.899895 1.216919 4.100841
[7,] 6.291140 3.800352 8.696908 7.237109 7.323137 6.6200508 0.8424691 7.773207 2.454885 8.108702
>

On 5/24/07, Milton Cezar Ribeiro <milton_ruser_at_yahoo.com.br> wrote:
>
> Hi there
>
> I made a correlation matrix from my data frama and I would like to delete
> all lines/rows when r-value is smaller than 0.7
>
> How can I do that?
>
> Kind regards,
>
> Miltinho
>
> __________________________________________________
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_stat.math.ethz.ch 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.
Received on Thu 24 May 2007 - 17:54:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 May 2007 - 19:31:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.