[R] (d,p,r,q) for all distributions, but no m?

2016-09-12 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
Today I need to compute the means for some distributions... and there's no easy way to do it! I mean (no pun intended), there is (d,p,r,q) for all distributions (like: dgamma, pgamma, rgamma, qgamma; dchisq, pchisq, rchisq, dchisp; etc), but there is no "m"-functions, like a mgamma to get the

Re: [R] Typographical error in the documentation of function strwidth?

2016-03-19 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
Peter Dalgaard wrote: > I don't think so. I'll give you that it should either be the (number of lines > - 1)*spacing > or (number of linefeeds)*spacing, but it's correct to count the height of "M" > only on the top line. > > -pd > > It is correct as written > Ah, ok, I see now. The "line

[R] Typographical error in the documentation of function strwidth?

2016-03-19 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
There might be a minor typographical error in the documentation of the function strwidth, namely, from ?strwidth we get: "Note that the ‘height’ of a string is determined only by the number of linefeeds ("\n") it contains: it is the (number of linefeeds - 1) times the line spacing plus the

Re: [R] Environment question

2015-11-13 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
I have another environment question. I understand why this works as expected: f.factory <- function() { y <- 2 fname <- paste("plus", y, sep = ".") f <- function(x) x + y assign(fname, f, envir = globalenv()) } f.factory() plus.2(2) # 4 and I also understand why this does NOT work:

[R] Environment question

2015-10-23 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
>From the code below: y <- 1 f1 <- function() { cat("y =", y, "\n") } f2 <- function() { y <- 2 f1() } f3 <- function() { y <- 3 f <- f1 f() } f4 <- function() { y <- 4 f <- function() { cat("y =", y, "\n") } f() } f1() f2() f3() f4() Clearly, f1(), f2() and f4() will

Re: [R] Annoyance with %/%

2015-03-11 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
shouldn't your last expression be: if (any(tst)) big.vector.1[tst] - big.vector.2[tst] Sure, that was a typo. Also, I know that `%%` does not make sense neither for Inf nor for big numbers, but `%/%` - since it's only a special case of `/` - should make sense; it should be equivalent

[R] Annoyance with %/%

2015-03-11 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
I've just found an annoyance with the behaviour of %/% which, BTW, violated the sacred rule that for all a, and non-zero b: a = b * (a %/% b) + a %% b Namely, that Inf %/% n is not Inf, but NaN. Why is this so? It's an annoyance, because in expressions like: big.vector.1[a, b, c] -

[R] Extract year from date

2015-03-11 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
I think these dates are from some historical database, as they are labeled BC. And the days might refer to some Epoch of ancient calendars, maybe the Chinese Calendar whose Epoch was 105 BC (at least if we can trust Wikipedia: https://en.wikipedia.org/wiki/Chinese_calendar ) Alberto Monteiro

Re: [R] Memory hungry routines

2014-12-30 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
Thanks to Duncan, Hadley and Henrik. Duncan, I used Rprof and could pinpoint the critical routine that was doing the memory crash. Henrik, you got it right: the culprit was a big matrix of integers, but where some of its fields are filled with -Inf and Inf. This matrix is global, it's used only

[R] Memory hungry routines

2014-12-29 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
Is there any way to detect which calls are consuming memory? I run a program whose global variables take up about 50 Megabytes of memory, but when I monitor the progress of the program it seems to allocating 150 Megabytes of memory, with peaks of up to 2 Gigabytes. I know that the global

[R] gsub regexp question

2014-10-15 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
I just found a curious behaviour of regexp and I'd like to share with y'all. gsub(^([[:alnum:]\\[\\]]*).*, \\1, array[n] - 10, perl=T) # works as expected (array[n]) gsub(^([[:alnum:]\\[\\]]*).*, \\1, array[n] - 10, perl=F) # doesn't work (a) I didn't find anything in the documentation explain

[R] Equivalent of chartr to numeric

2014-07-17 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
Is there any equivalent to chartr for numeric values? Meaning, something like: numerictr(c(-1, 42, 666), 1:3, numeric.stuff) that replaces in numeric.stuff (a vector, matrix, etc) all instances of -1 for 1, 42 for 2 and 666 for 3? Alberto Monteiro

Re: [R] Equivalent of chartr to numeric

2014-07-17 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
Replying to self: Is there any equivalent to chartr for numeric values? Meaning, something like: numerictr(c(-1, 42, 666), 1:3, numeric.stuff) that replaces in numeric.stuff (a vector, matrix, etc) all instances of -1 for 1, 42 for 2 and 666 for 3? match does it. Sorry to ask. Alberto

[R] Change the index argument of a series

2008-03-08 Thread Alberto Vieira Ferreira Monteiro
This is probably very trivial - so I can't find an answer in the help files. When I have a series x (x[1], x[2], ... x[n]) and I want to construct a new series y (y[1], y[2], ... y[m]) such that y's are either interpolations of the x's (when m n) or a weighted mean (when m n), is there any