Skip to content
Back to formatted view

Raw Message

Message-ID: <CANz9Z_L32KQcs6k1ArE6g8pdahX-8_g4VEFMtaoE9cK+EAf3tw@mail.gmail.com>
Date: 2012-05-21T16:31:11Z
From: Joshua Wiley
Subject: Changing selected elements of an array
In-Reply-To: <201205211827.58821.o.godoy@met.no>

On Mon, May 21, 2012 at 9:27 AM, ?ystein God?y <o.godoy at met.no> wrote:
> Hi Joshua,
>
> Many thanks for your quick reply.
>
>> You can do it by passing a matrix for indexing instead of two vectors.
>> ?Here's an example:
>>
>> tmpmat <- matrix(NA, nrow = 10, ncol = 10,
>> ? dimnames = list(letters[1:10], LETTERS[1:10]))
>>
>> tmpmat[cbind(c("d", "e", "f"), c("D", "E", "F"))] <- 100
>> tmpmat
>>
>> The matrix is created using cbind() to columnwise bind the two vectors
>> together. ?Then it does what you want I think.
>>
>> Hope this helps,
>
> This looks interesting and is what I want, but I am not fully understanding
> the output I receive. The input array has 100 elements while the resulting
> vector after replacement is 106 elements long. I have tried to understand the
> manual on this, but it is yet not obvious for me how I am supposed to handle
> this output.

I cannot reproduce this behavior.  On my system, the output has 100 elements.


> All the best
> ?ystein
> --
> Dr. Oystein Godoy
> Norwegian Meteorological Institute
> P.O.BOX 43, Blindern, N-0313 OSLO, Norway
> Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
> Fax:(+47) 2296 3050 Institute home page: http://met.no/



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/