Dear R afficianados!
I'm writing a script to create a frequency list for multiple files.
I've written a "for" loop to iterate through the selected folder
and
creating lists for each file. In the line "write(freq.list,
file=filename[[1]], sep="", append=FALSE)" I've written the
individual
lists to file. However, I would really like to keep them in memory for
use in the next process. Any ideas on how to store the file with its
unique file name in memory?
selected.files<-list.files(path=getwd(), pattern="*.txt") #select
all
the files from the working directory
for (i in 1:length(selected.files)) {
text.file<-scan(selected.files[[i]], what="char",
sep="\n", quote="",
comment.char="") #inputs the text file
text.file<-tolower(text.file) #changes all alphabetic characters to lower
case
text.file<-gsub("<.*?>", "", text.file, perl=T)
#removes tags
word.list<-strsplit(text.file, "\\W+") #extracts words from the
file
word.vector<-unlist(word.list) #changes output from strsplit back
into a vector
word.vector<-word.vector[nchar(word.vector)>0] #removes an empty strings
freq.list<-table(word.vector) #creates a table named integers which
are the word types and their frequencies
filename<-paste("freq.list", i, "txt",
sep=".") #creates a unique
file name for each iteration of this loop
write(freq.list, file=filename[[1]], sep="", append=FALSE) #writes
the current frequency list to file
}
Many thanks!
Joseph Sorell