I have a library of words and punctuation. I am trying to make a dataframe out of it so I can use it later on. The original data set has 2,000,000 rows with punctuation but it is a list. I am having trouble parsing out the punctuation from the list from the rest of the words. I would like spaces between each punctuation character from the words. I can easily do this in excel with find a replace. But want to do it in R. I have an example called = df, and the output I want in r called = output. I attached the code below with what I have so far. I tried str_split for How but it deleted "How " and returned nothing "".
#--------Upload 1st dataset and edit-------#
library("stringr")
sent1<-c("How did Quebec? 1 2 3")
sent2<-c("Why does valve = .245? .66")
sent3<-c("How do I use a period (.) comma [,] and hyphen {-} to columns?")
df <- data.frame(text = c(sent1,sent2,sent3))
df <- as.matrix(df)
str_split(df, " ")#spaces
#-------------output-------------#
words1<-c("How", "did" ,"Quebec"," ? ","1", "2" ,"3")
words2<-c('Why', "does", "valve"," = ",".245","?" ,".66")
words3<-c("How" ,"do", "I", "use", "a", "period", '(',".",')', "comma" ,'[',",","]" ,"and" ,"hyphen" ,"{","-",'}' ,"to" ,"columns",'?')
output<-data.frame(words1,words2,words3)