Advertisement
sabinaarndt

readLines

May 25th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.42 KB | None | 0 0
  1. filenames <- list.files(pattern="^.*\\.txt$")
  2.  
  3. rec <- list()
  4. l <- 1
  5.  
  6. for(i in 1:length(filenames))
  7.   {
  8.   records <- filenames[i]
  9.   a <- readLines(records)
  10.   head <- unlist(strsplit(a[1], "\t"))
  11.   for(j in 2:length(a))
  12.     {
  13.     line <- unlist(strsplit(a[j], "\t"))
  14.     rec[["noOfCols"]][l] <- length(line)
  15.     for(k in 1:length(head))
  16.       {
  17.       rec[[head[k]]][l] <- line[k]
  18.       }
  19.     l <- l+1
  20.     }
  21.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement