Subset data using non-sequential row numbers

I have a data frame with 30 rows and 100 columns (X).

I would like to create a new data frame (Y) with specific rows from the larger data frame.

For example, I would like data frame (Y) to contain rows 1 through 5, 10 through 14, and 20.

I know that I can use the code:


and obtain the first five rows, but I cannot work out a similar code to obtain rows 1:5, 10:14, and 20.


Generally, when selecting rows in a data frame or matrix, one uses the familiar X[rows, cols] format. It's helpful to remember that both of the parameters can be generated not simply as simple numbers or sequences, but also through the concatenation of numbers and sequences. Therefore, for your problem you can use something like the following:

Y <- X[c(1:5, 10:14, 20), ]

This will select rows 1 through 5, rows 10 through 14, and row 20, together with all of the columns in X, and assign the result to Y.

Need Your Help

NuGet package restore with Mono on Travis CI failing

c# .net mono nuget travis-ci

My project compiles &amp; runs fine on OSX and Windows. However, trying to get it hooked up to Travis CI, I get this error from NuGet (using version 2.8):

Transfering multiple parameters in the applet-servlet communication

java servlets applet

I am implementing an applet ---servlet communication. There are two parameters that need to be sent by applet to the servlet. I am not sure can I implement the transferring process as follows? If...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.