Scan exercises

January 11, 2016

(This article was first published on R-exercises, and kindly contributed to R-bloggers)

In the exercises below we cover the basics of the scan function. Before proceeding, first read section 7.2 of An Introduction to R.

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 scan 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 scan it from there.

Exercise 1
Read the file scan01.txt as a vector.

Exercise 2
Read the file scan02.txt:
a) As a vector
b) As a matrix with 10 rows.

Exercise 3
Read the file scan03.txt as a vector.

Exercise 4
Read the file scan04.txt as a matrix of 2 columns. Read only the 5 first rows. Finally, convert it to a data frame.

Exercise 5
Read the file scan05.txt as a list.

Exercise 6
Read the file scan05.txt as a list, read only the first 50 rows.

Exercise 7
Read the file scan.csv as a list.

Exercise 8
Read the file scan06.txt as a list. Read 10 rows of data.

Exercise 9
Read the file scan07.txt as a list.

Exercise 10
Read the file scan2.csv as a list.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)