[R] Getting started,

2009-03-26 Thread gug

Hello,

First of all, I'm new to R and I don't have anyone who already knows the
language to ask for tips, so please excuse my ignorance.

I'm trying to download data direct from the Federal Reserve statistics
website and graph it, using the following:

#This downloads the data from the Fed website
download.file("http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt","Eurodollar_deposits1M.dat";)

#This reads that data into a table
data_download=read.table("Eurodollar_deposits1M.dat",skip=8,sep=",",head=T)

#This is attempting to get R to read the date column, which is in
"mm/dd/" format
#I have restricted it to the first 50 data points (to keep it simple)
date_vec = as.Date(data_download[1:50,1],"%m/%d/%y")

#This reads the values again for just the first 50 data points
eurodollar_vec = data_download[1:50,2]

#This plots the date and data values.
plot(date_vec,eurodollar_vec)


A few issues with the output from this:

1) The date_vec data ends up looking like this "2019-01-04" - for some
reason all year 2019, irrespective of the actual year (e.g. 1971, 1972). 
Any suggestions as to where I am going wrong?

2) The chart ends up as a scatter diagram, not surprisingly.  I initially
tried to use the ts.plot() function but when I did, I found that it doesn't
use the date column in the data as the x axis.  Is there a way of creating a
time series that uses the date column, or alternatively, how would I turn
these two columns (date & value) into a line graph?

3) The y-axis output should be from about 4.5 to about 8.5, but the y-axis
shows as being about 430-670.  There also seems to be a line of points
across the top which are all of the same value - as though anything above
about 670 gets charted as 670.


I'm sorry for this being a "what am I doing wrong" post, but I have looked
through the manuals without success, and I am new enough to R that I don't
have a feel for ways round these sorts of problems.  Any suggestions would
be greatly appreciated.  Thanks.
-- 
View this message in context: 
http://www.nabble.com/Getting-started%2C-tp22719735p22719735.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Maximum number of tables combined with rbind

2009-06-20 Thread gug

Hello,

I have been using read.table to read data files into R, then rbind to
combine them into one table.  The column headings are all identical, so it
should be straightforward, and it seems to be working well so far.

My question is: What is the maximum number of tables that can be combined
with rbind?

Is it driven by the number of rows in the tables, by a constraint with the
syntax of rbind itself, by my PC's memory, or by some other constraint?  At
this point the data files I am reading in are approx 2,500 rows x 150
columns.

Thanks,

Guy Green
-- 
View this message in context: 
http://www.nabble.com/Maximum-number-of-tables-combined-with-rbind-tp24122126p24122126.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Maximum number of tables combined with rbind

2009-06-20 Thread gug

Thanks David - you're right, "PC" is not very informative.  I am using XP
Home with 4GB, though I don't think XP accesses more than 3GB.

>From following through the FAQ's and memory functions (e.g.
"memory.limit(size = NA)") it looks like R is getting about 1535Mb at the
moment.


David Winsemius wrote:
> 
>> My question is: What is the maximum number of tables that can be 
>> combined
>> with rbind?
>> Is it driven by the number of rows in the tables, by a constraint  with
>> the
>> syntax of rbind itself, by my PC's memory,
> 
> Yes, and the OS. "PC" is not a useful designation for an OS.
> 
>> or by some other constraint?  At this point the data files I am reading
>> in are approx 2,500 rows x 150
>> columns.
> 
> That should not be any problem. On an Intel-Mac w/ 8 GB there is no  
> problem with dataframes that are 500 times that size.
> 
> If this is on a Windows box, there is an RW-FAQ on the topic.
> 
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Maximum-number-of-tables-combined-with-rbind-tp24122126p24124984.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Warning messages when using rbind

2009-06-21 Thread gug

Hello,

I have been using a very simple rbind approach (simple enough for me to
understand) to combine data files within R.

It seems to work fine, but then generates warning messages for reasons that
I can't begin to understand.  The text below shows the issue.  

