similar to: how to coerce the result of sweep to be an array if result of FUN is a string?

Displaying 20 results from an estimated 9000 matches similar to: "how to coerce the result of sweep to be an array if result of FUN is a string?"

2004 May 10
7
strange behavior of names<-
Dear R-help, I've encounter what seems to me a strange problem with "names<-". Suppose I define the function: fun <- function(x, f) { m <- tapply(x, f, mean) ans <- x - m[match(f, unique(f))] names(ans) <- names(x) ans } which subtract out the means of `x' grouped by `f' (which is the same as, e.g., resid(lm(x~f)) if `f' is a factor).
2011 Apr 26
7
Second largest element from each matrix row
Hi, I need to extract the second largest element from each row of a matrix. Below is my solution, but I think there should be a more efficient way to accomplish the same, or not? set.seed(1) a <- matrix(rnorm(9), 3 ,3) sec.large <- as.vector(apply(a, 1, order, decreasing=T)[2,]) ans <- sapply(1:length(sec.large), function(i) a[i, sec.large[i]]) ans Thanks in advance for your
2004 Aug 06
1
preliminary Speex support in Sweep
Hi Jean-Marc and others, I put Speex support in Sweep (a sound editor) yesterday, and had some fun with it :) I'd like to get some feedback before releasing it publically. I'm not really used to speech codecs (I work more with music) but I've been quite impressed at the file size and quality (especially when you hear what I did with some of the sample files ;) I didn't have any
2007 Jun 29
1
sweep sanity checking?
A friend of mine just got bitten by the fact that sweep() will happily sweep out a STATS vector of an arbitrary length -- even one whose length is not a divisor of any of the margins -- without complaining. I know the answer to this could be "well just don't do that", but it's easy to make a mistake in which margin you're sweeping ... What would R-core think of the
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
1998 Aug 21
2
couldn't find FUN
The call to sweep in this function which was working in 0.62.2 is giving me trouble in 62.3: prcomponents <- function(x, center=TRUE, scale=TRUE, N=nrow(x)-1) {if (center) center <- apply(x,2,mean) else center <- rep(0, ncol(x)) if (scale) scale <- sqrt(apply(x,2,var)) else scale <- rep(1, ncol(x)) s <- svd(sweep(sweep(x,2, center),2, scale,
2010 Nov 29
2
R equivalent of Beaton's Sweep algorithm
I'm looking for an R equivalent of Beaton's (1964) Sweep algorithim for partial inversion of a matrix by pivoting. It implemented in SAS/IML as sweep(matrix, indices), described here http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/langref_sect266.htm and here for python http://adorio-research.org/wordpress/?p=262 -- Michael Friendly Email: friendly AT yorku
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 Dec 16
1
difference between the meaning of MARGIN in sweep() and apply()
For example, subtracting 1:2 from the rows of a two-column matrix: > t(apply(matrix(1:6,ncol=2),MARGIN=1,function(y) y - 1:2)) [,1] [,2] [1,] 0 2 [2,] 1 3 [3,] 2 4 > sweep(matrix(1:6,ncol=2),MARGIN=2,1:2,FUN="-") [,1] [,2] [1,] 0 2 [2,] 1 3 [3,] 2 4 Is there a logic to this difference, or is it just a quirk of the history of these
2010 Nov 18
3
sweep by levels of a factor
Hi, I'd appreciate help with this. I have a data matrix with one column, called f in the example below, a factor. I'd like to subtract the means from each of other columns for each level of the factor. That is, in the example, to go from the first matrix below to the second. I know SWEEP will take out means, but I want to do this for each level of the factor. f x 1 2 1
2006 Apr 11
4
Bootstrap and Jackknife Bias using Survey Package
Dear R users, I?m student of Master in Statistic and Data analysis, in New University of Lisbon. And now i?m writting my dissertation in variance estimation.So i?m using Survey Package to compute the principal estimators and theirs variances. My data is from Incoming and Expendire Survey. This is stratified Multi-stage Survey care out by National Statistic Institute of Mozambique. My domain of
2008 Aug 27
5
Integrate a 1-variable function with 1 parameter (Jose L. Romero)
Hey fellas: I would like to integrate the following function: integrand <- function (x,t) { exp(-2*t)*(2*t)^x/(10*factorial(x)) } with respect to the t variable, from 0 to 10. The variable x here works as a parameter: I would like to integrate the said function for each value of x in 0,1,..,44. I have tried Vectorize to no avail. Thanks in advance, jose romero
2011 Oct 05
4
SPlus to R
I'm trying to convert an S-Plus program to R.  Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help.  All I did was convert the underscores in S-Plus to the assignment operator <-.  Here are the first few lines of the S-Plus file:   sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8,              tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2),
2010 Aug 11
2
Sweeping a zoo series
Given a long zoo matrix, the goal is to "sweep" out a statistic from the entire length of the sequences. longzoomatrix<-zoo(matrix(rnorm(720),ncol=6),as.yearmon(outer(1900,seq(0,length=120)/12,"+"))) cnames<-c(12345,23456,34567,45678,56789,67890) colnames(longzoomatrix)<-cnames longzoomatrix[1:24,] 12345 23456 34567 45678
2009 Nov 23
3
FUN argument to return a vector in aggregate function
Hi All, I am currently doing the following to compute summary statistics of aggregated data: a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean) b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum) c = aggregate(warpbreaks$breaks, warpbreaks[,-1], length) ans = cbind(a, b[,3], c[,3]) This seems unnecessarily complex to me so I tried > aggregate(warpbreaks$breaks, warpbreaks[,-1],
2010 Aug 11
0
sweep and zoo objects
rc<-list(c( 123,321,234,543,654,768,986,987,246,284),c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")) # the matrix has rownames that are used as identifiers and columns # of time. 1 years worth of data. Thats the native format
2004 Aug 06
0
please test rc2 support in sweep :)
Hi, I'm updating speex support in sweep to RC2 and I'd like some advice on encoder options, and would appreciate some testing of the user interface. a screenshot of the updated speex encoding dialog: http://www.vergenet.net/~conrad/tmp/sw_speexRC2_1.png you can grab a tarball of sweep for testing here: http://www.vergenet.net/~conrad/tmp/sweep-0.8.0-speexRC2.tar.gz general
2006 Jul 12
0
Odd "sweep" error on older code
I''ve got a Rails project that has been on the shelf for a few months, and I''m picking it back up. I''ve frozen Rails at 1.1.4 in vendor/, and did the "rails ." and "rake rails:update" to get it up to a current Rails level. The code initially seems to be working fine, but when I go to my login method, I get a 500 error thrown. Looking in the
2010 Jul 22
0
sweep / mapply question
Dear list, I have a matrix, spc, that should row-wise be interpolated: E.g. spc <- matrix (1:1e6, ncol = 250, nrow = 4000, byrow = TRUE) spc [1:10, 1:10] shifts <- seq_len (nrow (spc)) wl <- seq_len (ncol (spc)) interpolate <- function (spc.row, shift, wl) spline (wl + shift, spc.row, xout = wl, method = "natural")$y interpolate (spc [1,], shift = shifts [1], wl = wl)
2010 Sep 21
2
Trouble with Optimization in "Alabama" Package
Hello, This is my first post to the help request list, so I'm going to err on the side of giving too much information. I'm working on writing a simulation in which agents will make repeated production and exchange decisions with randomly chosen partners. The idea is, all agents can produce two goods which they want to consume, they choose a value t in [0,10] which sets their production