Combine Variables in an imported data set

Hi all,

I need to use R for a school project due in a few days.
I have a dataset that I have imported to Rstudio and I have viewed it.

I need to combine over 1964 string variables into one cell (they're speeches over a few years)
For example:
Current Data:
Person 1 Speech 1 Speech 2 Speech 3 Speech 4
Person 2 Speech 1 Speech 2 Speech 3 Speech 4
Person 3 Speech 1 Speech 2 Speech 3 Speech 4
Person 4 Speech 1 Speech 2 Speech 3 Speech 4

Data I want:
Person 1 All Speeches Combined
Person 2 All Speeches Combined
Person 3 All Speeches Combined
Person 4 All Speeches Combined

Any help would be great!
Thanks,
Callum

The sample text created is too long to successfully create a dput object and reprex.

> DF
# A tibble: 4 x 5
  Person  Speech1               Speech2               Speech3              Speech4             
  <chr>   <chr>                 <chr>                 <chr>                <chr>               
1 Washin… Among the vicissitud… Such being the impre… I am again called u… Previous to the exe…
2 Adams   When it was first pe… The zeal and ardor o… Negligence of its r… In this dangerous c…
3 Jeffer… Called upon to under… During the contest o… Proceeding, fellow … On taking this stat…
4 Madison The present situatio… About to add the sol… May we not cherish … I should be destitu…
> DF %>% mutate(across(starts_with("Speech"),paste0, .names = "Combined")) %>%
+   select(Person,Combined)
# A tibble: 4 x 2
  Person     Combined                                                                          
  <chr>      <chr>                                                                             
1 Washington Among the vicissitudes incident to life no event could have filled me with greate…
2 Adams      When it was first perceived, in early times, that no middle course for America re…
3 Jefferson  Called upon to undertake the duties of the first executive office of our country,…
4 Madison    The present situation of the world is indeed without a parallel, and that of our …
> 

Depending on the plans for further processing the data, the resultant data frame may not be ideal. See the tidytext package for alternative ways of organizing textual data.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.