I'm struggling to get any code to run to save the vector a to save as a csv file. I'm keen to see what it looks like after I merge @65-70 text files together. My code to read in the files and merge is:
# set pathway to text files
folder<-"C:\\xxxxxx\\Text files"
# lists all files in pathway
list.files(path=folder)
# filters text files only
list.files(path=folder, pattern="*.txt")
# set vector
filelist<-list.files(path=folder, pattern="*.txt")
# assign pathways to files
paste(folder, "\\", filelist)
# removes separations in pathways by setting as empty
filelist<-paste(folder, "\\", filelist, sep="")
filelist
# apply a function to read in multiple txt files - warnings are OK
a<-lapply(filelist, FUN=readLines)
I can run head(a,n)
to see some of the data but tried to run different code to save it so I can examine if there any patterns.
This didn't work:
write.csv(a, file ="myfile.csv", row.names=FALSE)
brings up this error:
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 13336, 1004, 641, 114, 66, 1613, 118, 868, 0, 808, 2300, 771, 6096, 1466, 717, 110, 794, 4155, 875, 1139, 574, 43, 867, 970, 3252, 679, 4630, 836, 391, 1304, 219, 865, 1349, 7209, 878, 952, 1611, 16333, 430, 244, 3794, 2849, 1697, 895, 874, 2021, 693, 1537, 119, 2014, 3185, 3282, 2822, 275, 3547, 1517, 1636, 921, 543, 2411
Any help appreciated.
Update - used code to collapse and tried to save but still errors.
# apply a function to collaspe into a single element
corpus<-lapply(a, FUN=paste, collaspe=" ")
#save the file in our current working directory, without row names and save as csv
write.csv(corpus, file="corpus.csv", row.names=T)
Ran head to see some of the data head(corpus, 10)
The xxxxx elements are respondent responses so redacted. I want to save this group of text files to check for patterns in the data. The other text left in are the standard quetsions/text in the files I want to try and exclude.
[698] "c. Carbon Capture and Storage "
[699] " "
[700] " "
[701] " "
[702] " "
[703] " "
[704] "Q42. What steps, if any, should NI policy-makers consider with regard to the "
[705] "development or implementation of CCUS in NI? "
[706] " "
[707] "xxx "
[708] " "
[709] "xxxx xxxxxxxxx xxx xxxxx xxxxxxxxxx xxxxxx xxxxxx xxxxx be xxxxxxxxxxxxx "
[710] " "
[711] " "
[712] " "
[713] " "
[714] " "
[715] "\f "
[716] "d. Energy and the Economy "
[717] " "
[718] " "
[719] " "
[720] " "
[721] " "
[722] " "
[723] " "
[724] "Q43. What specific economic opportunities will arise from the decarbonisation of "
[725] "energy? "
[726] " "
[727] "Q44. What skills are needed to realise the potential economic benefits of energy in "
[728] "the future? "
[729] " "
[730] "Q45. What are your views on the future of overall energy demand in NI and how can "
[731] "we ensure that any potential demand growth aligns with our net zero carbon "
[732] "target? "
[733] " "
[734] "xxx "
[735] " "
[736] "xxxxxxxx xxxxxxxx xxxxxx xxxxx xxxx xxxxxx xxxxxx xxxxxxxx xxx xxxxx xxxxxx "
[737] "xx xxxxx xxx xxxxxxx xx xxxxx xxxxx xx x xxxxxxx xxxxxx "
[738] " "
[739] " "
[740] " "
[741] "\f "
[742] "e. Delivery Framework for an Energy Strategy "
[743] " "
[744] " "
[745] " "
[746] " "
[747] " "
[748] " "
[749] " "
[750] " "
[751] " "
[752] "Q46. Do the existing division of responsibilities and powers across government "
[753] "enable the most effective approach to the overall aim of decarbonising energy? "
[754] "If not, what are your suggestions for improvement? "
[755] " "
[756] " "
[757] " "