Hi
I would like to know J's manipulation for reading text file.
fd=:'mytestfile.txt' NB. TAB text file
NB. a \t 1 \t 2 \t 3
NB. b \t \t 5 \t 6
NB. c \t 7 \t \t 9
NB. d \t 10 \t 11 \t 12
NB. \t 13 \t 14 \t 15
fd2=:'mytestfile.csv' NB. CSV test file
load'files misc'
freads fd2
a,1,2,3
b,,5,6
c,7,,9
d,10,11,12
,13,14,15
freadr fd ;0 1
a 1 2 3
freadr fd ;1 1
b 5 6
freadr fd ;2 1
7 9
d
freadr fd ;3 1
10 11 1
freadr fd ;4 1
13 14
The 3rd and 4th rows are read differently. I expect that the following line
will come out.
freadr fd ;2 1
c 7 9
u=:'m' fread fd
u
a 1 2 3
b 5 6
c 7 9
d 10 11 12
13 14 15
TAB chop "1 u
+--+--+-----+----+
|a |1 |2 |3 |
+--+--+-----+----+
|b |5 |6 | |
+--+--+-----+----+
|c |7 | |9 |
+--+--+-----+----+
|d |10|11 |12 |
+--+--+-----+----+
|13|14|15 | |
+--+--+-----+----+
How can I get the following table?
+--+--+-----+----+
|a |1 |2 |3 |
+--+--+-----+----+
|b |NA|5 |6 |
+--+--+-----+----+
|c |7 |9 |NA |
+--+--+-----+----+
|d |10|11 |12 |
+--+--+-----+----+
|NA|13|14 |15 |
+--+--+-----+----+
R reads this text file as follows:
> u=read.table("mytestfile.txt",header=F,na.strings="",sep="\t")
> u
V1 V2 V3 V4
1 a 1 2 3
2 b NA 5 6
3 c 7 NA 9
4 d 10 11 12
5 <NA> 13 14 15
Do you have any convenient utility function for reading text files?
+++++++++++++++++++++++++++++
Toshinari Kamakura
Chuo University
1-13-27 Kasuga
Bunkyo-ku
Tokyo 112-8551, Japan
++++++++++++++++++++++++++++++
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm