1

I am trying to combine a series of character lists into one single file, but can't figure out how to do it. I explain my code below:

Maybe this a question under the theme of combine character lists. Unfortunately, I still did not know how to do this. Your help will be highly appreciated.

num = c(1:5)
aa = paste0(names, "class.", num)   ##read all 5 files, naming class.1, etc
aa = sapply(aa, scan, what = "character", quiet = T) ## scaning them into one list
class(aa) # its class is list
class(aa[[1]]) # this time, the class is character

## I tried to combine aa into one single file in the following step, 
## but it did not work well. Maybe a single file is not accurate, 
##but I hope this ‘file’ has the length of the sum of all above 5 files. 

all = rbind(aa, deparse.level = 0) 
## it gives the exactly same result as aa gives. The length of all is equal to 5
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Amy_777
  • 115
  • 3
  • 14
  • 3
    Does `unlist(aa)` give you what you want? – Dan Dec 01 '17 at 19:01
  • `rbind` doesn't work on lists. You can use `data.table::rbindlist`, `dplyr::bind_rows`, or in base `do.call(rbind, aa)` ([just like in my answer to your last question](https://stackoverflow.com/a/47583670/903061)). This will create a data frame or matrix, because you are talking about rows. If you just want a vector, `unlist` should be fine. – Gregor Thomas Dec 01 '17 at 19:01
  • Thank you very much, Gregor. unlist does work. But the do.call(rbind,aa) did not work well. R said, the number of columns of result is not a multiple of vector length (arg 1). – Amy_777 Dec 01 '17 at 19:10

0 Answers0