Re: [R] ggplot and boxplots

2018-03-12 Thread Richard M. Heiberger
It looks like your V3 is a factor.

testing_ggplot <- data.frame(
  V1=factor(c(256, 256, 256, 272, 272, 272)),
  V2=c("Disabled", "Disabled", "Enabled", "Disabled", "Enabled", "Enabled"),
  V3=681:686)

library(ggplot2)
ggplot(testing_ggplot, aes(V2,V3 )) + geom_boxplot() +
facet_wrap( ~ V1) + labs(title="what you want")
ggplot(testing_ggplot, aes(V2, factor(V3))) + geom_boxplot() +
facet_wrap( ~ V1) + labs(title="what you are getting")

On Mon, Mar 12, 2018 at 4:28 PM, Yectli Huerta via R-help
 wrote:
> Hi,
>
> I was wondering if someone could give me a hint or two. I'm having problems 
> generating ggplot2 boxplots . The plot that is has dots but no boxplots. 
> Below is the dataset
>
>> testing_ggplot
> V1V2 V3
> 1  256  Disabled 688.61
> 2  256  Disabled 698.63
> 3  256  Disabled 700.02
> 4  256  Disabled 693.36
> 5  256  Disabled  688.8
> 6  256  Disabled 697.72
> 7  256  Disabled 698.15
> 8  256  Disabled 693.98
> 9  256  Disabled 700.75
> ...
> 16 256   Enabled 698.35
> 17 256   Enabled 694.71
> 18 256   Enabled 705.53
> 19 256   Enabled 708.61
> 20 256   Enabled 693.33
> ...
> 32 272  Disabled 690.79
>
> 33 272  Disabled 687.14
> 34 272  Disabled 684.92
> 35 272  Disabled 687.87
> 36 272  Disabled 687.33
> 37 272   Enabled 696.22
> 38 272   Enabled 700.61
> 39 272   Enabled  695.2
> 40 272   Enabled 697.46
> 41 272   Enabled 696.83
> ...
>
> This command for some reason, fails to generate a boxplot
>> ggplot(testing_ggplot,aes(factor(V2),V3))+geom_boxplot() 
>> +facet_wrap(~as.factor(V1))
>
> I don't seem to figure out what is wrong with the ggplot command I'm using. I 
> attached a png with the generated plot
>
> thanks,
>
> yh
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bug report: override stopifnot() ?

2018-03-12 Thread Duncan Murdoch

On 12/03/2018 2:43 PM, Bert Gunter wrote:

Please stop this line of queries/"suggestions/speculations and read the
relevant docs **carefully**.

For example, from ?"=="

"Note

Do not use == and != for tests, such as in if expressions, where you must
get a single TRUE or FALSE. Unless you are absolutely sure that nothing
unusual can happen, you should use the identical
 function instead.
"


But stopifnot(expr) is not a test where you must get a single TRUE or 
FALSE.  See the Details section on its help page, or read its 
Description carefully (where "all" is used in the technical sense of the 
all() function), ignoring the final few words which seem to suggest that 
c(TRUE, TRUE) is not okay.


Duncan Murdoch



So you have already violated that specific warning, which led to the
confusion you evidence. Specifically:

Matrix(1)== Matrix(1)

1 x 1 Matrix of class "lsyMatrix"
  [,1]
[1,] TRUE

That is, the result is not a logical but a (S4) object of class "lsyMatrix"
that contains a logical. Whence your (expected) error message.

Cheers,

Bert





Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Mar 12, 2018 at 10:53 AM, Stepan Kasal  wrote:


Hello,

On Mon, Mar 12, 2018 at 09:30:59AM -0700, William Dunlap wrote:

Why don't you use
stopifnot( all(m1 == m2) )
?


good question.  Even though I use
aseert np.all(m1 == m2)
when working with NumPy, I got accustomed to the "handy shortcut"
that I can omit all() with R vectors and matrices.

Then I got trapped with the thing I reported.

On a second thought, omitting all() might have been bad idea from
the beginning; I should rather write all() routinely.
(It also reminds me that all.equal() is the right one in most cases.)

Is it true that using stopifnot() with non-scalar is considerd bad style?

If yes, could be perhaps stopifnot() enhanced to issue a warning to
teach new users of R, at least when they start using library(Matrix)?

If not, then enhancing stopifnot() to handle the case may be a good idea.

I also noticed the following:


a <- Matrix(1)
stopifnot(a == a)

Error: a == a is not TRUE

if(a==a)print(1)

Error in if (a == a) print(1) : argument is not interpretable as logical

Neither does work, but the first error message is much more confusing.

When thinking about it, stopifnot() should really issue a better error
message in this case.  Patch attached.  But I should perhaps send
it also to R-devel.

Stepan Kasal



On Mon, Mar 12, 2018 at 8:15 AM, Stepan Kasal  wrote:


Hello,
I stumbled over a problem:
stopifnot(m1 == m2)

It works with vector or matrix, but does not work for classes from

Matrix

package.

In the source of stopifnot(), there is all(m1 == m2) that would just

work,

but there is also is.logical(m1 == m2) that id FALSE.

Would it be possible if Matrix package redefined stopifnot() ?

(If there is a bug tracking database for package Matrix, I would be

happy

to insert this report there.)

Thank you very much for the package,
 Stepan Kasal

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] ggplot and boxplots

2018-03-12 Thread Yectli Huerta via R-help
Hi,

I was wondering if someone could give me a hint or two. I'm having problems 
generating ggplot2 boxplots . The plot that is has dots but no boxplots. Below 
is the dataset

