0

I have a directory of .txt files and need to combine then into one file. each file would be a separate line. I tried:

new_corpus <-VCorpus(DirSource("Downloads/data/"))

The data is in the file but I get an error

Error in DirSource(directory = "Downloads/data/") : 
empty directory

This is a bit basic but I was only given this information on how to create the corpus. What I need to do is take this file and create one factor that is the .txt and another with an ID, in the form of:

ID .txt
ID .txt
.......

EDIT To clarify on emilliman5 comment: I need both a data frame and a corpus. The example I am working from used a csv file with the data already tagged for a Naive Bayes problem. I can work through that example and all the steps. The data I have is in a different format. It is 2 directories (/ham and /spam) of short .txt files. I was able to create a corpus, when I changed my command to:

new_corpus <-VCorpus(DirSource("~/Downloads/data/"))

I have cleaned the raw data and can make DTM but at the end I will need to create a crossTable with the labels spam and ham. I do not understand how I insert that information into the corpus.

zx8754
  • 52,746
  • 12
  • 114
  • 209
user3137110
  • 339
  • 1
  • 2
  • 12

0 Answers0