[R] fast value replacement in (numeric) vector

2008-09-20 Thread Ling, Gary (Electronic Trading)
Hi R users, What is the fastest way to replace a(some) value(s) in a (numeric) vector? I checked ?replace, but its output is another vector. 1) I wonder if there's any function to perform in-place replacement? 2) Or any other function would do what I'm looking for with faster speed? # here is

Re: [R] fast value replacement in (numeric) vector

2008-09-20 Thread Ling, Gary (Electronic Trading)
yes, yes! I'm out of my mind. Thank you. -Original Message- From: hadley wickham [mailto:[EMAIL PROTECTED] Sent: Saturday, September 20, 2008 5:49 PM To: Ling, Gary (Electronic Trading) Cc: r-help@r-project.org Subject: Re: [R] fast value replacement in (numeric) vector On Sat, Sep 20

Re: [R] loop with splitted data

2008-09-10 Thread Ling, Gary (Electronic Trading)
Hi R users, I have a question which is some what related to this thread. Here is the setup: z is a list of lists, with no names. zz is same is z, but with names. with names on zz, I can crawl on the data with lapply, but I don't know how do the same on z (without names). Can someone help? ###

Re: [R] loop with splitted data

2008-09-10 Thread Ling, Gary (Electronic Trading)
YES! many many thanks, Jim. I know it'd be simple, yet I can't believe it's that simple. =) -gary -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 10, 2008 11:55 AM To: Ling, Gary (Electronic Trading) Cc: Peter Dalgaard; r-help@r-project.org

Re: [R] Conditional statement used in sapply()

2008-08-13 Thread Ling, Gary (Electronic Trading)
Hi Mark, How about this? result - sapply(split(res, res$Volume0)$`TRUE`, mean) There is one thing I'm not sure: is res$Volume a vector or single numeric? -gary -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Altaweel, Mark R. Sent: Wednesday, August

Re: [R] Between the values

2008-08-12 Thread Ling, Gary (Electronic Trading)
# between (a,b) a - 0 b - 1 x - rnorm(10) x unclass(cut(x, breaks=c(-Inf,a,b,Inf)))==2 -gary -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Tuesday, August 12, 2008 7:46 AM To: [EMAIL PROTECTED] Subject: [R] Between the

Re: [R] using acf() for multiple columns

2008-08-07 Thread Ling, Gary (Electronic Trading)
Hi Gary, Thanks for your reply. This works fine. Is there any way to send the ACF data to a matrix, so I could analyse the data in excel for e.g.? Thanks, rcoder Ling, Gary (Electronic Trading) wrote: Hi, here is one possible solution ... -gary ### example ### # create

Re: [R] Switch two rows in a matrix

2008-08-07 Thread Ling, Gary (Electronic Trading)
A - matrix(rnorm(16)4,4) o - c(1,3,2,4) A[o,o] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Zhang Yanwei - Princeton-MRAm Sent: Thursday, August 07, 2008 10:31 AM To: r-help@r-project.org Subject: [R] Switch two rows in a matrix Hi all, I have a 4

Re: [R] using acf() for multiple columns

2008-08-06 Thread Ling, Gary (Electronic Trading)
Hi, here is one possible solution ... -gary ### example ### # create a 500x3 multi-ts A - matrix(rnorm(1500),nrow=500) # misc. graphical setting par(mfrow=c(ncol(A),1)) # then our friend -- lapply(split(...)) lapply(split(A,col(A)), acf) #Or lapply(split(A,col(A)), function(ts) acf(ts,

Re: [R] Matrix multiplication

2008-08-06 Thread Ling, Gary (Electronic Trading)
Hi, Yes. this is a way, and relatively easy ... Using Reduce. Note: in order to use Reduce, you need an update-to-date version of R. I'm using 2.6.2. First you have to have all the matrices line up with correct dimensions, i.e. [m_1 x m_2] %*% [m_2 x m_3] %*% ... %*% [m_(n-1) x m_n] (u get my

Re: [R] Union of columns of two matrices

2008-08-06 Thread Ling, Gary (Electronic Trading)
Here is my attempt. I'm not sure if that's the most efficient way to do it, cause I'm cheating using the nice features from R, namely duplicated(). I assume the matrices have same number of rows. ### example ### ### background setup: simulate 2 matrices with some common columns (A - cbind(1:4,

Re: [R] PDF append help

2008-08-05 Thread Ling, Gary (Electronic Trading)
Hi, just don't turn if off immediately, see example below: Cheers, Gary # example pdf(file=/home/user/tmp/moreplots.pdf) for (i in 1:5) plot(rnorm(100)) dev.off() -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rajasekaramya Sent: Tuesday, August 05,

Re: [R] Howto Smooth a Curve Created with the Point Function

2008-08-04 Thread Ling, Gary (Electronic Trading)
Hi Gundala, You have to reorder the points, like below: #(your code ...) g - cbind(x,g.pdf)[order(x),] points(x=[,1],y=g[,2],type='l',col=red) Cheers, gary -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gundala Viswanath Sent: Monday, August 04, 2008