Skip to content

No subject

20 messages · HAKIM Nour-Eddine, Peter Dalgaard, Yves Gauvreau +13 more

#
Dear ,

I want to import Excel data (.XLS). Can you help me to this.

Best regards.

Nour-Eddine HAKIM


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
HAKIM Nour-Eddine <noureddine.hakim at axa-corporatesolutions.com> writes:
It's difficult without going via a text file, so you need to have
Excel on the machine. This is what I have been telling students
(part of the information is described for SPSS, so you get that as
well):

\item[SPSS:] Use |File, Export| menu in the data editor and export as
  a tab-separated file (for simplicity, say |mydata.txt| in the top
  directory on the |C:| drive). Make sure that it contains a header
  line with the variable names and use
  |read.csv2("C:/mydata.txt",sep="\t")| to read it in. This refers to
  locales where the comma is used as decimal separator, otherwise use
  |read.csv|.
  
  Alternatively, one can copy the data or a section of it directly to
  a text editor such as Notepad via the Windows copy and paste
  mechanism.  Note however that the variable names are not copied in
  this way, so one must either add them by hand (recommended) or use
  |read.csv2("C:/mydata.txt",sep="\t",header=F)| and add variable
  names later.


\item[Excel:] Use |File,Save as...| and choose tab-sep (|.txt|) or use
  the clipboard.  Subsequent data handling is similar to SPSS. Note
  that a header line will only be present if it was in the spreadsheet
  to begin with.
#
workspace.

YG

-----Message d'origine-----
De : owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch]De la part de HAKIM Nour-Eddine
Envoy? : Wednesday, December 06, 2000 6:03 AM
? : 'R-help at r-project.org'
Objet :


Dear ,

I want to import Excel data (.XLS). Can you help me to this.

Best regards.

Nour-Eddine HAKIM


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
I want to draw a random sample Y_1, ..., Y_n, iid Poisson,
but condition on their sum being equal to  k. Two
suggestions:

1)   lambda <- k / n ## optimal value
     ysum <- -1
     while (ysum != k){
        y <- rpois(n, lambda)
        ysum <- sum(y)
     }
     y

2) Aiming at Multinom(k, 1/n, ..., 1/n):

   y <- as.vector(table(factor(sample(n, k, replace = T), levels = 1:n)))

1) seems to be faster than 2), but my question is whether there is
something even better?  'sample' is fast enough, but how can I do
the rest (factor, table) smarter in 2)?

Thanks for any suggestions!

G?ran
#
Hello,

Wed, 6 Dec 2000 12:02:51 +0100, 
	HAKIM Nour-Eddine <noureddine.hakim at axa-corporatesolutions.com> wrote
I use Excel data.

save as CVS File (.cvs)

------
miyamura masashi (@_@;

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hakim,

I don't believe there is any direct way of doing this. Here are some 
options:

1) If you have Excel, save the file as text or csv.

2) Convert the .xls to text. One way to do this is to go to 
http://www.freeviewer.com. You can use their web page to produce a text 
version that you can paste into a data file.

