Re: [R] Age-Length key with kimura algorith

2007-08-29 Thread Alberto Murta
Hi Jorge

In fact I have been working with that method. I made a simple R function to 
apply it, and I'm sending you the code below. If you have any questions about 
it just send me a message.
Cheers

Alberto


On Tuesday 28 August 2007 8:44 pm, Jorge Cornejo Donoso wrote:
> Hi, I�m looking for information to implement the kimura method (kimura &
> Chikuni. 1987. Mixtures of empirical distributions: an interative
> application of the age length key) for calculation of fisheries age-length
> key.
>
> If someone have a manuals, methodology or examples about it I will be
> really gratefull if you could share it.
>
>
>
> Thanks in advance
>
>
>
> Jorge Cornejo Donoso
>
> Bi�logo Marino Menci�n Oceanograf�a y Calidad Ambiental
>
> Centro Trapananda, Universidad Austral de Chile
>
> Portales 73, Coyhaique, Chile
>
> Fono: +56(67)244520 fax: +56(67)239377
>
>
>
>
>   [[alternative HTML version deleted]]

-- 
 Alberto G. Murta
IPIMAR - National Institute of Fisheries and Marine Research
Avenida de Brasilia s/n; 1449-006 - Lisboa; Portugal
Tel: +351 213027000; Fax: +351 21 3015948; email: [EMAIL PROTECTED]
## Function to apply the method by Kimura and Chikuni (1987):
## Kimura, D.K. and Chikuni, S. (1987) Mixtures of empirical distributions:
##  an iterative application of the age-length key. Biometrics. 43, 23-35. 
## 'freq.mat' is a matrix with the number of fish in each length (row) and age 
(column) class.
## This matrix can be obtained by simple random sampling or length-stratified 
random sampling.
## 'length.vec1' and 'length.vec2' are vectors with the number of fish in each 
length-class in population 1
##  and population 2, respectively.

iterativeALK <- function(freq.mat, length.vec1, length.vec2, stop.value=0.001){
  if(length(length.vec1) != length(length.vec2) || length(length.vec2) != 
nrow(freq.mat) ||
 c(length.vec1, length.vec2, apply(freq.mat, 1, sum)) <= 0){
stop("The number of length-classes must be the same in all data sets and 
all length-classes
  must have been sampled.")
  }
  nij1.temp <- length.vec1 * freq.mat/apply(freq.mat, 1, sum)
  denom <- apply(nij1.temp, 2, sum)
  denom[denom==0] <- 1
  ialk.temp <- sweep(nij1.temp, 2, denom,"/")
  pj2.temp <- rep(1/length(age.class), length(age.class))
  criterion <- 10
  iterations <- 0
  while(criterion > stop.value){
iterations <- iterations + 1
pj2.temp.old <- pj2.temp
denom <- apply(sweep(ialk.temp, 2, pj2.temp, "*"),1, sum)
denom[denom==0] <- 1
alk.temp <- sweep(ialk.temp, 2, pj2.temp, "*")/denom
nij2.temp <- length.vec2 * alk.temp
pj2.temp <- apply(nij2.temp, 2, sum)/sum(nij2.temp)
criterion <- sum(abs(pj2.temp - pj2.temp.old))
  }
  output <- list("Number of fish in each length and age-class in population 2" 
= nij2.temp,
 "Number of iterations to convergence" = iterations)
  return(output)
}
__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] math-operations

2007-03-30 Thread Alberto Murta
On Friday 30 March 2007 14:46, Alberto Murta wrote:
> On Friday 30 March 2007 14:34, Schmitt, Corinna wrote:
> > Hallo R-experts,
> >
> > for a function I need to work with the commands "div" and "mod" known
> > from Pascal and Ruby. The only help I know is "ceiling()" and "floor()"
> > in R. Do "div" and "mod" exist? When yes please send me a little
> > example.
> >
> > In Pascal-Syntax I want:
> > 513 div 100 = 5
>
> trunc(513 / 5)

Sorry! it's   trunc(513 / 100)

