1. Data Collection: Select 1 page at random from your favorite literary book (2
ID: 3043641 • Letter: 1
Question
1. Data Collection: Select 1 page at random from your favorite literary book (2 pages if it is very short) Count the number of sentences. For each of the sentences, determine how many words each contains. Your sample will consist of datapoints on the number of words in each sentence. Count the length of each of the words on the page(s). For example, suppose we have 1 page with 1 sentence that says "Project must be typed for credit". "Project" has length 7, "must" has length 4, "be" has length 2, "typed" has length 5, "for has length 3, "credit has length 6. This is a sample of size 6 (total number of words on the page), and the values of the sample are 7, 4, 2, 5, 3, 6.Explanation / Answer
# example txt used
docs <- c("It is a truth universally acknowledged",
"that a single man in possession of a good fortune must be in want of a wife",
"So begins Pride and Prejudice, Jane Austen’s witty comedy of manners—one of the most popular novels of all time—that",
"features splendidly civilized sparring between the proud Mr. Darcy and the prejudiced Elizabeth Bennet as they play out their",
"spirited courtship in a series of eighteenth-century drawing-room intrigues.",
"Renowned literary critic and historian George Saintsbury in 1894 declared it the “most perfect, the most characteristic",
"the most eminently quintessential of its author’s works,” and Eudora Welty in the twentieth century described it as “irresistible and as nearly flawless as any fiction could be.")
docs # View the object created
strsplit(docs, " ")[[1]] #this code will split word in each sentence.
nchar(strsplit(docs, " ")[[1]]) #this code will give the length of each word in a sentence.
#Note according to the example used we have a total of 7 sentence, so just replace the number in the bracket to get the same result for 2nd sentence.
# strsplit(docs, " ")[[2]] & nchar(strsplit(docs, " ")[[2]])
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.