I built a text object, 'txt'
, that conforms to your original description.
dput(txt)
" V1 V2 V3 V4 V5 V6 V7 V8\n [1] 10074 10146 10079 10091 10040 10066 10009 10152\n [2] 10137 10136 10032 10139 10038 10122 10123 10095\n [3] 10046 10120 10062 10061 10149 10029 10030 10059\n [4] 10003 10028 10148 10050 10057 10100 10144 10084\n [5] 10076 10012 10114 10073 10026 10135 10130 10083\n [6] 10007 10119 10063 10078 10086 10160 10125 10087\n [7] 10031 10090 10021 10092 10093 10067 10106 10129\n [8] 10004 10102 10113 10134 10042 10064 10037 10140\n [9] 10101 10156 10060 10121 10097 10002 10109 10033\n[10] 10075 10096 10024 10089 10115 10147 10036 10103\n V9 V10 V11 V12 V13 V14 V15 V16\n [1] 10153 10107 10049 10143 10047 10126 10039 10018\n [2] 10065 10127 10048 10133 10108 10124 10117 10077\n [3] 10105 10051 10131 10069 10098 10058 10088 10006\n [4] 10132 10104 10112 10138 10128 10027 10043 10145\n [5] 10010 10072 10151 10111 10110 10052 10020 10082\n [6] 10023 10016 10044 10158 10159 10041 10155 10019\n [7] 10099 10008 10094 10142 10045 10068 10070 10015\n [8] 10013 10080 10053 10071 10085 10014 10056 10034\n [9] 10022 10011 10150 10054 10154 10035 10081 10118\n[10] 10116 10055 10017 10005 10025 10157 10141 10001"
tcon <- textConnection(txt) # the first description did not have commas
In place of txt
you can substitute a file() call; the principle being that you can read incrementally for a connection:
cbind( read.table(text= readLines(tcon,n=11), header=TRUE), # first 11 lines
read.table(text= readLines(tcon,n=11), header=TRUE)) # second 11
V1 V2 V3 V4 V5 V6 V7 V8
[1] 10074 10146 10079 10091 10040 10066 10009 10152
[2] 10137 10136 10032 10139 10038 10122 10123 10095
[3] 10046 10120 10062 10061 10149 10029 10030 10059
[4] 10003 10028 10148 10050 10057 10100 10144 10084
[5] 10076 10012 10114 10073 10026 10135 10130 10083
[6] 10007 10119 10063 10078 10086 10160 10125 10087
[7] 10031 10090 10021 10092 10093 10067 10106 10129
[8] 10004 10102 10113 10134 10042 10064 10037 10140
[9] 10101 10156 10060 10121 10097 10002 10109 10033
[10] 10075 10096 10024 10089 10115 10147 10036 10103
V9 V10 V11 V12 V13 V14 V15 V16
[1] 10153 10107 10049 10143 10047 10126 10039 10018
[2] 10065 10127 10048 10133 10108 10124 10117 10077
[3] 10105 10051 10131 10069 10098 10058 10088 10006
[4] 10132 10104 10112 10138 10128 10027 10043 10145
[5] 10010 10072 10151 10111 10110 10052 10020 10082
[6] 10023 10016 10044 10158 10159 10041 10155 10019
[7] 10099 10008 10094 10142 10045 10068 10070 10015
[8] 10013 10080 10053 10071 10085 10014 10056 10034
[9] 10022 10011 10150 10054 10154 10035 10081 10118
[10] 10116 10055 10017 10005 10025 10157 10141 10001
This does the same actions on a longer file. And conversion to a matrix remains trivial:
txt <-readLines(file("~/Downloads/YjwpsANG.txt"))
tcon <-textConnection(txt)
X <- cbind( read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE),
read.table(text= readLines(tcon,n=11), header=TRUE) )
head -11
of the file in question. Having said that, if additional column headers (likeV9
-V16
) are really interspersed within the file, then you'll need to usereadLines
, roll up your sleeves and do some post-processing. – hrbrmstrreadLines(textConnection(
or you can just read it from file byreadLines("name.txt")
– akrun