Skip to content

ommoting rows

6 messages · Jose Narillos de Santos, Bert Gunter, David Winsemius +2 more

#
Please read An Introduction to R (or other R tutorial) to learn about
indexing in R.

?"[" or ?subset also will tell you how to do it, but they are rather terse.

-- Bert

On Tue, Sep 18, 2012 at 12:08 PM, Jose Narillos de Santos
<narillosdesantos at gmail.com> wrote:

  
    
#
On Sep 18, 2012, at 12:08 PM, Jose Narillos de Santos wrote:

            
That text is mangled but this example of logical indexing should suffice, assuming that object is named "dat":
V1   V2 V3
1 -9552 9552  C
3  9614 9614  V
5 -9752 9752  C
#
Hi,
Try this:
?dat1<-data.frame(V1=c(-9552,0,9614,0,-9752,0,0),V2=c(9552,9653,9614,9527,9752,9883,9865),V3=c("C",0,"V",0,"C",0,0))
?as.matrix(subset(dat1,V3!=0))
#? V1????? V2???? V3 
#1 "-9552" "9552" "C"
#3 " 9614" "9614" "V"
#5 "-9752" "9752" "C"
A.K.




----- Original Message -----
From: Jose Narillos de Santos <narillosdesantos at gmail.com>
To: r-help <r-help at r-project.org>
Cc: 
Sent: Tuesday, September 18, 2012 3:08 PM
Subject: [R] ommoting rows

Hi I have an output data Data.csv

this style:

,"V1","V2","V3"? 1,"-9552","9552","C"? 2,"0","9653","0"
3,"9614","9614","V"? 4,"0","9527","0"? 5,"-9752","9752","C"
6,"0","9883","0"? 7,"0","9865","0"
I want to create a new matrix ommintg all the rows where third column has
0.

There is a way to do it easyly?

Many thanks in advance.

My final matrix will have:

,"V1","V2","V3"1,"-9552","9552","C"
3,"9614","9614","V"5,"-9752","9752","C"

??? [[alternative HTML version deleted]]

______________________________________________
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.
#
Hi,
On Sep 18, 2012, at 3:25 PM, Bert Gunter wrote:

            
That's a great start, but it might be helpful to provide a bit more specificity when directing a newcomer like Jose to the Introduction to R.  Perhaps by providing a link to the relevant sections like this...

Here are nice descriptions of four different ways to index a vector:

http://cran.r-project.org/doc/manuals/R-intro.html#Index-vectors  

These kinds of indexing techniques can be applied to each dimension of an array-like object such as your example.  You can see in David Winsemius' nice example that he applied the "logical" type of indexing to the rows of your data.

Cheers,
Ben
Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd. P.O. Box 475
West Boothbay Harbor, Maine   04575-0475 
http://www.bigelow.org