"x,y\n1,'a,b'"
7 Exercises (Chapter 7)
What function would you use to read a file where fields were separated with “|”?
Apart from
file
,skip
, andcomment
, what other arguments doread_csv()
andread_tsv()
have in common?What are the most important arguments to
read_fwf()
?Sometimes strings in a CSV file contain commas. To prevent them from causing problems, they need to be surrounded by a quoting character, like
"
or'
. By default,read_csv()
assumes that the quoting character will be"
. To read the following text into a data frame, what argument toread_csv()
do you need to specify?Identify what is wrong with each of the following inline CSV files. What happens when you run the code?
read_csv("a,b\n1,2,3\n4,5,6") read_csv("a,b,c\n1,2\n1,2,3,4") read_csv("a,b\n\"1") read_csv("a,b\n1,2\na,b") read_csv("a;b\n1;3")
Practice referring to non-syntactic names in the following data frame by:
set.seed(321) <- tibble( annoying `1` = 1:10, `2` = `1` * 2 + rnorm(length(`1`)) )
Extracting the variable called
1
.Plotting a scatterplot of
1
vs.2
.Creating a new column called
3
, which is2
divided by1
.Renaming the columns to
one
,two
, andthree
.