testread12=read.table("C:/Files/Test100.txt", head = T)
testread11=read.table("C:/Files/Test101.txt", head = T)
testbind1=rbind(testread12,testread11)
testbind2=rbind(testread11,testread12)

The testrbind1 line generates the following message:

"Warning message:
In `[<-.factor`(`*tmp*`, ri, value = c(0.00557998, -0.058016069,  :
  invalid factor level, NAs generated"

However the testrbind2 line works fine.  Although the data in the files is
different, the format (columns, etc) should be identical.  The fact that it
works in one order, but not the other, makes it very difficult for me to
understand what the problem is.

Files attached.  Any suggestions gratefully received.  Thanks,

Guy Green
http://www.nabble.com/file/p24130996/Test101.txt Test101.txt 
http://www.nabble.com/file/p24130996/Test100.txt Test100.txt 
-- 
View this message in context: 
http://www.nabble.com/Warning-messages-when-using-rbind-tp24130996p24130996.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Clearing out or reclaiming memory

2009-06-30 Thread gug

Hello,

Is there a command for freeing up the memory used by R in holding data
tables?

The structure of the procedure I have is as follows:

1)  Read multiple txt files in using read.table(...).
2)  Combine the read tables using rbind(...).
3)  Attach the data using attach(...) and then use do a multiple regression
using lm(...).

So far so good, but when I then perform a further regression by taking out
factors, I run into memory issues, getting warnings such as:

"1: In as.list.data.frame(X) :
   Reached total allocation of 1535Mb: see help(memory.size)"

As it stands, I have to close and then restart R, read in the same data
again and run with the new reduced number of factors.

My thinking was that, if I could reclaim the memory held by the already read
data files, keeping only the result of the rbind process, I could avoid the
duplication.  I have therefore tried (very amateurishly) to reset the read
data to zero using:

Read_data_1=(0)
Read_data_2=(0)... etc

Followed by:

gc()

However this doesn't get solve the problem.  Is there a better way of
getting R to "forget" the data tables it was holding and free up the memory?

