Re: [R] Updata Rdata File
Thanks for the response Duncan. I'm sorry I wasn't clear in my question. I need to add an additional value every day to the data and not update it. I know how to load and save but I dont' know how to add data. load(file=C:\\datafile.rdata) save(data,file=C:\\datafile.rdata) Thanks. Jason On Thu, Nov 18, 2010 at 6:56 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 18/11/2010 1:49 AM, Jason Kwok wrote: How do I add data to a .rdata file? In my case, I have a time series that needs to get updated every day. Load it, update the variables, save them. Duncan Murdoch [[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] Updata Rdata File
How do I add data to a .rdata file? In my case, I have a time series that needs to get updated every day. Thanks, Jason [[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] Plotting 2 Lines on the Same Chart
How do I plot two time series plots on the same chart? Thanks, Jason [[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] Plotting 2 Lines on the Same Chart
Thanks. 1 more question. When I use Plot(series1) lines(series2) The graph will use the y axis scaling for series 1 so some of series 2 is cut off. How do I control the y axis scaling? Thanks, Jason On Fri, Oct 29, 2010 at 2:10 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Fri, Oct 29, 2010 at 1:41 PM, Jason Kwok jayk...@gmail.com wrote: How do I plot two time series plots on the same chart? Try this: example(plot.ts) example(ts.plot) library(zoo) example(plot.zoo) library(lattice) example(xyplot.zoo) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com [[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] Returning highs and lows in R
I'm having trouble returning a rolling n period highest value for a data set. For each day I want to calculate the highest value over the last 3 days. I am using the following packages: zoo, xts, quantmod and TTR. Thanks, Jason GLD.Close 2010-10-01128.91 2010-10-04128.46 2010-10-05130.99 2010-10-06131.81 2010-10-07130.37 2010-10-08131.66 2010-10-11132.29 2010-10-12131.96 2010-10-13134.07 2010-10-14134.75 2010-10-15133.68 2010-10-18134.28 2010-10-19130.11 2010-10-20131.32 2010-10-21129.47 2010-10-22129.73 2010-10-25130.85 2010-10-26130.88 2010-10-27129.52 [[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] Returning highs and lows in R
Thanks for the help. I'm looking to calculate rolling max and means for the last 3 observations in my data including AND not including the current observation. I'm not sure how to offset the observations used. For the 3 period max, I would like to return the max value over the last 3 observations not including today. When I use the rollapply function to take the max, it will look look back 1 observation, take the current observation and look forward 1 observation. I would like to return look back observations 1-3 and return the max. merge(xx,rollapply(xx,3,max)) GLD.Close GLD.Close.1 2010-04-01110.26 NA 2010-04-05110.89 111.03 2010-04-06111.03 112.49 2010-04-07112.49 112.65 2010-04-08112.65 113.64 2010-04-09113.64 113.64 2010-04-12113.01 113.64 2010-04-13112.69 113.03 2010-04-14113.03 113.65 2010-04-15113.65 113.65 2010-04-16111.24 113.65 2010-04-19111.15 111.46 2010-04-20111.46 112.31 2010-04-21112.31 112.31 2010-04-22111.84 113.19 2010-04-23113.19 113.19 2010-04-26112.75 114.63 2010-04-27114.63 114.63 2010-04-28114.31 114.63 2010-04-29114.28 115.36 2010-04-30115.36 NA On Thu, Oct 28, 2010 at 12:45 PM, Bert Gunter gunter.ber...@gene.comwrote: Jason: Please read AND FOLLOW the posting guide on how to ask clear questions. Here, you need to more carefully define what you mean by the last 3 days. Do you mean:(a) the last 3 values in the series (including or excluding the present one?) or the last 3 calendar days -- e.g. for 10-05, only 10-05 and 10-04, since 10-01 is not within the last 3 calendar days.Also, do you have missing values, and, if so, how do you want to handle them. If you mean the former, for small amounts of data without any missings(say 100 million numeric values or less) and small n (like n=3), it's easy and should be pretty fast just to produce lagged columns and use pmax rowwise. If you mean the latter and have missing values, it may be considerably more difficult. However, offering anything more seems pointless until you have adequately specified what you want. Reproducible data and code for a start. Cheers, Bert On Thu, Oct 28, 2010 at 9:27 AM, Jason Kwok jayk...@gmail.com wrote: I'm having trouble returning a rolling n period highest value for a data set. For each day I want to calculate the highest value over the last 3 days. I am using the following packages: zoo, xts, quantmod and TTR. Thanks, Jason GLD.Close 2010-10-01128.91 2010-10-04128.46 2010-10-05130.99 2010-10-06131.81 2010-10-07130.37 2010-10-08131.66 2010-10-11132.29 2010-10-12131.96 2010-10-13134.07 2010-10-14134.75 2010-10-15133.68 2010-10-18134.28 2010-10-19130.11 2010-10-20131.32 2010-10-21129.47 2010-10-22129.73 2010-10-25130.85 2010-10-26130.88 2010-10-27129.52 [[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. -- Bert Gunter Genentech Nonclinical Biostatistics [[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] Returning highs and lows in R
I figured out how to offset my observations by 1 period by using the rollapply(xx,3,max,align=right), which would calculate the mean for (current observation, obs - 1 and obs -2 ). How would I further offset by 1 more period? Thanks, Jason On Thu, Oct 28, 2010 at 1:29 PM, Jason Kwok jayk...@gmail.com wrote: Thanks for the help. I'm looking to calculate rolling max and means for the last 3 observations in my data including AND not including the current observation. I'm not sure how to offset the observations used. For the 3 period max, I would like to return the max value over the last 3 observations not including today. When I use the rollapply function to take the max, it will look look back 1 observation, take the current observation and look forward 1 observation. I would like to return look back observations 1-3 and return the max. merge(xx,rollapply(xx,3,max)) GLD.Close GLD.Close.1 2010-04-01110.26 NA 2010-04-05110.89 111.03 2010-04-06111.03 112.49 2010-04-07112.49 112.65 2010-04-08112.65 113.64 2010-04-09113.64 113.64 2010-04-12113.01 113.64 2010-04-13112.69 113.03 2010-04-14113.03 113.65 2010-04-15113.65 113.65 2010-04-16111.24 113.65 2010-04-19111.15 111.46 2010-04-20111.46 112.31 2010-04-21112.31 112.31 2010-04-22111.84 113.19 2010-04-23113.19 113.19 2010-04-26112.75 114.63 2010-04-27114.63 114.63 2010-04-28114.31 114.63 2010-04-29114.28 115.36 2010-04-30115.36 NA On Thu, Oct 28, 2010 at 12:45 PM, Bert Gunter gunter.ber...@gene.comwrote: Jason: Please read AND FOLLOW the posting guide on how to ask clear questions. Here, you need to more carefully define what you mean by the last 3 days. Do you mean:(a) the last 3 values in the series (including or excluding the present one?) or the last 3 calendar days -- e.g. for 10-05, only 10-05 and 10-04, since 10-01 is not within the last 3 calendar days.Also, do you have missing values, and, if so, how do you want to handle them. If you mean the former, for small amounts of data without any missings(say 100 million numeric values or less) and small n (like n=3), it's easy and should be pretty fast just to produce lagged columns and use pmax rowwise. If you mean the latter and have missing values, it may be considerably more difficult. However, offering anything more seems pointless until you have adequately specified what you want. Reproducible data and code for a start. Cheers, Bert On Thu, Oct 28, 2010 at 9:27 AM, Jason Kwok jayk...@gmail.com wrote: I'm having trouble returning a rolling n period highest value for a data set. For each day I want to calculate the highest value over the last 3 days. I am using the following packages: zoo, xts, quantmod and TTR. Thanks, Jason GLD.Close 2010-10-01128.91 2010-10-04128.46 2010-10-05130.99 2010-10-06131.81 2010-10-07130.37 2010-10-08131.66 2010-10-11132.29 2010-10-12131.96 2010-10-13134.07 2010-10-14134.75 2010-10-15133.68 2010-10-18134.28 2010-10-19130.11 2010-10-20131.32 2010-10-21129.47 2010-10-22129.73 2010-10-25130.85 2010-10-26130.88 2010-10-27129.52 [[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. -- Bert Gunter Genentech Nonclinical Biostatistics [[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] Returning highs and lows in R
I was able to get what I wanted using the lag function to offset an addition period. lag(rollapply(xx,3,max),-2) or lag(rollapply(xx,3,max,align=right),-1) Thanks. Jason On Thu, Oct 28, 2010 at 1:49 PM, Jason Kwok jayk...@gmail.com wrote: I figured out how to offset my observations by 1 period by using the rollapply(xx,3,max,align=right), which would calculate the mean for (current observation, obs - 1 and obs -2 ). How would I further offset by 1 more period? Thanks, Jason On Thu, Oct 28, 2010 at 1:29 PM, Jason Kwok jayk...@gmail.com wrote: Thanks for the help. I'm looking to calculate rolling max and means for the last 3 observations in my data including AND not including the current observation. I'm not sure how to offset the observations used. For the 3 period max, I would like to return the max value over the last 3 observations not including today. When I use the rollapply function to take the max, it will look look back 1 observation, take the current observation and look forward 1 observation. I would like to return look back observations 1-3 and return the max. merge(xx,rollapply(xx,3,max)) GLD.Close GLD.Close.1 2010-04-01110.26 NA 2010-04-05110.89 111.03 2010-04-06111.03 112.49 2010-04-07112.49 112.65 2010-04-08112.65 113.64 2010-04-09113.64 113.64 2010-04-12113.01 113.64 2010-04-13112.69 113.03 2010-04-14113.03 113.65 2010-04-15113.65 113.65 2010-04-16111.24 113.65 2010-04-19111.15 111.46 2010-04-20111.46 112.31 2010-04-21112.31 112.31 2010-04-22111.84 113.19 2010-04-23113.19 113.19 2010-04-26112.75 114.63 2010-04-27114.63 114.63 2010-04-28114.31 114.63 2010-04-29114.28 115.36 2010-04-30115.36 NA On Thu, Oct 28, 2010 at 12:45 PM, Bert Gunter gunter.ber...@gene.comwrote: Jason: Please read AND FOLLOW the posting guide on how to ask clear questions. Here, you need to more carefully define what you mean by the last 3 days. Do you mean:(a) the last 3 values in the series (including or excluding the present one?) or the last 3 calendar days -- e.g. for 10-05, only 10-05 and 10-04, since 10-01 is not within the last 3 calendar days.Also, do you have missing values, and, if so, how do you want to handle them. If you mean the former, for small amounts of data without any missings(say 100 million numeric values or less) and small n (like n=3), it's easy and should be pretty fast just to produce lagged columns and use pmax rowwise. If you mean the latter and have missing values, it may be considerably more difficult. However, offering anything more seems pointless until you have adequately specified what you want. Reproducible data and code for a start. Cheers, Bert On Thu, Oct 28, 2010 at 9:27 AM, Jason Kwok jayk...@gmail.com wrote: I'm having trouble returning a rolling n period highest value for a data set. For each day I want to calculate the highest value over the last 3 days. I am using the following packages: zoo, xts, quantmod and TTR. Thanks, Jason GLD.Close 2010-10-01128.91 2010-10-04128.46 2010-10-05130.99 2010-10-06131.81 2010-10-07130.37 2010-10-08131.66 2010-10-11132.29 2010-10-12131.96 2010-10-13134.07 2010-10-14134.75 2010-10-15133.68 2010-10-18134.28 2010-10-19130.11 2010-10-20131.32 2010-10-21129.47 2010-10-22129.73 2010-10-25130.85 2010-10-26130.88 2010-10-27129.52 [[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. -- Bert Gunter Genentech Nonclinical Biostatistics [[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] CRAN vs R-Forge
What's the difference between the packages you get from CRAN and R-Forge? Are the packages you get from CRAN fully developed and R-Forge work-in-progress? Regards, Jason [[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] Importing CSV File
I'm trying to import a CSV file into R and when it gets imported, the entries get numbered down the left side. How do I get rid of that? Thanks, Jason * read.csv(file=C:\\Program Files\\R\\Test Data\\sales.csv,head=TRUE) Month Sales 1January 422 2 February 151 3 March 451 4 April 175 5May 131 6 June 307 7 July47 8 August12 9 September 488 10 October 122 11 November54 12 December 244 * [[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] Importing CSV File
Thanks for the response Erik. In this case, I would like to keep the row name as the month. How would I do that? Thanks, Jason On Sun, Oct 24, 2010 at 6:20 PM, Erik Iverson er...@ccbr.umn.edu wrote: On 10/24/2010 04:57 PM, Jason Kwok wrote: I'm trying to import a CSV file into R and when it gets imported, the entries get numbered down the left side. How do I get rid of that? When you imported the CSV file into R, an object of class data.frame was created, and since you did not assign it to a variable name, (e.g., df1 - read.csv(...) ), the object got printed. A data.frame object is going to have a row.names attribute by definition, which is what you're seeing. In ?data.frame, we see documentation for the row.names argument: If row.names was supplied as NULL or no suitable component was found the row names are the integer sequence starting at one (and such row names are considered to be automatic, and not preserved by as.matrix). The method that prints out a data.frame is called print.data.frame, and it does have an argument to suppress printing of the row.names. The question is, why do you not want row.names? Are they just distracting you when printed, or is there some reason not to carry them along in the object? --Erik Thanks, Jason * read.csv(file=C:\\Program Files\\R\\Test Data\\sales.csv,head=TRUE) Month Sales 1January 422 2 February 151 3 March 451 4 April 175 5May 131 6 June 307 7 July47 8 August12 9 September 488 10 October 122 11 November54 12 December 244 * [[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.
[R] If Statement Help
Price 2010-10-11 99 2010-10-12101 2010-10-13102 2010-10-14103 2010-10-15 99 2010-10-18 98 2010-10-19 97 2010-10-20101 2010-10-21101 2010-10-22101 I have this dataset and I only want to return instances when the Price is 100. If I use the code: Price 100 then it will evaluate each entry as TRUE or FALSE. What is the code to only return TRUE results? Thanks, Jay [[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] If Statement Help
Thanks for the help Jim. As a new user and member of this mailing list, I'm very impressed with all the support! Jay On Sat, Oct 23, 2010 at 10:21 PM, jim holtman jholt...@gmail.com wrote: Need to understand how 'indexing' is done in R: x - read.table(textConnection( Price + 2010-10-11 99 + 2010-10-12101 + 2010-10-13102 + 2010-10-14103 + 2010-10-15 99 + 2010-10-18 98 + 2010-10-19 97 + 2010-10-20101 + 2010-10-21101 + 2010-10-22101), header = TRUE) closeAllConnections() x Price 2010-10-1199 2010-10-12 101 2010-10-13 102 2010-10-14 103 2010-10-1599 2010-10-1898 2010-10-1997 2010-10-20 101 2010-10-21 101 2010-10-22 101 x[x$Price 100,, drop = FALSE] Price 2010-10-12 101 2010-10-13 102 2010-10-14 103 2010-10-20 101 2010-10-21 101 2010-10-22 101 On Sat, Oct 23, 2010 at 9:56 PM, Jason Kwok jayk...@gmail.com wrote: Price 2010-10-11 99 2010-10-12101 2010-10-13102 2010-10-14103 2010-10-15 99 2010-10-18 98 2010-10-19 97 2010-10-20101 2010-10-21101 2010-10-22101 I have this dataset and I only want to return instances when the Price is 100. If I use the code: Price 100 then it will evaluate each entry as TRUE or FALSE. What is the code to only return TRUE results? Thanks, Jay [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] If Statement Help
Thanks Jorge. It works. Is there a way to keep the actual price in the price column instead of TRUE/FALSE but filtering on when price100? Thanks, Jay On Sat, Oct 23, 2010 at 10:37 PM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Hi Jay, If x is your data, you could use subset() to do what you want: subset(x, Price 100) See ?subset for more information. HTH, Jorge On Sat, Oct 23, 2010 at 9:56 PM, Jason Kwok wrote: Price 2010-10-11 99 2010-10-12101 2010-10-13102 2010-10-14103 2010-10-15 99 2010-10-18 98 2010-10-19 97 2010-10-20101 2010-10-21101 2010-10-22101 I have this dataset and I only want to return instances when the Price is 100. If I use the code: Price 100 then it will evaluate each entry as TRUE or FALSE. What is the code to only return TRUE results? Thanks, Jay [[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.