In the exercises below we cover the basics of reading delimited data. Before proceeding, first read section 7.1 of An Introduction to R, and the help pages for the
Answers to the exercises are available here.
For each exercise we provide a data set that can be accessed through the link shown in the exercise. You can read the data from this link directly (clicking on it will show the url in the address bar of your browser), or you can download the data first to a local directory, and read it from there.
Read the file Table0.txt.
a) Change the names of the columns to
b) Change the row names so that they are the same as
Name, and remove the variable
Read the file Table1.txt, how many rows and columns does it have?
a) Reread the file and make the variable
Name be the row names. Make sure you read the variable as characters and not as factors.
Read the file Table2.txt, watch out for the first line.
Read the file Table3.txt, watch out for the first line and the missing values.
Read the file Table4.txt, watch out for the missing values and the decimal separator.
Read the file Table5.txt, watch out for the missing values and the decimal separator and the separator.
Read the file states1.csv, the names of the states should be the row names.
Read the file states2.csv, the names of the states should be the row names, watch out for the decimal separator and the separator.
Read the file states2.csv, watch out for the same as the last exercise plus the missing values. Add to the previous dataset, column-wise.
Read the file Table6.txt, check out the file first. Notice that the information is repeated, we only want the first non-repeated ones. Make sure to create only characters not factors this time around. Lastly, we don’t want the comments.