> testing_ggplot
V1V2 V3
1  256  Disabled 688.61
2  256  Disabled 698.63
3  256  Disabled 700.02
4  256  Disabled 693.36
5  256  Disabled  688.8
6  256  Disabled 697.72
7  256  Disabled 698.15
8  256  Disabled 693.98
9  256  Disabled 700.75
...
16 256   Enabled 698.35
17 256   Enabled 694.71
18 256   Enabled 705.53
19 256   Enabled 708.61
20 256   Enabled 693.33
...
32 272  Disabled 690.79

33 272  Disabled 687.14
34 272  Disabled 684.92
35 272  Disabled 687.87
36 272  Disabled 687.33
37 272   Enabled 696.22
38 272   Enabled 700.61
39 272   Enabled  695.2
40 272   Enabled 697.46
41 272   Enabled 696.83
...

This command for some reason, fails to generate a boxplot
> ggplot(testing_ggplot,aes(factor(V2),V3))+geom_boxplot() 
> +facet_wrap(~as.factor(V1))

I don't seem to figure out what is wrong with the ggplot command I'm using. I 
attached a png with the generated plot

thanks,

yh__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Gabor Grothendieck
split any mixed columns into letter and number columns
and then order can be used on that:

  DF <- data.frame(x = c("a10", "a2", "a1"))
  o <- do.call("order", transform(DF, let = gsub("\\d", "", x),
 no =
as.numeric(gsub("\\D", "", x)),
 x = NULL))
  DF[o,, drop = FALSE ]


On Mon, Mar 12, 2018 at 12:15 AM, Sebastien Bihorel
 wrote:
> Hi,
>
> Searching for functions that would order strings that mix characters and 
> numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found 
> the mixedsort and mixedorder from the gtools package.
>
> Problems:
> 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like 
> the order function does
> 2- gtools has not been updated in 2.5 years
>
> Are you aware of an equivalent of this function in base R or a another 
> contributed package (with correction of problem #1)?
>
> Thanks
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-es] Alternativa a rrefine

2018-03-12 Thread Javier Marcuzzi
Estimado Freddy Omar López Quintero

Me llama la atención que google deje su producto, hay dos posibilidades, un
problema serio o solo ofrecen la solución dentro de sus herramientas para
bigdata, habría que explorar lo que ofrecen como producto pago o de prueba.

Mi experiencia es estar un mes acomodando unos datos de una consultora para
ser analizados, muy feo porque me rompí la cabeza, si es por el tiempo y el
cobro me dio en rojo, por mi demora creo que dudaban de mí, logré
entregarlo y les gustó, luego contrataron a un grupo informático, paso
mucho tiempo, de casualidad me encuentro con el propietario de la empresa y
me comenta con afecto algunos problemas con informáticos, el acomodar los
datos a mano me llevó a conocer perfectamente esas cosas que a la vista no
son fáciles de visualizar porque todos dicen que hicieron bien su trabajo,
pero me dejó muy bien parado como profesional, cobré lo acordado, pude dar
un resultado, no oculté el problema descartando datos, y lo mejor que me
digan "te estafan", yo no soy el mejor, pero acomodando a mano conocí los
datos y a partir de eso llegué a un lugar donde los otros no llegaron, al
reconocimiento con afecto del que paga los sueldos y contrata profesionales.

Javier Rubén Marcuzzi

El 12 de marzo de 2018, 11:53, Freddy Omar López Quintero <
freddy.lopez.quint...@gmail.com> escribió:

> ¡Hola!
>
> Espero que estén muy bien.
>
> Consulta: ¿alguno tiene experiencia (y que la pueda compartir) utilizando
> alguna alternativa a rrefine (
> https://cran.r-project.org/web/packages/rrefine/
> vignettes/rrefine-vignette.html
> )?
>
> He utilizado rrefine y open refine (http://openrefine.org/) en general
> para
> corregir conjuntos de datos chicos, pero ya cuando los datos son demasiados
> para ocupar un csv, no me parece la mejor opción y por eso es mi inquietud.
>
> ¡Muchas gracias!
>
> --
> «...homines autem hominum causa esse generatos...»
>
> Cicero
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R] Error - PMML Conversion of a Random-Forest Model using the randomForest Package

2018-03-12 Thread Karthiko S
Hi All,

I am trying to convert random forest model developed into a pmml file.
randomForest package was used to build the model. The input to the model is
in the form of a matrix (term frequency matrix used for text analytics).
While i try to convert the model into a pmml file  an error pops.

Error in names (field$class) <-var.names
attempt to set an attribute on NULL

Would be great if anyone could please help me in over-coming this error.

Thanks and Regards
Karthik

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bug report: override stopifnot() ?

2018-03-12 Thread Bert Gunter
Please stop this line of queries/"suggestions/speculations and read the
relevant docs **carefully**.

For example, from ?"=="

"Note

Do not use == and != for tests, such as in if expressions, where you must
get a single TRUE or FALSE. Unless you are absolutely sure that nothing
unusual can happen, you should use the identical
 function instead.
"

So you have already violated that specific warning, which led to the
confusion you evidence. Specifically:
> Matrix(1)== Matrix(1)
1 x 1 Matrix of class "lsyMatrix"
 [,1]
[1,] TRUE

That is, the result is not a logical but a (S4) object of class "lsyMatrix"
that contains a logical. Whence your (expected) error message.

Cheers,

Bert





Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Mar 12, 2018 at 10:53 AM, Stepan Kasal  wrote:

