Using RClimate To Retrieve Climate Series Data

[This article was first published on Climate Charts & Graphs I » RClimate Script, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This post shows how to use RClimate.txt to retrieve a climate time series and write a csv file in 5 lines of R script.

One of my readers, Robert, wants to be able to download climate time series data and write it to a csv file.  The R script below shows how to  download the MEI data series and write a csv file.  For this example I will use the RClimate function (func_MEI) to retrieve the data. I then simply specify the path and file name link for the output file (note quotes around the output file name and then write  a csv file.

source("http://processtrends.com/files/RClimate.txt"
m <- func_MEI()
head(m)
output_link <- "C://R_Home/mei.csv"
write.csv(m, output_link, quote=FALSE, row.names = F)

Let’s walk through the lines to see what is going on:

 

source(“http://processtrends.com/files/RClimate.txt”;
This line is telling R to read and have available the R script functions in the source file.

m <- func_MEI()
This line is telling R to assign the results of func_MEI() to the m data.frame. I have added 20 climate time series to RClimate similar to func_MEI.

head(m)
This line displays the first 6 lines of the m data.frame so that we can be sure that func_MEI() returned some data.

output_link <- “C://R_Home/mei.csv”
This line assigns the target file path and name where I want the csv file saved.

write.csv(m, output_link, quote=FALSE, row.names = F)
This line writes the m data to a csv file located at the path and fie name specified in output_link.

If I want to see the func_MEI() R script, I just have to enter func_MEI in the R console  and R will display the func_MEI() script on the console.

Filed under: Citizen Climate Science, Do-it-yourself Climate Science, Global Warming, RClimate Script Tagged: Climate Trends, R scripts

To leave a comment for the author, please follow the link and comment on their blog: Climate Charts & Graphs I » RClimate Script.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)