शुरू करेंमुफ़्त में शुरू करें

Fixing case problems

Finally, you might want to transform strings to a common case. You've seen you can use str_to_upper() and str_to_lower(), but there is also str_to_title() which transforms to title case, in which every word starts with a capital letter.

This is another situation where stringi functions offer slightly more functionality than the stringr functions. The stringi function stri_trans_totitle() allows a specification of the type which, by default, is "word", resulting in title case, but can also be "sentence" to give sentence case: only the first word in each sentence is capitalized.

Try outputting the catcidents in a consistent case.

यह अभ्यास पाठ्यक्रम का हिस्सा है

String Manipulation with stringr in R

पाठ्यक्रम देखें

अभ्यास निर्देश

A character vector of cat-related accidents has been pre-defined in your workspace as catcidents.

  • Store the first five elements of catcidents as cat5.
  • Use writeLines() to display cat5.
  • Repeat but now pass cat5 transformed to title case with str_to_title().
  • Try again using stri_trans_totitle() instead. This should be identical to str_to_title().
  • Finally, display the first 5 elements of cat5 transformed to sentence case, by passing the type argument to stri_trans_totitle().

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

library(stringi)

# Get first five catcidents
cat5 <- ___

# Take a look at original
___

# Transform to title case
___

# Transform to title case with stringi
___

# Transform to sentence case with stringi
___
कोड संपादित करें और चलाएँ