similar to: apply ( , , table)

Displaying 20 results from an estimated 40000 matches similar to: "apply ( , , table)"

2004 Feb 06
3
column names in matrix vs. data frame in R 1.8
Is the difference in behavior below, introduced in 1.8, inconsistent or, at least, undesirable? I couldn't find this in the NEWS. On the one hand, > a <- matrix (1:4, nrow=2) > a <- data.frame (a) > names (a) <- c("break","next") > names (a) [1] "break" "next" On the other, > a <- matrix (1:4, nrow=2) > dimnames(a)
2010 Aug 03
2
How to name matrices from a list with lapply ?
Dear list, I have a list of matrices : i1 <- matrix(1:10, nrow = 2, ncol = 5) i2 <- matrix(11:20, nrow = 2, ncol = 5) j <- list(i1 = i1, i2 = i2) I would like to attribute names to each dimension, for each matrix, as follows : $i1 B1 B2 B3 B4 B5 A1 1 3 5 7 9 A2 2 4 6 8 10 $i2 B1 B2 B3 B4 B5 A1 11 13 15 17 19 A2 12 14 16 18 20 However, I have to use lapply function and attribute
2003 Mar 05
2
reserved words documentation
I wanted a data frame component to be named "next", for example: > m <- data.frame (matrix (0, nrow=2, ncol=2)) > names (m) <- c("prev", "next") > m prev next 1 0 0 2 0 0 But "next" being reserved prevents $ indexing without quotes: > m$next Error: syntax error > m$"next" [1] 0 0 Although they are mostly
2010 Aug 23
3
extracting p-values from Anova objects (from the car library)
Dear all, is there anyone who can help me extracting p-values from an Anova object from the car library? I can't seem to locate the p-values using str(result) or str(summary(result)) in the example below > A <- factor( rep(1:2,each=3) ) > B <- factor( rep(1:3,times=2) ) > idata <- data.frame(A,B) > fit <- lm( cbind(a1_b1,a1_b2,a1_b3,a2_b1,a2_b2,a2_b3) ? sex,
2005 Jan 13
4
zero index and lazy evaluation in ifelse()
I don't understand this behavior: > a <- c(0, 1, 2, 3) > b <- c(1, 2, 3, 4) > ifelse (a == 0, 0, b[a]) [1] 0 2 3 1 rather than the desired 0 1 2 3. Thanks for any explanation.
2013 Sep 04
2
Random products of rows in a matrix
Hello everybody, Without any loop and any package, I would like to return N products of M rows in a matrix A : Today, I managed to do it with a loop : B <- matrix(NA, ncol = ncol(A), nrow = 0) for (i in 1 : N) B <- rbind(B, apply(A[sample(1 : nrow(A), M, replace = T), ], 2, prod)) Do you have a solution ? Thank you in advance ! [[alternative HTML version deleted]]
2013 Feb 23
1
how to calculate left kronecker product?
For an application, I have formulas defined in terms of a left Kronecker product of matrices, A,B, meaning A \otimes_L B = {A * B[i,j]} -- matrix on the left multiplies each element on the right. The standard kronecker() function is the right Kronecker product, A \otimes_R B = {A[i,j] * B} -- matrix on the right multiplies each element on the left. The example below shows the result 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
2004 Mar 30
4
rank() vs SAS proc rank
SAS proc rank has ties options of high and low that would allow producing ranks of the type found in the sports pages, e.g., rank (c(1,1,2,2,2,2,3)) == 1 1 3 3 3 3 7 Could R support these ties.methods?
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".
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<-
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])
2009 Feb 06
1
Linear model: contrasts
Hey, I am modelling a linear regression Y=X*B+E. To compute the effect of ?group? the B-values of the regressors/columns that code the interaction effects (col. 5-8 and col. 11-14, see below) have to be weighted with non-zero elements within the contrast "Group 1" minus "Group 2" (see below). My first understanding was that the interaction effects add up to zero in each group.
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?
2013 Mar 19
1
How can I eliminate a loop over a data.table?
I've two data.tables as shown below: *** N = 10 A.DT <- data.table(a1 = c(rnorm(N,0,1)), a2 = NA)) B.DT <- data.table(b1 = c(rnorm(N,0,1)), b2 = 1:N) setkey(A.DT,a1) setkey(B.DT,b1) *** I tried to change my previous data.frame implementation to a data.table implementation by changing the for-loop as shown below: *** for (i in 1:nrow(B.DT)) { for (j in nrow(A.DT):1) { if
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,]
2006 Sep 11
5
Successive Graphs
Hello! I have written an R script on a Windows platform where I calculate eight result matrices I plot using matplot. I would like to display the resulting plots successively, rather than simultaneously, and I was wondering if anyone could point me in the right direction as to how to do this. The graphs pop up in this manner by default when I run my script in S-PLUS, with tabs separating them so I
2003 Apr 04
3
creating function bodies using body()
I'm having trouble figuring out how to create a function using "body<-" (). The help file for body() says that the argument should be a list of R expressions. However if I try that I get an error: > tmpfun <- function(a, b=2){} > body(tmpfun) <- list(expression(z <- a + b),expression(z^2)) Error in as.function.default(c(formals(f), value), envir) :
2007 Aug 07
1
Naming Lists
Hi Im pretty new to R and I have run in to a problem. How do I name all the levels in this list. Lev1 <- c("A1","A2") Lev2 <- c("B1","B2") Lev3 <- c("C1","C2") MyList <- lapply(Lev1,function(x){ lapply(Lev2,function(y){ lapply(Lev3,function(z){ paste(unlist(x),unlist(y),unlist(z)) })})}) I would like to name the different
2012 May 04
7
Breaking up a Row in R (transpose)
I have the following: Time A1 A1 B1 B1 C1 C2 x y x y x y 0 5 6 6 7 7 9 1 3 4 4 3 9 9 2 5 2 6 4 7 4 I want to change it to the following: 0 1 2 x y x y x y A1 5 6 3 4 5 2 B1