> Hello,
>
> On Mon, Mar 12, 2018 at 09:30:59AM -0700, William Dunlap wrote:
> > Why don't you use
> >stopifnot( all(m1 == m2) )
> > ?
>
> good question.  Even though I use
>aseert np.all(m1 == m2)
> when working with NumPy, I got accustomed to the "handy shortcut"
> that I can omit all() with R vectors and matrices.
>
> Then I got trapped with the thing I reported.
>
> On a second thought, omitting all() might have been bad idea from
> the beginning; I should rather write all() routinely.
> (It also reminds me that all.equal() is the right one in most cases.)
>
> Is it true that using stopifnot() with non-scalar is considerd bad style?
>
> If yes, could be perhaps stopifnot() enhanced to issue a warning to
> teach new users of R, at least when they start using library(Matrix)?
>
> If not, then enhancing stopifnot() to handle the case may be a good idea.
>
> I also noticed the following:
>
> > a <- Matrix(1)
> > stopifnot(a == a)
> Error: a == a is not TRUE
> > if(a==a)print(1)
> Error in if (a == a) print(1) : argument is not interpretable as logical
>
> Neither does work, but the first error message is much more confusing.
>
> When thinking about it, stopifnot() should really issue a better error
> message in this case.  Patch attached.  But I should perhaps send
> it also to R-devel.
>
> Stepan Kasal
>
>
> > On Mon, Mar 12, 2018 at 8:15 AM, Stepan Kasal  wrote:
> >
> > > Hello,
> > > I stumbled over a problem:
> > >stopifnot(m1 == m2)
> > >
> > > It works with vector or matrix, but does not work for classes from
> Matrix
> > > package.
> > >
> > > In the source of stopifnot(), there is all(m1 == m2) that would just
> work,
> > > but there is also is.logical(m1 == m2) that id FALSE.
> > >
> > > Would it be possible if Matrix package redefined stopifnot() ?
> > >
> > > (If there is a bug tracking database for package Matrix, I would be
> happy
> > > to insert this report there.)
> > >
> > > Thank you very much for the package,
> > > Stepan Kasal
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bug report: override stopifnot() ?

2018-03-12 Thread Stepan Kasal
Hello,
I'm sorry that I aswer to my own mail; I forgot to attach the patch.
Patch below,
   Stepan Kasal

On Mon, Mar 12, 2018 at 06:53:00PM +0100, Stepan Kasal wrote:
> When thinking about it, stopifnot() should really issue a better error
> message in this case.  Patch attached.  But I should perhaps send
> it also to R-devel.


--- stopifnot-orig.r2018-03-12 18:49:01.439484100 +0100
+++ stopifnot.r 2018-03-12 18:48:55.721846700 +0100
@@ -1,16 +1,20 @@
-function (...)
+function (...) 
 {
   n <- length(ll <- list(...))
-  if (n == 0L)
+  if (n == 0L) 
 return(invisible())
   mc <- match.call()
-  for (i in 1L:n) if (!(is.logical(r <- ll[[i]]) && !anyNA(r) &&
+  for (i in 1L:n) if (!(is.logical(r <- ll[[i]]) && !anyNA(r) && 
 all(r))) {
 ch <- deparse(mc[[i + 1]], width.cutoff = 60L)
-if (length(ch) > 1L)
+if (length(ch) > 1L) 
   ch <- paste(ch[1L], "")
-stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all TRUE"),
-  ch), call. = FALSE, domain = NA)
+if (is.logical(r)) {
+  msg <- ngettext(length(r), "%s is not TRUE", "%s are not all TRUE")
+} else {
+  msg <- gettext("%s is not of type \"logical\"")
+}
+stop(sprintf(msg, ch), call. = FALSE, domain = NA)
   }
   invisible()
 }

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bug report: override stopifnot() ?

2018-03-12 Thread Stepan Kasal
Hello,

On Mon, Mar 12, 2018 at 09:30:59AM -0700, William Dunlap wrote:
> Why don't you use
>stopifnot( all(m1 == m2) )
> ?

good question.  Even though I use
   aseert np.all(m1 == m2)
when working with NumPy, I got accustomed to the "handy shortcut"
that I can omit all() with R vectors and matrices.

Then I got trapped with the thing I reported.

On a second thought, omitting all() might have been bad idea from
the beginning; I should rather write all() routinely.
(It also reminds me that all.equal() is the right one in most cases.)

Is it true that using stopifnot() with non-scalar is considerd bad style?

If yes, could be perhaps stopifnot() enhanced to issue a warning to
teach new users of R, at least when they start using library(Matrix)?

If not, then enhancing stopifnot() to handle the case may be a good idea.

I also noticed the following:

> a <- Matrix(1)
> stopifnot(a == a)
Error: a == a is not TRUE
> if(a==a)print(1)
Error in if (a == a) print(1) : argument is not interpretable as logical

Neither does work, but the first error message is much more confusing.

When thinking about it, stopifnot() should really issue a better error
message in this case.  Patch attached.  But I should perhaps send
it also to R-devel.

Stepan Kasal


> On Mon, Mar 12, 2018 at 8:15 AM, Stepan Kasal  wrote:
> 
> > Hello,
> > I stumbled over a problem:
> >stopifnot(m1 == m2)
> >
> > It works with vector or matrix, but does not work for classes from Matrix
> > package.
> >
> > In the source of stopifnot(), there is all(m1 == m2) that would just work,
> > but there is also is.logical(m1 == m2) that id FALSE.
> >
> > Would it be possible if Matrix package redefined stopifnot() ?
> >
> > (If there is a bug tracking database for package Matrix, I would be happy
> > to insert this report there.)
> >
> > Thank you very much for the package,
> > Stepan Kasal
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Sebastien Bihorel

