Thanks, Michael. I was, however, after a function I coul use for both
extracting and replacing subarrays. In case anybody else stumbles over
this problem, here is my solution. Its programming is most probably
horribly clumsy:
ind.datacube = function(
##title create logical index matrices for
I'm just wondering
When I use your function on your data I get a result that is not very
intuitive. Is this what you were trying to do?
(I took the liberty of setting dims to 3 since 'auto', 1, and 2 didn't
work.
data- array(rnorm(64),dim=c(4,4,4))
indices-
Hi Jannis,
Like Gene, I'm not entirely sure what your code is intended to do, but it
wasn't hard to adapt mine to at least print out the desired slice through
the higher-dimensional array:
cubeValues - function(Insert, Destination, Location) {
Location = as.matrix(Location)
Location =
Thanks, Gene, for your hint! I indeed did not check any possible
situation and my function was not returning what I intened it to return.
This updated version, however, should. I am sure there are much easier
ways (or ready made functions) to do the same.
ind.datacube = function(
##title
(I was just about to send this before your last reply)
As a more general tip, I find that using %in% is easier to understand than
is.element and setdiff because it can be more universal, especially when
combined with all and the !.
To me the functions like setdiff are easier to read, but harder
This function you wrote is interesting, but I almost missed it since I
didn't see a direct example!
cubeValues(NULL, data, indices)
cubeValues(1, data, indices)
cubeValues(c(1,2), data, indices)
(sorry if I'm beating a dead horse here)
On Thu, Aug 4, 2011 at 2:58 PM, R. Michael Weylandt
As currently implemented it works for both Location and Destination (I
really should think of some better variable names) of any dimensionality,
but it does assume that if say, you give a 2d location, those correspond to
the first two dimensions of destination.
But if you give 1d or 3d, e.g., for
Your function only works for the first dimensions (e.g. indices
indicating the positions in the first two dimensions in datacube), correct?
Otherwise it looks very handy! And certainly more elegent than my
function monster!
Jannis
On 08/04/2011 09:58 PM, R. Michael Weylandt wrote:
Hi
Thanks for all the replies!Unfortunately the solutions only work for
extracting subsets of the data (which was exactly what I was asking for)
and not to replace subsets with other values. I used them, however, to
program a rather akward function to do that. Seems I found one of the
few aspects
This might be a little late: but how about this (slightly clumsy) function:
putValues - function(Insert, Destination, Location) {
Location = as.matrix(Location)
Location = array(Location,dim(Destination))
Destination[Location] - Insert
return(Destination)
}
It currently
Dear R community,
I have a general question regarding indexing in multidiemensional arrays.
Imagine I have a three dimensional array and I only want to extract on
vector along a single dimension from it:
data- array(rnorm(64),dim=c(4,4,4))
result - data[1,1,]
If I want to extract
On 11-08-01 5:38 AM, Jannis wrote:
Dear R community,
I have a general question regarding indexing in multidiemensional arrays.
Imagine I have a three dimensional array and I only want to extract on
vector along a single dimension from it:
data- array(rnorm(64),dim=c(4,4,4))
result-
On Aug 1, 2011, at 10:50 AM, Duncan Murdoch wrote:
On 11-08-01 5:38 AM, Jannis wrote:
Dear R community,
I have a general question regarding indexing in multidiemensional
arrays.
Imagine I have a three dimensional array and I only want to extract
on
vector along a single dimension
What do you think about this?
apply(data, 3, '[', indices)
On Mon, Aug 1, 2011 at 4:38 AM, Jannis bt_jan...@yahoo.de wrote:
Dear R community,
I have a general question regarding indexing in multidiemensional arrays.
Imagine I have a three dimensional array and I only want to extract on
14 matches
Mail list logo