Rick Bilonick
HAKIM Nour-Eddine wrote:

            
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On 06 Dec 2000 12:37:50 +0100 Peter Dalgaard BSA
<p.dalgaard at biostat.ku.dk> wrote:

            
Or on a Linux machine you can use Gnumeric 
(http://www.gnome.org/gnumeric)

Zoltan Barta


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
I've collected various implementations of multinomial deviate generation
in S/R.  There's an "rmult" package by Jonathan Rougier on STATLIB's S
archive (http://lib.stat.cmu.edu/S/rmult), which runs unmodified under R,
but is much slower than your code #1.

  The following code (which I didn't write but have tweaked -- it could be
improved further; unfortunately I don't have the author's name any more)
is much faster *if* you can generate all of your deviates at the same
time, but twice as slow if you do them one at a time.

## (rmult.gb1 and rmult.gb2 are just your code)

tot <- 100000
system.time(for (i in 1:tot) rmult.gb1(5,10))
## [1] 21.27  1.02 22.37  0.00  0.00
system.time(for (i in 1:tot) rmult.gb2(5,10))
## [1] 137.78   3.59 142.22   0.00   0.00
system.time(for (i in 1:tot) rmulti(1,rep(1/5,5),10))
## [1] 50.07  1.05 51.36  0.00  0.00
system.time(rmulti(tot,rep(1/5,5),10))  ## vectorize
## [1] 0.17 0.02 0.19 0.00 0.00

rmulti<-function (n, size, prob)
  ## pick multinomial deviates
{
  if (size==0) stop("rmulti: size==0")
  if (is.matrix(prob)) {
    l <- ncol(prob)
    totp <- prob %*% rep(1, l)
  }
  else {
    l <- length(prob)
    totp <- sum(prob)
    prob <- matrix(prob, nrow = 1)
  }
  siz <- rep(size, length.out = n)
  x <- matrix(numeric(n * l), ncol = l)
  for (i in 1:(l - 1)) {
    ## inserted min() to deal with roundoff problems that led to p>1.0
    x[, i] <- rbinom(n, siz, min(prob[, i]/totp,1.0))
    siz <- siz - x[, i]
    totp <- totp - prob[, i]
    totp[totp <= 0] <- 1
  }
  x[,l]<-siz
  x
}
On Wed, 6 Dec 2000, gb wrote:

            

  
    
#
On Wed, 6 Dec 2000, Richard A. Bilonick wrote:

            
Isn't is possible to access an Excell document via ODBC ?

Just asking, I have not tested it...

Alexandre Fayolle
#
Alexandre Fayolle <Alexandre.Fayolle at logilab.fr> writes:
I know you can go the other way and import a table from an ODBC
connection into an Excel spreadsheet.  I did that recently.  

For this kind of exchange Excel is the client on the ODBC connection.
I would be surprised if one were able to transfer data the other way
by making Excel function as an ODBC server. Excel doesn't seem to have
a way of enforcing consistency in the contents of cells in a column
and consistency in columns is important for many other systems that
can use ODBC connections.  In some ways consistent storage and
interpretation for all the elements of a column is the defining
feature of a relational database table.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hello,

Wed, 06 Dec 2000 22:25:11 +0900, 
	Miyamura Masashi <kightjp at livedoor.com> wrote
Sorry, I mean "CSV".
------
miyamura masashi (@_@;

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
I got answers from Peter D., Ben Bolker, and Yudi Pawitan:

Peter's suggestion:
tabulate(sample(n, k, replace = T), n)
'tabulate' was what I couldn't find!

Yudi's is in the same spirit:
table(ceiling(n*runif(k)))
Change that to 'tabulate(ceiling(n*runif(k)), n)'
and I also get what I want.

Ben's
rmulti<-function (n, size, prob)
[............] (see his letter)

is much slower for _one_ replicate (n=1), but it vectorizes
and performs very well for large  n (note that Peter's and
Yudi's  'n'  is  'length(prob)'  in Ben's function).
And it puts no restriction on 'prob'.

We can however generalize  'sample' to
tabulate(sample(n, k, replace = T, prob = p), n)
but the vectorization is still to be done.

Many thanks to the three of you!

G?ran

Original question:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
It is not necessary to have excel if you are running Linux. Gnumeric can
read excel files and you can transform the files to text there.

----------------------------------------------
Kari Ruohonen
Finnish Game and Fisheries Research Institute
Socioeconomic and Aquaculture Research

Evo Fisheries Research Station
16970 Evo, Finland
tel. +358-20-5751430, +358-40-5238321 (mobile)
fax  +358-20-5751429

http://www.rktl.fi
On 6 Dec 2000, Peter Dalgaard BSA wrote:

            
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
1 day later
#
Alexandre Fayolle <Alexandre.Fayolle at logilab.fr> writes:
You need a driver and it will work. For a free, multi-platform solution
to not having Excel try StarOffice 5.2 (www.sun.com/staroffice).

Mark

--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
HAKIM Nour-Eddine <noureddine.hakim at axa-corporatesolutions.com> writes:
Save as .CSV (comma separated) and use read.table() in R.

Mark

--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi all,

A couple of days ago, I posted a message regarding the support for heteroscedasticity testing in R. In fact, there are several tests and methods to assess whether the residuals of a model are heteroscedastic or not. The one for which I was claiming information can be found in William Greene's "Econometric Analysis", chapter 12. It's about White's *estimator*, not test, and it consists in replacing the beta's variance's traditionnal estimator by a new one calculated with the least squares residuals (instead of sigma square).
There is also a White test for heteroscadsticity, but it is said to be extremely general (Greene, p.508), and it uses the White's estimator described above. 

SO, the only thing that seems to be missing in R is the calculation of that very estimator, and the new regression that can be performed from it. If, anyone else than myself is interested in this feature, please let me know.

Bye! Vincent.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Sat, 9 Dec 2000 E97249 at edu.essec.fr wrote:

            
Code for a collection of these "sandwich" variance estimators for
generalised linear models can be found at
   http://www.biostat.washington.edu/~thomas/weave.html
The functions are intended for various sorts of correlated response data,
but independent data can be analysed as a special case. I don't have code
for the re-estimation, though.


	-thomas

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
1 day later
#
On 6 Dec 2000, Douglas Bates wrote:

            
Doug's caveats are right, but Excel *is* an ODBC server, and I have
actually imported from Excel into R using RODBC.  The naming
conventions were a nightmare, though.

ODBC is not just about relational databases, in that ODBC bridges can make
other systems look like relational databases, even text files (which cna be
useful if they are compressed).
4 days later
#
Is there an implementation of the Dirichlet distribution somewhere in one
of the libraries?  Or for S-plus somewhere?

John


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Some code (originally contributed by Ian Wilson
<i.wilson at maths.abdn.ac.uk>

## functions for the "Dirichlet function", the multidimensional ##
generalization of the beta distribution: it's the Bayesian canonical ##
distribution for the parameter estimates of a multinomial ## distribution.

"pdirichlet" and "qdirichlet" (distribution function and quantiles) would
be more difficult because you'd first have to decide how to define the
distribution function for a multivariate distribution ... I'm sure this
could be done but I don't know how


logD <- function(a) {
    sum(lgamma(a)) - lgamma(sum(a))
 }
######################################################
ddirichlet<-function(x,alpha)
  ## probability density for the Dirichlet function, where x=vector of
## probabilities
  ## and (alpha-1)=vector of observed samples of each type
  ## ddirichlet(c(p,1-p),c(x1,x2)) == dbeta(p,x1,x2)
{
    s<-sum((alpha-1)*log(x))
    exp(sum(s)-logD(alpha))
}
######################################################
rdirichlet<-function(n,a)
  ## pick n random deviates from the Dirichlet function with shape
## parameters a
{
    l<-length(a);
    x<-matrix(rgamma(l*n,a),ncol=l,byrow=TRUE);
    sm<-x%*%rep(1,l);
    x/as.vector(sm);
}
On Thu, 14 Dec 2000 j.logsdon at lancaster.ac.uk wrote: