Displaying 20 results from an estimated 50000 matches similar to: "Generalized 2D list/array/whatever?"
2006 Sep 20
2
Unexpected behavior of apply() over a 3d array
Dear listeRs,
I'm finding that apply() behaves strangely when used on a 3-d array. For
example:
> at <- array(1:27,dim=c(3,3,3))
> at
, , 1
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
, , 2
[,1] [,2] [,3]
[1,] 10 13 16
[2,] 11 14 17
[3,] 12 15 18
, , 3
[,1] [,2] [,3]
[1,] 19 22 25
[2,] 20 23 26
2009 Apr 21
1
Functions in lists or arrays?
I have a problem where I need to have a "driver" style R program that will
extend itself, given more
'source("extra.R")' style lines. IE: easy to modify by other people. The
problem becomes when I
would like to create an array or list of functions. Each function, possibly
hundreds of them, are really
created by other programs, generating an *.R file. So for
2015 Dec 17
1
array() ignores illegal non-list dimnames
Is there a reason that array() silently ignores dimnames that are not
a list but matrix() gives an error?
> str(matrix(11:14, 2, 2, dimnames=c("Rows","Cols")))
Error in matrix(11:14, 2, 2, dimnames = c("Rows", "Cols")) :
'dimnames' must be a list
> str(array(11:14, dim=c(2, 2), dimnames=c("Rows","Cols")))
int
2010 Nov 27
1
return vector of element names for vector, matrix or array
Just as as.vector() takes a vector, matrix or array and returns a
vector in row-major order,
I'd like to write a function to take such an object and return the
dimension names,
pasted with some separator, as a similar vector.
Here is something ugly cobbled together to demonstrate what I want: a
function to work
for any number of dimensions.
vecnames <- function(x, sep=':') {
2004 Jan 14
1
array(list(),c(2,5)) gives error in R 1.8.1
Hi
In R 1.7 the following worked fine:
> array(list(),c(2,5))
[,1] [,2] [,3] [,4] [,5]
[1,] NULL NULL NULL NULL NULL
[2,] NULL NULL NULL NULL NULL
now in R 1.8.1 I get the error:
Error in rep.int(data, t1) : invalid number of copies in "rep"
In addition: Warning message:
NAs introduced by coercion
thanks for help, I need this possibility for storing objects (lm
results) in
2011 May 16
1
Extracting the dimnames of an array with variable dimensions
Hi list,
In a function I am writing, I need to extract the dimension names of
an array. I know this can be acheived easily using dimnames() but my
problem is that I want my function to be robust when the number of
dimensions varies. Consider the following case:
foo <- array(data = rnorm(32), dim = c(4,4,2),
dimnames=list(letters[1:4], LETTERS[1:4], letters[5:6]))
# What I want is to extract
2012 Jan 13
2
multidimensional array calculation
Hello,
probably it is quite easy but I can get it: I have
mulitple numeric vectors and a function using
all of them to calculate a new value:
L <- c(200,400,600)
AR <- c(1.5)
SO <- c(1,3,5)
T <- c(30,365)
fun <- function(L,AR,SO,T){
exp(L*AR+sqrt(SO)*log(T))
}
How can I get an array or dataframe where
all possible combinations of the factors are listed
and the new value is
2000 Mar 22
3
segmentation fault with 1D array (PR#500)
Here's a nasty one. The following has caused a segmentation
fault and possibly also a bus error.
fred <- 1:6
dim(fred) <- 6
dimnames(fred) <- list(LETTERS[1:6])
mm <- matrix(1:12, 2, 6)
mm %*% fred # segmentation fault here
In the case without the dimnames assignment the result is OK.
Cheers, Jonathan.
--please do not edit the information below--
Version:
platform =
2012 Jun 02
2
Add a dim to an array
Dear list,
I'm trying to add a new dim to a multidimensional array. My array looks
like this
a1 <- array(1:8, c(2, 2, 2))
dimnames(a1) <- list(A = c("A1", "A2"),
B = c("B1", "B2"),
D = c("D1", "D2"))
I would like to add a new dim 'group' with the value "low".
2003 Oct 31
4
Array Dimension Names
I would like to reference array dimensions by name in an apply and a summary
function. For example:
apply(x, "workers", sum)
Is there a better way to do this than creating a new attribute for the array
and then creating new methods for apply and summary? I don't want to name
the individual elements of each dimension (such as with dimnames) but rather
name the dimensions. Thanks
2010 Mar 16
2
Dimnames of array inside loop
hello R-helpers,
I have an array
acuracia <- array(NA, dim = c(1, 1, A, B, C))
which is first defined and in the example above with dimensions 1x1xAxBxC.
My array is then filled using 3 loops (I am not well familiar yet with
lapply or sapply functions so I am still a loop-user):
for (i in 1:A){
for (j in 1:B){
for (k in 1:C){
acuracia[,,i,j,k] <- correlacao / (sqrt(ac))
}
}
}
then I
2012 Jun 04
2
Convert 2-dim array to 3-dim array
Hello R-users,
I'd like to load data from a CSV-file to a 3-dimensional array. However
the default seems to be 2-dimensional. It would also be ok to load the
data and then convert it to a 3-dimensional structure.
I've been trying:
dat = read.csv(filename)
myArr = as.array(dat, dim = c(12,100,3))
However, I get an error message:
Error in `dimnames<-.data.frame`(`*tmp*`,
2010 Nov 30
1
warning creating an as.array method in a package
[Env: R 2.11.1, Win Xp, using Eclipse/StatET]
In a package I'm working on, I want to create as.matrix() and as.array()
methods for a particular kind of
object (log odds ratios). These are returned in a loddsratio object as
the $coefficients component,
a vector, but really reflect an underlying (R-1)x(C-1)xstrata array,
whose attributes are contained in other
components.
I define coef,
2012 Aug 08
1
dimnames in array
Hello,
I'm working with an array; I'm trying to make it so that an array of
dim(42,2,2) has names whose length corresponds to that of the array,
and am hoping someone with experience with this can see what I'm not
doing correctly:
data11 = array(0,c(41,2,2))
y = lsoda(x0,times,fhn$fn.ode,pars)#This is make.fhn() from colloc
infer package#
y = y[,2:3]
2010 Dec 09
1
warning creating an as.array method in a package
I posted on this topic to r-help, but never got a sufficient answer, so
I'm reposting here.
[Env: R 2.11.1, Win Xp, using Eclipse/StatET]
In a package I'm working on, I want to create as.matrix() and as.array()
methods for a particular kind of
object (log odds ratios). These are returned in a loddsratio object as
the $coefficients component,
a vector, but really reflect an underlying
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
??
> z <- array(1:24,dim=2:4)
> all.equal(f(z,3),f2(z,3))
[1] "Attributes: < Component ?dim?: Mean relative difference: 0.4444444 >"
[2] "Mean relative difference: 0.6109091"
In fact,
> dim(f(z,3))
[1] 2 3 4
> dim(f2(z,3))
[1] 3 4 2
Have I made some sort of stupid error here? Or have I misunderstood
what was wanted?
Cheers,
Bert
Bert Gunter
2004 Jul 02
2
Error:length of dimnames [2] not equal to array extent ?
Hi everyone,
I have the following problem:
I want to perform a LDA with the function lda().
My data object mat.data is a matrix with dimensions
> dim(mat.data)
[1] 1228 44
and my grouping vector grp has length 1228:
> length(grp)
[1] 1228
Every time I call lda(), the following error message occurs:
> lda(mat.data,grp)
Error in lda.default(x, grouping, ...) : length of dimnames [2]
2017 Jun 01
3
Reversing one dimension of an array, in a generalized case
Here is an alternative approach using apply(). Note that with apply() you are reversing rows or columns not indices of rows or columns so apply(junk, 2, rev) reverses the values in each column not the column indices. We actually need to use rev() on everything but the index we are interested in reversing:
f2 <- function(a, wh) {
dims <- seq_len(length(dim(a)))
dims <-
2005 Feb 17
1
Subsetting using dimnames on S4 array-based class
Hello,
I did send this message to r-help and got no reply, no I am resubmitting
here in case this was a bit too specific for the other list.
Many thanks,
Iago
From:
Iago Mosqueira
<imosqueira@suk.azti.es>
To:
r-help@stat.math.ethz.ch
Subject:
Subsetting using dimnames on S4
array-based class
2011 Apr 20
1
Error in dimnames(x) for Poisson EWMA model
I am attempting to run a Poisson EWMA model using Patrick Brandt's source code. I get the following error when I run the code:
Error in dimnames(x) <- dn :
length of 'dimnames' [1] not equal to array extent
Dimnames(x) looks like this:
[[1]]
NULL
[[2]]
[1] "mip" "div" "nom" "unity" "mood"