okay so today we will start playing around with R and will use GDP as our ginny pig.

okay so first do the following:

1. DOWNLOAD R

2. Create a folder and call it “R” on your desktop. Then type in

*getwd()*

this will produce the current place where R finds stuff (you know the data you need to manipulate)

3. Copy whatever getwd() produced and paste it into the following function setwd()

and type /Desktop/R after it. It should look as follows:

*setwd(“/Users/stevensabol/Desktop/R”)*

4. Go to FRED and download a data set into excel, convert the file to a CSV file. Make sure to name it something simple and straight to the point, then save it in your R folder.

5. Then type the following into R:

*GDP<-read.csv(“gdp.csv”)*

I have GDP because that is the series I am using. If you are using the CPI then type CPI where I typed GDP. Its that simple. Its easy to get confused so make sure you keep it simple.

Okay this next part is confusing because it very well might be redundant, but do it anyway.

6. Type in,

*GDP=scan(“/Users/stevensabol/Desktop/R/gdp.csv”)*

this seems to actually get the data in right.

7. Then you have to convert the series into a time series so R can understand:

*GDP=ts(GDP,start=1,frequency=1)*

“Start” denotes where you want your observations to start. for me it is one, because the first observation makes no sense (not that you can see it anyway). Frequency denotes the number of records in the data per observation.

8. At this point it may make sense to plot what you have. So go for it!

*plot(GDP,ylab=”REAL GDP”,main=”U.S.”)*

ylab denotes the y axis label

main denotes the main label

Here is what my plot looks like:

More lessons will come shortly!

Keep Dancin’

Steven J.

*Related*

To

**leave a comment** for the author, please follow the link and comment on their blog:

** The Dancing Economist**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as:

Data science,

Big Data, R jobs, visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...