[R] row selection
David Winsemius
dwinsemius at comcast.net
Fri Oct 9 19:23:40 CEST 2009
On Oct 9, 2009, at 12:41 PM, Ashta wrote:
> Hi all,
>
> Thank you for your help. Now I am able to select every 5th row of
> the data
> from the main data set (x)
> using
>
> sub1<- x[seq(1, nrow(x), by=5), ]
>
>
> So sub1 contains one fith of the data set X. I want also create
> another
> data set that will contain the remaining data set from X (ie., four
> fifth
> of the data set).
sub1<- x[-seq(1, nrow(x), by=5), ]
>
> Any help is highly appreciated.
>
> I have a matrix named x with N by C
> I want to select every 5 th rrow from matrix x I used the following
> code
>> n<- nrow(x)
>>> for(i in 1: n){
>> + b <- a[i+5,]
>>> b
>> }
>
>
>> sc < x[seq(1, nrow(x), by=5), ]
>
>>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org
>> ]
>> On Behalf Of David Winsemius
>> Sent: Thursday, October 08, 2009 4:19 PM
>> To: Ashta
>> Cc: R help
>> Subject: Re: [R] row selection
>>
>>
>> On Oct 8, 2009, at 4:14 PM, Ashta wrote:
>>
>>> Hi all,
>>> I have a matrix named x with N by C
>>> I want to select every 5 th rrow from matrix x I used the following
>>> code
>>> n<- nrow(x)
>>>> for(i in 1: n){
>>> + b <- a[i+5,]
>>>> b
>>> }
>>> Error: subscript out of bounds
>>
>> What did you expect when "i" in your loop counter became one greater
>> than the number of rows?
>>
>>>
>>
>>
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list