[R] How to create an array/list/vector of POSIXlt objects?
Hi Guys, I'm cooking up my own time series code. I'm creating a data frame with first column as timestamp in POSIXlt format. I'm hit on problems like this > dtt=array(dim = 2) > t=as.POSIXlt( strptime("07/12/07 13:20:01", "%m/%d/%Y %H:%M:%S",tz="GMT")) > dtt [1] NA NA > t [1] "0007-07-12 13:20:01 GMT" > dtt[1]=t Warning message: In dtt[1] = t : number of items to replace is not a multiple of replacement length > class(dtt) [1] "list" > class(t) [1] "POSIXt" "POSIXlt" > unclass(t) $sec [1] 1 $min [1] 20 $hour [1] 13 $mday [1] 12 $mon [1] 6 $year [1] -1893 $wday [1] 4 $yday [1] 192 $isdst [1] 0 attr(,"tzone") [1] "GMT" Seems like POSIXlt is a matrix so that it can not be embedded into an element of the array? Any suggestions? Cheers, Bo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to do Clustered Standard Errors for Regression in R?
I can't seem to find the right set of commands to enable me to do perform a regression with cluster-adjusted standard-errors. There seems to be nothing in the archives about this -- so this thread could help generate some useful content. I've searched everywhere. Can anyone point me to the right set of commands? An example would be most helpful as well. Bo [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to make a vector/list/array of POSIXlt object?
Hi Guys, I'm cooking up my time series code. I want a data frame with first column as timestamp in POSIXlt format. I hit on this the problem of how to create an array/list/vector of POSIXlt objects. Code is as follows > dtt=array(dim = 2) > t=as.POSIXlt( strptime("07/12/07 13:20:01", "%m/%d/%Y %H:%M:%S",tz="GMT")) > dtt [1] NA NA > t [1] "0007-07-12 13:20:01 GMT" > dtt[1]=t Warning message: In dtt[1] = t : number of items to replace is not a multiple of replacement length > class(dtt) [1] "list" > class(t) [1] "POSIXt" "POSIXlt" > unclass(t) $sec [1] 1 $min [1] 20 $hour [1] 13 $mday [1] 12 $mon [1] 6 $year [1] -1893 $wday [1] 4 $yday [1] 192 $isdst [1] 0 attr(,"tzone") [1] "GMT" Seems like POSIXlt is matrix in this case. Any suggestions? Cheers, B _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to make a vector/list/array of POSIXlt object?
Hi Gabor, I'm using this code but it doesn't work for me > strptime2<-function (date,time) as.POSIXct(strptime(paste(date,time), > "%m/%d/%Y %H:%M:%S")) > dt=mapply(strptime2, "01/01/2008", "00:00:00", SIMPLIFY=FALSE, > USE.NAMES=FALSE) > df=data.frame(X1=dt,X2=1) > dt [[1]] [1] "2008-01-01 Eastern Standard Time" > df structure.1199163600..class...c..POSIXtPOSIXcttzone.. X2 12008-01-01 1 Here df looks very wrong to me. So I tested this code: > df2=data.frame(X1=as.POSIXct(Sys.time()),X2=1) > df2 X1 X2 1 2008-02-17 23:43:08 1 > class(df2$X1) [1] "POSIXt" "POSIXct" Ah this worked as I expected. So some tweaking here - SIMPLIFY is set TRUE now: > strptime2<-function (date,time) as.POSIXct(strptime(paste(date,time), > "%m/%d/%Y %H:%M:%S")) > dt=mapply(strptime2, "01/01/2008", "00:00:00", SIMPLIFY=TRUE, USE.NAMES=FALSE) > df=data.frame(X1=dt,X2=1) > df X1 X2 1 1199163600 1 > class(df$X1) [1] "numeric" Hmm... it worked, but not in a way I wanted. The class info is missing. So how to get the result like this below? I do need that mapply + strptime(paste), cos my CSV file is formatted in that way! > df2 X1 X2 1 2008-02-17 23:43:08 1 > class(df2$X1) [1] "POSIXt" "POSIXct" Any insight? Cheers, Bo > Date: Sun, 17 Feb 2008 15:53:28 -0500 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] How to make a vector/list/array of POSIXlt object? > CC: r-help@r-project.org > > Normally one uses POSIXct rather than POSIXlt for storage. See R News 4/1 for > more info on date and time classes. > > On Feb 17, 2008 3:45 PM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > > > Hi Guys, > > > > I'm cooking up my time series code. I want a data frame with first column > > as timestamp in POSIXlt format. > > > > I hit on this the problem of how to create an array/list/vector of POSIXlt > > objects. Code is as follows > > > > > > > > > dtt=array(dim = 2) > > > t=as.POSIXlt( strptime("07/12/07 13:20:01", "%m/%d/%Y %H:%M:%S",tz="GMT")) > > > dtt > > [1] NA NA > > > t > > [1] "0007-07-12 13:20:01 GMT" > > > dtt[1]=t > > Warning message: > > In dtt[1] = t : > > number of items to replace is not a multiple of replacement length > > > class(dtt) > > [1] "list" > > > class(t) > > [1] "POSIXt" "POSIXlt" > > > unclass(t) > > $sec > > [1] 1 > > > > $min > > [1] 20 > > > > $hour > > [1] 13 > > > > $mday > > [1] 12 > > > > $mon > > [1] 6 > > > > $year > > [1] -1893 > > > > $wday > > [1] 4 > > > > $yday > > [1] 192 > > > > $isdst > > [1] 0 > > > > attr(,"tzone") > > [1] "GMT" > > > > > > > > Seems like POSIXlt is matrix in this case. > > > > Any suggestions? > > > > Cheers, > > > > B > > _ > > [[elided Hotmail spam]] > > > >[[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > _ Need to know the score, the latest news, or you need your Hotmail®-get your "fix". [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to make a vector/list/array of POSIXlt object?
Ta. I will give that code a bash. Could you explain why my code didn't work? > Date: Mon, 18 Feb 2008 00:25:44 -0500 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] How to make a vector/list/array of POSIXlt object? > CC: r-help@r-project.org > > If the problem is that you have a vector of dates, a vector of times > and a vector of data and you want to create a data frame with one > POSIXct column and one column of data then try this: > > dd <- c("01/22/2008", "02/13/2008") > tt <- c("01:01:00", "23:01:12") > dat <- 1:2 > > data.frame(dt = strptime(paste(dd, tt), "%m/%d/%Y %H:%M:%S"), dat) > > # if you don't need subsecond data or time zones you could use chron > > library(chron) > data.frame(dt = chron(dd, tt), dat) > > If this is intended to be a time series you might want to look at the zoo > package. It has three vignettes that give more info. > > > On Feb 17, 2008 11:54 PM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > Hi Gabor, > > > > I'm using this code but it doesn't work for me > > > > > strptime2<-function (date,time) as.POSIXct(strptime(paste(date,time), > > "%m/%d/%Y %H:%M:%S")) > > > dt=mapply(strptime2, "01/01/2008", "00:00:00", SIMPLIFY=FALSE, > > USE.NAMES=FALSE) > > > df=data.frame(X1=dt,X2=1) > > > dt > > [[1]] > > [1] "2008-01-01 Eastern Standard Time" > > > > > df > > structure.1199163600..class...c..POSIXtPOSIXcttzone.. X2 > > 12008-01-01 1 > > > > Here df looks very wrong to me. > > > > So I tested this code: > > > > > df2=data.frame(X1=as.POSIXct(Sys.time()),X2=1) > > > df2 > >X1 X2 > > 1 2008-02-17 23:43:08 1 > > > class(df2$X1) > > [1] "POSIXt" "POSIXct" > > > > Ah this worked as I expected. > > > > So some tweaking here - SIMPLIFY is set TRUE now: > > > > > strptime2<-function (date,time) as.POSIXct(strptime(paste(date,time), > > "%m/%d/%Y %H:%M:%S")) > > > dt=mapply(strptime2, "01/01/2008", "00:00:00", SIMPLIFY=TRUE, > > USE.NAMES=FALSE) > > > df=data.frame(X1=dt,X2=1) > > > df > > X1 X2 > > 1 1199163600 1 > > > class(df$X1) > > [1] "numeric" > > > > Hmm... it worked, but not in a way I wanted. The class info is missing. > > > > So how to get the result like this below? I do need that mapply + > > strptime(paste), cos my CSV file is formatted in that way! > > > > > df2 > >X1 X2 > > 1 2008-02-17 23:43:08 1 > > > class(df2$X1) > > [1] "POSIXt" "POSIXct" > > > > > > Any insight? > > > > Cheers, > > > > Bo > > > > > > > > > Date: Sun, 17 Feb 2008 15:53:28 -0500 > > > From: [EMAIL PROTECTED] > > > To: [EMAIL PROTECTED] > > > Subject: Re: [R] How to make a vector/list/array of POSIXlt object? > > > CC: r-help@r-project.org > > > > > > > > > > Normally one uses POSIXct rather than POSIXlt for storage. See R News 4/1 > > for > > > more info on date and time classes. > > > > > > On Feb 17, 2008 3:45 PM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > > > > > > > Hi Guys, > > > > > > > > I'm cooking up my time series code. I want a data frame with first > > column as timestamp in POSIXlt format. > > > > > > > > I hit on this the problem of how to create an array/list/vector of > > POSIXlt objects. Code is as follows > > > > > > > > > > > > > > > > > dtt=array(dim = 2) > > > > > t=as.POSIXlt( strptime("07/12/07 13:20:01", "%m/%d/%Y > > %H:%M:%S",tz="GMT")) > > > > > dtt > > > > [1] NA NA > > > > > t > > > > [1] "0007-07-12 13:20:01 GMT" > > > > > dtt[1]=t > > > > Warning message: > > > > In dtt[1] = t : > > > > number of items to replace is not a multiple of replacement length > > > > > class(dtt) > > > > [1] "list" > > > > > class(t) > > > > [1] "POSIXt" "POSIXlt" > > > > > unclass(t) > > > > $sec > > > > [1] 1
[R] question on lag.zoo
Hi Guys, I'm using zoo package now. I found lag is not doing what I assumed. > x <- zoo(11:21) > z <- zoo(1:10, yearqtr(seq(1959.25, 1961.5, by = 0.25)), frequency = 4) > x 1 2 3 4 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 19 20 21 > lag(x) 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 > z 1959 Q2 1959 Q3 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4 1961 Q1 1961 Q2 1961 Q3 1 2 3 4 5 6 7 8 9 10 > lag(z) 1959 Q1 1959 Q2 1959 Q3 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4 1961 Q1 1961 Q2 1 2 3 4 5 6 7 8 9 10 Why z and lag (z) are of same length while lag(x) is shorter by one than x? I assume lag(z) would give me like this: 1959 Q3 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4 1961 Q1 1961 Q2 1961 Q3 2 3 4 5 6 7 8 9 10 ie preserve the relationship between timestamp and the value. Same things applies to lag(x) but I guess both make sense: 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 or 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Any insight? Cheers, Bo _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Idioms for a timeseries operation - moving window
Hi Guys, Need your wisdom on this. Say I have a time series (in zoo format) like this > x <- zoo(11:21) > x 1 2 3 4 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 19 20 21 I want to do a "moving window sampling" of it. The result can either be a matrix or a dataframe like this my.super.moving.window(x, length=3, by=1) 11 12 13 12 13 14 13 14 15 14 15 16 18 19 20 19 20 21 This shouldn't be new. Many many people must have done this before. Any idea what's the best(efficient and elegant) way to do this? Cheers, Bo _ Climb to the top of the charts! Play the word scramble challenge with star power. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Idioms for a timeseries operation - moving window
Thanks. Problem solved. > rollapply(x,3,force, align="left") 1 1 2 3 2 2 3 4 3 3 4 5 4 4 5 6 5 5 6 7 6 6 7 8 7 7 8 9 8 8 9 10 > x<-1:10 > embed(x, 3)[, 3:1] [,1] [,2] [,3] [1,]123 [2,]234 [3,]345 [4,]456 [5,]567 [6,]678 [7,]789 [8,]89 10 > > Date: Sun, 2 Mar 2008 10:04:38 -0500 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] Idioms for a timeseries operation - moving window > CC: r-help@r-project.org > > Try: > > rollapply(x, 3, force) > > or > > embed(x, 3)[, 3:1] > > On Sun, Mar 2, 2008 at 9:53 AM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > > > I needed that matrix for following calculations. So I don't think roll* > > would work for me. > > > > Re: embed > > > > > x <- 1:10 > > > embed (x, 3) > > [,1] [,2] [,3] > > [1,]321 > > [2,]432 > > [3,]543 > > [4,]654 > > [5,]765 > > [6,]876 > > [7,]987 > > [8,] 1098 > > > x > > [1] 1 2 3 4 5 6 7 8 9 10 > > > > The matrix is in revered order. Anyway to put the matrix in the original > > order? Ie > > 1 2 3 > > 2 3 4 > > ... > > > > > > Cheers, > > Bo > > > > > > > > > > > Date: Sun, 2 Mar 2008 09:40:09 -0500 > > > From: [EMAIL PROTECTED] > > > To: [EMAIL PROTECTED] > > > Subject: Re: [R] Idioms for a timeseries operation - moving window > > > CC: r-help@r-project.org > > > > > > > > See > > > > > > ?embed > > > > > > and from zoo see: > > > ?rollapply > > > ?rollmean > > > ?rollmax > > > > > > There is a function coded in C in the caTools package for speed. > > > > > > > > > On Sun, Mar 2, 2008 at 9:24 AM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > > > > > > > Hi Guys, > > > > > > > > Need your wisdom on this. > > > > > > > > Say I have a time series (in zoo format) like this > > > > > > > > > > > > > x <- zoo(11:21) > > > > > x > > > > 1 2 3 4 5 6 7 8 9 10 11 > > > > 11 12 13 14 15 16 17 18 19 20 21 > > > > > > > > > > > > I want to do a "moving window sampling" of it. The result can either be > > a matrix or a dataframe like this > > > > > > > > my.super.moving.window(x, length=3, by=1) > > > > > > > > 11 12 13 > > > > 12 13 14 > > > > 13 14 15 > > > > 14 15 16 > > > > > > > > 18 19 20 > > > > 19 20 21 > > > > > > > > This shouldn't be new. Many many people must have done this before. Any > > idea what's the best(efficient and elegant) way to do this? > > > > > > > > Cheers, > > > > > > > > Bo > > > > > > > > > > > > > > > > > > > > _ > > > > Climb to the top of the charts! Play the word scramble challenge with > > star power. > > > > > > > > [[alternative HTML version deleted]] > > > > > > > > > > > > __ > > > > R-help@r-project.org mailing list > > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > > > > > > > Shed those extra pounds with MSN and The Biggest Loser! Learn more. _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Idioms for a timeseries operation - moving window
Ah! Gabor is the man. BTW I don't have zoo-faq. (I actually googled it out) This is what I have: Vignettes in package zoo: zoo-quickrefzoo Quick Reference (source, pdf) zoo zoo: An S3 Class and Methods for Indexed Totally Ordered Observations (source, pdf) It's a typical windows xp install of R 2.6.1. Any idea why? Cheers, Bo > Date: Sun, 2 Mar 2008 09:40:09 -0500 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] Idioms for a timeseries operation - moving window > CC: r-help@r-project.org > > See > > ?embed > > and from zoo see: > ?rollapply > ?rollmean > ?rollmax > > There is a function coded in C in the caTools package for speed. > > > On Sun, Mar 2, 2008 at 9:24 AM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > > > Hi Guys, > > > > Need your wisdom on this. > > > > Say I have a time series (in zoo format) like this > > > > > > > x <- zoo(11:21) > > > x > > 1 2 3 4 5 6 7 8 9 10 11 > > 11 12 13 14 15 16 17 18 19 20 21 > > > > > > I want to do a "moving window sampling" of it. The result can either be a > > matrix or a dataframe like this > > > > my.super.moving.window(x, length=3, by=1) > > > > 11 12 13 > > 12 13 14 > > 13 14 15 > > 14 15 16 > > > > 18 19 20 > > 19 20 21 > > > > This shouldn't be new. Many many people must have done this before. Any > > idea what's the best(efficient and elegant) way to do this? > > > > Cheers, > > > > Bo > > > > > > > > > > _ > > Climb to the top of the charts! Play the word scramble challenge with star > > power. > > > >[[alternative HTML version deleted]] > > > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > _ 08 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Idioms for a timeseries operation - moving window
I needed that matrix for following calculations. So I don't think roll* would work for me. Re: embed > x <- 1:10 > embed (x, 3) [,1] [,2] [,3] [1,]321 [2,]432 [3,]543 [4,]654 [5,]765 [6,]876 [7,]987 [8,] 1098 > x [1] 1 2 3 4 5 6 7 8 9 10 The matrix is in revered order. Anyway to put the matrix in the original order? Ie 1 2 3 2 3 4 ... Cheers, Bo > Date: Sun, 2 Mar 2008 09:40:09 -0500 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] Idioms for a timeseries operation - moving window > CC: r-help@r-project.org > > See > > ?embed > > and from zoo see: > ?rollapply > ?rollmean > ?rollmax > > There is a function coded in C in the caTools package for speed. > > > On Sun, Mar 2, 2008 at 9:24 AM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > > > Hi Guys, > > > > Need your wisdom on this. > > > > Say I have a time series (in zoo format) like this > > > > > > > x <- zoo(11:21) > > > x > > 1 2 3 4 5 6 7 8 9 10 11 > > 11 12 13 14 15 16 17 18 19 20 21 > > > > > > I want to do a "moving window sampling" of it. The result can either be a > > matrix or a dataframe like this > > > > my.super.moving.window(x, length=3, by=1) > > > > 11 12 13 > > 12 13 14 > > 13 14 15 > > 14 15 16 > > > > 18 19 20 > > 19 20 21 > > > > This shouldn't be new. Many many people must have done this before. Any > > idea what's the best(efficient and elegant) way to do this? > > > > Cheers, > > > > Bo > > > > > > > > > > _ > > Climb to the top of the charts! Play the word scramble challenge with star > > power. > > > >[[alternative HTML version deleted]] > > > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] elegant way to minus on each row of a matrix
How to do this in an elegant way formatrix/data frame/zoo? mat= 1 2 3 4 5 6 7 8 9 vector= 1 2 3 result= 0 1 2 2 3 4 4 5 6 ie 1-1 2-1 3-1 4-2 5-2 6-2 7-3 8-3 9-3 Thanks in advance. _ 08 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] elegant way to minus on each row of a matrix
Brilliant! > t1=matrix(1:15,5,3) > t1 [,1] [,2] [,3] [1,]16 11 [2,]27 12 [3,]38 13 [4,]49 14 [5,]5 10 15 > t2=1:5 > t2 [1] 1 2 3 4 5 > sweep(t1, 1, t2) [,1] [,2] [,3] [1,]05 10 [2,]05 10 [3,]05 10 [4,]05 10 [5,]05 10 > Date: Sun, 2 Mar 2008 14:56:22 -0300 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] elegant way to minus on each row of a matrix > CC: r-help@r-project.org > > Try this: > > sweep(mat, 1, vec) > > > On 02/03/2008, Bo Zhou <[EMAIL PROTECTED]> wrote: > > > > How to do this in an elegant way formatrix/data frame/zoo? > > > > mat= > > 1 2 3 > > 4 5 6 > > 7 8 9 > > > > vector= > > 1 > > 2 > > 3 > > > > > > result= > > 0 1 2 > > 2 3 4 > > 4 5 6 > > > > ie > > 1-1 2-1 3-1 > > 4-2 5-2 6-2 > > 7-3 8-3 9-3 > > > > Thanks in advance. > > > > _ > > > > > > 08 > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O _ Need to know the score, the latest news, or you need your Hotmail®-get your "fix". [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] elegant way to minus on each row of a matrix
Hi Dimitris and everyone I tried this but now I know why it didn't work out for me initially. > t1=matrix(1:10,5,2) > t2=matrix(1,5,1) > t2 [,1] [1,]1 [2,]1 [3,]1 [4,]1 [5,]1 > t1 [,1] [,2] [1,]16 [2,]27 [3,]38 [4,]49 [5,]5 10 > t1-as.vector(t2) [,1] [,2] [1,]05 [2,]16 [3,]27 [4,]38 [5,]49 > t1-t2 Error in t1 - t2 : non-conformable arrays I'm too used to Matlab I guess. Cheers, Bo > Date: Sun, 2 Mar 2008 18:56:15 +0100 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > CC: r-help@r-project.org > Subject: Re: [R] elegant way to minus on each row of a matrix > > try this: > > mat <- matrix(1:9, 3, 3, TRUE) > dat <- as.data.frame(mat) > vec <- 1:3 > > result.mat <- mat - vec > result.dat <- dat - vec > result.mat > result.dat > > > I hope it helps. > > Best, > Dimitris > > > Dimitris Rizopoulos > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/(0)16/336899 > Fax: +32/(0)16/337015 > Web: http://med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > Quoting Bo Zhou <[EMAIL PROTECTED]>: > > > > > How to do this in an elegant way formatrix/data frame/zoo? > > > > mat= > > 1 2 3 > > 4 5 6 > > 7 8 9 > > > > vector= > > 1 > > 2 > > 3 > > > > > > result= > > 0 1 2 > > 2 3 4 > > 4 5 6 > > > > ie > > 1-1 2-1 3-1 > > 4-2 5-2 6-2 > > 7-3 8-3 9-3 > > > > Thanks in advance. > > > > _ > > > > > > 08 > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > _ 08 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] elegant way to minus on each row of a matrix
Hi Mark, (CC'ing r-help) Only need to change the parameter from 1 to 2 after that it worked great. Thanks > t1=matrix(1:15,5,3) > t1 [,1] [,2] [,3] [1,]16 11 [2,]27 12 [3,]38 13 [4,]49 14 [5,]5 10 15 > t2=1:5 > t2 [1] 1 2 3 4 5 > apply(t1,2, function(x) x - t2) [,1] [,2] [,3] [1,]05 10 [2,]05 10 [3,]05 10 [4,]05 10 [5,]05 10 > > Date: Sun, 2 Mar 2008 12:51:53 -0500 > From: [EMAIL PROTECTED] > Subject: RE: [R] elegant way to minus on each row of a matrix > To: [EMAIL PROTECTED] > > try result<-apply(mat,1, function(.row) .row - vector) but I don't have R > here so make sure it works. > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Bo Zhou > Sent: Sunday, March 02, 2008 12:43 PM > To: r-help@r-project.org > Subject: [R] elegant way to minus on each row of a matrix > > > How to do this in an elegant way formatrix/data frame/zoo? > > mat= > 1 2 3 > 4 5 6 > 7 8 9 > > vector= > 1 > 2 > 3 > > > result= > 0 1 2 > 2 3 4 > 4 5 6 > > ie > 1-1 2-1 3-1 > 4-2 5-2 6-2 > 7-3 8-3 9-3 > > Thanks in advance. > > _ > > > 08 > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > _ 08 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Finance
Just like David said, I doubt you can get the symbology databased for free (distribution license/fee reasons). (Or if you know any please let me know :-) I'm sure nobody would like to prepare this mapping manually. This is what I would try: 1. Get today's open or close price from Bloomberg for your symbol pool. This is should be cheap enough. 2. Find a large list of Yahoo symbols' current open/close prices. 2. Then write some code to match them based on the prices. Well this will not magically give all you want but it's a good start and I'm sure it will give you a big chunk of what you needed. Cheers, Bo > Date: Thu, 13 Mar 2008 08:18:47 -0500 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED]; r-help@r-project.org > Subject: Re: [R] R Finance > > I guess I would create a mapping table to convert between the symbols > from Bloomberg and from Yahoo. > You should be able to just create it once and add to it as new symbols > appear on your screens. Most of the symbols should be the same so you > could omit those. If it all has to be automated, you could use > RBloomberg to get the tickers from the ISINs in one call, but there may > still be other transformations needed, such as "XYZ/A" to "XYZA" or > whatever. > HTH, > > David L. Reiner, PhD > Head Quant > Rho Trading Securities, LLC > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Ruby > Sent: Thursday, March 13, 2008 6:44 AM > To: r-help@r-project.org > Subject: [R] R Finance > > Hi, > > I am an R novice working with financial data. I am developing a > portfolio strategy evaluation technique to back-test the performance > of our screens; checking how the screened stock would've performed > over the period in question. > > I am using quantmod in R to download the historical data from yahoo > and then analyzing it using PerformanceAnalytics. My problem is that, > as our screens are done using Bloomberg, my list of screened stocks > only has Bloomberg tickers and ISINs. Does anybody know of a method > which could convert ISINs to yahoo tickers/symbols?? Or a method of > accessing yahoo historical data from an ISIN (instead of a symbol > call)? I would prefer not to use RBloomberg to download the data as > the data calls would be extensive in testing. > > Thank you!! > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. _ Need to know the score, the latest news, or you need your Hotmail®-get your "fix". [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 3d graph aspect ratio question
3d graph aspect ratio questionþ Hi guys, What's the counterpart of rgl package's aspect3d() in Lattice package? aspect3d() : Description: This function sets the apparent ratios of the x, y, and z axes of the current bounding box. Usage: aspect3d(x, y = NULL, z = NULL) Arguments: x: The ratio for the x axis, or all three ratios, or '"iso"' y: The ratio for the y axis z: The ratio for the z axis Details: If the ratios are all 1, the bounding box will be displayed as a cube approximately filling the display. Values may be set larger or smaller as desired. Aspect '"iso"' signifies that the coordinates should all be displayed at the same scale, i.e. the bounding box should not be rescaled. (This corresponds to the default display before 'aspect3d' has been called.) Partial matches to '"iso"' are allowed. 'aspect3d' works by modifying 'par3d("scale")'. Value: The previous value of the scale is returned invisibly. Thanks, Bo _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rgl persp3d bounding box color problem.
Hi guys, I hit on a problem when I use rgl. Could you try to run the code here in this link and see why the first persp3d gives a red bounding box and the second shows black? http://rafb.net/p/g1i7ur33.html (sorry for not pasting the code here directly but my previous email got filtered by this list so I suspect my code looks like spam to the spam filter) I'm expecting black color to be the right result but the code is virtually same except different data size. Looks like a mem bug to me? BTW you will need to install the rgl package Thanks, Bo _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl persp3d bounding box color problem.
Thanks, Duncan. What's your platform? Could this be an issues related to my platform? I'm on Ubuntu 8.10 64bit using cran's R package. I built rgl package on my machine using install.packages(). I'm going to give it a try in windows. I would be very grateful if anyone using similar setup could give it a try. Thanks, Bo > Date: Sun, 1 Mar 2009 07:03:10 -0500 > From: murd...@stats.uwo.ca > To: bozhou1...@hotmail.com > CC: r-help@r-project.org > Subject: Re: [R] rgl persp3d bounding box color problem. > > On 28/02/2009 4:20 PM, Bo Zhou wrote: > > Hi guys, > > > > I hit on a problem when I use rgl. > > > > Could you try to run the code here in this link and see why the first > > persp3d gives a red bounding box and the second shows black? > > They both show as black on my system. > > Duncan Murdoch > > > > > http://rafb.net/p/g1i7ur33.html > > > > (sorry for not pasting the code here directly but my previous email got > > filtered by this list so I suspect my code looks like spam to the spam > > filter) > > > > I'm expecting black color to be the right result but the code is virtually > > same except different data size. Looks like a mem bug to me? > > > > > > BTW you will need to install the rgl package > > > > Thanks, > > > > Bo > > > > _ > > > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl persp3d bounding box color problem.
site down.. here is the code library(rgl) plot1: persp3d(x=1:11,y=1:210,z=matrix(rep(1,11*210),11,210),col=matrix(rep("#FF",11*210),11,210)) plot2: persp3d(x=1:11,y=1:10,z=matrix(rep(1,11*10),11,10),col=matrix(rep("#FF",11*10),11,10)) Thanks! Bo > Date: Mon, 2 Mar 2009 09:28:31 +1100 > Subject: Re: [R] rgl persp3d bounding box color problem. > From: remkoduur...@gmail.com > To: bozhou1...@hotmail.com > > I would not mind trying, but the link no longer works... > > Remko > > > - > Remko Duursma > Post-Doctoral Fellow > > Centre for Plant and Food Science > University of Western Sydney > Hawkesbury Campus > Richmond NSW 2753 > > Dept of Biological Science > Macquarie University > North Ryde NSW 2109 > Australia > > Mobile: +61 (0)422 096908 > > > > On Mon, Mar 2, 2009 at 8:16 AM, Bo Zhou wrote: > > > > > > Thanks, Duncan. > > > > What's your platform? Could this be an issues related to my platform? I'm > > on Ubuntu 8.10 64bit using cran's R package. I built rgl package on my > > machine using install.packages(). I'm going to give it a try in windows. > > > > I would be very grateful if anyone using similar setup could give it a try. > > > > Thanks, > > Bo > > > >> Date: Sun, 1 Mar 2009 07:03:10 -0500 > >> From: murd...@stats.uwo.ca > >> To: bozhou1...@hotmail.com > >> CC: r-help@r-project.org > >> Subject: Re: [R] rgl persp3d bounding box color problem. > >> > >> On 28/02/2009 4:20 PM, Bo Zhou wrote: > >> > Hi guys, > >> > > >> > I hit on a problem when I use rgl. > >> > > >> > Could you try to run the code here in this link and see why the first > >> > persp3d gives a red bounding box and the second shows black? > >> > >> They both show as black on my system. > >> > >> Duncan Murdoch > >> > >> > > >> > http://rafb.net/p/g1i7ur33.html > >> > > >> > (sorry for not pasting the code here directly but my previous email got > >> > filtered by this list so I suspect my code looks like spam to the spam > >> > filter) > >> > > >> > I'm expecting black color to be the right result but the code is > >> > virtually same except different data size. Looks like a mem bug to me? > >> > > >> > > >> > BTW you will need to install the rgl package > >> > > >> > Thanks, > >> > > >> > Bo > >> > > >> > _ > >> > > >> > > >> > [[alternative HTML version deleted]] > >> > > >> > __ > >> > R-help@r-project.org mailing list > >> > https://stat.ethz.ch/mailman/listinfo/r-help > >> > PLEASE do read the posting guide > >> > http://www.R-project.org/posting-guide.html > >> > and provide commented, minimal, self-contained, reproducible code. > >> > > > > _ > > > > > >[[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl persp3d bounding box color problem.
Thanks Duncan. I haven't got a chance to try it in windows yet. But I won't be surprised if it's my driver's fault. I had OpenGL problems on this dell laptop before. > Date: Sun, 1 Mar 2009 18:29:20 -0500 > From: murd...@stats.uwo.ca > To: bozhou1...@hotmail.com > CC: remkoduur...@gmail.com; r-help@r-project.org > Subject: Re: [R] rgl persp3d bounding box color problem. > > On 01/03/2009 5:54 PM, Bo Zhou wrote: > > site down.. > > > > here is the code > > > > library(rgl) > > > > plot1: > > persp3d(x=1:11,y=1:210,z=matrix(rep(1,11*210),11,210),col=matrix(rep("#FF",11*210),11,210)) > > > > plot2: > > persp3d(x=1:11,y=1:10,z=matrix(rep(1,11*10),11,10),col=matrix(rep("#FF",11*10),11,10)) > > Works fine on Mac OS 10.5 too. Looks like a bug in your OpenGL driver... > > Duncan Murdoch > > > > > > Thanks! > > > > Bo > >> Date: Mon, 2 Mar 2009 09:28:31 +1100 > >> Subject: Re: [R] rgl persp3d bounding box color problem. > >> From: remkoduur...@gmail.com > >> To: bozhou1...@hotmail.com > >> > >> I would not mind trying, but the link no longer works... > >> > >> Remko > >> > >> > >> - > >> Remko Duursma > >> Post-Doctoral Fellow > >> > >> Centre for Plant and Food Science > >> University of Western Sydney > >> Hawkesbury Campus > >> Richmond NSW 2753 > >> > >> Dept of Biological Science > >> Macquarie University > >> North Ryde NSW 2109 > >> Australia > >> > >> Mobile: +61 (0)422 096908 > >> > >> > >> > >> On Mon, Mar 2, 2009 at 8:16 AM, Bo Zhou wrote: > >>> > >>> Thanks, Duncan. > >>> > >>> What's your platform? Could this be an issues related to my platform? I'm > >>> on Ubuntu 8.10 64bit using cran's R package. I built rgl package on my > >>> machine using install.packages(). I'm going to give it a try in windows. > >>> > >>> I would be very grateful if anyone using similar setup could give it a > >>> try. > >>> > >>> Thanks, > >>> Bo > >>> > >>>> Date: Sun, 1 Mar 2009 07:03:10 -0500 > >>>> From: murd...@stats.uwo.ca > >>>> To: bozhou1...@hotmail.com > >>>> CC: r-help@r-project.org > >>>> Subject: Re: [R] rgl persp3d bounding box color problem. > >>>> > >>>> On 28/02/2009 4:20 PM, Bo Zhou wrote: > >>>>> Hi guys, > >>>>> > >>>>> I hit on a problem when I use rgl. > >>>>> > >>>>> Could you try to run the code here in this link and see why the first > >>>>> persp3d gives a red bounding box and the second shows black? > >>>> They both show as black on my system. > >>>> > >>>> Duncan Murdoch > >>>> > >>>>> http://rafb.net/p/g1i7ur33.html > >>>>> > >>>>> (sorry for not pasting the code here directly but my previous email got > >>>>> filtered by this list so I suspect my code looks like spam to the spam > >>>>> filter) > >>>>> > >>>>> I'm expecting black color to be the right result but the code is > >>>>> virtually same except different data size. Looks like a mem bug to me? > >>>>> > >>>>> > >>>>> BTW you will need to install the rgl package > >>>>> > >>>>> Thanks, > >>>>> > >>>>> Bo > >>>>> > >>>>> _ > >>>>> > >>>>> > >>>>> [[alternative HTML version deleted]] > >>>>> > >>>>> __ > >>>>> R-help@r-project.org mailing list > >>>>> https://stat.ethz.ch/mailman/listinfo/r-help > >>>>> PLEASE do read the posting guide > >>>>> http://www.R-project.org/posting-guide.html > >>>>> and provide commented, minimal, self-contained, reproducible code. > >>> _ > >>> > >>> > >>>[[alternative HTML version deleted]] > >>> > >>> __ > >>> R-help@r-project.org mailing list > >>> https://stat.ethz.ch/mailman/listinfo/r-help > >>> PLEASE do read the posting guide > >>> http://www.R-project.org/posting-guide.html > >>> and provide commented, minimal, self-contained, reproducible code. > >>> > > > > _ > > > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > _ Hotmail® is up to 70% faster. Now good news travels really fast. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] A question about r anaysing microarry data!Thank you!
Dear, Thank you for cheking the mail! I'm Bo, student in TTU, and had a problem in using r for analyzing microarry data. This is what I write in r: library(limma) argets <- readTargets(file="targets.txt") *targets.txt is a tab-delimited file with columns: "SlideNumber", "FileName", "Cy3", "Cy5". The filenames refer to the feature extraction files for each array in the experiment. RG<-read.maimages(targets, source="agilent",wt.fun=myfunFE,columns=list(R="rProcessedSignal",G="gProcessedSignal")) *In this step , cannot open file'Imm 10 Cy3_TM 10 Cy5 ': No such file or directory ,and I 've tried to path= "d:\\Imm 10 Cy3_TM 10 Cy5" or setwd ,but the same error, so I donot know how to tell to find this file,could you help me to figure it out? Thank you so much! Sincerely, Bo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.