[R] Scanning tab-separated numbers

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Mon Mar 1 22:39:22 CET 2004



Murray Jorgensen wrote:
> I want to paste in the following numbers into a scan:
> 
> 0.023    0.032    0.054    0.069    0.081    0.094
> 0.105    0.127    0.148    0.169    0.188    0.216
> 
> they are separated by tabs alone, unless my mailer has done something to 
> the tabs.
> 
> Now have a look at this:
> 
>  > scan()
> 1: 0.0230.0320.0540.0690.0810.094
> 1: 0.1050.1270.1480.1690.1880.216
> Error in scan() : "scan" expected a real, got 
> "0.0230.0320.0540.0690.0810.094"
>  > scan(sep="\t")
> 1: 0.0230.0320.0540.0690.0810.094
> 1: 0.1050.1270.1480.1690.1880.216
> Error in scan(sep = "   ") : "scan" expected a real, got 
> "0.0230.0320.0540.0690.0810.094"
>  >
> 
> Platform: Windows XP   Release 1.8.1
> 
> I can't seem to scan in tab-separated numbers even when I try to tell R 
> to expect that. (this may be related to the Sweave problem I mentioned a 
> few days ago.)
> 
> Murray
> 

If you save the numbers to a file (say "x.txt") then

scan("x.txt", sep = "\t")

should do it. Or highlight your text, copy to the clipboard ("Ctrl-C"), 
and try:

scan("clipboard", sep = "\t")

Read the help for ?scan.

-sundar




More information about the R-help mailing list