>
> > 513 mod 100 = 13
>
> 513 %% 100
>
> > How can I get this in R-syntax?
> >
> > Thanks, Corinna
> >
> > __
> > 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 and provide commented,
> > minimal, self-contained, reproducible code.

-- 
   Alberto G. Murta
IPIMAR - Portuguese Institute of Fisheries and Marine Research
Avenida de Brasilia s/n; 1449-006 Lisboa; Portugal
Tel: +351 213027120; Fax: +351 213015948; email: [EMAIL PROTECTED]

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] math-operations

2007-03-30 Thread Alberto Murta
On Friday 30 March 2007 14:34, Schmitt, Corinna wrote:
> Hallo R-experts,
>
> for a function I need to work with the commands "div" and "mod" known
> from Pascal and Ruby. The only help I know is "ceiling()" and "floor()"
> in R. Do "div" and "mod" exist? When yes please send me a little
> example.
>
> In Pascal-Syntax I want:
> 513 div 100 = 5

trunc(513 / 5)

> 513 mod 100 = 13

513 %% 100

>
> How can I get this in R-syntax?
>
> Thanks, Corinna
>
> __
> 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 and provide commented, minimal,
> self-contained, reproducible code.

-- 
   Alberto G. Murta
IPIMAR - Portuguese Institute of Fisheries and Marine Research
Avenida de Brasilia s/n; 1449-006 Lisboa; Portugal
Tel: +351 213027120; Fax: +351 213015948; email: [EMAIL PROTECTED]

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Very slow read.table on Linux, compared to Win2000 [Broad cast]

2006-06-29 Thread Alberto Murta
On Wednesday 28 June 2006 15:45, Patrick Connolly wrote:
> On Wed, 28-Jun-2006 at 04:43PM -0700, Alberto Murta wrote:
> |> I have a pentium 4 pc with 256 MB of RAM, so I made a text file, tab
> |>
> |> separated, with column names and 15000 x 483 integers:
> |> > system("ls -l teste.txt")
> |>
> |> -rw-r--r--  1 amurta  amurta  16998702 Jun 28 16:08 teste.txt
> |>
> |> the time it took to import it was around 15 secs:
> |> > system.time(teste <- read.delim("teste.txt"))
> |>
> |> [1] 15.349  0.244 16.597  0.000  0.000
> |>
> |> so I think lack of RAM must not be the main problem.
> |> Cheers
> |>
> |> Alberto
> |>
> |> > version
> |>
> |>_
> |> platform   i386-unknown-freebsd6.1
> |> arch   i386
> |> os freebsd6.1
> |> system i386, freebsd6.1
> |> status
> |> major  2
> |> minor  3.1
> |> year   2006
> |> month  06
> |> day01
> |> svn rev38247
> |> language   R
> |> version.string Version 2.3.1 (2006-06-01)
>
> Doesn't tell us about your window manager.  I'd suspect you're using a
> light one.

I'm using KDE 3.5.2 (a not so light one) and running R in emacs.

-- 
  Alberto G. Murta
IPIMAR - Institute of Fisheries and Marine Research 
Avenida de Brasilia; 1449-006 Lisboa; Portugal
Tel: +351 213027120; Fax: +351 213015948

__
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


Re: [R] Very slow read.table on Linux, compared to Win2000 [Broad cast]

2006-06-28 Thread Alberto Murta
I have a pentium 4 pc with 256 MB of RAM, so I made a text file, tab 
separated, with column names and 15000 x 483 integers:

> system("ls -l teste.txt")
-rw-r--r--  1 amurta  amurta  16998702 Jun 28 16:08 teste.txt

the time it took to import it was around 15 secs:

> system.time(teste <- read.delim("teste.txt"))
[1] 15.349  0.244 16.597  0.000  0.000

so I think lack of RAM must not be the main problem.
Cheers

Alberto


> version
   _
platform   i386-unknown-freebsd6.1
arch   i386
os freebsd6.1
system i386, freebsd6.1
status
major  2
minor  3.1
year   2006
month  06
day01
svn rev38247
language   R
version.string Version 2.3.1 (2006-06-01)



On Wednesday 28 June 2006 05:43, Liaw, Andy wrote:
> From: Peter Dalgaard
>
> > <[EMAIL PROTECTED]> writes:
> > > Dear all,
> > >
> > > I read.table a 17MB tabulator separated table with 483
> > > variables(mostly numeric) and 15000 observations into R.
> >
> > This takes a
> >
> > > few seconds with R 2.3.1 on windows 2000, but it takes
> >
> > several minutes
> >
> > > on my Linux machine. The linux machine is Ubuntu 6.06, 256 MR RAM,
> > > Athlon 1600 processor. The windows hardware is better
> >
> > (Pentium 4, 512 RAM), but it shouldn't make such a difference.
> >
> > > The strange thing is that even doing something with the data(say a
> > > histogram of a variable, or transforming integers into a factor)
> > > takes really long time on the linux box and the computer
> >
> > seems to work
> >
> > > extensively with the hard disk.
> > > Could this be caused by swapping ? Can I increase the
> >
> > memory allocated to R somehow ?
> >
> > > I have checked the manual, but the memory options allowed for linux
> > > don't seem to help me (I may be doing it wrong, though ...)
> > >
> > > The code I run:
> > >
> > > TBO <-
> >
> > read.table(file="TBO.dat",sep="\t",header=TRUE,dec=",");   #
> > this takes forever
> >
> > > TBO$sexe<-factor(TBO$sexe,labels=c("man","vrouw"));   #
> >
> > even this takes like 30 seconds, compared
> >
> > > to nothing on Win2000
> > >
> > > I'd be grateful for any suggestions,
> >
> > Almost surely, the fix is to insert more RAM chips. 256 MB
> > leaves you very little space for actual work these days, and
>
> Try running Windows on the 256MB box and you'll see why Peter recommended
> the above.  Consider yourself lucky that R actually still does something
> useful under Unbuntu with so little RAM.  If adding more RAM is not an
> option, perhaps not running X altogether would help.
>
> Andy
>
> > a 17MB file will get expanded to several times the original
> > size during reading and data manipulations. Using a
> > lightweight window manager can help, but you usually regret
> > the switch for other reasons.
> >
> >
> > --
> >O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
> >   c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> >  (*) \(*) -- University of Copenhagen   Denmark  Ph:
> > (+45) 35327918
> > ~~ - ([EMAIL PROTECTED])  FAX:
> > (+45) 35327907
> >
> > __
> > 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
>
> __
> 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

-- 
  Alberto G. Murta
IPIMAR - Institute of Fisheries and Marine Research 
Avenida de Brasilia; 1449-006 Lisboa; Portugal
Tel: +351 213027120; Fax: +351 213015948

__
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


[R] Automatic differentiation (was: Re: D(dnorm...)?)

2006-01-26 Thread Alberto Murta
On Thursday 26 January 2006 07:56, [EMAIL PROTECTED] wrote:
> While symbolic computation is handy, I actually think a more pressing
> addition to R is some kind of automatic differentiation facility,
> particularly 'reverse mode' AD, which can be spectacular.  There are
> free tools available for it as well, though I don't know how well
> developed they are.  See:
>
> http://www-unix.mcs.anl.gov/autodiff/AD_Tools/
>
> I admit this is not quite the same thing, but for statistical
> computations this is, in my experience, the key thing you need.  (Well,
> for frequentist estimation at any rate...)
>
> There are commercial systems that use this idea already, of course.  Two
> that I know of are 'ADMB' (and its associated 'ADMB-RE' for random
> effects) estimation and of course the 'S-NUOPT' module for another
> system not unlike R.
>
> ADMB is, frankly, difficult to use but it performs so well and so
> quickly once you get it going nothing else seems to come close to it.  I
> has become almost a de-facto standard at the higher end of the fishery
> stock assessment game, for example, where they are always fitting huge,
> highly complex and very non-linear models.
>
> Bill V.
>

I think AD Model Builder is mainly used for fisheries assessment in North 
America and, it seems, also in Australia. In Europe, R is still the de-facto 
standard for fisheries assessment. However, I'd like to support Bill 
Venables' suggestion. I've been resisting to adopt AD model builder, or to 
start using again that other system not unlike R, mainly because of the 
licence price and because I really like R as a tool for almost everything. 
But an AD function would really make a huge difference for my work. There are 
free tools that can be used to perform AD on C or Fortran code (e.g. 
http://www.autodiff.org). One of the difficulties to use them with R is the 
need to translate the R code into C of Fortran code, but probably there are 
many other problems that I'm not able to see.

Alberto
-- 
  Alberto G. Murta <[EMAIL PROTECTED]>
National Institute of Agriculture and Fisheries Research
Avenida de Brasilia 1449-006 Lisboa Portugal
Tel: +351 213027120 | Fax: +351 213015948

__
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


Re: [R] A comment about R:

2006-01-04 Thread Alberto Murta
Mensagem original de Patrick Burns (Terça, 3 de Janeiro de 2006 19:28):
> Wensui Liu wrote:
> >Another big difference between R and other computing language such as
> >SPSS/SAS/STATA.
> >You can easily get a job using SPSS/SAS/STATA. But it is extremely
> > difficult to find a job using R. ^_^.
>
> Actually in finance it is getting easier all the time for
> knowledge of R to be a significant benefit.
>

That is also true in fisheries assessment and modelling (at least in Europe).

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal
Phone: +351 213027120 | Fax:+351 213015948

__
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


[R] R for Palm OS

2004-10-26 Thread Alberto Murta
Dear all

Has anyone tried to compile R for the Palm OS?

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027120
Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Confidence intervals for predicted values in nls

2004-06-04 Thread Alberto Murta
Ops! 
I apologise for posting my last message to the R list by mistake.


-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Confidence intervals for predicted values in nls

2004-06-04 Thread Alberto Murta
Parece que não tiveste grandes ajudas. Eu se fosse a ti fazia isso com um 
bootstrap bem planeado

Alberto


On Thursday 03 June 2004 21:22, Prof Brian Ripley wrote:
> On Thu, 3 Jun 2004, Cristina Silva wrote:
> > I have tried to estimate the confidence intervals for predicted values of
> > a nonlinear model fitted with nls. The function predict gives the
> > predicted values and the lower and upper limits of the prediction, when
> > the class of the object is lm or glm. When the object is derived from
> > nls, the function predict (or predict.nls) gives only the predicted
> > values. The se.fit and interval aguments are just ignored.
>
> Thre are no such arguments either to the generic function nls() nor its
> "nls" method.  Please do read the documentation!
>
> > Could anybody tell me how to estimate the confidence intervals for the
> > predicted values (not the model parameters), using an object of class
> > nls?
>
> First you need to understand how to do this in theory: thereafter it is a
> programming task.  Hint: to find a confidence region for the parameters is
> not at all easy, as the examples in MASS (the book) and elsewhere show,
> and there is no guarantee that the confidence region for the prediction
> will be a single interval.

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Size of R user base

2004-04-20 Thread Alberto Murta
On Tuesday 20 April 2004 15:02, Philippe Grosjean wrote:

> No software is eternel. I think a good picture of the change in time of R
> users would be an interesting tool to have an idea on how well it fits or
> don't fit users' needs. Moreover, if you develop for both R and S-PLUS, and
> think to develop only for one software only in the future, it would be nice
> to know what fraction of the "S language and environment" users you miss
> this way.

I think this kind of marketing concerns don't have much to do with a 
cooperative software project like R. There is a direct way of knowing user's 
needs -- and that is subscribing to this list. 
If R is going to become obsolete one day, it will probably more because of 
lack of developers than because of lack of users, and there isn't always a 
linear relation between these two.


-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Mahalanobis

2004-03-26 Thread Alberto Murta
Dear all

Why isn'it possible to calculate Mahalanobis distances with R for a matrix 
with 1 row (observations) more than the number of columns (variables)?

> mydata <- matrix(runif(12,-5,5), 4, 3)
> mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata))
[1] 2.25 2.25 2.25 2.25

> mydata <- matrix(runif(420,-5,5), 21, 20)
> mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata))
 [1] 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762 
