similar to: Recycling Rule

Displaying 20 results from an estimated 10000 matches similar to: "Recycling Rule"

2024 Feb 27
2
converting MATLAB -> R | element-wise operation
Why anything but sweep? The fundamental data type in Matlab is a matrix... they don't have vectors, they have Nx1 matrices and 1xM matrices. Vectors don't have any concept of "row" vs. "column". Straight division is always elementwise with recycling as needed, and matrices are really vectors in row-major order: 1 2 3 4 5 6 is really 1 4 2 5 3 6 and when you do
2004 Oct 26
2
Idiom for column operations?
Is there a better way to express operations between matrices and column vectors than transposing the matrix twice? This is the kind of thing I'm talking about: m = matrix(1:20, 3, 4) v = colSums(m) t(t(m) / v) ## <-- kinda ugly, ain't it? I thought of converting the column vector to a matrix: m / matrix(v, nrow = nrow(m), ncol = length(v), byrow = TRUE) But that seems even
2005 Jun 20
6
sweep() and recycling
Hi I had a hard-to-find bug in some of my code the other day, which I eventually traced to my misusing of sweep(). I would expect sweep() to give me a warning if the elements don't recycle nicely, but X <- matrix(1:36,6,6) sweep(X,1,1:5,"+") [,1] [,2] [,3] [,4] [,5] [,6] [1,] 2 9 16 23 30 32 [2,] 4 11 18 25 27 34 [3,] 6 13 20 22
2009 Jul 03
2
Deos anyone know of a summary of conformability rules? along with a specific problem
The rules for conformability of objects required for various operators remain a mystery as do some related problems like the rules for recycling in creating arrays etc. Would someone be able to direct me to where such rules are stated? In a related vein, there are all manner of operations that are readily coded in Gauss or in MATA that fail, often mysteriously, in R. Are there some
2007 Sep 26
2
generate fourth vector based on known correlations
I am trying to generate a fourth vector,z, given three known and fixed vectors, x1,x2,x3 with corresponding known and fixed correlations with themeselves and with z. That is, all correlations are known and prespecified. How can I do this? Thank you, ben
2024 Feb 29
2
[External] converting MATLAB -> R | element-wise operation
I decided to do a direct comparison of transpose and sweep. library(microbenchmark) NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE) # Example matrix lambda <- c(2, 3, 4) # Example vector colNN <- t(NN) microbenchmark( sweep = sweep(NN, 2, lambda, "/"), transpose = t(t(NN)/lambda), colNN = colNN/lambda ) Unit: nanoseconds expr min lq
2009 Mar 17
2
sweep?
I am having a hard time understanding just what 'sweep' does. The documentation states: Return an array obtained from an input array by sweeping out a summary statistic. So what does it mean "weeping out a summary statistic"? Thank you. Kevin
2007 Nov 15
5
Multiply each column of array by vector component
Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This seems so basic but I can't figure out how to do it without a loop. Any suggestions? Michal.
2010 Dec 20
1
transposing panel data
I am currently trying to transpose some large panel data set ie transposing multiple rows in into a single column. instead the transpose functionality transposes all rows into columns. my sample data set looks like below: ACCT_NUM ACCOUNT_NAME TRAN_AMT DATE EMPLOYER 101913 GK 7489 30-Apr-10 PENSION 101913 GK 7489 30-May-10 PENSION 101913
2010 Oct 19
1
Implementing R's recycling rule
Hi I want to use R's recycling rule. At the moment I am using the following: x <- c(1, 2, 3) n <- 10 ## so using the recycling rules, I would like to get from FUN(x, n)==1 ## I am doing: xRecycled <- rep(x, length.out=n)[n] This works, but it seems to me that I am missing something really basic here - is there more straightforward way of doing this? Cheers, Rainer -- NEW
2006 Nov 09
5
DUNDi precache
Does anyone have any information on how to use DUNDi precaching? Mark Spencer made a post 2 years ago where he hinted it may be possible to configure DUNDi such that you could centralise your DUNDi registration info by using precaching, instead of having each DUNDi peer meshed with every other one... http://lists.digium.com/pipermail/dundi/2004-October/000189.html However, it seems that no
2010 May 16
3
Vector recycling and zoo
I am a bit confused about the different approaches taken to recycling in plain data frames and zoo objects. When carrying out simple arithmetic, dataframe seem to recycle single arguments, zoo objects do not. Here is an example > x <- data.frame(a=1:5*2, b=1:5*3) > x a b 1 2 3 2 4 6 3 6 9 4 8 12 5 10 15 > x$a/x$a[1] [1] 1 2 3 4 5 > x <- zoo(x) > x$a/x$a[1] 1 1 >
2006 Dec 20
3
Rotating a distribution plot by 90 degrees
Hi, Can I rotate a plot (e.g. a distribution plot) by 90 degrees? The barplot function provides the "horiz" command but that's not availeable for the base package functions. I found an old advice from Paul Murrell on a similar problem suggesting to use viewports (grid package). Yet I couldn't reproduce his examples successfully. And going through the examples in the current grid
2008 Aug 25
3
Maintaining repeated ID numbers when transposing with reshape
I have a dataset in "long" format that looks something like this: ID TEST RESULT 1 A 17 1 A 12 1 B 15 1 C 12 2 B 8 2 B 9 Now what I would like to do is transpose it like so: ID TEST A TEST B TEST C 1 17 15 12 1 12 . . 2
2012 Mar 17
2
Reading then transposing from file
Hi, I'm an R beginner and I'm struggling with what should be a rudimentary task. My data is along these lines: ID name1 name2 name3 name4 Class 0 1 0 2 Var1 A B C A Var2 B C C A Var3 C A B A etc. I'm using the following: foo <- data.frame(t(read.table("file", header=FALSE))) but of course now it's not using ID, Class, etc. as column names. As you can imagine,
2012 Feb 09
2
fill an array by rows
I've dug around but not been able to find anything, am probably missing something obvious. How can I fill a three-dimensional (or higher dimension) array by rows instead of columns. eg new1 <- array(c(1:125), c(5,5,5)) works fine for me but fills it by columns and new2 <- array(c(1:125), c(5,5,5), byrow=TRUE) throws an error. Am I missing something obvious? I also tried
2024 Feb 27
4
converting MATLAB -> R | element-wise operation
So, trying to convert a very long, somewhat technical bit of lin alg MATLAB code to R. Most of it working, but raninto a stumbling block that is probaably simple enough for someone to explain. Basically, trying to 'line up' MATLAB results from an element-wise division of a matrix by a vector with R output. Here is a simplified version of the MATLAB code I'm translating: NN = [1,
2001 May 20
4
ssh - NO SALE or NO GIVE ?
Thanks to everyone who has replied to my emails so far - to summarise: AIX allows setting of rlogin=false and and a su group, or a list of users that are permitted to "su" to root. ( or other functional ids ) This means with entries in /etc/ftpusers, it is possible to : 1/ Track who used root via sulog and or external logging 2/ Protect root even if the root password is compromised 3/
2005 May 20
1
R: looping
hi all i have a simple question. code is displayed below. how can i use a vectorised command in order to do this (ie replace the loop)? (ie apply, lapply, sweep, etc) z<-matrix(c(1:9),3,3) top<-c(1.5,5.5,9) for (i in 1:3) z[z[,i]>top[i]]<-top[i]
2010 Apr 23
6
transpose? reshape? flipping? challenge with data frame
Greetings all, I am having difficulty transposing, reshaping, flipping (not sure which) a data frame which is read from a DBF file. I have tried using t(), reshape() and other approaches without success. Can anyone please suggest an way (elegant or not) of flipping this data around ? The initial data is like propsum (defined below), and I want it to look like tpropsum once reformed. >