[R] min() return factor class values

2007-01-09 Thread Milton Cezar Ribeiro
Hi R-friends
   
  I don´t know why the min() function below return the min value as factor. 
When i force the aicc.min using a as.numeric() function, it return a factor 
index (1,2,..) and not min value as I want. By the way, I included a 
sessionInfo() at the end of this e-mail.
   
  In fact I had the same problem (values as factor) on other part of my script 
and I noticed that it occour when I use cbind(). It is real?
   
  Any idea? 
   
  Kind regards,
   
  Miltinho
   
   especies.aicc.min-data.frame()
 for (sp in levels(especies.aicc$especie)) 
+ {
+ sele-subset(especies.aicc,especie==sp)
+ especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc)))
+ }
 especies.aicc.min
sp aicc.min
1 Attila.rufus  6.7387056413613
2 Automolus.leucophthalmus 125.791300522824
 class(especies.aicc.min$aicc.min)
[1] factor
 
---
   sessionInfo()
R version 2.4.0 (2006-10-03) 
i386-pc-mingw32 
  locale:
LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252
  attached base packages:
[1] methods   stats graphics  grDevices utils datasets  
base 
 


 __


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


Re: [R] min() return factor class values

2007-01-09 Thread Peter Dalgaard
Milton Cezar Ribeiro wrote:
 Hi R-friends

   I don´t know why the min() function below return the min value as factor. 
 When i force the aicc.min using a as.numeric() function, it return a factor 
 index (1,2,..) and not min value as I want. By the way, I included a 
 sessionInfo() at the end of this e-mail.
   
min() is not doing anything out of the ordinary, but cbind'ing it with
the character vector sp coerces it to character and rbind'ing to a data
frame turns character vectors into factors...

The whole thing looks like it could be a straightforward application of
aggregate().

   In fact I had the same problem (values as factor) on other part of my 
 script and I noticed that it occour when I use cbind(). It is real?

   Any idea? 

   Kind regards,

   Miltinho

especies.aicc.min-data.frame()
   
 for (sp in levels(especies.aicc$especie)) 
 
 + {
 + sele-subset(especies.aicc,especie==sp)
 + 
 especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc)))
 + }
   
 especies.aicc.min
 
 sp aicc.min
 1 Attila.rufus  6.7387056413613
 2 Automolus.leucophthalmus 125.791300522824
   
 class(especies.aicc.min$aicc.min)
 
 [1] factor
   
 ---
sessionInfo()
 R version 2.4.0 (2006-10-03) 
 i386-pc-mingw32 
   locale:
 LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252
   attached base packages:
 [1] methods   stats graphics  grDevices utils datasets  
 base 
   

   


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


Re: [R] min() return factor class values

2007-01-09 Thread Zoltan Kmetty
Hi Milton!

I don't know why, but this thing happend with me too, quite a lot times.
It's a useful way that convert the value type like that:

*as.numeric(as.character(min(...)))*

Zoltan

2007/1/9, Milton Cezar Ribeiro [EMAIL PROTECTED]:

 Hi R-friends

 I don´t know why the min() function below return the min value as
 factor. When i force the aicc.min using a as.numeric() function, it return
 a factor index (1,2,..) and not min value as I want. By the way, I included
 a sessionInfo() at the end of this e-mail.

 In fact I had the same problem (values as factor) on other part of my
 script and I noticed that it occour when I use cbind(). It is real?

 Any idea?

 Kind regards,

 Miltinho

  especies.aicc.min-data.frame()
  for (sp in levels(especies.aicc$especie))
 + {
 + sele-subset(especies.aicc,especie==sp)
 + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min
 (sele$aicc)))
 + }
  especies.aicc.min
sp aicc.min
 1 Attila.rufus  6.7387056413613
 2 Automolus.leucophthalmus 125.791300522824
  class(especies.aicc.min$aicc.min)
 [1] factor
 
 ---
  sessionInfo()
 R version 2.4.0 (2006-10-03)
 i386-pc-mingw32
 locale:

 LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252
 attached base packages:
 [1] methods   stats graphics  grDevices utils
 datasets  base
 


 __


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




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


Re: [R] min() return factor class values

2007-01-09 Thread Milton Cezar Ribeiro
Dear Peter,
   
  I tryed something like 
   
  head(especies.aicc)
 especie aicc
