Edit R data frame almost like in Excel

Edit R data frame almost like in Excel

Do you want to edit R data frame like an Excel table? It is not possible the same way. But on the other hand, there is a solution that is comfortable enough to edit a few entries.

Here is my data frame. Imagine that it comes from a source that I cannot edit. There is one value that should be there (NA).

df <- data.frame(
  id = as.character(c("00129", "00121", NA, "00127", "00130", "00128", "00111")),
  agent = as.character(c("David", "John", "Paul", "Kate", "Thomas", "Alma", "Grace"))
)

#     id  agent
#1 00129  David
#2 00121   John
#3    NA   Paul
#4 00127   Kate
#5 00130 Thomas
#6 00128   Alma
#7 00111  Grace

Edit R data frame almost like in Excel

There is an R base function edit that opens a new window with the data frame data.

To save changes, assign that to the same data frame like this.

df <- edit(df)

If you are working in RStudio, you might be surprised how the window will look like in R. Maybe not so pretty, but you can do what you need. You can even add a new column (Var 3 in the picture).

Edit R data frame almost like in Excel

Make necessary changes.

Edit R data frame almost like in Excel

After closing that window, check your data frame. All changes should be there.

df

#     id  agent
#1 00129  David
#2 00121   John
#3 00123   Paul
#4 00127   Kate
#5 00130 Thomas
#6 00128   Alma
#7 00111  Grace

There is a more serious solution to that with package editData.

Here is another handy approach. Sometimes it is useful to quickly copy data from R to Excel to do some quick checkups.

Are you new to R programming but an experienced Excel user? This Datacornering post might be just for you. How to switch from Excel to R

 





Posted

in

,

Comments

Leave a Reply

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