This is a follow up question. How can I add n empty strings between _ so that every row has exactly 10 words separated by _ each?
- The data is:
> head(dfLong, 10)
# A tibble: 5 x 1
word
<chr>
1 Jason_Oscar_Maleeka_Janet_Gabriel_Raheema_Bryce_Nasreen_Hishaam_Thadduse
2 Marcos_Daijah_Chassity_Carlito_Chidiebere_Matthew_Maureene_Jillian_Markus_Aaron
3 Ramziyya_Marquez_Kiera_Farajallah_Larisa_Davier_Shujaa_Vincent_Orlando_Joseph
4 Desean_Chelsea_Faadil_Christopher_Aarifa_Joel_Matthew_Jacob_Aeones_Matthew
5 Jacob_Savannah_Nadia_Kaleem ### THIS IS WHAT I NEED TO CHANGE
>
- Desired output:
1 Jason_Oscar_Maleeka_Janet_Gabriel_Raheema_Bryce_Nasreen_Hishaam_Thadduse
2 Marcos_Daijah_Chassity_Carlito_Chidiebere_Matthew_Maureene_Jillian_Markus_Aaron
3 Ramziyya_Marquez_Kiera_Farajallah_Larisa_Davier_Shujaa_Vincent_Orlando_Joseph
4 Desean_Chelsea_Faadil_Christopher_Aarifa_Joel_Matthew_Jacob_Aeones_Matthew
5 Jacob_Savannah_Nadia_Kaleem_''_''_''_''_''_'' ## LIKE THIS
Questions:
1: I need EVERY row to have exatcly 10 words each. In cases in which the amount of words is not exactly divisible by 10, I want to insert empty strings between _, like this: _ ' ' _. tidyverse
and stringr
solutions would be much appreciated! Thanks!
2: Later on, I also need another df in which ALL rows are combined into a new cell. This answer helped me. But, before merging the rows, I need to make sure that I have exactly 10 words per row (later on, I'll be displaying every 10 words of this data in a UI using Js split('_').slice(v,v+10).join("<br>"))
, I'll split them by 10 and display one below the other). Thanks in advance.
- Data:
dput(df)
structure(list(word = c("Jason_Oscar_Maleeka_Janet_Gabriel_Raheema_Bryce_Nasreen_Hishaam_Thadduse",
"Marcos_Daijah_Chassity_Carlito_Chidiebere_Matthew_Maureene_Jillian_Markus_Aaron",
"Ramziyya_Marquez_Kiera_Farajallah_Larisa_Davier_Shujaa_Vincent_Orlando_Joseph",
"Desean_Chelsea_Faadil_Christopher_Aarifa_Joel_Matthew_Jacob_Aeones_Matthew",
"Jacob_Savannah_Nadia_Kaleem")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame"))