Я пытаюсь сделать с моими данными две вещи. Данные выглядят так:
# A tibble: 10 x 2
grp newCol
<int> <chr>
1 6303 "The company sees earnings of $3.40 to $3.60 a share for all of 2008, agai…
2 7686 " -- reaffirmed its fiscal 2015 guidance of per share diluted earnings b…
3 9577 "Analysts polled by FactSet anticipate earnings of 96 cents a share, down …
4 6475 ""
5 5229 "The company also expects income to be \"significantly impacted\" by costs…
6 2648 "Hoku also expects losses for the foreseeable future on significant cost i…
7 3691 "St. Louis-based Emerson now sees full-year earnings of $2.40 to $2.60 a s…
8 9297 ""
9 2080 "The restaurant group also raised its earnings guidance for fiscal 2007 to…
10 3513 "Guidance, For the full fiscal year 2008, the Company is moderating its pr…
Я могу запустить следующее:
x <- d %>%
mutate(
extractedWords = str_extract_all(newCol, "([^\\s]+\\s){2}earnings(\\s[^\\s]+){12}")
)
Где я получаю:
# A tibble: 10 x 1
extractedWords
<list>
1 <chr [1]>
2 <chr [3]>
3 <chr [1]>
4 <chr [0]>
5 <chr [0]>
6 <chr [0]>
7 <chr [1]>
8 <chr [0]>
9 <chr [2]>
10 <chr [4]>
Сначала я хочу изменить str_extract_all(newCol, "([^\\s]+\\s){2}earnings(\\s[^\\s]+){12}")
- который в настоящее время извлекает 2 слова перед словом earnings
и 12 слов после слова earnings
. Я хочу изменить его так, чтобы он извлекал слова перед символом доллара $
.
Во-вторых, я хочу unnest
столбцов. Когда я запускаю:
x %>%
unnest(extractedWords)
Количество строк в данных изменяется от 10
до 12
. Я хочу unnest
, но вставить c("text", more text")
во что-то вроде text, more text
или разделить |
(или другой вариант).
Данные:
d <- structure(list(grp = c(6303L, 7686L, 9577L, 6475L, 5229L, 2648L,
3691L, 9297L, 2080L, 3513L), newCol = c("The company sees earnings of $3.40 to $3.60 a share for all of 2008, against $2.74 a share from continuing operations in 2007, an increase of 24% to 31%. ",
" -- reaffirmed its fiscal 2015 guidance of per share diluted earnings between , We believe the guidance outlook for fiscal 2015 remains realistic and takes into consideration the heightened competitive market trends for the Diagnostics segment offset by strategic investments that target the growing outpatient segment and further growth of our Life Science segment through our focus on global expansion, increasing industrial market efforts, and emerging success in the AgriBio and genomics research areas., FISCAL 2015 GUIDANCE REAFFIRMED, For the fiscal year ending September 30, 2015, management expects net revenues to be in the range of $193 million to $200 million and per share diluted earnings to be between $0.85 and $0.91. The per share estimates assume an increase in average diluted shares outstanding from approximately 41.9 million at fiscal 2014 year end to approximately 42.4 million at fiscal 2015 year end. The revenue and earnings guidance provided in this press release is from expected internal growth and does not include the impact of any additional acquisitions the Company might complete during fiscal 2015.",
"Analysts polled by FactSet anticipate earnings of 96 cents a share, down 10 cents from a year earlier. Revenue is expected to have decreased 5.5% to $30.4 billion, which would mark the fourth consecutive quarterly decline after six years of growth. Verizon has said it expects earnings and sales will be roughly flat this year.",
"", "The company also expects income to be \"significantly impacted\" by costs related to its pending acquisition of SRS Labs Inc. (SRSL)., The company also expects income to be \"significantly impacted\" by costs related to its pending acquisition of SRS Labs Inc. (SRSL).",
"Hoku also expects losses for the foreseeable future on significant cost increases. ",
"St. Louis-based Emerson now sees full-year earnings of $2.40 to $2.60 a share, down from its February forecast of $2.70 to $2.95 a share. The company also expects net sales for the fiscal year to fall 13% to 15% to $21 billion to $21.7 billion. Sales are expected to be hurt by about 5% because of currency translations, but boosted by 1% because of acquisitions.",
"", "The restaurant group also raised its earnings guidance for fiscal 2007 to a range of $3.45 a share to $3.50 a share, and said its expects earnings for the third quarter ending in July of 85 cents to 89 cents a share and same-store sales growth of 5% to 6%. ",
"Guidance, For the full fiscal year 2008, the Company is moderating its previously issued guidance and expects net sales to be approximately $950 million and earnings per diluted share to be approximately $1.00, which includes approximately $0.45 per diluted share of restructuring charges and other unusual items. For the twelve months ended February 2, 2008, net sales were $1.09 billion and earnings per diluted share were $2.59., Set forth below is our reconciliation of net earnings per share, calculated in accordance with generally accepted accounting principles, or GAAP, to net earnings per share, as adjusted, for certain historical periods and certain future periods. For reference, we also include our previous guidance for third quarter fiscal 2008. Net earnings per share, as adjusted, excludes (i) the net impact of certain restructuring costs and other unusual items as well as the write off of unamortized financing costs during the first three quarters of fiscal 2008 and (ii) the anticipated impact of certain restructuring costs in the fourth quarter of fiscal 2008. We believe that investors often look at ongoing operations as a measure of assessing performance and as a basis for comparing past results against future results. Therefore, we believe that presenting our results and expected results excluding these items provides useful information to investors because this allows investors to make decisions based on our ongoing operations. We use the results excluding these items to discuss our business with investment institutions, our board of directors and others. Further, we believe that presenting our results and expected results excluding these items provides useful information to investors because this allows investors to compare our results and our expected results for the periods presented to other periods., Guidance Results for Guidance Guidance"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-10L))