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,130 points
160 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
0 votes
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 in Data Analytics by Sophie may
• 9,870 points
747 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 in Data Analytics by anonymous
34 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
104 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
108 views
0 votes
2 answers

How to sort a data frame by columns in R?

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

answered Aug 21 in Data Analytics by anonymous
• 31,840 points
149 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,690 points
145 views
0 votes
2 answers

How to write lines to a text file in R?

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

answered May 24 in Data Analytics by anonymous
2,502 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
131 views