[R] Easy cut & paste from Excel to R?
Bernhard Bruemmer
bbruemmer at web.de
Fri Feb 18 09:24:33 CET 2005
Peter Dalgaard <p.dalgaard at biostat.ku.dk> writes:
> Ken Knoblauch <knoblauch at lyon.inserm.fr> writes:
>
>> Here is something quick & dirty for Mac that may be serviceable in
>> some cases, while awaiting someone with greater understanding of
>> programming connections than I have currently.
>>
>> With the following copied to the clipboard from Excell: H T Q F 1 2
>> 3.3 a 3 5 10.2 b 5 9 11 A
>>
>> I tried in R:
>>
>> read.table(pipe("pbpaste"),header=TRUE) H T Q F 1 1 2 3.3 a 2 3 5
>> 10.2 b 3 5 9 11.0 A Warning message: incomplete final line found by
>> readTableHeader on `pbpaste' >
>> str(read.table(pipe("pbpaste"),header=TRUE)) `data.frame': 3 obs. of
>> 4 variables: $ H: int 1 3 5 $ T: int 2 5 9 $ Q: num 3.3 10.2 11 $ F:
>> Factor w/ 3 levels "A","a","b": 2 3 1 Warning message: incomplete
>> final line found by readTableHeader on `pbpaste'
>>
>> I haven't been able to track down readTableHeader yet. The warning
>> occurs even without headers in the data.
>
> I think the "Header" means the first handful of lines (up to 5) used
> to determine the file layout.
>
> FWIW, here's what you can do with oocalc and tcltk on Linux:
>
>> library(tcltk)
>> read.delim(textConnection(tclvalue(tcl("clipboard","get"))))
> col1 col2 1 12 NA 2 34 56
An alternative solution for X11 is provided by the utility program xclip
(http://people.debian.org/~kims/xclip). After selecting the desired
data in, say, oocalc, the data can be
read using the appropriate read.table variant:
data <- read.delim(pipe("xclip -o"))
showConnections() does not reveal any problems after this command.
--
Dr. Bernhard Brümmer
Institute of Agricultural Economics
Georg-August-Universität Göttingen
Platz der Göttinger Sieben 5
37073 Göttingen
Germany
Tel +49 (0)551 394811 Fax +49 (0)551 399866
More information about the R-help
mailing list