How to convert a text mining termDocumentMatrix into excel or csv in R

0 votes

To have more clarity on the Question take an example I have character vector "exmp"

exmp[1]<-"Josh, Ron, Sam"

exmp[2]<-"Alice, Joshua, Pam, Bob, Darren"

I don't know how to do it.

Thank you in Advance.

Apr 5, 2018 in Data Analytics by DataKing99
• 8,250 points
1,961 views

1 answer to this question.

0 votes

By assuming that all the values are separated by commas

#max number of elements

max_m<-max(unlist(lapply(strsplit(exmp,","),length)))

#all rows should have same length

lapply(strsplit(Names,','),function(x) {length(x) <- max_m;x})

#Create a data Frame

ras <- do.call(rbind,lapply(strsplit(Names,','),function(x) {length(x) <- max_m;x}))

#save the file

write.csv(ras,'output.csv')
answered Apr 5, 2018 by DeepCoder786
• 1,720 points

Related Questions In Data Analytics

+1 vote
2 answers
+1 vote
1 answer
0 votes
1 answer

How to convert JSON into CSV in R programming?

Use the jsonlite::fromJSON to read the data into ...READ MORE

answered Jan 24, 2019 in Data Analytics by Sophie may
• 10,620 points
7,116 views
0 votes
1 answer

How to import and clean a text file into dataframe in R?

You can use readLines() or read.table() depending ...READ MORE

answered Jul 16, 2019 in Data Analytics by anonymous
6,516 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,393 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,814 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,838 views
0 votes
1 answer

How to replace NA values in a dataframe with Zero's ?

It is simple and easy: df1<-as.data.frame(matrix(sample(c(NA, 1:10), 100, ...READ MORE

answered Apr 10, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
2,079 views
0 votes
3 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

answered May 24, 2019 in Data Analytics by anonymous
19,076 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,705 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP