Re: [R] Easy cut & paste from Excel to R?

From: roger bos <roger.bos_at_gmail.com>
Date: Fri 30 Sep 2005 - 22:48:08 EST

Thanks Gabor and Petr. It seems that all you have to do is use 'clipboard' and not 'file("clipboard")' as we were doing. The row.names won't copy if you use file. I don't know if that is a bug or a feature, but if you were debugging someones code who already had 'file()' there, it would be hard to figure out that that was the culprut.
 Roger

 On 9/29/05, Petr Pikal <petr.pikal@precheza.cz> wrote:
>
> Hi
>
> Works for me.
>
> write.excel <- function (tab, ...) write.table(tab, "clipboard", sep
> = "\t", row.names = F)
>
> write.excel(a)
>
> from your example shows in Excel after ctrl-V as a table with names.
>
> HTH
>
> Petr
>
>
>
>
>
> On 29 Sep 2005 at 12:12, Jose Quesada wrote:
>
> Date sent: Thu, 29 Sep 2005 12:12:00 +0100
> From: Jose Quesada <quesada@gmail.com>
> To: Werner Wernersen <pensterfuzzer@yahoo.de>
> Copies to: r-help@stat.math.ethz.ch
> Subject: Re: [R] Easy cut & paste from Excel to R?
> Send reply to: Jose Quesada <quesada@gmail.com>
> <mailto:r-help-request@stat.math.ethz.ch?subject=unsubscribe>
> <mailto:r-help-request@stat.math.ethz.ch?subject=subscribe>
>
> > Sorry to revive and old topic, but writing to the clipboard seems to
> > have a problem for me: column names are ignored. Example:
> >
> > # ~~~~~~~~~~~~~~~~~~~~~~~
> > # write.clipboard
> > # ~~~~~~~~~~~~~~~~~~~~~~~
> > write.clipboard = function(obj) {
> > write.table(obj, file("clipboard"), sep="\t", row.names=F,
> > col.names=T)
> > }
> >
> > a= matrix(1:4,2,2)
> > colnames(a) = c("a", "b")
> >
> > write.clipboard(a)
> > a = as.data.frame(a)
> > write.clipboard(a)
> >
> > both attempts will paste the date without column names.
> > Any idea why?
> >
> > Thanks,
> > -Jose
> >
> > On 2/16/05, Werner Wernersen <pensterfuzzer@yahoo.de> wrote:
> > > Thank you all very much for the answers!
> > > The read.table / read.delim2 commands are exactly what
> > > I was looking for to get
> > > a couple of numbers or a little matrix quickly into R
> > > without creating an extra
> > > text file every time.
> > >
> > > And it works the other way around as well:
> > > write.table(x, file("clipboard"), sep="\t")
> > > Fantastic!
> > >
> > > Thanks again,
> > > Werner
> > >
> > > Nick Drew wrote:
> > > > I've had good luck with the scan() function when I
> > > > want to get a few numbers from Excel into R quickly
> > > to
> > > > use it as a calculator. CAVEAT: you have to have the
> > > > numbers you want to copy in a column not a row in
> > > > Excel. For example:
> > > >
> > > > In Excel your data are in a column as follows:
> > > > Col A
> > > > 1
> > > > 2
> > > > 3
> > > >
> > > > Then copy the 3 cells (e.g. 1, 2,3) in Excel and
> > > open
> > > > R and type in:
> > > >
> > > >>data <- scan()
> > > >
> > > >
> > > > Then Paste using Ctrl-V. Hit the Enter key. You know
> > > > have an object called "data" that you can use and
> > > > manipulate in R.
> > > >
> > > > I've taken this even further by creating an R
> > > function
> > > > that will take a column of numbers from Excel and
> > > then
> > > > scan() them into R, create a matrix, and then
> > > perform
> > > > a Chi-square test. Let me know if you'd like to know
> > > > more. I'm a beginner and if I can do so can you!!
> > > >
> > > > ~Nick
> > > >
> > > >
> > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > >
> > >
> > > > http://promotions.yahoo.com/new_mail
> > > >
> > > >
> > >
> > > ______________________________________________
> > > R-help@stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide!
> > > http://www.R-project.org/posting-guide.html
> > >
> >
> >
> > --
> > Jose Quesada, PhD.
> >
> > j.quesada@warwick.ac.uk ESRC Postdoctoral Fellow
> > http://lsa.colorado.edu/~quesadaj Dept. of PSychology
> > http://www.andrew.cmu.edu/~jquesada University of Warwick
> > office H114 Phone: +44 024 765 23 759
> > Coventry, UK
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
>
> Petr Pikal
> petr.pikal@precheza.cz
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Sep 30 22:54:26 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:05:14 EST