19.04762 19.04762 19.04762 19.04762
[13] 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762 
19.04762

> mydata <- matrix(runif(132,-5,5), 12, 11)
> mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata))
 [1] 10.08333 10.08333 10.08333 10.08333 10.08333 10.08333 10.08333 10.08333 
10.08333 10.08333 10.08333 10.08333

Thanks in advance

Alberto Murta

> version
 _
platform i686-pc-linux-gnu
arch i686 
os   linux-gnu
system   i686, linux-gnu  
status
major1
minor8.1  
year 2003 
month11   
day  21   
language R

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] "Statistiques avec R"

2004-03-05 Thread Alberto Murta
The following note was placed today in the web site: 

" Note to english-speaking readers (2004/03/05): Many people have asked me if 
an English version of this document was on the way. The French version is 
still unfinished, but I hope it will be over before summer. I shall then 
consider translating it into English. "

So, an english version may appear in some months.

Alberto

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] "Statistiques avec R"

2004-03-04 Thread Alberto Murta
Thank you for your suggestion. It is really a very good (and pretty) 
introduction to R.
Cheers

Alberto

On Thursday 04 March 2004 11:36, Shigeru Mase wrote:
> Dear R users,
>
> I want to share my joy with you. Please see the following
> excellent introduction to R "Statistiques avec R " by
> Vincent Zoonekynd
>
> http://zoonek2.free.fr/UNIX/48_R/all.html
>
> In paticular, you can see a lot of fascinating graphics
> examples of R from which you can get many hints.
>
> Soryy if this is already well-known, but the CRAN search
> did not show nothing with the keyword "Zoonekynd".
>
> Cheers,
>
> Shigeru Mase,
> Dept. Comp. and Math. Sciences
> Tokyo Institute of Technology,
> Meguro, Tokyo, Japan 152-8550
>
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] vectorization question

2003-08-18 Thread Alberto Murta
Thank you very much to Tony Plate for his really clear explanation, and to 
Prof Ripley for his time solving this deficiency (IMHO)


On Friday 15 August 2003 08:44, Martin Maechler wrote:
>
> Thank you, Tony.  This certainly was the most precise
> explanation on this thread.
>
> Everyone note however, that this has been improved (by Brian
> Ripley) in the current R-devel {which should be come R 1.8 in October}.
> There, also "$<-" assignment of data frames does check things
> and in this case will do the same replication as the [,] or [[]]
> assignments do.
> For back compatibility (with S-plus and earlier R versions), I'd
> still recommend using bracket "[" rather than "$" assignment for
> data frames.
>
> Martin Maechler <[EMAIL PROTECTED]>   http://stat.ethz.ch/~maechler/
> Seminar fuer Statistik, ETH-Zentrum  LEO C16  Leonhardstr. 27
> ETH (Federal Inst. Technology)8092 Zurich SWITZERLAND
> phone: x-41-1-632-3408fax: ...-1228   <><
>
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://www.ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] vectorization question

2003-08-14 Thread Alberto Murta
Dear all

I recently noticed the following error when cohercing a data.frame into a 
matrix:

> example <- matrix(1:12,4,3)
> example <- as.data.frame(example)
> example$V4 <- 0
> example
  V1 V2 V3 V4
1  1  5  9   0
2  2  6 10  0
3  3  7 11  0
4  4  8 12  0
> example <- as.matrix(example)
Error in as.matrix.data.frame(example) : dim<- length of dims do not match the 
length of object

However, if the column to be added has the right number of lines, there's no 
error:

> example <- matrix(1:12,4,3)
> example <- as.data.frame(example)
> example$V4 <- rep(0,4)
> example
  V1 V2 V3 V4
1  1  5  9  0
2  2  6 10  0
3  3  7 11  0
4  4  8 12  0
> example <- as.matrix(example)
> example
  V1 V2 V3 V4
1  1  5  9  0
2  2  6 10  0
3  3  7 11  0
4  4  8 12  0

Shouldn't it work well both ways? I checked the attributes and dims of the 
data frame and they are the same in both cases. Where's the difference that 
originates the error message?
Thanks in advance

