0% found this document useful (0 votes)
34 views1 page

Classwork 5

This document provides instructions for a classwork assignment in R involving baby name data. Students are asked to: 1) Store the first 50 baby names as a vector and check it is a vector 2) Use a for loop to print statements about the length of each name using paste() and nchar() 3) Redo the for loop using str_c() without separators 4) Redo the for loop using str_c() with separators

Uploaded by

CHAI TZE ANN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Classwork 5

This document provides instructions for a classwork assignment in R involving baby name data. Students are asked to: 1) Store the first 50 baby names as a vector and check it is a vector 2) Use a for loop to print statements about the length of each name using paste() and nchar() 3) Redo the for loop using str_c() without separators 4) Redo the for loop using str_c() with separators

Uploaded by

CHAI TZE ANN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DSA212 Data Science with R School of Economics

Classwork 5 Singapore Management University


Dr. Jing Rong GOH
Solutions should be written in Rmd.

Libraries to load for this classwork: tidyverse, and babynames

Q1. Store the first 50 names of the babynames dataframe as a vector names50.
• Use the is.vector() function to check that names50 is indeed a vector.
Q2. Using a for loop, print the following statement for all names in vector names50. You should google
and use the paste() and nchar() function to make your life easier. Your for loop should print all
the following in a single run:
• “The name Mary consists of 4 characters.”
• “The name Anna consists of 4 characters.”
• …
• “The name Josephine consists of 9 characters.”
Q3. Redo Q2 but with the str_c() function but without seperators.
Q4. Redo Q2 but with the str_c() function and with seperators.

Strictly confidential – Do not distribute without prior permission from the author(s).

You might also like