Displaying 20 results from an estimated 20000 matches similar to: "Add a dim to an array"
2017 Jun 06
2
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
Hi,
It's nice to be able to define S4 classes with slots that correspond
to standard attributes:
setClass("A1", slots=c(names="character"))
setClass("A2", slots=c(dim="integer"))
setClass("A3", slots=c(dimnames="list"))
By doing this, one gets a few methods for free:
a1 <- new("A1", names=letters[1:3])
2013 Mar 12
2
big edge list to adjacency matrix
I have huge list of edges with weights.
a1 b1 w1
a2 b2 w2
a3 b3 w3
a1 b1 w4
a3 b1 w5
I have to convert it into 2 dim matrix
b1 b2 b3
a1 max(w1,w4) 0 0
a2 0 w2 0
a3 w5 0 w3
if edges repeated take the maximum weights. How do this efficiently without
using for loop? Any idea.
thanks
Avi
[[alternative
2017 Jun 06
1
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
I've fixed this and will commit soon.
Disregard my dim<-() example; that behaves as expected (the class needs a
dim<-() method).
Michael
On Tue, Jun 6, 2017 at 5:16 AM, Michael Lawrence <michafla at gene.com> wrote:
> Thanks for the report. The issue is that one cannot set special attributes
> like names, dim, dimnames, etc on S4 objects. I was aready working on this
>
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
2009 Mar 20
4
how to make aggregation in R ?
Hi,
I am trying to aggregate the sum of my test data.frame as follow:
testDF <- data.frame(v1 = c("a", "a", "a", "a", "a", "b", "b", "b", "b",
"b", "c", "c", "c", "c", "c", "d", "d", "d", "d",
2005 Jun 03
2
rearrange data
Dear all:
I have this:
A1 B1 C1 D1 E1
A2 B2 C2 D2 E2
A3 B3 C3 D3 E3
And I want this
A1 E1
B1 E1
C1 E1
D1 E1
A2 E2
B2 E2
C2 E2
D2 E2
A3 E3
B3 E3
C3 E3
D3 E3
Example:
m<- matrix(1:15,nrow=3,byrow=T)
m
v<- unlist(list(t(m[,1:4])))
u<- rep(c(5,10,15),c(4,4,4))
data.frame(v,u)
This is the result I want but I would like to learn a simpler way to do it.
Any clue?
2010 May 06
2
Data frame "pivoting"
Dear R experts,
I am trying to solve this problem, related to the possibility of
changing the shape of a data frame using a "pivoting-like" function.
I have a dataframe df of observations as follows:
ID VALIDITY YEAR PROPERTY PROPERTY VALUE
A1 2007 P1 V1
A1 2007 P2 V2
A1 2007 P3 V3
A1 2008 P1 V10
A1 2008 P2 V20
A2 2007 P5 V50
A2 2008 P6 V20
A3 2007
2013 Nov 21
1
how can I import a number of datsets in a folder in my working directory to a list in R
Hi,
Suppose, if I create 15 files in my working directory.
set.seed(48)
lapply(1:15,function(i) {m1 <- matrix(sample(1:20,1686*2,replace=TRUE),nrow=1686,ncol=2); write.table(m1,paste0("file_",i,".txt"),row.names=FALSE,quote=FALSE)})
?D <-dir()
D1 <- D[order(as.numeric(gsub("\\D+","",D)))]
D1
?res <- t(sapply(D1,function(x) {x1<-
2011 Jan 10
1
Using combn
Dear list,
I want to apply the "table" function to every pair of variables in df
and the return should be a list.
setwd(123)
asd <- data.frame(a1=sample(1:4, 20, replace=TRUE),
a2=sample(1:4, 20, replace=TRUE),
a3=sample(1:4, 20, replace=TRUE),
a4=sample(1:4, 20, replace=TRUE))
with(asd, table(a1, a2))
with(asd, table(a1,
2007 Mar 09
1
Applying some equations over all unique combinations of 4 variables
#I have a data set that looks like this. A bit more
complicated actually with
# three factor levels but these calculations need to
be done on one factor at a
#I then have a set of different rates that are applied
#to it.
#dataset
cata <- c( 1,1,6,1,1,2)
catb <- c( 1,2,3,4,5,6)
doga <- c(3,5,3,6,4, 0)
data1 <- data.frame(cata, catb, doga)
rm(cata,catb,doga)
data1
# start rates
#
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)
2011 Oct 26
1
Calculate the difference using ave
Dear R users,
It may be very simple but it is being difficult for me.
I'd like to calculate the difference in percent between to measures.
My data looks like this:
set.seed(123)
df1 <- data.frame(measure = rep(c("A1", "A2", "A3"), each=3),
water = sample(c(100:200), 9),
tide = sample(c(-10:+10), 9))
df1
# What I want to calculate is:
2004 Jul 08
2
Getting elements of a matrix by a vector of column indice s
See if the following helps:
> m <- outer(letters[1:5], 1:4, paste, sep="")
> m
[,1] [,2] [,3] [,4]
[1,] "a1" "a2" "a3" "a4"
[2,] "b1" "b2" "b3" "b4"
[3,] "c1" "c2" "c3" "c4"
[4,] "d1" "d2" "d3" "d4"
[5,]
2013 Feb 07
1
Merging data in arrays
Dear All,
Here is a hypothetical sample (sorry for the clumsy code):
A1 <- matrix(1:5, nrow=5, ncol=1)
A2 <- matrix(6:10, nrow=5, ncol=1)
A3 <- matrix(11:15, nrow=5, ncol=1)
A4 <- matrix(16:20, nrow=5, ncol=1)
A5 <- matrix(21:25, nrow=5, ncol=1)
A6 <- matrix(26:30, nrow=5, ncol=1)
B1 <- matrix(c(A1, A2, A3), nrow=5, ncol=3)
B2 <- matrix(c(A2, A3, A4), nrow=5, ncol=3)
B3
2009 Oct 29
3
Removing & generating data by category
Dear R users,
Basically, from the following arbitrary data set:
a <-
data.frame(id=c(c("A1","A2","A3","A4","A5"),c("A3","A2","A3","A4","A5")),loc=c("B1","B2","B3","B4","B5"),clm=c(rep(("General"),6),rep("Life",4)))
> a
2007 Nov 13
7
combine two dataframe
I have two data frame A and B adn want to cross them.
A has format as:
a1 a2 a3
1 2 3
2 3 1
1 3 2
...
B:
b1 b2
1 2
2 1
...
the combine result shall be something like
a1 a2 a3 b1 b2
1 2 3 1 2
1 2 3 2 1
2 3 1 1 2
2 3 1 2 1
1 3 2 1 2
1 3 2 2 1
....
is there a function able of doing this instead of loops?
Thanks,
Sun
2007 Apr 09
3
sem vs. LISREL: sem fails
I am new to R.
I just tried to recreate in R (using sem package and the identical input data) a solution for a simple measurment model I have found before in LISREL. LISREL had no problems and converged in just 3 iterations.
In sem, I got no solution, just the warning message:
"Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
in: sem.default(ram =
2012 Apr 25
1
Create new Vector based on two colums
Hello,
I am trying to get a new vector 'x1' based on the not NA-values in
column 'a' and 'b'. I found a way but I am sure this is not the best
solution. So any ideas on how to "optimize" this would be great!
m <- factor(c("a1", "a1", "a2", "b1", "b2", "b3", "d1", "d1"), ordered
2005 Mar 19
2
simple problem, but not for me
Hello, I'm new in R and I want to do one thing that is very easy in excel, however, I cant do it in R.
Suppose we have the data frame:
data<- data.frame(A=c("a1","a2","a3","a4","a5"))
I need to obtain another column in the same data frame (lets say B=c(b1,b2,b3,b4,b5) in the following way:
b1=a1/(a1+a2+a3+a4+a5)
2005 Aug 15
2
queer data set
I have a dataset that is basically structureless. Its dimension varies
from row to row and sep(s) are a mixture of tab and semi colon (;) and
example is
HEADER1 HEADER2 HEADER3 HEADER3
A1 B1 C1 X11;X12;X13
A2 B2 C2 X21;X22;X23;X24;X25
A3 B3 C3
A4 B4 C4 X41;X42;X43
A5 B5 C5 X51
etc., say. Note that a blank