For info: I am also specifying colClasses when first reading the data in, to
try to make it more memory-efficient (following:
http://www.biostat.jhsph.edu/~rpeng/docs/R-large-tables.html).

Other alternatives are trying the 3GB switch (XP Home, with 4GB RAM). 
Another alternative is trying to use the sqldf package to bring the data in,
which one poster very helpfully suggested in response to an earlier
question.  I may end up trying that, but as I have not used SQL, I am a
little daunted by the prospect.

I would really appreciate any suggestions.  Thanks.

Guy Green
-- 
View this message in context: 
http://www.nabble.com/Clearing-out-or-reclaiming-memory-tp24268680p24268680.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Clearing out or reclaiming memory

2009-06-30 Thread gug

Thanks - that's great.  A combination of "object.size", "rm" and "gc" seems
to be enough for me to work out what was causing the problem and then get
beyond it.

In particular, using "rm" on the result of the multiple regression seems to
make a big difference: it wasn't obvious to me before, but of course the
memory taken up by that result doesn't get freed up when running a new
regression to the same output name.  Also not obvious to me was that it was
the regression expression itself that was taking up so much memory, as
opposed to just the underlying data.

I've been using "attach" because I was following one of the approaches
recommended in this "Basic Statistics and R" tutorial
(http://ehsan.karim.googlepages.com/lab251t3.pdf), in order to be able to
easily use the column headings within the regression formula.

I hadn't used "detach" at this point because I was aiming to use the same
data (i.e. the result of the rbind) in the later operations, with only the
factors being tested changing.  I will look into the "with" approach you
mention - thanks for that.

Thanks again,
Guy


jholtman wrote:
> 
> You can use 'rm' to remove objects.  Are you remembering to do a 'detach'
> after the 'attach'?  Why are you using 'attach' (I personally avoid it)?
> Think about using 'with'.  Take a look at the size of the objects you are
> working with (object.size) to understand where you might have problems. 
> Use
> 'search' to see what still might be attached.  I think that as long as
> something is 'attached' memory is not freed up after 'rm' until you do the
> 'detach'
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem that you are trying to solve?
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Clearing-out-or-reclaiming-memory-tp24268680p24270331.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Clearing out or reclaiming memory

2009-06-30 Thread gug

Thanks to everyone who has posted.  These posts have really helped me to
budge forward my understanding of R, as well as giving me a couple of new
areas that I still need to work on.

These (below) won't be news to the people who have posted, but for anyone
who is in my position, here are a couple of expressions that I came across
as a result of following these leads, that are quite useful:

  sapply(ls(), function(x) object.size(get(x)))
-This lists all objects with the memory each is using (I should be honest
and say that, never having used "sapply" before, I don't truly understand
the syntax of this, but it seems to work).

  rm(list=ls())
-This clears out the memory for every object.

Guy


Bert Gunter wrote:
> 
> 
> It is usually better (and easier) to use the data argument that comes with
> many modelling functions
> 
> -- Yes. And for functions without a data argument, see  ?with.
> 
> Bert Gunter
> Genentech Nonclinical Biostatistics
> 

-- 
View this message in context: 
http://www.nabble.com/Clearing-out-or-reclaiming-memory-tp24268680p24281964.html
Sent from the R help mailing list archive at Nabble.com.

__
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 list R object properties & save workspace?

2009-07-23 Thread gug

Hi Matej,

You can also try:

sapply(ls(), function(x) object.size(get(x)))

or 

eapply(.GlobalEnv, object.size) 

which list all objects - as with ls() - but giving their sizes.

I'm also quite new to R so am not sure which other properties you could hope
to get out of it, but by substituting another command for the "object.size"
command - e.g. "str" or "summary" - you can get other information out of it
for every object: with "str", a similar and perhaps identical output to what
Duncan Murdoch suggested with ls.str().

You could try looking up the str() function and see if there are properties
that you are interested in.  E.g. 

 sapply(ls(), function(x) str(get(x), give.length = TRUE))
which lists everything with length as [1:...].  You could also look at: 

browseEnv(envir  =  .GlobalEnv,  properties = NULL)

Guy


Matej Kovacic wrote:
> 
> Hi,
> I am new to R and have a couple of questions.
> 
> I know how to list all objects (with ls()), but how to list all
> properties of them?
> 
> For instance, I found function object.size(), but I would also like to
> know whether one object is a dataset or just one vector (variable) or
> even only one value, etc...
> 
> And another question - how to save workspace to a custom location while
> running R? Is there any command for that?
> 
> Thanks,
> Matej
> 
-- 
View this message in context: 
http://www.nabble.com/How-to-list-R-object-properties---save-workspace--tp24604549p24624120.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Problems with Boxplot

2009-09-02 Thread gug

Hello,

I have been having difficulty getting boxplot to give the output I want -
probably a result of the way I have been handling the data.

The data is arranged in columns: each date has two sets of data.  The number
of data points varies with the date, so each column is of different length. 
I want to get a series of boxplots with the date along the x-axis, with
alternating colors, so that it is easy to see the difference between the
results within each date, as well as across dates.

testdata<- c("C:\\Files\\R\\Sample R code\\Post trial data.csv")
data_headings <- read.table(testdata, skip = 0, sep = ",", header =
FALSE)[1,]
my_data <- read.table(testdata, skip = 1, sep = ",", na.strings =
"na",header = FALSE)
boxplot(my_data*100, names = data_headings, outline = FALSE, range = 0.3,
border = c(2,4))

The result is a boxplot, but it does not show the date along the bottom (the
"names = data_headings" bit achieves nothing).  I can alternatively try
this:

new_data<- read.table(testdata, skip = 0, sep = ",", na.strings =
"na",header = TRUE)
boxplot(new_data,outline = FALSE, range = 0.3,border = c(2,4))

This takes all the data and plots it, but I then lose the ability to
multiply by 100 (I'm trying to show percentages: e.g. 10% as "10", rather
than as "0.1").

1) My first question is: is there a simple way of getting both dates along
the x-axis and the "*100" calculation (or percentages)?

2) Next is how can I put a legend somewhere to show that red is "data set 1"
and blue is "data set 2".

