Beginner's guide to R: Syntax quirks you'll want to know

Part 5 of our hands-on guide covers some R mysteries you'll need to understand.

Page 6 of 6

Most R experts will discourage newbies from "cheating" this way: Falling back on SQL makes it less likely you'll power through learning R syntax. However, it's there for you in a pinch -- or as a useful way to double-check whether you're getting back the expected results from an R expression.

Examine and edit data with a GUI

Speaking of cheating, if you don't want to use the command line to examine and edit your data, R has a couple of options. The edit() function brings up an editor where you can look at and edit an R object, such as


Invoking R's data editing window with the edit() function.

This can be useful if you have a data set with a lot of columns that are wrapping in the small command-line window. However, since there's no way to save your work as you go along -- changes are saved only when you close the editing window -- and there's no command-history record of what you've done, the edit window probably isn't your best choice for editing data in a project where it's important to repeat/reproduce your work.

In RStudio you can also examine a data object (although not edit it) by clicking on it in the workspace tab in the upper-right window.

Saving and exporting your data

In addition to saving your entire R workspace with the save.image() function and various ways to save plots to image files, you can save individual objects for use in other software. For example, if you have a data frame just so and would like to share it with colleagues as a tab- or comma-delimited file, say for importing into a spreadsheet, you can use the command:

write.table(myData, "testfile.txt", sep="\t")

This will export all the data from an R object called myData to a tab-separated file called testfile.txt in the current working directory. Changing sep="\t" to sep="c" will generate a comma-separated file and so on.

Next: More resources for boosting your R skills.

See the entire beginner's guide to R:

Part 1: Introduction to R

Part 2: Getting your data into R

Part 3: Easy ways to do basic data analysis with R

Part 4: Painless data visualization using R

Part 5: Syntax quirks you'll want to know about R

Part 6: Useful resources for R

This article, Beginner's guide to R: Syntax quirks you'll want to know, was originally published at

Sharon Machlis is online managing editor at Computerworld. Her e-mail address is You can follow her on Twitter @sharon000, on Facebook, on Google+ or by subscribing to her RSS feeds: articles; and blogs.

Read more about business intelligence/analytics in Computerworld's Business Intelligence/Analytics Topic Center.

This story, "Beginner's guide to R: Syntax quirks you'll want to know" was originally published by Computerworld.

| 1 2 3 4 5 6 Page 6
From CIO: 8 Free Online Courses to Grow Your Tech Skills
View Comments
Join the discussion
Be the first to comment on this article. Our Commenting Policies