1 Attila.rufus 17.15934
2 Attila.rufus 11.41371
3 Attila.rufus 11.41371
4 Attila.rufus 19.55998
5 Attila.rufus 17.23780
6 Attila.rufus 19.22545
   
   especies.min-aggregate.data.frame(especies.aicc,list
 (Especie=especies.aicc$especie),max)
   
  But it works fine only for mean FUN and not for min and max. Also also, 
when I use mean I got the following warnings:
   
   especies.min-aggregate.data.frame(especies.aicc,list 
 (Especie=especies.aicc$especie),mean)

  Warning messages:
1: argument is not numeric or logical: returning NA in: mean.default(X[[1]], 
...) 
2: argument is not numeric or logical: returning NA in: mean.default(X[[2]], 
...) 
   
  In fact I need only min() and max().
   
  Miltinho
  -

Peter Dalgaard [EMAIL PROTECTED] escreveu:
  Milton Cezar Ribeiro wrote:
 Hi R-friends
 
 I don´t know why the min() function below return the min value as factor. 
 When i force the aicc.min using a as.numeric() function, it return a factor 
 index (1,2,..) and not min value as I want. By the way, I included a 
 sessionInfo() at the end of this e-mail.
 
min() is not doing anything out of the ordinary, but cbind'ing it with
the character vector sp coerces it to character and rbind'ing to a data
frame turns character vectors into factors...

The whole thing looks like it could be a straightforward application of
aggregate().
 
 In fact I had the same problem (values as factor) on other part of my script 
 and I noticed that it occour when I use cbind(). It is real?
 
 Any idea? 
 
 Kind regards,
 
 Miltinho
 
  especies.aicc.min-data.frame()
 
 for (sp in levels(especies.aicc$especie)) 
 
 + {
 + sele-subset(especies.aicc,especie==sp)
 + 
 especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc)))
 + }
 
 especies.aicc.min
 
 sp aicc.min
 1 Attila.rufus 6.7387056413613
 2 Automolus.leucophthalmus 125.791300522824
 
 class(especies.aicc.min$aicc.min)
 
 [1] factor
 
 ---
  sessionInfo()
 R version 2.4.0 (2006-10-03) 
 i386-pc-mingw32 
 locale:
 LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252
 attached base packages:
 [1] methods stats graphics grDevices utils datasets base 
 

 


-- 
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




 __


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


Re: [R] min() return factor class values

2007-01-09 Thread Peter Dalgaard
Milton Cezar Ribeiro wrote:
 Dear Peter,

   I tryed something like 

   head(especies.aicc)
  especie aicc
 1 Attila.rufus 17.15934
 2 Attila.rufus 11.41371
 3 Attila.rufus 11.41371
 4 Attila.rufus 19.55998
 5 Attila.rufus 17.23780
 6 Attila.rufus 19.22545

especies.min-aggregate.data.frame(especies.aicc,list
  (Especie=especies.aicc$especie),max)
   
Make sure to aggregate only the part of your data frame that is numeric:

 x - read.table(stdin())

0:  especie aicc

1: 1 Attila.rufus 17.15934

2: 2 Attila.rufus 11.41371

3: 3 Attila.rufus 11.41371

4: 4 Attila.rufus 19.55998

5: 5 Attila.rufus 17.23780

6: 6 Attila.rufus 19.22545

7:

 aggregate(x[2], list(x$especie), min)

   Group.1 aicc

1 Attila.rufus 11.41371

 aggregate(x[2], list(x$especie), max)

   Group.1 aicc

1 Attila.rufus 19.55998

 aggregate(x, list(x$especie), max) # this breaks

Error in Summary.factor(..., na.rm = na.rm) :

max not meaningful for factors


   But it works fine only for mean FUN and not for min and max. Also 
 also, when I use mean I got the following warnings:

