tags:

views:

103

answers:

2

Hello

How can I select several not continuous rows ?

If I wanted to select rows 1 to 7 I'll write mydata[,1:7]

But what if I need to select rows 1 to 5 and 10 to 15?

+1  A: 

mydata[:,range(1,6)+range(10,16)]. In python a suppose.

Bernardo Kyotoku
+5  A: 

Briefly:

  1. Your example is wrong, you selected columns. You meant mydata[1:7,]
  2. The generalisation is easy: change the indexing expression as in mydata[ c(1:5, 10:15), ]

You may want to acquaint yourself with the An Introduction to R manual that came with your R installation to learn more about indexing.

Dirk Eddelbuettel
OK, thanks. I confused the words. I've read that book but there are many details
@user425895 : You shouldn't read it. You should **use** it. None of my students would even dare to ask that question. If the Introduction to R is too difficult for you, take the R Guide of Owen. I hope you have enough experience with Google to find that one by yourself...
Joris Meys
@user425895: but you expect other people to have read the introduction **and** tell you what it says whenever you have a question that could easily be answered by reading it? Is it that time consuming to point your web browser to the online HTML version of the manual (that Dirk linked you to) and find the answer for yourself? Instead, you send an email to R-Help and post a question here and then wait for the answer? You'll be far more productive if you learn to solve the simple things yourself and save the R-help list and websites like this for the harder things not covered in the manuals.
Gavin Simpson
A bit harsh with the RTFM/LMGTFY rant here guys.
Brandon Bertelsen