Method 1: In RStudio using Import Dataset
-
Choose Import Dataset > From Text (readr) and enter the URL, then press Import.
-
-
Keep First Row as Names checked
-
For ISCAM files, change the Delimiter to Tab.
-
Press Update to preview the data.
-
You can set the dataset name (e.g.,
births).
-
Note: With other data files, you may need to consider how "missing values" are coded.
Method 2: In R using URL directly
births = read.table("http://www.rossmanchance.com/iscam4/data/USbirthsJan2024.txt",
header=TRUE, sep="\t")
nrow(births) # Check number of observations
Method 3: In R using copy and paste
Open the data file link from the data files page, select all, copy, and then in R use the following command (Keep in mind that R is case sensitive):
# PC:
births = read.table("clipboard", header=TRUE)
# MAC:
births = read.table(pipe("pbpaste"), header=TRUE)
The
header command indicates the variables have names.
Method 4: Txt files on your computer
births = read.table(file.choose(), header=TRUE)
-
To see the data, type
View(births) or
head(births)
-
Next you can "attach" the file to be able to use variable names directly:
attach(births) # Now R knows what the "birthweight" variable is
or you need to clarify to R which datafile you are using (e.g.,
births$birthweight).
-
Other input options, depending on how the data you are pasting is formatted, include:
-
sep="\t" separated by tabs
-
na.strings="*" how to code missing values
-
strip.white=TRUE strip extra white space