especies.min-aggregate.data.frame(especies.aicc,list 
  (Especie=especies.aicc$especie),mean)

   Warning messages:
 1: argument is not numeric or logical: returning NA in: mean.default(X[[1]], 
 ...) 
 2: argument is not numeric or logical: returning NA in: mean.default(X[[2]], 
 ...) 

   In fact I need only min() and max().

   Miltinho
   -

 Peter Dalgaard [EMAIL PROTECTED] escreveu:
   Milton Cezar Ribeiro wrote:
   
 Hi R-friends

 I don´t know why the min() function below return the min value as factor. 
 When i force the aicc.min using a as.numeric() function, it return a factor 
 index (1,2,..) and not min value as I want. By the way, I included a 
 sessionInfo() at the end of this e-mail.

 
 min() is not doing anything out of the ordinary, but cbind'ing it with
 the character vector sp coerces it to character and rbind'ing to a data
 frame turns character vectors into factors...

 The whole thing looks like it could be a straightforward application of
 aggregate().
   
 In fact I had the same problem (values as factor) on other part of my script 
 and I noticed that it occour when I use cbind(). It is real?

 Any idea? 

 Kind regards,

 Miltinho

 
 especies.aicc.min-data.frame()
   
 for (sp in levels(especies.aicc$especie)) 

   
 + {
 + sele-subset(especies.aicc,especie==sp)
 + 
 especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc)))
 + }

 
 especies.aicc.min

   
 sp aicc.min
 1 Attila.rufus 6.7387056413613
 2 Automolus.leucophthalmus 125.791300522824

 
 class(especies.aicc.min$aicc.min)

   
 [1] factor

 ---
 
 sessionInfo()
   
 R version 2.4.0 (2006-10-03) 
 i386-pc-mingw32 
 locale:
 LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252
 attached base packages:
 [1] methods stats graphics grDevices utils datasets base 



 


   


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


Re: [R] min() return factor class values

2007-01-09 Thread Benilton Carvalho
Milton,

have you looked at the structure of your data.frame?

str(especies.aicc)

Are you sure especies.aicc is defined as numeric?

b

On Jan 9, 2007, at 10:51 AM, Milton Cezar Ribeiro wrote:

 Dear Peter,

   I tryed something like

 head(especies.aicc)
  especie aicc
 1 Attila.rufus 17.15934
 2 Attila.rufus 11.41371
 3 Attila.rufus 11.41371
 4 Attila.rufus 19.55998
 5 Attila.rufus 17.23780
 6 Attila.rufus 19.22545

 especies.min-aggregate.data.frame(especies.aicc,list
  (Especie=especies.aicc$especie),max)

   But it works fine only for mean FUN and not for min and  
 max. Also also, when I use mean I got the following warnings:

 especies.min-aggregate.data.frame(especies.aicc,list
  (Especie=especies.aicc$especie),mean)

   Warning messages:
 1: argument is not numeric or logical: returning NA in: mean.default 
 (X[[1]], ...)
 2: argument is not numeric or logical: returning NA in: mean.default 
 (X[[2]], ...)

   In fact I need only min() and max().

   Miltinho
   -

 Peter Dalgaard [EMAIL PROTECTED] escreveu:
   Milton Cezar Ribeiro wrote:
 Hi R-friends

 I don´t know why the min() function below return the min value  
 as factor. When i force the aicc.min using a as.numeric()  
 function, it return a factor index (1,2,..) and not min value as I  
 want. By the way, I included a sessionInfo() at the end of this e- 
 mail.

 min() is not doing anything out of the ordinary, but cbind'ing it with
 the character vector sp coerces it to character and rbind'ing to a  
 data
 frame turns character vectors into factors...

 The whole thing looks like it could be a straightforward  
 application of
 aggregate().

 In fact I had the same problem (values as factor) on other part of  
 my script and I noticed that it occour when I use cbind(). It is  
 real?

 Any idea?

 Kind regards,

 Miltinho

 especies.aicc.min-data.frame()

 for (sp in levels(especies.aicc$especie))

 + {
 + sele-subset(especies.aicc,especie==sp)
 + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min 
 (sele$aicc)))
 + }

 especies.aicc.min

 sp aicc.min
 1 Attila.rufus 6.7387056413613
 2 Automolus.leucophthalmus 125.791300522824

 class(especies.aicc.min$aicc.min)

 [1] factor

 ---
 sessionInfo()
 R version 2.4.0 (2006-10-03)
 i386-pc-mingw32
 locale:
 LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica. 
 1252;LC_MONETARY=English_Jamaica. 
 1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252
 attached base packages:
 [1] methods stats graphics grDevices utils datasets  
 base





 -- 
 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




  __


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

__
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.