read.delim
Aside from .csv files, there are also the .txt files which are basically text files. You can import these functions with read.delim(). By default, it sets the sep argument to "\t" (fields in a record are delimited by tabs) and the header argument to TRUE (the first row contains the field names).
In this exercise, you will import hotdogs.txt, containing information on sodium and calorie levels in different hotdogs (Source: UCLA). The dataset has 3 variables, but the variable names are not available in the first line of the file. The file uses tabs as field separators.
This exercise is part of the course
Importing Data in R (Part 1)
Exercise instructions
- Import the data in
"hotdogs.txt"withread.delim(). Call the resulting data framehotdogs. The variable names are not on the first line, so make sure to set theheaderargument appropriately. - Call
summary()onhotdogs. This will print out some summary statistics about all variables in the data frame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import hotdogs.txt: hotdogs
# Summarize hotdogs