I have a data file with the #
sign as delimiter, that I would like to read with the read.file
command.
First of all; it's a big data file and I don't want to change the delimiter because:
#
sign as delimiter, so I don't want to change the data files every time when I would like to read a these files againSo I assumed I could use the sep
argument of the read.file
command. But it didn't worked out for the #
sign as I expected. Only the first column is read. I tried some different delimiters, all worked fine, except for the #
sign. See below for some examples, including the #
delimiter.
The file looks like:
H1#H2#H3
a#b#c
d#e#f
Code in R performed including results, for the same file where I changed the delimiter. For =
, |
, @
and $
it works fine, but not for #
...
> read.table(file='test_data.dat', check.names=F, sep='=', header=T)
H1 H2 H3
1 a b c
2 d e f
> read.table(file='test_data.dat', check.names=F, sep='|', header=T)
H1 H2 H3
1 a b c
2 d e f
> read.table(file='test_data.dat', check.names=F, sep='@', header=T)
H1 H2 H3
1 a b c
2 d e f
> read.table(file='test_data.dat', check.names=F, sep='$', header=T)
H1 H2 H3
1 a b c
2 d e f
> read.table(file='test_data.dat', check.names=F, sep='#', header=T)
H1
1 a
2 d
Could anybody help me on this? Is this a known 'bug'? Is there a workaround?
Thanks in advance for the help!
The comment character is also #
, so you need something like:
read.table(file='tmp.txt', check.names=FALSE, sep='#',
header=TRUE, comment.char="@")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With