Data may be entered into a Google Sheet and then loaded into RStudio with the following steps.
- Open Google Sheets.
- Enter the data with each variable in a separate column and each individual in separate rows. Make sure that the first row contains the variable names (without spaces).
google-sheets data entry
- Rename the sheet (click on “Untitled spreadsheet” and give a new name).
- Publish the sheet to the web by selecting the
Filemenu and thePublish to the websubmenu. In the ensuing dialog box, change “Entire Document” to “Sheet1” and “Web Page” to “Comma-separated values (.csv)”. Then press thePublishbutton and pressOKwhen asked to confirm publishing. The dialog box will now look similar to that below.
google-sheets link
- Select and copy (CTRL-C or CMD-C) the entire link shown in the box above.
- Open RStudio.
- Enter and run the line below (but with your link between the quotes).
> df <- read.csv("https://docs.google.com/spreadsheets/d/1faowQw7tvVXM-4vM6CYEb6CjSMchMWLh17S5FWh1Pt4/pub?gid=0&single=true&output=csv")
> str(df)
'data.frame': 11 obs. of 2 variables:
$ type : Factor w/ 2 levels "humanities","science": 2 2 2 2 1 1 1 1 1 1 ...
$ books: int 7 1 3 2 17 12 9 6 15 13 ...
> df
type books
1 science 7
2 science 1
3 science 3
4 science 2
5 humanities 17
6 humanities 12
7 humanities 9
8 humanities 6
9 humanities 15
10 humanities 13
11 humanities 17