Data Editor

There is a data editor within R that can be accessed from the menu bar by selecting Edit/Data editor.... You provide the name of the matrix or dataframe containing the material you want to edit (this has to be a dataframe that is active in the current R session, rather than one which is stored on file), and a Data Editor window appears. Alternatively, you can do this from the command line using the fix function (e.g. fix(data.frame.name)). Suppose you want to edit the bacteria dataframe which is part of the MASS library:

library(MASS)
attach(bacteria)
fix(bacteria)

The window has the look of an Excel spreadsheet, and you can change the contents of the cells, navigating with the cursor or with the arrow keys. My preference is to do all of my data preparation and data editing in Excel itself (because that is what it is good at). Once checked and edited, I save the data from Excel to a tab-delimited text file (*.txt) that can be imported to R very simply using the function called read.tabl (p. 98). One of the most persistent frustrations for beginners is that they cannot get their data imported into R. Things that typically go wrong at the data input stage and the necessary remedial actions are described on p. 98.

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.