Displaying 20 results from an estimated 10000 matches similar to: "Convert 2-dim array to 3-dim array"
2012 Mar 21
2
list of matrices
Hello dear R-users,
I am currently trying to fill some datasatructure (array, list, hash...)
with matrices that are calculated by a function and do vary in size:
mylist = list()
for(i in 1:n)
mylist[i] = function(...) # returns a matrix
print(mylist[1]) # prints only the first element of the matrix
How can I store and afterwards access the matrices that are calculated
by my function?
2017 Jun 01
2
subletting an array according to dimnames
Hi all,
I have a three dimensional array with the corresponding dimension names.
I would like to subset the array according to the dimension names. For
example,
suppose I want to extract the values corresponding to A=20, B=10, C=0. I
know I
can do:
P2[dimnames(P2)$A==20, dimnames(P2)$B==10, dimnames(P2)$C==0]
But is there a better way for doing this? Thanks for your help!
Hanna
>
2008 Mar 05
3
How to make a 2-dim array being "interpreted" as an array rather than as a matrix
Dear List
A 2-dimensional array seems to be "interpreted" as a matrix whereas higher dimensional arrays are interpreted as arrays, e.g.
> a1 <- array(1:8,c(2,2,2))
> class(a1)
[1] "array"
> a2 <- array(1:4,c(2,2))
> class(a2)
[1] "matrix"
If I write a generic function (apologies if this is the wrong word) on arrays as
foo <- function(x)
2009 Jan 12
1
x <- 1:2; dim(x) <- 2? A vector or not?
Ran into the follow intermediate case in an external package (w/
recent R v2.8.1 patched and R v2.9.0 devel):
> x <- 1:2
> dim(x) <- 2
> dim(x)
[1] 2
> x
[1] 1 2
> str(x)
int [, 1:2] 1 2
> nrow(x)
[1] 2
> ncol(x)
[1] NA
> is.vector(x)
[1] FALSE
> is.matrix(x)
[1] FALSE
> is.array(x)
[1] TRUE
> x[1]
[1] 1
> x[,1]
Error in x[, 1] : incorrect number of
2012 Apr 19
3
How to "flatten" a multidimensional array into a dataframe?
Hi,
I have a three dimensional array, e.g.,
my.array = array(0, dim=c(2,3,4), dimnames=list( d1=c("A1","A2"),
d2=c("B1","B2","B3"), d3=c("C1","C2","C3","C4")) )
what I would like to get is then a dataframe:
d1 d2 d3 value
A1 B1 C1 0
A2 B1 C1 0
.
.
.
A2 B3 C4 0
I'm sure there is one function to do
2010 Sep 08
2
Drop single-dimensional array
Hi Simon, thank you for the concise reply.
Do you mean the reported behavior of drop() is not a bug?
It looks like a borderline bug to me (see below), but I'm not the judge of
that. If this is the intended behavior and serves an actual purpose, then
that could be explicitly documented in a \note{} on the help page.
Such a note would slightly reduce the surprise of users running into this
2017 Jun 02
0
subletting an array according to dimnames
Have you tried P2["20", "10", "0"] ?
Jean
On Thu, Jun 1, 2017 at 3:10 PM, li li <hannah.hlx at gmail.com> wrote:
> Hi all,
> I have a three dimensional array with the corresponding dimension names.
> I would like to subset the array according to the dimension names. For
> example,
> suppose I want to extract the values corresponding to A=20,
2012 Oct 02
2
Problem with mutli-dimensional array
I want to make a multi-dimensional array. To be specific I want to make the
following array
results<-array(0,dim=c(2,2,64,7))
This is the code I have created but it gives no result due to the error
"subscript out of bound".
x<-rep(7,7) # Missingness in intervention
y<-rep(7,7) # Missingness in control
2009 Jul 25
1
Determine the dimension-names of an element in an array in R
Hi:
How can I extract the dimension-names of a pre-defined element in a
multidimensional array in R ?
A toy example is provided below:
I have a 4-dimensional array with each dimension having certain length. In
the below example, "mydatastructure" explains the structure of my data.
mydatastructure = array(0, dim=c(length(b),length(z),length(x),length(d)),
dimnames=list(b,z,x,d))
where,
2007 Nov 15
1
HELP: How to subtract a vector out of each row of a matrix or array
Hi All,
I am having great trouble doing something pretty simple.
Here is what I did:
> x <- read.table("clipboard")
> dim (x)
[1] 126 10
> typeof(x)
[1] "list"
> w <- array(x)
> typeof(w)
"list"
Q1: How come after constructing an array out of the list, the type of
the array is still "list"?
> w <- as.array(x)
Error in
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".
2006 Feb 15
2
arrays of lists in R ("cell arrays" in Matlab)
Dear all
I would like to have some data in the form of a 2-dimensional array
(matrix) of lists, so that I can easily find the desired list object by
indexing the structure by rows and columns. In matlab there exists a
data type called "cell array": a matrix of "cells", which are composite
objects very similar to R lists.
I know that in R you can create 1-dimensional
2010 Dec 13
1
Qs re writing/reading arrays, dataframes
Hi! I'm just getting started with R (and with the analysis of large
datasets in general). I have several beginner-level questions whose
answers I have not been able to find, and was hoping one of you would
be kind enough to throw me a cluebrick or two.
I have a 6-dimensional numeric array (which I'll call myarray) that is
"fully named". By this I mean that non-NULL dimnames
2004 Aug 20
3
Loss of rownames and colnames
Hi,
I am working on some microarray data, and have some problems with
writing iterations.
In essence, the problem is that objects with three dimensions don't
have rownames and colnames. These colnames and rownames would
otherwise still be there in 2 dimensional objects.
I need to generate multiple iterations of a 2 means-clustering
algorithm, and these objects thus probably need 3
2010 Jan 21
2
Create a multi dimensional array from a data frame
Hello all,
I have data from a csv that i need to coerce into a multi dimensional
array. As you can see from my sample code i have yet to master building
efficient code. I can sort of do what i want but its very cumbersome code
and i know there is a better way to do it, i am just not expereinced enought
yet. So for the following:
#Create Data
h1i1a1<-sample(1:20, 5, replace=TRUE)
2008 Mar 15
3
empty array
Hi the list
Is it possible to create an empty matrix ? I do not mean an matrix with
a single value that is NA (which is not empty) but a real empty one,
with length=0.
I do not understand why we have length(numeric()), length(factor()) and
length(character()) to zero, and length(array()) to one... Any rason for
that ?
Thanks
Christophe
2005 Jan 21
6
dim vs length for vectors
Hi all,
I'm not sure if this is a feature or a bug (and I did read the
FAQ and the posting guide, but am still not sure). Some of my
students have been complaining and I thought I just might ask:
Let K be a vector of length k. If one types dim(K), you get
NULL rather than [1] k. Is this logical?
Here's the way I explain it (and maybe someone can provide a
more accurate
2003 Jul 11
3
short puzzles
Dear R users,
can someone help with these short puzzles?
1) Is there a function like outer() that evaluates a three-argument function
on a threedimensional grid - or else how to define such a function, say,
outer.3()? E.g., calculate (x/y)^z on (x,y,z) element of {1,2,3}x{3,4}x{4,5} and
return the results in a 3-dimensional array. I would naively use outer() on
two of the arguments within a
2007 Jul 31
1
Naming rows/columns in a 3 dimensional array/dataframe
Can I assign names to rows/columns in a i x k x j matrix / dataframe?
This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not the intended recipient, please telephone or email the sender and delete this message and any attachment from your system. If you are not the intended recipient you must not copy this message or
2012 Aug 13
4
dimnames in an array(I'll be grateful if this message will be passed to all list users)
Hello,
I'm hoping someone with a wide experience with R may be able to see
what the program is trying to tell me.
I've got an array:
y1=rnorm(41,0.2)
y2=rnorm(41,0.2)
y3=rbind(y1,y2)
data11<-array(0,c(41,2,2))
data11[,1,]=y3
data11[,2,]=y3
rownames(data11)<-rownames(data11, do.NULL = FALSE, prefix = "Obs.")
colnames=c("V","R")