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

Nick Drew drewbrewit at yahoo.com
Wed Feb 16 14:08:36 CET 2005


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




More information about the R-help mailing list