3) Is it possible to get the date to straddle across each of the two dates
it covers: as it is, one tick has the date, the other does not.

4) Is it possible to show both the median and the mean with boxplot?

5) Finally, the code works as described above (i.e. up to a point) with the
"Post trial data.csv" file I have posted.  However when I try with a larger
file ("Larger trial.csv", also posted), I get the message: "Error in
scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :  line
145 did not have 50 elements" when I get to the "data_headings" line.  I
have no idea why R is seeing a difference between these two files.
http://www.nabble.com/file/p25256461/Post%2Btrial%2Bdata.csv
Post+trial+data.csv  http://www.nabble.com/file/p25256461/Larger%2Btrial.csv
Larger+trial.csv 
Thanks for any suggestions,

Guy Green
 

-- 
View this message in context: 
http://www.nabble.com/Problems-with-Boxplot-tp25256461p25256461.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Problems with Boxplot

2009-09-03 Thread gug

I'm posting answers to my own Q's here - as far as I have answers - first so
that people don't spend time on them, and second in case the solutions are
helpful to anyone else in future.

1) My first question is: is there a simple way of getting both dates along
the x-axis and the "*100" calculation (or percentages)?
I still don't know how to change the format of the y-axis tick labels.  I'd
be interested if anyone has a quick way to get percentages and additionally,
how do I get numbers in the "0,000" format along the x or y-axis?  In the
meantime, I can live with this.

2) Next is how can I put a legend somewhere to show that red is "data set 1"
and blue is "data set 2".
I did this with the following text:
legend("top", c("Top","Bottom"), cex=1.5, lty=1:2, fill=c("lightblue",
"salmon"), bty="n")

3) Is it possible to get the date to straddle across each of the two dates
it covers: as it is, one tick has the date, the other does not.
I didn't manage to do this, but as there were over 20 dates in the final
data (i.e. 40 plots), by changing the width of the chart window, not every
plot was labeled anyway and it was clear enough.

4) Is it possible to show both the median and the mean with boxplot?
I gave up on this, but I think the data looks OK in the end with just the
boxplot defaults.

5) Finally, the code works as described above (i.e. up to a point) with the
"Post trial data.csv" file I have posted.  However when I try with a larger
file ("Larger trial.csv", also posted), I get the message: "Error in
scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :  line
145 did not have 50 elements" when I get to the "data_headings" line.  I
have no idea why R is seeing a difference between these two files.
I ended up finding that even for specific small files, I got this error
message, which prevented me from processing the data and so was fatal to the
code.  I narrowed it down to a small file, and then looked at the csv file
in notepad.  The bottom of the file (which was just 2 columns of data, of
different column lengths), was along these lines:

-0.48013245,0.095652174
-0.039344262,-0.067142857
0.018022077,-0.079295154
-0.078534031,
0.010054845,
0.096153846,
0.177568018
0.013818182
0.002402883
 
It seemed that R could cope with empty columns - as long as there was a ","
to indicate that there was indeed a column, but it could NOT cope with a
column that didn't exist (because there was no ",").  The problem was that
Excel, which was generating the CSV file, wasn't putting "," to indicate
empty columns in certain circumstances.  The solution was to fill the empty
cells in Excel with "na" before saving as CSV.  Excel then saves it
correctly, and R deals with it correctly.  

The final code (though without the y-axis formatting being fixed) is:

testdata<- c("C:\\Files\\R\\Sample R code\\Post trial data.csv")
new_data<- read.table(testdata, skip = 0, sep = ",", na.strings =
"na",header = TRUE)
x11(width=16, height=7, pointsize=14)
boxplot(new_data,outline = FALSE, col = c("lightblue", "salmon"), las =1,
boxwex = 0.5) 
legend("top", c("Label for blue boxes","Label for red boxes"), cex=1.5,
lty=1:2, fill=c("lightblue", "salmon"), bty="n");
title(main="Chart title text", cex.main = 1.8)
grid()  

Guy


gug wrote:
> 
> Hello,
> 
> I have been having difficulty getting boxplot to give the output I want -
> probably a result of the way I have been handling the data.
> 
> The data is arranged in columns: each date has two sets of data.  The
> number of data points varies with the date, so each column is of different
> length.  I want to get a series of boxplots with the date along the
> x-axis, with alternating colors, so that it is easy to see the difference
> between the results within each date, as well as across dates.
> 
> testdata<- c("C:\\Files\\R\\Sample R code\\Post trial data.csv")
> data_headings <- read.table(testdata, skip = 0, sep = ",", header =
> FALSE)[1,]
> my_data <- read.table(testdata, skip = 1, sep = ",", na.strings =
> "na",header = FALSE)
> boxplot(my_data*100, names = data_headings, outline = FALSE, range = 0.3,
> border = c(2,4))
> 
> The result is a boxplot, but it does not show the date along the bottom
> (the "names = data_headings" bit achieves nothing).  I can alternatively
> try this:
> 
> new_data<- read.table(testdata, skip = 0, sep = ",", na.strings =
> "na",header = TRUE)
> boxplot(new_data,outline = FALSE, range = 0.3,border = c(2,4))
> 
> This takes all the d

Re: [R] Problems with Boxplot

2009-09-04 Thread gug

Hi Petr,

Thanks for these comments.

I'm sorry that my post was not clear.  I was referring to the questions in
my original post/code/file uploads, but I had forgotten to include an
updated file (now attached 
http://www.nabble.com/file/p25304663/Post%2Btrial%2Bdata.csv
Post+trial+data.csv ) to work with the new code:

testdata<- c("C:\\Files\\R\\Sample R code\\Post trial data.csv")
new_data<- read.table(testdata, skip = 0, sep = ",", na.strings =
"na",header = TRUE)
x11(width=16, height=7, pointsize=14)
boxplot(new_data,outline = FALSE, col = c("lightblue", "salmon"), las =1,
boxwex = 0.5) 
legend("top", c("Label for blue boxes","Label for red boxes"), cex=1.5,
lty=1:2, fill=c("lightblue", "salmon"), bty="n");
title(main="Chart title text", cex.main = 1.8)
grid() 

