Message-ID: <201205211827.58821.o.godoy@met.no>
Date: 2012-05-21T16:27:58Z
From: Øystein Godøy
Subject: Changing selected elements of an array
In-Reply-To: <CANz9Z_KyWf6cAzqRH6KYzmL8w-j8SW-riprS1waVwtYRFGQgEg@mail.gmail.com>
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.
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/