Skip to content

import data

6 messages · Peng Jiang, Emiliano Guevara, Simon Urbanek +2 more

#
Hi ,
  I have some data in Numbers, which is a data managing software for  
Mac OS. How can I import them to R ?
  Or how can I import my data from R to Numbers ?  Any interfaces  
between R and Numbers or something ?

  I am a newbie so if the question is toooooo simple, please take it  
easy.

  Thanks!











--------------------------
Peng Jiang
??
Ph.D. Candidate

Antai College of Economics & Management
????????
Department of Mathematics
???
Shanghai Jiaotong University (Minhang Campus)
800 Dongchuan Road
200240 Shanghai
P. R. China
#
Hi,

There's many ways to do it. I would suggest using comma separated  
values as a "bridge" filetype.

 From Numbers, save your data as a .csv file (comma separated value).
Then, in R, import the data from the file using:

 > read.csv(file.csv)

That should be it,

Best wishes,

E.
On Jun 13, 2008, at 05:34 AM, Peng Jiang wrote:

            
****************************************
Emiliano R. Guevara
Facolt? di Lingue e Lett. Straniere
Dipart. di Lingue e Lett. Straniere
Universit? di Bologna
Via Cartoleria 5 (40124) Bologna, Italia
   http://morbo.lingue.unibo.it/
   emiliano.guevara at unibo.it
   emiguevara at gmail.com
#
On Jun 13, 2008, at 4:43 AM, Emiliano Guevara wrote:

            
I find copy/paste more convenient for most simple tables - simply  
select the table in Numbers, press <Cmd><C> (Copy) and then read the  
clipboard in R:

read.table(pipe("pbpaste"))

Cheers,
Simon
#
I agree with Simon that copy paste is the easiest way to go.

However, because I was unable to remember the 
read.table(pipe("pbpaste")) command and wanted to 
give instructions to students that were platform 
independent, I created a little function 
(read.clipboard) that works on PCs or Macs .  It 
is available in the psych package:
"read.clipboard" <-
function(header=TRUE,...) {
     MAC<-Sys.info()[1]=="Darwin"    #are we on a Mac using the Darwin system?
    if (!MAC ) {if (header) 
read.clipboard<-read.table(file("clipboard"),header=TRUE,...)
             else read.clipboard<-read.table(file("clipboard"),...) }
     else {
    if (header) read.clipboard<-  read.table(pipe("pbpaste"),header=TRUE,...)
    else read.clipboard<- read.table(pipe("pbpaste"),...)}
    }

With the addition of  a sep="," option, it can also read csv copied files:


"read.clipboard.csv" <-
function(header=TRUE,sep=',',...) {  #same as read.clipboard(sep=',')
     MAC<-Sys.info()[1]=="Darwin"    #are we on a Mac using the Darwin system?
    if (!MAC ) {if (header) 
read.clipboard<-read.table(file("clipboard"),header=TRUE,sep,...)
             else read.clipboard<-read.table(file("clipboard"),sep,...) }
     else {
    if (header) read.clipboard<- 
read.table(pipe("pbpaste"),header=TRUE,sep,...)
    else read.clipboard<- read.table(pipe("pbpaste") ,sep,...)}
    }


Bill
At 10:53 AM -0400 6/13/08, Simon Urbanek wrote:

  
    
  
#
I agree that the difference between Mac and others WRT clipboard is a  
bit annoying. I'll see if I can fix that.

Thanks,
Simon
On Jun 13, 2008, at 11:16 AM, William Revelle wrote:

            
#
On Fri, 13 Jun 2008, Simon Urbanek wrote:

            
If you do, can you leave a way to read from the X11 primary selection for 
those who like to use X11 applications on Mac OS?  I'm not objecting to 
file="clipboard" changing its meaning, but "X11_clipboard" is taken, so 
perhaps "X11_primary" or some such.

Brian