Thanks for your reply. I take this is also a no to my question and appreciated 
the suggested mixedrank function and its usage with do.call.

Thanks


- Original Message -
From: "Jeff Newmiller" 
To: "Bert Gunter" 
Cc: "Sebastien Bihorel" , "R-help" 

Sent: Monday, March 12, 2018 2:11:03 AM
Subject: Re: [R] Equivalent of gtools::mixedsort in R base

x <- c( "a1", "a10", "a2" )
y <- c( "b10", "b2", "a12", "ca1" )

DF <- expand.grid( x = x, y = y )
# randomize
set.seed( 42 )
DF <- DF[ sample( nrow( DF ) ), ]

# missing from gtools
mixedrank <- function( x ) {
   seq.int( length( x ) )[ gtools::mixedorder(x) ]
}

o <- do.call( order, lapply( DF, mixedrank ) )
DF[ o, ]

# or, as Bert suggests:

myrank <- function( v ) {
   vu <- unique(v)
   vl <- regmatches( vu,regexec("^([A-Za-z]+)(\\d+)$",vu))
   alph <- sapply( vl, function(s) s[2] )
   digt <- as.integer( sapply( vl, function(s) s[3] ) )
   o <- order( alph, digt )
   vo <- ordered( v, levels=vu[ o ] )
}

o2 <- do.call( order, lapply( DF, myrank ) )
DF[ o2, ]

?order
?ordered
?rank

On Sun, 11 Mar 2018, Bert Gunter wrote:

> ???
>
>> y <- sort( c("a1","a2","a10","a12","a100"))
>> y
> [1] "a1"   "a10"  "a100" "a12"  "a2"
>> mixedsort(y)
> [1] "a1"   "a2"   "a10"  "a12"  "a100"
>
> **Please read the docs!** They say that mixedsort() and mixedorder()  both
> take a **single vector**  as the argument to be sorted or ordered and, as
> the above indicates, they perform exactly as advertised. **Unlike
> order()**. So of course your do.call() construction fails.
>
> So presumably you have a data frame with multiple columns of mixed alpha
> and numerics?  (A reproducible example would be most helpful here.)
>
> If this is the case, one **possibly dumb** approach (you have been warned!)
> would be to turn each column into an ordered factor and then call order()
> on the data frame of ordered factors via do.call() as above. i.e.
>
>> y1 <- ordered(y,lev = mixedsort(y))
>> y1
> [1] a1   a10  a100 a12  a2
> Levels: a1 < a2 < a10 < a12 < a100
>> order(y1)
> [1] 1 5 2 4 3
>
> (this is just for 1 vector to show how the idea would work).
>
> Of course, if this is **not** what you want, you'll need to clarify,
> hopefully with a reprex. Or hope that someone else has better insight than
> I.
>
> Cheers,
> Bert
>
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel <
> sebastien.biho...@cognigencorp.com> wrote:
>
>> Hi,
>>
>> Searching for functions that would order strings that mix characters and
>> numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I
>> found the mixedsort and mixedorder from the gtools package.
>>
>> Problems:
>> 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call
>> like the order function does
>> 2- gtools has not been updated in 2.5 years
>>
>> Are you aware of an equivalent of this function in base R or a another
>> contributed package (with correction of problem #1)?
>>
>> Thanks
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Sebastien Bihorel
Hi, 

Point taken... although this error is not returned in older version of R (3.1.2 
does not have any issue with your test case... not sure when the added layer of 
check was introduced). 


From: "William Dunlap"  
To: "Sebastien Bihorel"  
Cc: r-help@r-project.org 
Sent: Monday, March 12, 2018 10:56:43 AM 
Subject: Re: [R] Equivalent of gtools::mixedsort in R base 

1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like 
the order function does 

This is tangential, but do.call(order, mydataframe) is not safe to use in a 
general purpose function either - you need to remove the names from 
the second argument: 
> d <- data.frame(method=c("New","New","Old","Old","Old"), result=5:1) 
> do.call(order, d) 
Error in match.arg(method) : 'arg' must be NULL or a character vector 
> do.call(order, unname(as.list(d))) 
[1] 2 1 5 4 3 


Bill Dunlap 
TIBCO Software 
wdunlap [ http://tibco.com/ | tibco.com ] 

On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel < [ 
mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com 
] > wrote: 


Hi, 

Searching for functions that would order strings that mix characters and 
numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found 
the mixedsort and mixedorder from the gtools package. 

Problems: 
1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like 
the order function does 
2- gtools has not been updated in 2.5 years 

Are you aware of an equivalent of this function in base R or a another 
contributed package (with correction of problem #1)? 

Thanks 

__ 
[ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To 
UNSUBSCRIBE and more, see 
[ https://stat.ethz.ch/mailman/listinfo/r-help | 
https://stat.ethz.ch/mailman/listinfo/r-help ] 
PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html 
| http://www.R-project.org/posting-guide.html ] 
and provide commented, minimal, self-contained, reproducible code. 





[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Sebastien Bihorel

So I take this is a no to my initial question. 

Cheers too. 

PS: some users just ask questions to get straight answers not to get a solution 
to their problem :D 


From: "Bert Gunter"  
To: "Sebastien Bihorel"  
Cc: "R-help"  
Sent: Monday, March 12, 2018 12:57:00 AM 
Subject: Re: [R] Equivalent of gtools::mixedsort in R base 

??? 

> y <- sort( c("a1","a2","a10","a12","a100")) 
> y 
[1] "a1" "a10" "a100" "a12" "a2" 
> mixedsort(y) 
[1] "a1" "a2" "a10" "a12" "a100" 

**Please read the docs!** They say that mixedsort() and mixedorder() both take 
a **single vector** as the argument to be sorted or ordered and, as the above 
indicates, they perform exactly as advertised. **Unlike order()**. So of course 
your do.call() construction fails. 

So presumably you have a data frame with multiple columns of mixed alpha and 
numerics? (A reproducible example would be most helpful here.) 

If this is the case, one **possibly dumb** approach (you have been warned!) 
would be to turn each column into an ordered factor and then call order() on 
the data frame of ordered factors via do.call() as above. i.e. 

> y1 <- ordered(y,lev = mixedsort(y)) 
> y1 
[1] a1 a10 a100 a12 a2 
Levels: a1 < a2 < a10 < a12 < a100 
> order(y1) 
[1] 1 5 2 4 3 

(this is just for 1 vector to show how the idea would work). 

Of course, if this is **not** what you want, you'll need to clarify, hopefully 
with a reprex. Or hope that someone else has better insight than I. 

Cheers, 
Bert 




Bert Gunter 

"The trouble with having an open mind is that people keep coming along and 
sticking things into it." 
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) 

On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel < [ 
mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com 
] > wrote: 


Hi, 

Searching for functions that would order strings that mix characters and 
numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found 
the mixedsort and mixedorder from the gtools package. 

Problems: 
1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like 
the order function does 
2- gtools has not been updated in 2.5 years 

Are you aware of an equivalent of this function in base R or a another 
contributed package (with correction of problem #1)? 

Thanks 

__ 
[ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To 
UNSUBSCRIBE and more, see 
[ https://stat.ethz.ch/mailman/listinfo/r-help | 
https://stat.ethz.ch/mailman/listinfo/r-help ] 
PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html 
| http://www.R-project.org/posting-guide.html ] 
and provide commented, minimal, self-contained, reproducible code. 





[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bug report: override stopifnot() ?

2018-03-12 Thread William Dunlap via R-help
Why don't you use
   stopifnot( all(m1 == m2) )
?

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Mar 12, 2018 at 8:15 AM, Stepan Kasal  wrote:

> Hello,
> I stumbled over a problem:
>stopifnot(m1 == m2)
>
> It works with vector or matrix, but does not work for classes from Matrix
> package.
>
> In the source of stopifnot(), there is all(m1 == m2) that would just work,
> but there is also is.logical(m1 == m2) that id FALSE.
>
> Would it be possible if Matrix package redefined stopifnot() ?
>
> (If there is a bug tracking database for package Matrix, I would be happy
> to insert this report there.)
>
> Thank you very much for the package,
> Stepan Kasal
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bug report: override stopifnot() ?

2018-03-12 Thread Stepan Kasal
Hello,
I stumbled over a problem:
   stopifnot(m1 == m2)

It works with vector or matrix, but does not work for classes from Matrix 
package.

In the source of stopifnot(), there is all(m1 == m2) that would just work,
but there is also is.logical(m1 == m2) that id FALSE.

Would it be possible if Matrix package redefined stopifnot() ?

(If there is a bug tracking database for package Matrix, I would be happy to 
insert this report there.)

Thank you very much for the package,
Stepan Kasal

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-es] Contar categorías después de ciertos valores

2018-03-12 Thread Guillermo.Vinue
Muchas gracias Carlos y Javier por la ayuda.

Saludos,

Guillermo

> Hola,
> 
> Esta es una forma...
> 
> #-
> 
> x <- c(3, "A", "B", 5, "A", 4, 5, "A", "A", 3)
> x_n <- as.numeric(x)
> 
> cat_val <- unique(x[is.na(x_n)])
> num_val <- x_n[!is.na(x_n)]
> 
> df <- data.frame(
>   x_n = x_n,
>   y = 1:length(x_n),
>   x = x,
>   x_l = is.na(df$x_n)
>  )
> 
> num_df <- data.frame( nume = 0, letra = 0)
> cont <- 0
> for(i in 1:nrow(df)) {
>   if (df[i, 4] == FALSE & df[i + 1, 4] != FALSE & i < nrow(df)) {
> num <- df[i, 1]
>   }
>   if (df[i, 4] != FALSE) {
> cont <- cont + 1
> num_df[cont, 1]  <-  num
> num_df[cont, 2] <- as.vector(df[i, 3])
>   }
>   if (df[i, 4] == FALSE & df[i + 1, 4] == FALSE & i < nrow(df)) {
> cont <- cont + 1
> num <- df[i, 1]
> num_df[cont, 1] <-  num
> num_df[cont, 2] <- 0
>   }
> 
> }
> 
> 
> library(dplyr)
> library(tidyr)
> 
> res_df <- num_df %>%
>   group_by(nume, letra) %>%
>   summarize( res = n()) %>%
>   spread( letra, res)
> 
> res_df[is.na(res_df)] <- 0
> res_df
> 
> #-
> 
> 
> Que produce este resultado:
> 
> > res_df
> # A tibble: 3 x 4
> # Groups:   nume [3]
>nume   `0` A B
>  
> 13.0.1.1.
> 24.1.0.0.
> 35.0.3.0.
> 
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
> 
> 
> El 9 de marzo de 2018, 16:02,  escribió:
> 
> > Hola,
> >
> > Estoy intentando averiguar cómo contar el número de categorías situadas
> > después de ciertos valores. Por ejemplo, en el siguiente vector:
> >
> > x <- c(3, "A", "B", 5, "A", 4, 5, "A", "A", 3)
> >
> > el resultado que quisiera obtener es:
> >
> > Valor -> Resultado
> > 3 -> 1 A y 1 B
> > 4 -> 0 A y 0 B
> > 5 -> 3 A y 0 B
> >
> > ¿Alguien tiene alguna sugerencia?.
> >
> > Muchas gracias de antemano.
> >
> > Guillermo
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
> 
> 
> 
> -- 
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
> 

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread William Dunlap via R-help
   1- mixedorder does not work in a "do.call(mixedorder, mydataframe)"
call like the order function does

This is tangential, but do.call(order, mydataframe) is not safe to use in a
general purpose function either - you need to remove the names from
the second argument:
  > d <- data.frame(method=c("New","New","Old","Old","Old"), result=5:1)
  > do.call(order, d)
  Error in match.arg(method) : 'arg' must be NULL or a character vector
  > do.call(order, unname(as.list(d)))
  [1] 2 1 5 4 3


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel <
sebastien.biho...@cognigencorp.com> wrote:

> Hi,
>
> Searching for functions that would order strings that mix characters and
> numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I
> found the mixedsort and mixedorder from the gtools package.
>
> Problems:
> 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call
> like the order function does
> 2- gtools has not been updated in 2.5 years
>
> Are you aware of an equivalent of this function in base R or a another
> contributed package (with correction of problem #1)?
>
> Thanks
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-es] Alternativa a rrefine

2018-03-12 Thread Freddy Omar López Quintero
¡Hola!

Espero que estén muy bien.

Consulta: ¿alguno tiene experiencia (y que la pueda compartir) utilizando
alguna alternativa a rrefine (
https://cran.r-project.org/web/packages/rrefine/vignettes/rrefine-vignette.html
)?

He utilizado rrefine y open refine (http://openrefine.org/) en general para
corregir conjuntos de datos chicos, pero ya cuando los datos son demasiados
para ocupar un csv, no me parece la mejor opción y por eso es mi inquietud.

¡Muchas gracias!

-- 
«...homines autem hominum causa esse generatos...»

Cicero

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R] Package gamlss used inside foreach() and %dopar% fails to find an object

2018-03-12 Thread Nik Tuzov

Hello Mikis:

Thanks a lot, it worked. Could you tell me what the problem was?

Regards,
Nik


- Original Message -
From: r-help-requ...@r-project.org
To: "r-help" 
Sent: Sunday, March 11, 2018 6:00:02 AM
Subject: R-help Digest, Vol 181, Issue 11

Send R-help mailing list submissions to
r-help@r-project.org

To subscribe or unsubscribe via the World Wide Web, visit
https://stat.ethz.ch/mailman/listinfo/r-help
or, via email, send a message with subject or body 'help' to
r-help-requ...@r-project.org

You can reach the person managing the list at
r-help-ow...@r-project.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of R-help digest..."


Today's Topics:

   1. . Package gamlss used inside foreach() and %dopar% fails to
  find an object (Nik Tuzov) (Dimitrios Stasinopoulos)
   2. error message from sqldf (Ding, Yuan Chun)
   3. Re: error message from sqldf
  (=?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos)

--

Message: 1
Date: Sat, 10 Mar 2018 13:34:59 +
From: Dimitrios Stasinopoulos 
To: r-help@r-project.org
Cc: Nik ntuzov.com>
Subject: [R] . Package gamlss used inside foreach() and %dopar% fails
to find an object (Nik Tuzov)
Message-ID:
<424dc535-4caf-4dd5-8bd5-eb19bf6f7...@staff.londonmet.ac.uk>
Content-Type: text/plain; charset="utf-8"

Dear Nik 

Try the following code 


loo_predict.mu <- function(model.obj, input.data) {
  yhat <- foreach(i = 1 : nrow(input.data), .packages="gamlss", .combine = 
rbind) %dopar% {
updated.model.obj <- update(model.obj, data = input.data[-i, ])
predict(updated.model.obj, what = "mu", data = input.data[-i, ],
newdata = input.data[i,], type = "response")
  }
  return(data.frame(result = yhat[, 1], row.names = NULL))
}

par.run <- loo_predict.mu(model3, input.processed.cut)

The predict command in this case also need the old data.

Thanks
Mikis 



Prof Dimitrios Mikis Stasinopoulos
stasi...@staff.londonmet.ac.uk




[[alternative HTML version deleted]]




--

Message: 2
Date: Sat, 10 Mar 2018 21:30:42 +
From: "Ding, Yuan Chun" 
To: "r-help@r-project.org" 
Subject: [R] error message from sqldf
Message-ID:
coh.org>
Content-Type: text/plain; charset="utf-8"

Dear R users,

I got the following error message from running sqldf code in R.   do you know 
how to fix it?  I read the sqldf package instruction and did not find a 
solution.

Thank you,

Ding

chr10 <- sqldf("select * from manifest where CHR==10")

UCN3cpg <-  sqldf("select * from chr10 where MAPINFO between 5405573 and 
5407594),
overwrite = TRUE")
Error: Table chr10 exists in database, and both overwrite and append are FALSE


>





-
-SECURITY/CONFIDENTIALITY WARNING-
This message (and any attachments) are intended solely f...{{dropped:22}}




--

Message: 3
Date: Sat, 10 Mar 2018 16:53:35 -0500
From: =?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos 
To: r-help@r-project.org
Subject: Re: [R] error message from sqldf
Message-ID: <20180310215335.GD5049@equipaje>
Content-Type: text/plain; charset="iso-8859-1"

On Sat, Mar 10, 2018 at 09:30:42PM +, Ding, Yuan Chun wrote:
> chr10 <- sqldf("select * from manifest where CHR==10")
> 
> UCN3cpg <-  sqldf("select * from chr10 where MAPINFO between 5405573 and 
> 5407594),
> overwrite = TRUE")
> Error: Table chr10 exists in database, and both overwrite and append are FALSE

Could it be that `chr10` already exists when you try to run your code. 
What about rewriting it as:

chr10 <- sqldf("select * from manifest where CHR==10", overwrite = TRUE)

Also, it seems to me that the second line is not closing the quotes 
properly. Shouldn't this be correct instead?

UCN3cpg <-  sqldf("select * from chr10 where MAPINFO between 5405573 and 
5407594",
  overwrite = TRUE)

Cheers,

-- 
José María (Chema) Mateos
https://rinzewind.org/blog-es || https://rinzewind.org/blog-en




--

Subject: Digest Footer

___
R-help@r-project.org 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.


--

End of R-help Digest, Vol 181, Issue 11

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Help on Aggregation

2018-03-12 Thread PIKAL Petr
Hi

The first question is simple. You should use aggregate and cut but first you 
need to transfer your data to date/time format by strptime.

test<-read.table("clipboard", header=T)
test$cas<-strptime(paste(test$Date, test$Time), format="%Y/%m/%d %H:%M:%S")

Below is the data.

aggregate(test[,4:6], list(cut(test$cas, "days")), mean, na.rm=T)
 Group.1   Temp_C Pressure_kPa   RH
1 2014-03-28 32.25714 95.94286 54.21429
2 2014-03-29 32.23750 96.09167 59.29583
3 2014-03-30 27.35000 96.05000 83.15000

The second one is difficult if impossible to answer.

read.csv(file.choose(),header=TRUE)
This seems to be OK. So my guess is that the original file is not csv or that 
it has some hidden characters elsewhere.

Cheers
Petr

dput(test)
structure(list(Neph_no = c(9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L
), Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = 
c("2014/03/28",
"2014/03/29", "2014/03/30"), class = "factor"), Time = structure(c(11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 1L, 2L, 3L), .Label = 
c("00:00:00",
"01:00:00", "02:00:00", "03:00:00", "04:00:00", "05:00:00", "06:00:00",
"07:00:00", "08:00:00", "09:00:00", "10:00:00", "11:00:00", "12:00:00",
"13:00:00", "14:00:00", "15:00:00", "16:00:00", "17:00:00", "18:00:00",
"19:00:00", "20:00:00", "21:00:00", "22:00:00", "23:00:00"), class = "factor"),
Temp_C = c(38.4, 37.8, 36.7, 35.4, 34.1, 32.7, 31.8, 31.2,
30.6, 29.8, 29.1, 28.6, 28, 27.4, 27, 27.1, 27, 27.8, 30.4,
33.7, 36.3, 37.7, 38.7, 38.9, 39.4, 38.9, 38.2, 37.4, 35.8,
33.9, 31.4, 29.4, 29, 26.5, 27, 27.5, 27.4, 27.3, 27.1, 27.6,
27.8), Pressure_kPa = c(95.9, 95.8, 95.8, 95.8, 95.8, 95.9,
96, 96, 96.1, 96.1, 96.1, 96, 96, 95.9, 96, 96, 96.1, 96.1,
96.2, 96.3, 96.3, 96.3, 96.3, 96.1, 96, 95.9, 95.8, 95.8,
95.9, 96, 96.1, 96.3, 96.3, 96.2, 96.1, 96.1, 96, 96, 96,
96.1, 96.1), RH = c(29.7, 29.2, 35.1, 38.9, 44, 52.9, 55.1,
57.8, 62.1, 68.1, 69.5, 68.3, 71.9, 76.4, 80.6, 80.4, 80.5,
78.1, 66.8, 54, 45, 38.8, 34.7, 32.6, 30.2, 31.5, 33.8, 35.4,
39.5, 46.9, 59.8, 72.9, 69.6, 81.7, 82.9, 81.7, 82.6, 83.1,
84.5, 81.8, 81), cas = structure(list(sec = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), hour = c(10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L,
2L), mday = c(28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L), mon = c(2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), year = c(114L, 114L,
114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L,
114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L,
114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L,
114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L), wday = c(5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 0L, 0L, 0L), yday = c(86L, 86L,
86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L,
87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L,
87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L,
88L, 88L, 88L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, -1L), zone = c("CET", "CET", "CET", "CET", "CET",
"CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET",
"CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET",
"CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET",
"CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", ""
), gmtoff = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, 

[R] Help on Aggregation

2018-03-12 Thread Emeka Don
Dear All,
1.I have been trying to aggregate my data but I have not been getting it
correctly. In the data I want to convert hourly data into daily averages.
Here is a sample of the data:
Neph_no Date Time Temp_C   Pressure_kPa RH
9   2014/03/28  10:00:00 38.4 95.9 29.7
9   2014/03/28  11:00:00 37.8 95.8 29.2
9   2014/03/28  12:00:00 36.7 95.8 35.1
9   2014/03/28  13:00:00 35.4 95.8 38.9
9   2014/03/28  14:00:00 34.1 95.8 44
9   2014/03/28  15:00:00 32.7 95.9 52.9
9   2014/03/28  16:00:00 31.8 96 55.1
9   2014/03/28  17:00:00 31.2 96 57.8
9   2014/03/28  18:00:00 30.6 96.1 62.1
9   2014/03/28  19:00:00 29.8 96.1 68.1
9   2014/03/28  20:00:00 29.1 96.1 69.5
9   2014/03/28  21:00:00 28.6 96 68.3
9   2014/03/28  22:00:00 28 96 71.9
9   2014/03/28  23:00:00 27.4 95.9 76.4
9   2014/03/29  00:00:00 27 96 80.6
9   2014/03/29  01:00:00 27.1 96 80.4
9   2014/03/29  02:00:00 27 96.1 80.5
9   2014/03/29  03:00:00 27.8 96.1 78.1
9   2014/03/29  04:00:00 30.4 96.2 66.8
9   2014/03/29  05:00:00 33.7 96.3 54
9   2014/03/29  06:00:00 36.3 96.3 45
9   2014/03/29  07:00:00 37.7 96.3 38.8
9   2014/03/29  08:00:00 38.7 96.3 34.7
9   2014/03/29  09:00:00 38.9 96.1 32.6
9   2014/03/29  10:00:00 39.4 96 30.2
9   2014/03/29  11:00:00 38.9 95.9 31.5
9   2014/03/29  12:00:00 38.2 95.8 33.8
9   2014/03/29  13:00:00 37.4 95.8 35.4
9   2014/03/29  14:00:00 35.8 95.9 39.5
9   2014/03/29  15:00:00 33.9 96 46.9
9   2014/03/29  16:00:00 31.4 96.1 59.8
9   2014/03/29  17:00:00 29.4 96.3 72.9
9   2014/03/29  18:00:00 29 96.3 69.6
9   2014/03/29  19:00:00 26.5 96.2 81.7
9   2014/03/29  20:00:00 27 96.1 82.9
9   2014/03/29  21:00:00 27.5 96.1 81.7
9   2014/03/29  22:00:00 27.4 96 82.6
9   2014/03/29  23:00:00 27.3 96 83.1
9   2014/03/30  00:00:00 27.1 96 84.5
9   2014/03/30  01:00:00 27.6 96.1 81.8
9   2014/03/30  02:00:00 27.8 96.1 81

2. I have some data of about 6100 rows and 6 columns, but anytime i read it
into R, it removes the header and a large chunk of the data.( i:e it will
import from row 3550-6099). This is the code i used for it
"met_data=read.csv(file.choose(),header=TRUE)", so, how do I read the
entire data into R without missing some?
Thank you.

-- 
Onyeuwaoma Nnaemeka Dom

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Jeff Newmiller

x <- c( "a1", "a10", "a2" )
y <- c( "b10", "b2", "a12", "ca1" )

DF <- expand.grid( x = x, y = y )
# randomize
set.seed( 42 )
DF <- DF[ sample( nrow( DF ) ), ]

# missing from gtools
mixedrank <- function( x ) {
  seq.int( length( x ) )[ gtools::mixedorder(x) ]
}

o <- do.call( order, lapply( DF, mixedrank ) )
DF[ o, ]

# or, as Bert suggests:

myrank <- function( v ) {
  vu <- unique(v)
  vl <- regmatches( vu,regexec("^([A-Za-z]+)(\\d+)$",vu))
  alph <- sapply( vl, function(s) s[2] )
  digt <- as.integer( sapply( vl, function(s) s[3] ) )
  o <- order( alph, digt )
  vo <- ordered( v, levels=vu[ o ] )
}

o2 <- do.call( order, lapply( DF, myrank ) )
DF[ o2, ]

?order
?ordered
?rank

On Sun, 11 Mar 2018, Bert Gunter wrote:


???


y <- sort( c("a1","a2","a10","a12","a100"))
y

[1] "a1"   "a10"  "a100" "a12"  "a2"

mixedsort(y)

[1] "a1"   "a2"   "a10"  "a12"  "a100"

**Please read the docs!** They say that mixedsort() and mixedorder()  both
take a **single vector**  as the argument to be sorted or ordered and, as
the above indicates, they perform exactly as advertised. **Unlike
order()**. So of course your do.call() construction fails.

So presumably you have a data frame with multiple columns of mixed alpha
and numerics?  (A reproducible example would be most helpful here.)

If this is the case, one **possibly dumb** approach (you have been warned!)
would be to turn each column into an ordered factor and then call order()
on the data frame of ordered factors via do.call() as above. i.e.


y1 <- ordered(y,lev = mixedsort(y))
y1

[1] a1   a10  a100 a12  a2
Levels: a1 < a2 < a10 < a12 < a100

order(y1)

[1] 1 5 2 4 3

(this is just for 1 vector to show how the idea would work).

Of course, if this is **not** what you want, you'll need to clarify,
hopefully with a reprex. Or hope that someone else has better insight than
I.

Cheers,
Bert




Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel <
sebastien.biho...@cognigencorp.com> wrote:


Hi,

Searching for functions that would order strings that mix characters and
numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I
found the mixedsort and mixedorder from the gtools package.

Problems:
1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call
like the order function does
2- gtools has not been updated in 2.5 years

Are you aware of an equivalent of this function in base R or a another
contributed package (with correction of problem #1)?

Thanks

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.



---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.