Alberto

platform i686-pc-linux-gnu
arch i686 
os   linux-gnu
system   i686, linux-gnu  
status
major1
minor7.1  
year 2003 
month06   
day  16   
language R


-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://www.ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] vectorization question

2003-08-14 Thread Alberto Murta
Thank you very much. I just would expect that 'as.matrix' would have the same 
behaviour as 'data.matrix' when all columns in a data frame are numeric.
Regards

Alberto

On Thursday 14 August 2003 16:41, Liaw, Andy wrote:
> If you look at the structure, you'll see:
> > x$V4 <- 0
> > str(x)
>
> `data.frame':   4 obs. of  4 variables:
>  $ V1: int  1 2 3 4
>  $ V2: int  5 6 7 8
>  $ V3: int  9 10 11 12
>  $ V4: num 0
>
> Don't know if this is the intended result.  In any case, you're probably
> better off using data.matrix, as
>
> > data.matrix(x)
>
>   V1 V2 V3 V4
> 1  1  5  9  0
> 2  2  6 10  0
> 3  3  7 11  0
> 4  4  8 12  0
>
> HTH,
> Andy
>
> > -Original Message-
> > From: Alberto Murta [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, August 14, 2003 12:50 PM
> > To: [EMAIL PROTECTED]
> > Subject: [R] vectorization question
> >
> >
> > Dear all
> >
> > I recently noticed the following error when cohercing a
> > data.frame into a
> >
> > matrix:
> > > example <- matrix(1:12,4,3)
> > > example <- as.data.frame(example)
> > > example$V4 <- 0
> > > example
> >
> >   V1 V2 V3 V4
> > 1  1  5  9   0
> > 2  2  6 10  0
> > 3  3  7 11  0
> > 4  4  8 12  0
> >
> > > example <- as.matrix(example)
> >
> > Error in as.matrix.data.frame(example) : dim<- length of dims
> > do not match the
> > length of object
> >
> > However, if the column to be added has the right number of
> > lines, there's no
> >
> > error:
> > > example <- matrix(1:12,4,3)
> > > example <- as.data.frame(example)
> > > example$V4 <- rep(0,4)
> > > example
> >
> >   V1 V2 V3 V4
> > 1  1  5  9  0
> > 2  2  6 10  0
> > 3  3  7 11  0
> > 4  4  8 12  0
> >
> > > example <- as.matrix(example)
> > > example
> >
> >   V1 V2 V3 V4
> > 1  1  5  9  0
> > 2  2  6 10  0
> > 3  3  7 11  0
> > 4  4  8 12  0
> >
> > Shouldn't it work well both ways? I checked the attributes
> > and dims of the
> > data frame and they are the same in both cases. Where's the
> > difference that
> > originates the error message?
> > Thanks in advance
> >
> > Alberto
> >
> > platform i686-pc-linux-gnu
> > arch i686
> > os   linux-gnu
> > system   i686, linux-gnu
> > status
> > major1
> > minor7.1
> > year 2003
> > month06
> > day  16
> > language R
> >
> >
> > --
> >  Alberto G. Murta
> > Institute for Agriculture and Fisheries Research (INIAP-IPIMAR)
> > Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351
> > 213027062 Fax:+351 213015948 |
> > http://www.ipimar-iniap.ipimar.pt/pelagicos/
> >
> >
> > __
> > [EMAIL PROTECTED] mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>
> ---
>--- Notice:  This e-mail message, together with any attachments, contains
> information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA),
> and/or its affiliates (which may be known outside the United States as
> Merck Frosst, Merck Sharp & Dohme or MSD) that may be confidential,
> proprietary copyrighted and/or legally privileged, and is intended solely
> for the use of the individual or entity named on this message.  If you are
> not the intended recipient, and have received this message in error, please
> immediately return this by e-mail and then delete it.
>
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
 Alberto G. Murta
Institute for Agriculture and Fisheries Research (INIAP-IPIMAR) 
Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
Fax:+351 213015948 | http://www.ipimar-iniap.ipimar.pt/pelagicos/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help