Re: [R] row selection

2009-10-11 Thread Bernardo Rangel Tura
On Thu, 2009-10-08 at 16:14 -0400, 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
> 
> Can any body point out the problem?

Hi Ashta,

If I understand your request you need select row 5,10,15, ...
In this case you can use this script:

x[1:nrow(n)%%5==0]


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

__
R-help@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.


Re: [R] row selection

2009-10-09 Thread David Winsemius


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-boun...@r-project.org [mailto:r-help-boun...@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

__
R-help@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.


Re: [R] row selection

2009-10-09 Thread Nutter, Benjamin
sub3 <- x[-seq(1, nrow(x), by=5), ]
 
Notice the '-' in front of the seq() command.  This will select
everything but what is in the sequence.

 



From: Ashta [mailto:sewa...@gmail.com] 
Sent: Friday, October 09, 2009 12:42 PM
To: Nutter, Benjamin
Cc: r-help@r-project.org
Subject: Re: [R] row selection


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).

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-boun...@r-project.org
[mailto:r-help-boun...@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


__
R-help@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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for
use\...{{dropped:13}}

__
R-help@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.




===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:16}}

__
R-help@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.


Re: [R] row selection

2009-10-09 Thread Ashta
 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).

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-boun...@r-project.org [mailto:r-help-boun...@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
>
> __
> R-help@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.
>
>
> ===
>
> P Please consider the environment before printing this e-mail
>
> Cleveland Clinic is ranked one of the top hospitals
> in America by U.S. News & World Report (2008).
> Visit us online at http://www.clevelandclinic.org for
> a complete listing of our services, staff and
> locations.
>
>
> Confidentiality Note:  This message is intended for use\...{{dropped:13}}
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] row selection

2009-10-08 Thread Khanh Nguyen
The problem is your loop condition.

For example, when i reaches (n-3), a[i + 5, ] is out of bounds.

-k

On Thu, 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
>
> Can any body point out the problem?
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] row selection

2009-10-08 Thread David Winsemius


On Oct 8, 2009, at 4:18 PM, David Winsemius wrote:



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?


Perhaps (assuming that b has been created with same dimensions as a:
for (i in seq(1, nrow(a), by= 5) { b=a[i,] }


Which I suspect will not give you what you want, either, since that  
code would overwrite be each time through the loop, so maybe:



for (i in seq(1, nrow(a), by= 5) { b=rbind(b, a[i,] ) }


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


Re: [R] row selection

2009-10-08 Thread Nutter, Benjamin
> x[seq(1, nrow(x), by=5), ] 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@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

__
R-help@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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
R-help@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.


Re: [R] row selection

2009-10-08 Thread David Winsemius


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

__
R-help@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.


[R] row selection

2009-10-08 Thread Ashta
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

Can any body point out the problem?

[[alternative HTML version deleted]]

__
R-help@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.