I am new to R programming...
I have multiple text files with a word in each line:
i want to import all the text files and create a data frame.. Something like this:
library(rTextTools)
data(USCongress)
View(USCongress)
I want the words to be in a single line and then create a data.frame with variable 'text' just like in the reference data(USCongress) please help
Session Info:
R version 3.0.3 (2014-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] magrittr_1.5 RTextTools_1.4.2 SparseM_1.05
loaded via a namespace (and not attached):
[1] bitops_1.0-6 BradleyTerry2_1.0-5 brglm_0.5-9 car_2.0-21 caret_6.0-37 caTools_1.17.1
[7] class_7.3-9 codetools_0.2-8 coin_1.0-24 colorspace_1.2-4 digest_0.6.4 e1071_1.6-4
[13] foreach_1.4.2 ggplot2_1.0.0 glmnet_1.9-8 grid_3.0.3 gtable_0.1.2 gtools_3.4.1
[19] ipred_0.9-3 iterators_1.0.7 kernlab_0.9-19 lattice_0.20-27 lava_1.2.6 lme4_1.1-7
[25] MASS_7.3-35 Matrix_1.1-2 maxent_1.3.3.1 minqa_1.2.4 modeltools_0.2-21 munsell_0.4.2
[31] mvtnorm_1.0-1 nlme_3.1-113 nloptr_1.0.4 nnet_7.3-8 parallel_3.0.3 party_1.0-18
[37] plyr_1.8.1 prodlim_1.4.5 proto_0.3-10 randomForest_4.6-10 Rcpp_0.11.3 reshape2_1.4
[43] rpart_4.1-5 sandwich_2.3-2 scales_0.2.4 slam_0.1-32 splines_3.0.3 stats4_3.0.3
[49] stringr_0.6.2 strucchange_1.5-0 survival_2.37-7 tau_0.0-18 tm_0.5-10 tools_3.0.3
[55] tree_1.0-35 zoo_1.7-11
I tried this:
Data <- paste0("h:/desktop/datasci/new",list.files("~/new/")) %>%
+ sapply(.,read.table) %>%
+ do.call(rbind,.) %>%
+ apply(.,1,paste0,collapse=" ") %>%
+ data.frame(text=.,row.names=NULL)
but this gives me an error:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'h:/desktop/datasci/new': Permission denied
Thanks