Skip to content
Back to formatted view

Raw Message

Message-ID: <DFCABD19-4BD3-46D7-A7E5-486211AD1EDE@comcast.net>
Date: 2011-01-14T04:00:48Z
From: David Winsemius
Subject: Sorting a vector with conditions
In-Reply-To: <1294967210469-3217031.post@n4.nabble.com>

On Jan 13, 2011, at 8:06 PM, ADias wrote:

>
> Hi,
>
> Suposse I have a vector:
>
> v->c(10,13,4,6,45,27,32,21,1,8,14,36)

NOT executable R.

>
> how do i sort just the odd numbers leaving the rest - the even  
> numbers - on
> the same positions as they already are on the vector?

 > v[v %% 2 !=0] <- sort(v[v %% 2 !=0])
 > v
  [1] 10  1  4  6 13 21 32 27 45  8 14 36
>

David Winsemius, MD
West Hartford, CT