moRe

December 20, 2012
By

(This article was first published on Paleocave Blog » R, and kindly contributed to R-bloggers)

more_more_more_main_a2Hopefully my first R post whetted your apatite for open source data software.  I’m gearing up for more R posts regardless.  I thought I’d do a quick post about a couple of useful commands, ‘View’ and ‘fix’. When you first break the shackles of Excel one of the toughest things is not being able to see your data. Try this, fire up R (go download it and install it if you haven’t already) and let’s call up a built-in dataset by typing

volcano


You get a big barf load of numbers in your R interpreter window. This is enough to send lots of people running back to Excel as fast as they can say ‘Bill Gates.’ Ok, admittedly that isn’t nice to look at. If you want to view your data in a more visually appealing way you can use the View command (make sure your capitalize the ‘V’).

View(volcano)

Now things look more like they do in a spreadsheet. If you’re on a Windows machine this is really works well, you’ll probably have a scrollable window pop up with slider bars and everything. On Mac OS it’s a little more janky. You’ll get an X11 window that you can use your arrow keys to navigate around.

Ok, looking good! What if you’ve loaded in your data, you’re looking it over and you see an error (misspelling maybe)? Do you have to open up your file in Excel, fix it, and re-save it as a csv, and then open it up again in R? No. No you don’t. You can use the fix command (but have care, things can get confusing this way).

volcanoII <- fix(volcano)

will allow you to open up an editable window, make changes by clicking the error with your mouse, and typing in the correction. The changes will be saved in a new data frame called volcanoII (because that's what you typed on the left side of the <- ). Here is the caveat, the data edits aren't saved in the original file, just in R. If you want to save a copy of your edited data frame, you'll have to write out a file from R (use write.table). Alright, hopefully this pushes you a little farther towards dumping your spreadsheet program for data analysis.

Share

To leave a comment for the author, please follow the link and comment on their blog: Paleocave Blog » R.

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

Comments are closed.

Sponsors

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)