moRe

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

About Patrick

I'm usually a paleontologist or an isotope geochemist, but I like statistics, math history, markets, and soccer on less technical levels. My posts could involve any or all of the above, or anything else for that matter.

4 thoughts on “moRe

  1. I really like these R posts and I hope you write more of them. I study animal behaviour and am using R a lot to analyse my data, it’s a great program but also a very steep learning curve!

    1. Sam,
      Glad these are helpful! I was kinda wondering if they were useful to anyone. I’d be willing to take requests if you have a specific topic you want me to tackle next.

      1. Yes they’re helpful! I don’t know if you’d be able to tackle this in a blog post but something about writing loops would be really useful.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.