I'm still not clear how I can get the number format showing #,###.  E.g.
with this code and attached file, the scale shows as "2000", "1" etc.  I
don't know how to show 2,000. 10,000 etc.  I have looked through sprintf
(thanks for suggesting that - I'd spent hours looking without finding it)
and it seems incredibly flexible, but the formats shown are more scientific
in focus.  I still haven't been able to find a way of getting a "comma
style".

Thanks again

Guy


Petr Pikal wrote:
> 
> Hi
> 
> it is rather difficult to understand what you mean by your 
> questions/answers without real reproducible code.
> 
> r-help-boun...@r-project.org napsal dne 03.09.2009 13:41:11:
> 
>> I'd be interested if anyone has a quick way to get percentages and 
> additionally, how do I get numbers in the "0,000" format along the x or
> y-axis?  In the meantime, I can live with this.
> 
> plot(1:10,1:10, axes=F)
> axis(2, at=c(2,3,7,9), labels=c(1.2, 2.38, 13.54, 16.8))
> 
> the same applies with boxplot.
> 
> by
> 
> bbb<- boxplot()
> 
> you obtain an object which is used by bxp. See help page for boxplot, 
> section See also
> 
>> ...
> 
> See also par for graphic options, format and or sprintf for formating 
> numbers 
> 
> Regards
> Petr
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Problems-with-Boxplot-tp25256461p25304663.html
Sent from the R help mailing list archive at Nabble.com.

__
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 2.9.2 memory max - object vector size

2009-09-11 Thread gug

At the risk of stating the obvious:

  - rm(.)  # clears specific objects out of memory as soon as they're no
longer needed in the routine.

  - sapply(ls(), function(x) object.size(get(x)))  #lists all objects with
the memory each is using.

  - rm(list=ls())  #clears out all objects, e.g. before the routine, to free
up memory.

Guy


S. Few wrote:
> 
> ##  PROBLEM:
> 
> I have memory limit problems. R and otherwise. My dataframes for
> merging or subsetting are about 300k to 900k records.
> I've had errors such as vector size too large. gc() was done.reset
> workspace, etc.
> 

-- 
View this message in context: 
http://www.nabble.com/R-2.9.2-memory-max---object-vector-size-tp25390745p25398830.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Simple time series questions

2009-09-11 Thread gug

Thanks - that works great.

Do you have any suggestions about the grid() problem - i.e. that the
vertical gridlines do not line up with the x-axis tickmarks (which are
years)?

I can't see on what basis the vertical gridlines are being positioned, but
it doesn't look good that they are not lined up with anything.

Thanks,

Guy


DKOD wrote:
> 
> This script worked for me. Be sure to put in your correct link.
> 
>   link <- "C:\\R_Home\\Charts & Graphs Blog\\R_Chart_Doc\\text_data.csv"
>   testdata<- read.table(link, head = T, sep = ",",na.strings = "na")
>   test_date = as.Date(testdata$Date,"%d-%m-%y") 
> 
>   plot(test_date, testdata$Model, type="l", log="y") 
>   points(test_date, testdata$BaseDataA, type = "l", col = "red")
>   points(test_date, testdata$BaseDataB, type = "l", col = "blue")
> 
> You add 2nd and 3rd series with points command
> 
> Hope this helps.
> 
> Kelly
> 
>  http://chartsgraphs.wordpress.com http://chartsgraphs.wordpress.com 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Simple-time-series-questions-tp25398419p25399928.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Simple time series questions

2009-09-11 Thread gug

I'm sure this is a really simple problem, but I've spent hours digging and I
keep running into roadblocks.

I'm trying to get a simple chart with three time series.  Similar to the
attached example 
http://www.nabble.com/file/p25398419/Excel%2Bchart%2Bexample.pdf
Excel+chart+example.pdf , something that was quite easy to do in Excel,
except that I need a log y-axis: something that R can do and Excel can't.

The data is in the attached CSV file 
http://www.nabble.com/file/p25398419/test%2Bchart%2Bdata.csv
test+chart+data.csv .  I can read it in OK, and create separate charts:

testdata<- read.table("C:\\Files\\test chart data.csv", head = T, sep =
",",na.strings = "na")
test_date = as.Date(testdata$Date,"%d-%m-%y")
test_data_model = testdata$Model
test_date_baseA = testdata$BaseDataA
test_date_baseB = testdata$BaseDataB
plot(test_date, test_data_model,type='l',log="y")
plot(test_date, test_data_baseA,type='l',log="y")
plot(test_date, test_data_baseB,type='l',log="y")
grid()

(Clearly at this point, each chart over-writes the previous one.)

Next I try to get them onto a single chart, sharing the same y-axis.  I'm
sure I haven't done this very elegantly, but here goes:

frame_model = data.frame(a=test_date,b=test_data_model)
frame_A = data.frame(a=test_date,b=test_data_baseA)
frame_B = data.frame(a=test_date,b=test_data_baseB)
ts_model = ts(frame_model$b)
ts_a = ts(frame_A$b)
ts_b = ts(frame_B$b)
ts.plot(ts_model,ts_a,ts_b,col=c("blue","red","green"),log="y")

The problem is that I no longer have the date along the y-axis.  How can I
get that back?

Finally, when I plot the separate time series, the grid() function geneates
a grid where the vertical lines are not lined up with the year tick marks. 
I interpreted the topic help as saying that by default they would match the
tick marks.  How can I achieve that?

Thanks for any suggestions,

Guy Green
-- 
View this message in context: 
http://www.nabble.com/Simple-time-series-questions-tp25398419p25398419.html
Sent from the R help mailing list archive at Nabble.com.

__
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.