[R] Steps for installing RHBASE library for R

2012-08-24 Thread Divya Kakkillaya B
Hi,

  Can someone please tell me what are the steps to follow for installing RHBASE 
library for R 2.15.1.



Regards,
Divya

 CAUTION - Disclaimer *
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are 
not 
to copy, disclose, or distribute this e-mail or its contents to any other 
person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has 
taken 
every reasonable precaution to minimize this risk, but is not liable for any 
damage 
you may sustain as a result of any virus in this e-mail. You should carry out 
your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this 
e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS End of Disclaimer INFOSYS***

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


[R] cygwin utf-8 problem with "help"

2012-08-24 Thread Ralf Goertz
Hi,

In R under cygwin I have trouble to correctly display help in text
format. One problem arises when there are single qoutes in the text like
in "?help" which looks like this

helppackage:utils R Documentation

Documentation

Description:


Usage:

 help(topic, package = NULL, lib.loc = NULL,
  verbose = getOption("verbose"),
  try.all.packages = getOption("help.try.all.packages"),
  help_type = getOption("help_type"))
 
Arguments:











Details:

 The following types of help are available:

Plain text help


...

The whole paragraph containing typographic single quotes is not displayed. I
can work around that a bit by issuing

tools::Rd2txt_options(code_quote=FALSE)

but there are still those single quotes like in 

"See `Details´ for what happens if this is omitted."


Furthermore, lines with bullets don't get indented and no bullets are
displayed (the "Plain text help" line above). I am using a UTF-8 locale.
When setting LANG to "C" or a latin1 locale, help is displayed
correctly, but then there are all sorts of problems with non ASCII
characters.

What can I do?

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


Re: [R] Regular expressions: stuck again...

2012-08-24 Thread Noia Raindrops
Hello,

try this:

x <- c("SELECT [public_tblFiche].[Fichenr], [public_tblArtnr].[Artnr]", "SELECT 
public_tblFiche.Fichenr, public_tblArtnr.Artnr")

# > The square backets [ and ] should removed
x <- gsub("[][]", "", x)

# > and xxx_xxx.xxx should become \"xxx\".\"xxx\"\".\"xxx\"
x <- gsub("([[:alpha:]]+)_([[:alpha:]]+)\\.([[:alpha:]]+)", 
"\"\\1\".\"\\2\".\"\\3\"", x)


-- 
Noia Raindrops
noia.raindr...@gmail.com

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


Re: [R] updating elements of a vector sequentially - is there a faster way?

2012-08-24 Thread Berend Hasselman

On 24-08-2012, at 06:49, Gopi Goteti wrote:

> I would like to know whether there is a faster way to do the below
> operation (updating vec1).
> 
> My objective is to update the elements of a vector (vec1), where a
> particular element i is dependent on the previous one. I need to do this on
> vectors that are 1 million or longer and need to repeat that process
> several hundred times. The for loop works but is slow. If there is a faster
> way, please let me know.
> 
> probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6)
> p10 <- 0.6
> p00 <- 0.4
> vec1 <- rep(0, 10)
> for (i in 2:10) {
>  vec1[i] <- ifelse(vec1[i-1] == 0,
>ifelse(probs[i]ifelse(probs[i] }


ifelse works on vectors. You should use if() ... else .. here.
You can also precompute  ifelse(probs[i] identical(vec1,vec2)
[1] TRUE
> identical(vec1,vec3)
[1] TRUE
> identical(vec1,vec4)
[1] TRUE

> system.time(vec1 <- f1(vec1))[3]
elapsed 
  2.922 
> system.time(vec2 <- f2(vec1))[3]
elapsed 
  0.403 
> system.time(vec3 <- f1.c(vec1))[3]
elapsed 
2.4 
> system.time(vec4 <- f2.c(vec1))[3]
elapsed 
  0.084 

A simple loop and using precomputed values achieves a significant speedup 
compared to your original code.
Using the compiler package to compile f2  gains even more sppedup.

Berend

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


Re: [R] updating elements of a vector sequentially - is there a faster way?

2012-08-24 Thread Petr Savicky
On Thu, Aug 23, 2012 at 09:49:33PM -0700, Gopi Goteti wrote:
> I would like to know whether there is a faster way to do the below
> operation (updating vec1).
> 
> My objective is to update the elements of a vector (vec1), where a
> particular element i is dependent on the previous one. I need to do this on
> vectors that are 1 million or longer and need to repeat that process
> several hundred times. The for loop works but is slow. If there is a faster
> way, please let me know.
> 
> probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6)
> p10 <- 0.6
> p00 <- 0.4
> vec1 <- rep(0, 10)
> for (i in 2:10) {
>   vec1[i] <- ifelse(vec1[i-1] == 0,
> ifelse(probs[i] ifelse(probs[i] }

Hi.

If p10 is always more than p00, then try the following.

  probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6)
  p10 <- 0.6
  p00 <- 0.4
 
  # original code  
  vec1 <- rep(0, 10)
  for (i in 2:10) {
vec1[i] <- ifelse(vec1[i-1] == 0,
  ifelse(probs[i] p00, then a10 <= a00. In this situation, the recurrence
satisfies the following. If a10[i] == a00[i], then vec1[i] is the
common value and does not depend on vec1[i-1]. If a10[i] < a00[i],
then vec1[i] is equal to vec1[i-1]. The suggested code creates an
initial vec2, which contains NA at the positions, which depend on
the previous value. Then, it iterates copying each value to the
next, if the next is NA. The efficiency depends on the length of
the sequencies of consecutive NA in the initial vec2. If there are
many, but only short sequencies of consecutive NA, the code can
be more efficient than a loop over all elements.

Hope this helps.

Petr Savicky.

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


Re: [R] updating elements of a vector sequentially - is there a faster way?

2012-08-24 Thread PIKAL Petr
Hi

Well, I am not sure if this is what you want but same result can be achieved by

vec1 <- (probs>=p00)*(probs>=p10)

Petr


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Gopi Goteti
> Sent: Friday, August 24, 2012 6:50 AM
> To: r-help@r-project.org
> Subject: [R] updating elements of a vector sequentially - is there a
> faster way?
> 
> I would like to know whether there is a faster way to do the below
> operation (updating vec1).
> 
> My objective is to update the elements of a vector (vec1), where a
> particular element i is dependent on the previous one. I need to do
> this on vectors that are 1 million or longer and need to repeat that
> process several hundred times. The for loop works but is slow. If there
> is a faster way, please let me know.
> 
> probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6) p10 <- 0.6 p00 <-
> 0.4
> vec1 <- rep(0, 10)
> for (i in 2:10) {
>   vec1[i] <- ifelse(vec1[i-1] == 0,
> ifelse(probs[i] ifelse(probs[i] 
> Thanks
> GG
> 
>   [[alternative HTML version deleted]]
> 
> __
> 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.

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


Re: [R] updating elements of a vector sequentially - is there a faster way?

2012-08-24 Thread Petr Savicky
On Fri, Aug 24, 2012 at 10:34:14AM +0200, Petr Savicky wrote:
> On Thu, Aug 23, 2012 at 09:49:33PM -0700, Gopi Goteti wrote:
> > I would like to know whether there is a faster way to do the below
> > operation (updating vec1).
> > 
> > My objective is to update the elements of a vector (vec1), where a
> > particular element i is dependent on the previous one. I need to do this on
> > vectors that are 1 million or longer and need to repeat that process
> > several hundred times. The for loop works but is slow. If there is a faster
> > way, please let me know.
> > 
> > probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6)
> > p10 <- 0.6
> > p00 <- 0.4
> > vec1 <- rep(0, 10)
> > for (i in 2:10) {
> >   vec1[i] <- ifelse(vec1[i-1] == 0,
> > ifelse(probs[i] > ifelse(probs[i] > }
> 
> Hi.
> 
> If p10 is always more than p00, then try the following.
[...]
>   # modification 
>   a10 <- ifelse(probs   a00 <- ifelse(probs   vec2 <- ifelse(a10 == a00, a10, NA)
>   vec2[1] <- 0
>   n <- length(vec2)
>   while (any(is.na(vec2))) {
>   shift <- c(NA, vec2[-n])
>   vec2 <- ifelse(is.na(vec2), shift, vec2)
>   }

Hi.

Let me suggest a variant of this, which can be more efficient
in some cases.

  probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6)

  p10 <- 0.6
  p00 <- 0.4

  # original code  
  vec1 <- rep(0, 10)
  for (i in 2:10) {
vec1[i] <- ifelse(vec1[i-1] == 0,
  ifelse(probs[i]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] updating elements of a vector sequentially - is there a faster way?

2012-08-24 Thread Noia Raindrops
Hello,

Each block of probs range from p00 to p10 is last value before the block.

Example:
  probs: .1 .1 .5 .5 .5 .9 .9
  vec1 :  0  0  0  0  0  1  1
  
  probs: .9 .9 .5 .5 .5 .1 .1
  vec1 :  1  1  1  1  1  0  0

So you can eliminate a loop.


# modification 
f5 <- function () {
  vec1 <- as.numeric(as.character(cut(probs, breaks = c(0, p00, p10, 1), labels 
= c(0, 0.5, 1), include.lowest = TRUE, right = FALSE)))
  # = ifelse(probs < p10, ifelse(probs < p00, 0, 0.5), 1)
  vec1 <- replace(vec1, 1, 0)
  vec1 <- rle(vec1)
  vec1 <- within(unclass(vec1), values[values == 0.5] <- values[which(values == 
0.5) - 1])
  vec1 <- inverse.rle(vec1)
  vec1
}

# original
f1 <- function() {
  vec1 <- rep(0, length(probs))
  for (i in 2:length(probs)) {
vec1[i] <- ifelse(vec1[i-1] == 0,
 ifelse(probs[i] < p10, 0, 1),
 ifelse(probs[i] < p00, 0, 1))
  }
  vec1
}

f2 <- function(vec1) {
  val.p10 <- ifelse(probs < p10, 0, 1)
  val.p00 <- ifelse(probs < p00, 0, 1)
  vec1 <- rep(0, length(probs))
  for (i in 2:length(probs)) {
vec1[i] <- if(vec1[i-1] == 0) val.p10[i] else val.p00[i]
  }
  vec1
}

f3 <- function () {
  a10 <- ifelse(probs < p10, 0, 1)
  a00 <- ifelse(probs < p00, 0, 1)
  vec1 <- ifelse(a10 == a00, a10, NA)
  vec1[1] <- 0
  n <- length(vec1)
  while (any(is.na(vec1))) {
shift <- c(NA, vec1[-n])
vec1 <- ifelse(is.na(vec1), shift, vec1)
  }
  vec1
}

f4 <- function () {
  a10 <- ifelse(probs < p10, 0, 1)
  a00 <- ifelse(probs < p00, 0, 1)
  vec1 <- ifelse(a10 == a00, a10, NA)
  vec1[1] <- 0
  n <- length(vec1)
  while (1) {
i <- which(is.na(vec1))
if (length(i) == 0) break
vec1[i] <- vec1[i-1]
  }
  vec1
}

set.seed(1)
probs <- runif(1)
p10 <- 0.6
p00 <- 0.4

identical(f1(), f2())
## [1] TRUE
identical(f1(), f3())
## [1] TRUE
identical(f1(), f4())
## [1] TRUE
identical(f1(), f5())
## [1] TRUE

# with random probs
rbenchmark::benchmark(f1(), f2(), f3(), f4(), f5(), columns = c("test", 
"replications", "elapsed", "relative"), replications = 100)
##   test replications elapsed  relative
## 1 f1()  100  31.456 42.279570
## 2 f2()  100   4.879  6.557796
## 3 f3()  100   2.503  3.364247
## 4 f4()  100   0.939  1.262097
## 5 f5()  100   0.744  1.00

# with biased probs
probs <- rep(0.5, 1000)
rbenchmark::benchmark(f1(), f2(), f3(), f4(), f5(), columns = c("test", 
"replications", "elapsed", "relative"), replications = 100)
##   test replications elapsed   relative
## 1 f1()  100   2.917  30.385417
## 2 f2()  100   0.448   4.67
## 3 f3()  100  32.439 337.906250
## 4 f4()  100   3.635  37.864583
## 5 f5()  100   0.096   1.00


-- 
Noia Raindrops
noia.raindr...@gmail.com

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


[R] diagonal matrix, array attributes and how to keep from setting an attribute on "NULL"

2012-08-24 Thread aleksandr russell
Hello,

I've put the short version here and if anyone wants to run the code with
CollocInfer, I've given the full version in the file "analysis".

  I come at the question of array attributes and dimnames
 to try to simplify.

In a CollocInfer LS.profile analysis using this array 'Y' constructed
as follows:



w=rnorm(41,.05)
z=rnorm(41,.06)

yX<-cbind(w,z)
y<-as.array(yX)
colnames(y)=c("V","R")

Y<-array(0,c(41,2,2))
Y[,1,]=y
Y[,2,]=y



 I receive an error

Error in as.array.default(Y) : attempt to set an attribute on NULL


So I think to name the attributes :

varnames=c("V","R")

rownames(Y)<-rownames(Y, do.NULL = FALSE, prefix = "Obs.")
colnames(Y)[1:2]=c("one","two")

assign("dimnames(Y)",list(rownames(Y),varnames,colnames(Y)))

Y2<-as.array(Y,dimnames=dimnames(Y))
assign("Y",Y2)

then rerun the analysis with the same result

Now traceback() gives:


7: as.array.default(Y)
6: as.array(Y)
5: kronecker(X, Y)
4: kronecker(X, Y)
3: diag(rep(1, nrep)) %x% basisvals$bvals.obs
2: LS.setup(pars, coefs, fn, basisvals, lambda, fd.obj, more, data,
   weights, times, quadrature, eps = 1e-06, posproc, poslik,
   discrete, names, sparse)
1: Profile.LS(fhn, data = data2, times = times, pars = pars, coefs = coefs,
   lambda = lambda, out.meth = "nls", control.in = control.in,
   control.out = control.out)

the first four numbers here(7..4) seem okay when I call each; but in number 3:
calling the given text produces the error:

error in evaluating the argument 'X' in selecting a method for
function 'kronecker': Error in diag(rep(1, nrep)) :
error in evaluating the argument 'x' in selecting a method for
function 'diag': Error: object 'nrep' not found

At the outset in the manual, Hooker refers to the diagonal matrix,  it
seems without further explanation:

In order to demonstrate replicated observations, we make use of another 
set of
data generated at dierent initial conditions. We then need
concatenate these ob-
servations in time, and create new values for bvals and weights. The 
function
diag.block from the simex package is used below, but there are several 
packages
in R that provide block-diagonal matrices.

I have a feeling this diagonal matrix is a component of R analysis
that, if corrected here,
could produce results, and I would be grateful if anyone who has
experience with its use
could offer some help.

A
Okay here I come at the question of attributes and dimnames
from another direction.


times = seq(0,20,0.5)
   pars = c(0.2,0.2,3)
   names(pars) = c('a','b','c')
   x0 = c(-1,1)
   names(x0) = c('V','R')
   fhn = make.fhn()
w=rnorm(41,.05)
z=rnorm(41,.06)

yX<-cbind(w,z)
y<-as.array(yX)
colnames(y)=c("V","R")

#a perturbation:#

u=rnorm(41,.02)
v=rnorm(41,.02)

m13=w+u
m14=w+v

m15<-cbind(m13,m14)

data<-m15
 knots = seq(0,20,0.2)
   norder = 3
   nbasis = length(knots) + norder - 2
   range = c(0,20)
   bbasis = create.bspline.basis(range=range, nbasis=nbasis, norder=norder,
   breaks=knots)
fd.data = array(data,c(nrow(data),1,ncol(data)))
   fd.data = array(data,c(nrow(data),1,ncol(data)))
  varnames=c("V","R")
 
  DEfd = Data2fd(fd.data, times, bbasis,
   fdnames=list(NULL,NULL,varnames) )
coefs = DEfd$coefs
   colnames(coefs) = varnames
   control=list()
   control$trace = 0
   control$maxit = 1000
   control$maxtry = 10
   control$reltol = 1e-6
   control$meth = "BFGS"
   control.in = control
   control.in$reltol = 1e-12
   control.in$print.level = 0
   control.in$iterlim = 1000
   control.out = control
   control.out$trace = 2
   lambda = c(1,1)
   res0 = Profile.LS(fhn,data,times,pars,coefs=coefs,basisvals=bbasis,
   lambda=lambda,in.meth='nlminb',out.meth='ProfileGN',
   control.in=control.in,control.out=control.out)


#(This is 'y' for an initial analysis of the FhN data.)#


#so far no problem: the arrays 'y' and 'data' are both acceptable

now we want to extend this to two replicates of the data to be analyzed:#

data2 = array(0,c(41,2,2))

m16<-rnorm(41,.2)




m20=cbind(m16,m16)
m21<-as.array(m20,dim=c(41,2))
m22<-rnorm(41,.1)
m20=cbind(m22,m22)
m23<-as.array(m20,dim=c(41,2))

data2[,1,]=m21+y
data2[,2,]=m23+y

fd.data2 = array(data2,c(nrow(data2),2,ncol(data2)))
DEfd2 = Data2fd(fd.data2, times, bbasis,
fdnames=list(NULL,NULL,varnames))
res3 = Profile.LS(fhn, data=data2, times=times, pars=pars,
coefs=coefs, lambda=lambda, out.meth='nls',
control.in=control.in, control.out=control.out)

#Rather than parameter estimates, as with the single replicate analysis, this 
produces the error:

Error in as.array.default(Y) : attempt to set an attribute on NULL
  
So thinking that the dimnames of either array are the "NULL" that R is 
referring to, 
I supply dimnames to the two arrays involved, data2, and y:#

r

Re: [R] updating elements of a vector sequentially - is there a faster way?

2012-08-24 Thread Petr Savicky
On Thu, Aug 23, 2012 at 09:49:33PM -0700, Gopi Goteti wrote:
> I would like to know whether there is a faster way to do the below
> operation (updating vec1).
> 
> My objective is to update the elements of a vector (vec1), where a
> particular element i is dependent on the previous one. I need to do this on
> vectors that are 1 million or longer and need to repeat that process
> several hundred times. The for loop works but is slow. If there is a faster
> way, please let me know.
> 
> probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6)
> p10 <- 0.6
> p00 <- 0.4
> vec1 <- rep(0, 10)
> for (i in 2:10) {
>   vec1[i] <- ifelse(vec1[i-1] == 0,
> ifelse(probs[i] ifelse(probs[i] }

Hi.

There are already several solutions, which use the fact that each
output value either does not depend on the previous value or is its
copy. The following implements this using rle() function.

  probs <- c(.1, .3, .2, .4, .7, .9, .3, .4, .5, .6)
  p10 <- 0.6
  p00 <- 0.4

  # original code  
  vec1 <- rep(0, 10)
  for (i in 2:10) {
vec1[i] <- ifelse(vec1[i-1] == 0,
  ifelse(probs[i]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] select most frequent value in set of variables

2012-08-24 Thread Sam Dekeyser
Hi, 

Shortly after my first post I posted an answer including the fix I found; which 
seems to work. Through the archives I found that my code snippet got filtered 
out and appended as an attachment (which was not my intent).

This was my suggestion:

for(i in seq(length(ss$name))) {
color <- names(which.max(table(c(ss$color1[i], ss$color2[i], 
ss$color3[i]

if(is.null(color))
{
ss$color_med[i] <- NA
}
else 
{
ss$color_med[i] <- as.integer(color)
}
}

Thank you for your suggestions!
Sam


Op 20-aug-2012, om 18:04 heeft arun het volgende geschreven:

> HI,
> 
> Slightly different way:
> unlist(lapply(apply(mat,1,count),function(x) max(x[2])))
>  #[1] 2 1 2 1 1 2 2 2 2 1 2 1 2 2 2 1 1 1 2 2
> 
> 
> 
> - Original Message -
> From: PIKAL Petr 
> To: Sam Dekeyser ; "r-help@r-project.org" 
> 
> Cc: 
> Sent: Monday, August 20, 2012 10:08 AM
> Subject: Re: [R] select most frequent value in set of variables
> 
> Hi
> 
> It is really a typical example of a question which has probably very simple 
> solution but hardly anybody can give you a rasonable answer.
> 
> How your data look like?
> What is the structure of your data?
> 
> set.seed(1)
> x<-sample(1:4, 60, replace=T)
> mat<-as.factor(x)
> dim(mat) <- c(20,3)
> 
>> sapply(apply(mat,1, table), max)
> [1] 2 1 2 1 1 2 2 2 2 1 2 1 2 2 2 1 1 1 2 2
>> names(sapply(apply(mat,1, table), which.max))
> [1] "4" "1" "3" "1" "1" "4" "1" "2" "3" "1" "2" "1" "2" "1" "4" "1" "2" "1" 
> "3"
> [20] "2"
> 
> gives you the most frequent value in each row of matrix mat.
> 
> Petr
> 
> 
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Sam Dekeyser
>> Sent: Monday, August 20, 2012 10:48 AM
>> To: r-help@r-project.org
>> Subject: [R] select most frequent value in set of variables
>> 
>> Hi,
>> 
>> I would like to select the most frequent value level in a set of three
>> variables.
>> 
>> Three different observators have judged hair color in study subjects.
>> Mostly they judge the same color, sometimes there is a slight
>> difference. I want to know what most of the observators have chosen (so
>> at least 2) from the 3 observations. E.g. If two out of three
>> observators decide the hair is black, then it's likely not to be brown.
>> 
>> Let's say that i have 3 variables: color1, color2, color3. Each have 4
>> possible levels (fair up to black, 1-4). I would like a new variable
>> containing this 'most frequent judgement'.
>> 
>> I have already searched through the knowledge base and many posts but I
>> haven't found what I'm looking for.
>> 
>> Is this possible?
>> 
>> Thank you in advance!
>> Sam
>> 
>> __
>> 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.
> 
> __
> 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.
> 

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


[R] plot curve on surface

2012-08-24 Thread Michael Meyer


Greetings,

I would like to plot a curve (in color red) on a surface in a 3D plot.
Say

    x <- as.vector(seq(-1,1,0.2))
    dim(x) <- c(length(x),1)
    y <- as.vector(seq(-1,1,0.2))
    dim(y) <- c(1,length(y))
    
    z <- x%*%y # (x_iy_j)

# 3D plot of z(x,y)=xy:
persp(x,y,z)
 
Now I would like to plot the curve z=z(x,x) in red on this surface.
How do I do that?
 
Many thanks,
 
Michael Meyer

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


Re: [R] plot curve on surface

2012-08-24 Thread S Ellison
> I would like to plot a curve (in color red) on a surface in a 3D plot.

Perhaps trans3d would be relevant?
?persp 's examples include an example of adding a line to a 3d plot using 
trans3d

S

***
This email and any attachments are confidential. Any use...{{dropped:8}}

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


[R] R minimal calculation error

2012-08-24 Thread Frederik Bertling
Hi,

I'm doing some easy calculations to normalize some values. This looks like
this:

x=mean(a+b+c+d ...)
a=a-x
b=b-x
c=c-x
d=d-x
...
mean(a+b+c+d ...) ---> Should now be 0!
However, I'm getting results like -2.315223e-18
This is really near to 0 but not very aesthetic.

Can I prevent this? Or is this behaviour desired?
Thank you very much!
Burtan

-- 
Frederik Bertling
Steinhausenstr. 37, 45147 Essen, Deutschland
Mobil: 017661103480*
*

[[alternative HTML version deleted]]

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


Re: [R] Why was my R process killed spontaneously?

2012-08-24 Thread flora flora
Thanks for your reply.

Does what you said by resources mean memory or something else? Inside my
loop, I removed the objects that are created but not used by the next loop
and did garbage collection as well. Do you have any idea how I should
modify my code such that the system won't kill it? Thanks.





On Thu, Aug 23, 2012 at 5:06 PM, Jeff Newmiller wrote:

> Yes. Operating systems kill processes that consume excessive resources.
> That excess may arise from one large computation or from a small one on top
> of many other allocations... the "straw that broke the camel's back"
> problem.
> ---
> 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
> ---
> Sent from my phone. Please excuse my brevity.
>
> flora flora  wrote:
>
> >I tried to use gpuCor function in the gputools package of R to calcuate
> >the
> >pairwise correlations of a matrix of 40,000 columns.
> >
> >Becuase there would be memory issues if I use the whole matrix at a
> >time, I
> >splitted the matrix into submatrix of 10,000 columns and then calculate
> >the
> >pairwise correlation of different submatrices. There are altogether 4
> >submatrices, so I need to calculate the pearson correlation of sub
> >matrix 1
> >with sub matrix 1,2,3,4, and sub matrix 2 with submatrix 1,2,3,4, etc.
> >
> >The program runs well at first, but at the last step, which is
> >calculating
> >the correlation between submatrix 4 with itself, the program was killed
> >and
> >gave no error messages.
> >
> >Have anybody else encountered this before?
> >
> >Actually it doesn't have to be related with gpuCor. Just generally
> >speaking, in what circumstances would a R program be killed
> >spontaneously
> >without any error messages?
> >
> >Thanks.
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >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.
>
>

[[alternative HTML version deleted]]

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


[R] Branch and Bound

2012-08-24 Thread Davila David
Hi, 
Is there a Branch and Bound routines or library for R?. 
Thanks,

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


[R] Euclidean distance function

2012-08-24 Thread Arbuckle
Hi,

I should preface this problem with a statement that although I am sure this
is a really easy function to write, I have tried and failed to get my head
around writing functions in R. I can use R where functions exist to do what
I want done, but have found myself completely incapable of writing them
myself.

The problem is that I have a table with several rows of species and several
columns of trait data for each species. Now what I want to do is, for each
possible pair of species, extract the Euclidean distance between them based
on specified trait data columns. While as far as I can see the dist()
function could manage this to some extent for 2 dimensions (traits) for each
species, I need a more generalised function that can handle n-dimensions.
Ideally this function would allow me to choose which columns (traits) to use
to calculate the Euclidean distance rather than having to reformat the
dataset every time.

In the hope of clarifying this with a simplified example, I want to take a
dataset like this:

Species x  y  z  n
spA  2.9 34.2 0.5415.7
spB  5.5 46.5 0.4519.4
spC  1.4 48.6 0.8424.8
spD  8.3 56.1 0.4821.3

Then extract the Euclidean distances using the general equation
d=sqrt[(x2-x1)^2+(y2-y1)^2+...+(n2-n1)^2] for particular data columns. So in
this example I might want the distances using the traits x, z and n, thereby
specifying the equation to be d=sqrt[(x2-x1)^2+(z2-z1)^2+(n2-n1)^2], and
return a distance matrix as follows (calculated distances represented by .
for the purposes of this example):

Species spA spB spC
spB  .
spC  .   .
spD  .   .   .

I hope this makes sense. I only presume that this would be a quick and easy
function to write on the basis that the underlying process is basically
simple maths repeated for each pair of species. Again I have no experience
in writing custom functions (no matter how simple) and just can't seem to
get into my head how to go about it.

I look forward to your response and hope someone gets bored enough to
quickly write out the code to implement this function. Thank you in advance.

Best wishes,

Kev



--
View this message in context: 
http://r.789695.n4.nabble.com/Euclidean-distance-function-tp4641177.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Branch and Bound

2012-08-24 Thread Noia Raindrops
Hi,

Do you try 'RSiteSearch("Branch Bound")'?

-- 
Noia Raindrops
noia.raindr...@gmail.com

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


Re: [R] Random effects in gam (mgcv 1.7-19)

2012-08-24 Thread Simon Wood

Silje,

Thanks for reporting this. Should be fixed for version 1.7-20 (but 
please let me know if not!)


best,
Simon

On 14/08/12 12:08, silje skår wrote:

Hi,

I am using the gam function in the mgcv package, I have random effects in
my model (bs="re") this has worked fine, but after I updated the mgcv
package to version 1.7-19 I recive an error message when I run the model.




fit1<-gam(IV~s(RUTE,bs="re")+s(T13)+s(H40)+factor(AAR)+s(V3)+s(G1)+s(H1)+s(V1)+factor(LEDD),data=data5,method="ML")

summary.gam(fit1)

Error in mroot(Ve[ind, ind]) : Supplied matrix not symmetric

This same model worked fine before I updated the mgcv package, does anyone
know why I now get the error message?

Another question I have is if anyone knows how I can compare two gam models
that includes "re" terms? As far as I understand an anova is not the best
way when I have "re" terms.

Best regards
Silje Skår

[[alternative HTML version deleted]]



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




--
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603   http://people.bath.ac.uk/sw283

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


Re: [R] R minimal calculation error

2012-08-24 Thread Marc Schwartz
On Aug 24, 2012, at 5:48 AM, Frederik Bertling 
 wrote:

> Hi,
> 
> I'm doing some easy calculations to normalize some values. This looks like
> this:
> 
> x=mean(a+b+c+d ...)
> a=a-x
> b=b-x
> c=c-x
> d=d-x
> ...
> mean(a+b+c+d ...) ---> Should now be 0!
> However, I'm getting results like -2.315223e-18
> This is really near to 0 but not very aesthetic.
> 
> Can I prevent this? Or is this behaviour desired?
> Thank you very much!
> Burtan



Read this:

 
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

Regards,

Marc Schwartz

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


Re: [R] patchDVI: how to pass encoding of the .Rnw file?

2012-08-24 Thread Marius Hofert
Dear Duncan,

many thanks for helping. It works fine.

Cheers,

Marius

Duncan Murdoch  writes:

> On 12-08-19 3:47 PM, Marius Hofert wrote:
>> Dear Duncan,
>>
>> I recently asked a question concerning patchDVI on r-help, see
>>
>> ,
>> | https://stat.ethz.ch/pipermail/r-help/2012-August/321780.html
>> `
>>
>> Unfortunately, no one could help. I was wondering if you know a solution to 
>> the
>> above problem. Any hint is highly appreciated.
>
> Sorry, I'm writing this while offline, so I can't quote your message.
> The issue was that if the main .tex file uses \input to include another file,
> and that file needs to be processed by Sweave, then the usual encoding
> detection method (looking for \usepackage[utf8]{inputenc} or similar) won't
> work, because you can't put that line in the secondary file.
>
> The solution is the same as when using Sweave:  put a default encoding into
> the call to SweavePDF (or the similar functions).  For example, my editor
> always executes this command when asked to process a .Rnw file:
>
> patchDVI::SweavePDF('%2', stylepath=FALSE,
> preview="f:/SumatraPDF/SumatraPDF \x25s",
> encoding="utf8")
>
> The %2 is a place holder for the filename to process.  The preview argument
> invokes the PDF previewer that knows Synctex; the stylepath and encoding
> arguments are passed to Sweave.  Because I chose encoding="utf8", Sweave
> will assume that encoding as the default for files.  Another encoding  can be
> explicitly declared.
>
> When I have multi-file projects, I make use of .TexRoot and .SweaveFiles
> in each of the files so I can make the whole project each time;
> see the patchDVI vignette (section 6) for details of how they work.
>
> I think you also asked how to do this in Emacs; I've got no idea about that.
>
> Duncan Murdoch

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


Re: [R] Error while installing gsubfn_0.6-4.tar.gz for R 2.15.1

2012-08-24 Thread Gabor Grothendieck
I have never seen that before. It has been independently verified that
gsubfn works on Fedora Red Hat as you can see here:

http://cran.r-project.org/web/checks/check_results_gsubfn.html

The message about Tcl/Tk in your log suggests that there is something
wrong with your version of R itself.  See FAQ2:
http://code.google.com/p/gsubfn/#FAQs

Given that its been independently verified to install properly on
fedora red hat and that your log shows that your version of R is
broken you may need to get a proper version of R.

The following things may not be sufficient given the above but you
could try it just in case:

options(gsubfn.engine = FALSE)
install.packages("gsubfn") # do NOT use dep=TRUE

Let me know when you resolve it so we can add something to the FAQ.

Regards.

On Fri, Aug 24, 2012 at 2:45 AM, Divya Kakkillaya B
 wrote:
> Hi,
>
>   I am getting the follwoing error while installing gsubfn_0.6-4.tar.gz 
> library for R. R version is 2.15.1 and i am installing on Redhat linux 
> version 2.6.18-238.9.1.el5 
> (mockbu...@x86-002.build.bos.redhat.com)
>  (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50))
>
>
>
> * installing to library â/home/mapred/installables/R/libraryâ
> * installing *source* package âgsubfnâ ...
> ** package âgsubfnâ successfully unpacked and MD5 sums checked
> ** R
> ** demo
> ** inst
> ** byte-compile and prepare package for lazy loading
> Warning: S3 methods â$.tclvarâ, â$<-.tclvarâ, âas.character.tclObjâ, 
> âas.character.tclVarâ, âas.double.tclObjâ, âas.integer.tclObjâ, 
> âas.logical.tclObjâ, âas.raw.tclObjâ, âprint.tclObjâ, â[[.tclArrayâ, 
> â[[<-.tclArrayâ, â$.tclArrayâ, â$<-.tclArrayâ, ânames.tclArrayâ, 
> ânames<-.tclArrayâ, âlength.tclArrayâ, âlength<-.tclArrayâ, âtclObj.tclVarâ, 
> âtclObj<-.tclVarâ, âtclvalue.defaultâ, âtclvalue.tclObjâ, âtclvalue.tclVarâ, 
> âtclvalue<-.defaultâ, âtclvalue<-.tclVarâ, âclose.tkProgressBarâ were 
> declared in NAMESPACE but not found
> Error : .onLoad failed in loadNamespace() for 'tcltk', details:
>   call: fun(libname, pkgname)
>   error: Tcl/Tk support is not available on this system
> Error : package/namespace load failed for âtcltkâ
> Error : unable to load R code in package âgsubfnâ
> ERROR: lazy loading failed for package âgsubfnâ
>
>
>
> Regards,
> Divya
>
>  CAUTION - Disclaimer *
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
> for the use of the addressee(s). If you are not the intended recipient, please
> notify the sender by e-mail and delete the original message. Further, you are 
> not
> to copy, disclose, or distribute this e-mail or its contents to any other 
> person and
> any such actions are unlawful. This e-mail may contain viruses. Infosys has 
> taken
> every reasonable precaution to minimize this risk, but is not liable for any 
> damage
> you may sustain as a result of any virus in this e-mail. You should carry out 
> your
> own virus checks before opening the e-mail or attachment. Infosys reserves the
> right to monitor and review the content of all messages sent to or from this 
> e-mail
> address. Messages sent to or from this e-mail address may be stored on the
> Infosys e-mail system.
> ***INFOSYS End of Disclaimer INFOSYS***
>
> __
> 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.



-- 
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
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] Error while installing gsubfn_0.6-4.tar.gz for R 2.15.1

2012-08-24 Thread Gabor Grothendieck
Sorry, I just double checked and the options statement should be:

options(gsubfn.engine = "R")

Again, I am not sure if that is sufficient given that there is clearly
something wrong with your version of R.

On Fri, Aug 24, 2012 at 8:59 AM, Gabor Grothendieck
 wrote:
> I have never seen that before. It has been independently verified that
> gsubfn works on Fedora Red Hat as you can see here:
>
> http://cran.r-project.org/web/checks/check_results_gsubfn.html
>
> The message about Tcl/Tk in your log suggests that there is something
> wrong with your version of R itself.  See FAQ2:
> http://code.google.com/p/gsubfn/#FAQs
>
> Given that its been independently verified to install properly on
> fedora red hat and that your log shows that your version of R is
> broken you may need to get a proper version of R.
>
> The following things may not be sufficient given the above but you
> could try it just in case:
>
> options(gsubfn.engine = FALSE)
> install.packages("gsubfn") # do NOT use dep=TRUE
>
> Let me know when you resolve it so we can add something to the FAQ.
>
> Regards.
>
> On Fri, Aug 24, 2012 at 2:45 AM, Divya Kakkillaya B
>  wrote:
>> Hi,
>>
>>   I am getting the follwoing error while installing gsubfn_0.6-4.tar.gz 
>> library for R. R version is 2.15.1 and i am installing on Redhat linux 
>> version 2.6.18-238.9.1.el5 
>> (mockbu...@x86-002.build.bos.redhat.com)
>>  (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50))
>>
>>
>>
>> * installing to library â/home/mapred/installables/R/libraryâ
>> * installing *source* package âgsubfnâ ...
>> ** package âgsubfnâ successfully unpacked and MD5 sums checked
>> ** R
>> ** demo
>> ** inst
>> ** byte-compile and prepare package for lazy loading
>> Warning: S3 methods â$.tclvarâ, â$<-.tclvarâ, âas.character.tclObjâ, 
>> âas.character.tclVarâ, âas.double.tclObjâ, âas.integer.tclObjâ, 
>> âas.logical.tclObjâ, âas.raw.tclObjâ, âprint.tclObjâ, â[[.tclArrayâ, 
>> â[[<-.tclArrayâ, â$.tclArrayâ, â$<-.tclArrayâ, ânames.tclArrayâ, 
>> ânames<-.tclArrayâ, âlength.tclArrayâ, âlength<-.tclArrayâ, âtclObj.tclVarâ, 
>> âtclObj<-.tclVarâ, âtclvalue.defaultâ, âtclvalue.tclObjâ, âtclvalue.tclVarâ, 
>> âtclvalue<-.defaultâ, âtclvalue<-.tclVarâ, âclose.tkProgressBarâ were 
>> declared in NAMESPACE but not found
>> Error : .onLoad failed in loadNamespace() for 'tcltk', details:
>>   call: fun(libname, pkgname)
>>   error: Tcl/Tk support is not available on this system
>> Error : package/namespace load failed for âtcltkâ
>> Error : unable to load R code in package âgsubfnâ
>> ERROR: lazy loading failed for package âgsubfnâ
>>
>>
>>
>> Regards,
>> Divya
>>
>>  CAUTION - Disclaimer *
>> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
>> for the use of the addressee(s). If you are not the intended recipient, 
>> please
>> notify the sender by e-mail and delete the original message. Further, you 
>> are not
>> to copy, disclose, or distribute this e-mail or its contents to any other 
>> person and
>> any such actions are unlawful. This e-mail may contain viruses. Infosys has 
>> taken
>> every reasonable precaution to minimize this risk, but is not liable for any 
>> damage
>> you may sustain as a result of any virus in this e-mail. You should carry 
>> out your
>> own virus checks before opening the e-mail or attachment. Infosys reserves 
>> the
>> right to monitor and review the content of all messages sent to or from this 
>> e-mail
>> address. Messages sent to or from this e-mail address may be stored on the
>> Infosys e-mail system.
>> ***INFOSYS End of Disclaimer INFOSYS***
>>
>> __
>> 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.
>
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com



-- 
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
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] R minimal calculation error

2012-08-24 Thread Rui Barradas

Hello,

This is FAQ 7.31 Why doesn't R think these numbers are equal?

As for your second question whether this behavior is desirable I think 
so, we should be aware that floating-point arithmetics has limits. In 
your case, a precision limit. At an R pompt run the instructions


?.Machine
.Machine$double.eps

to see the limits, and more.

As for your first question, you can't prevent but you can correct based 
on a chosen accuracy.
Your mesurements were made with how many digits? I doubt you have 16 
digits of accuracy. It's possible but it's not usual, it's rare. So you 
can round your final value using round().


set.seed(4130)
x <- runif(10)
#?scale
(s <- sum( scale(x, scale = FALSE) ))
#?round
round(s, digits = 10) # suppose you can only be sure of 10 digits.
round(s, digits = 15) # still zero
round(s, digits = 16) # precision loss

Hope this helps,

Rui Barradas

Em 24-08-2012 11:48, Frederik Bertling escreveu:

Hi,

I'm doing some easy calculations to normalize some values. This looks like
this:

x=mean(a+b+c+d ...)
a=a-x
b=b-x
c=c-x
d=d-x
...
mean(a+b+c+d ...) ---> Should now be 0!
However, I'm getting results like -2.315223e-18
This is really near to 0 but not very aesthetic.

Can I prevent this? Or is this behaviour desired?
Thank you very much!
Burtan



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


Re: [R] Euclidean distance function

2012-08-24 Thread Jean V Adams
Kev,

The dist() function handles more than 2 dimensions.
Using the example you provided ...

mydat <- structure(list(Species = c("spA", "spB", "spC", "spD"), 
x = c(2.9, 5.5, 1.4, 8.3), 
y = c(34.2, 46.5, 48.6, 56.1), 
z = c(0.54, 0.45, 0.84, 0.48), 
n = c(15.7, 19.4, 24.8, 21.3)), 
.Names = c("Species", "x", "y", "z", "n"), 
class = "data.frame", row.names = c(NA, -4L))
dist(mydat [, c("x", "z", "n")])

Jean


Arbuckle  wrote on 08/24/2012 05:56:51 AM:
> 
> Hi,
> 
> I should preface this problem with a statement that although I am sure 
this
> is a really easy function to write, I have tried and failed to get my 
head
> around writing functions in R. I can use R where functions exist to do 
what
> I want done, but have found myself completely incapable of writing them
> myself.
> 
> The problem is that I have a table with several rows of species and 
several
> columns of trait data for each species. Now what I want to do is, for 
each
> possible pair of species, extract the Euclidean distance between them 
based
> on specified trait data columns. While as far as I can see the dist()
> function could manage this to some extent for 2 dimensions (traits) for 
each
> species, I need a more generalised function that can handle 
n-dimensions.
> Ideally this function would allow me to choose which columns (traits) to 
use
> to calculate the Euclidean distance rather than having to reformat the
> dataset every time.
> 
> In the hope of clarifying this with a simplified example, I want to take 
a
> dataset like this:
> 
> Species x  y  z  n
> spA  2.9 34.2 0.5415.7
> spB  5.5 46.5 0.4519.4
> spC  1.4 48.6 0.8424.8
> spD  8.3 56.1 0.4821.3
> 
> Then extract the Euclidean distances using the general equation
> d=sqrt[(x2-x1)^2+(y2-y1)^2+...+(n2-n1)^2] for particular data columns. 
So in
> this example I might want the distances using the traits x, z and n, 
thereby
> specifying the equation to be d=sqrt[(x2-x1)^2+(z2-z1)^2+(n2-n1)^2], and
> return a distance matrix as follows (calculated distances represented by 
.
> for the purposes of this example):
> 
> Species spA spB spC
> spB  .
> spC  .   .
> spD  .   .   .
> 
> I hope this makes sense. I only presume that this would be a quick and 
easy
> function to write on the basis that the underlying process is basically
> simple maths repeated for each pair of species. Again I have no 
experience
> in writing custom functions (no matter how simple) and just can't seem 
to
> get into my head how to go about it.
> 
> I look forward to your response and hope someone gets bored enough to
> quickly write out the code to implement this function. Thank you in 
advance.
> 
> Best wishes,
> 
> Kev

[[alternative HTML version deleted]]

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


Re: [R] Why was my R process killed spontaneously?

2012-08-24 Thread Jeff Newmiller
Yes, the resources operating systems usually kill for are memory.

No, you have not provided a reproducible example. In general, you need to do 
something different, such as choose a different algorithm, run on a different 
computer, or split your problem into smaller pieces.
---
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
--- 
Sent from my phone. Please excuse my brevity.

flora flora  wrote:

>Thanks for your reply.
>
>Does what you said by resources mean memory or something else? Inside
>my
>loop, I removed the objects that are created but not used by the next
>loop
>and did garbage collection as well. Do you have any idea how I should
>modify my code such that the system won't kill it? Thanks.
>
>
>
>
>
>On Thu, Aug 23, 2012 at 5:06 PM, Jeff Newmiller
>wrote:
>
>> Yes. Operating systems kill processes that consume excessive
>resources.
>> That excess may arise from one large computation or from a small one
>on top
>> of many other allocations... the "straw that broke the camel's back"
>> problem.
>>
>---
>> 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
>>
>---
>> Sent from my phone. Please excuse my brevity.
>>
>> flora flora  wrote:
>>
>> >I tried to use gpuCor function in the gputools package of R to
>calcuate
>> >the
>> >pairwise correlations of a matrix of 40,000 columns.
>> >
>> >Becuase there would be memory issues if I use the whole matrix at a
>> >time, I
>> >splitted the matrix into submatrix of 10,000 columns and then
>calculate
>> >the
>> >pairwise correlation of different submatrices. There are altogether
>4
>> >submatrices, so I need to calculate the pearson correlation of sub
>> >matrix 1
>> >with sub matrix 1,2,3,4, and sub matrix 2 with submatrix 1,2,3,4,
>etc.
>> >
>> >The program runs well at first, but at the last step, which is
>> >calculating
>> >the correlation between submatrix 4 with itself, the program was
>killed
>> >and
>> >gave no error messages.
>> >
>> >Have anybody else encountered this before?
>> >
>> >Actually it doesn't have to be related with gpuCor. Just generally
>> >speaking, in what circumstances would a R program be killed
>> >spontaneously
>> >without any error messages?
>> >
>> >Thanks.
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> >__
>> >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.
>>
>>

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


[R] POSIXct-coerced NA's not considered NA by is.na()

2012-08-24 Thread Alexander Shenkin
Hello folks,

I found a strangeness while experimenting with POSIXct vectors and
lists.  It seems that coerced NA's aren't "real" NAs, at least as
considered by is.na()?

> date_vec = c(as.POSIXct(now()), as.POSIXct(now()+1),NA,"b")
> date_vec
[1] "2012-08-22 15:00:46 COT" "2012-08-22 15:00:47 COT" NA

[4] NA
Warning message:
In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
> date_vec[4]
[1] NA
Warning message:
In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
> is.na(date_vec[4])
[1] FALSE
> is.na(date_vec[3])
[1] TRUE
> is.POSIXct(date_vec[4])
[1] TRUE

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


Re: [R] R minimal calculation error

2012-08-24 Thread Petr Savicky
On Fri, Aug 24, 2012 at 12:48:54PM +0200, Frederik Bertling wrote:
> Hi,
> 
> I'm doing some easy calculations to normalize some values. This looks like
> this:
> 
> x=mean(a+b+c+d ...)
> a=a-x
> b=b-x
> c=c-x
> d=d-x
> ...
> mean(a+b+c+d ...) ---> Should now be 0!
> However, I'm getting results like -2.315223e-18
> This is really near to 0 but not very aesthetic.
> 
> Can I prevent this? Or is this behaviour desired?

Hi.

This is a consequence of the limited precision, which is used
for speed. Examples of this type exist also for the decimal
arithmetic. Using 3 digit precision, the arithmetic mean of
the three numbers 1.02, 1.01, 1.01 is 1.01. So, the sum of the
differences

  1.02 - 1.01
  1.01 - 1.01
  1.01 - 1.01

is not zero.

See functions zapsmall(), all.equal().

Hope this helps.

Petr Savicky.

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


[R] (no subject)

2012-08-24 Thread Lynn Hutchings
I'm very new to R and just finding my way, so be gentle!



I've hit a swift halt doing some summary statistics on a simple continuous data 
field, divided into two categories. I'm getting the following error message. I 
am unclear why length(names(tth$Mins.to.hospital)) is zero and how to alter 
this. This is preventing me from carrying the summary data forward to any 
further analyses, which I need to create some new variables to account for the 
missing data points.



I'm sure this is a very simple error, and I apologise for asking!



Lynn







The output is below - I have the epicalc program loaded.

> aggregate(tth$Mins.to.hospital, by=list(DIRECT=tth$JR.1st.hospital))

 Note:
  Missing values removed.

  DIRECT count..  sum..mean.. median.. sd.. min.. max.$
1 No  76 202607 2665.8816  630 5297.410   217 26495
2Yes 319  57859  181.3762   70 1314.982 0 23180
Warning messages:
1: In names(y)[length(names(y))] <- paste("count", as.character(substitute(x)), 
 :
  number of items to replace is not a multiple of replacement length
2: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
  number of items to replace is not a multiple of replacement length
3: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
  number of items to replace is not a multiple of replacement length
4: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
  number of items to replace is not a multiple of replacement length
5: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
  number of items to replace is not a multiple of replacement length
6: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
  number of items to replace is not a multiple of replacement length
7: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
  number of items to replace is not a multiple of replacement length
> colnames(tth)
[1] "Time.to.hospital.arrival.present.only" "Mins.to.hospital"  
"JR.1st.hospital"
> length(names(tth$Mins.to.hospital))
[1] 0
> length(paste("Count", as.character(substitute(tth$JR.1st.hospital
[1] 3

[[alternative HTML version deleted]]

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


Re: [R] Euclidean distance function

2012-08-24 Thread Arbuckle
Thank you kindly for both of the replies I've received, that does indeed work
perfectly. I had been looking at the description of that function and it
reads as though it only deals with 2-dimensional data. Thanks again!

Kev



--
View this message in context: 
http://r.789695.n4.nabble.com/Euclidean-distance-function-tp4641177p4641193.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] apply a function separately on each element of a list

2012-08-24 Thread Daniel Malter
The easiest way may be to use lmList in the nlme library:

#simulate data
d<-rep(1:10,each=10)
x<-rnorm(100)
e<-rnorm(100)
y<-2*x+e

require(nlme) #or install and load package

lmList(y~x|d)

#predicted values are obtained with:

predict(lmList(y~x|d)

HTH,
Daniel





jeff6868 wrote
> 
> Hi everybody,
> 
> I have a question about applying a specific function (with the
> calculations I want to do), on a list of elements.
> 
> Each elements are like a data.frame (with nrows and ncolumns), and have
> the same structure.
> At frist, I had a big data.frame that I splitted in all my elements of my
> list. They have been splitted by day.
> For example, the name of the first element of my list is "2011-01-01", and
> is a data.frame corresponding to all my data from this specific date. Then
> my second element is "2011-01-02", etc
> 
> My question is: how can I apply a function on each element separately (a
> bit like a loop)?
> 
> For example, if my data from the first element "2011-01-01" is:
> element1 <- data.frame(x=rnorm(1:10),data=c(1:10))
> 
> I would like to do a regression between "x" and "data (so lm(data ~x) ),
> to get the predicted values of the regression, and then to keep the
> results in a new object.
> 
> And then, do the same with the second element (regression between "x" and
> "data" of the second element), keep the results of the predicted values
> and keep the results.
> 
> ... and so one with 200 elements.
> 
> Is there any way to do this?
> 
> Thanks a lot!
> 




--
View this message in context: 
http://r.789695.n4.nabble.com/apply-a-function-separately-on-each-element-of-a-list-tp4641186p4641204.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Euclidean distance function

2012-08-24 Thread Rui Barradas

Hello,

You don't need to write a function. Try the following.


nms <- paste0("species", 1:4)
mat <- matrix(rnorm(16), ncol=4, dimnames = list(nms, nms))
?dist
dist(mat)
dist(mat, diag = TRUE, upper = TRUE)

Hope this helps,

Rui Barradas

Em 24-08-2012 11:56, Arbuckle escreveu:

Hi,

I should preface this problem with a statement that although I am sure this
is a really easy function to write, I have tried and failed to get my head
around writing functions in R. I can use R where functions exist to do what
I want done, but have found myself completely incapable of writing them
myself.

The problem is that I have a table with several rows of species and several
columns of trait data for each species. Now what I want to do is, for each
possible pair of species, extract the Euclidean distance between them based
on specified trait data columns. While as far as I can see the dist()
function could manage this to some extent for 2 dimensions (traits) for each
species, I need a more generalised function that can handle n-dimensions.
Ideally this function would allow me to choose which columns (traits) to use
to calculate the Euclidean distance rather than having to reformat the
dataset every time.

In the hope of clarifying this with a simplified example, I want to take a
dataset like this:

Species x  y  z  n
spA  2.9 34.2 0.5415.7
spB  5.5 46.5 0.4519.4
spC  1.4 48.6 0.8424.8
spD  8.3 56.1 0.4821.3

Then extract the Euclidean distances using the general equation
d=sqrt[(x2-x1)^2+(y2-y1)^2+...+(n2-n1)^2] for particular data columns. So in
this example I might want the distances using the traits x, z and n, thereby
specifying the equation to be d=sqrt[(x2-x1)^2+(z2-z1)^2+(n2-n1)^2], and
return a distance matrix as follows (calculated distances represented by .
for the purposes of this example):

Species spA spB spC
spB  .
spC  .   .
spD  .   .   .

I hope this makes sense. I only presume that this would be a quick and easy
function to write on the basis that the underlying process is basically
simple maths repeated for each pair of species. Again I have no experience
in writing custom functions (no matter how simple) and just can't seem to
get into my head how to go about it.

I look forward to your response and hope someone gets bored enough to
quickly write out the code to implement this function. Thank you in advance.

Best wishes,

Kev



--
View this message in context: 
http://r.789695.n4.nabble.com/Euclidean-distance-function-tp4641177.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] apply a function separately on each element of a list

2012-08-24 Thread jeff6868
Hi everybody,

I have a question about applying a specific function (with the calculations
I want to do), on a list of elements.

Each elements are like a data.frame (with nrows and ncolumns), and have the
same structure.
At frist, I had a big data.frame that I splitted in all my elements of my
list. They have been splitted by day.
For example, the name of the first element of my list is "2011-01-01", and
is a data.frame corresponding to all my data from this specific date. Then
my second element is "2011-01-02", etc

My question is: how can I apply a function on each element separately (a bit
like a loop)?

For example, if my data from the first element "2011-01-01" is:
element1 <- data.frame(x=rnorm(1:10),data=c(1:10))

I would like to do a regression between "x" and "data (so lm(data ~x) ), to
get the predicted values of the regression, and then to keep the results in
a new object.

And then, do the same with the second element (regression between "x" and
"data" of the second element), keep the results of the predicted values and
keep the results.

... and so one with 200 elements.

Is there any way to do this?

Thanks a lot!



--
View this message in context: 
http://r.789695.n4.nabble.com/apply-a-function-separately-on-each-element-of-a-list-tp4641186.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] (no subject)

2012-08-24 Thread jim holtman
What are your expectations as to what
"length(names(tth$Mins.to.hospital))" should be returning?  You need
to at least provide some data so we can reproduce the error, or
'str(tth)'.  My guess is that tth$Mins.to.hospital does not have any
'names' attributes and therefore your error.  So what is the problem
you are trying to solve with the expression that is giving the error?

On Fri, Aug 24, 2012 at 8:51 AM, Lynn Hutchings
 wrote:
> I'm very new to R and just finding my way, so be gentle!
>
>
>
> I've hit a swift halt doing some summary statistics on a simple continuous 
> data field, divided into two categories. I'm getting the following error 
> message. I am unclear why length(names(tth$Mins.to.hospital)) is zero and how 
> to alter this. This is preventing me from carrying the summary data forward 
> to any further analyses, which I need to create some new variables to account 
> for the missing data points.
>
>
>
> I'm sure this is a very simple error, and I apologise for asking!
>
>
>
> Lynn
>
>
>
>
>
>
>
> The output is below - I have the epicalc program loaded.
>
>> aggregate(tth$Mins.to.hospital, by=list(DIRECT=tth$JR.1st.hospital))
>
>  Note:
>   Missing values removed.
>
>   DIRECT count..  sum..mean.. median.. sd.. min.. max.$
> 1 No  76 202607 2665.8816  630 5297.410   217 26495
> 2Yes 319  57859  181.3762   70 1314.982 0 23180
> Warning messages:
> 1: In names(y)[length(names(y))] <- paste("count", 
> as.character(substitute(x)),  :
>   number of items to replace is not a multiple of replacement length
> 2: In names(y)[length(names(y))] <- paste(FUN[i], 
> as.character(substitute(x)),  :
>   number of items to replace is not a multiple of replacement length
> 3: In names(y)[length(names(y))] <- paste(FUN[i], 
> as.character(substitute(x)),  :
>   number of items to replace is not a multiple of replacement length
> 4: In names(y)[length(names(y))] <- paste(FUN[i], 
> as.character(substitute(x)),  :
>   number of items to replace is not a multiple of replacement length
> 5: In names(y)[length(names(y))] <- paste(FUN[i], 
> as.character(substitute(x)),  :
>   number of items to replace is not a multiple of replacement length
> 6: In names(y)[length(names(y))] <- paste(FUN[i], 
> as.character(substitute(x)),  :
>   number of items to replace is not a multiple of replacement length
> 7: In names(y)[length(names(y))] <- paste(FUN[i], 
> as.character(substitute(x)),  :
>   number of items to replace is not a multiple of replacement length
>> colnames(tth)
> [1] "Time.to.hospital.arrival.present.only" "Mins.to.hospital"
>   "JR.1st.hospital"
>> length(names(tth$Mins.to.hospital))
> [1] 0
>> length(paste("Count", as.character(substitute(tth$JR.1st.hospital
> [1] 3
>
> [[alternative HTML version deleted]]
>
> __
> 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] Pseudo R squared in gls model

2012-08-24 Thread Mike Miller

On Thu, 23 Aug 2012, Gary Dong wrote:

I'm wondering if the gls function reports pseudo R. I do not see it by 
summary(). If the package does not report, can I calculate it in this 
way?


Adjusted pseudo R squared = 1 - [(Loglik(beta) - k ) / Loglik(null)] where
k is the number of IVs.



We've been using this R² instead, but I'm not sure if it is available in 
any package:


Buse, A. (1973), "Goodness of Fit in Generalized Least Squares 
Estimation," American Statistician, 27, 106-108.


http://www.jstor.org/stable/10.2307/2683631

Equation 15.  Make sure to compute y-bar correctly (it is the regression 
coefficient in the intercept-only model).


To do GLS, we have been using OLS after transformation (multiplying by the 
"T" matrix in Buse's notation) where T'T = inv(V).  So the equation on the 
final page works for us.


Let me know if you can't access that PDF and I'll send a copy.

Mike

--
Michael B. Miller, Ph.D.
Minnesota Center for Twin and Family Research
Department of Psychology
University of Minnesota__
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.


Re: [R] (no subject)

2012-08-24 Thread Rui Barradas

Hello,

You must post a data example to get some help. Use

dput( head(tth, 50) )  # paste the output of this in a post

As for the warnings, they are not errors. They are telling you that it 
can't make a replacement. substitute(x) is probably returning NULL and 
the aggregate return value's column names are ill formed, 'count..' 
where it should be 'count.Mins.to.hospital'.


Anyway, post a data example.

Hope this helps,

Rui Barradas

Em 24-08-2012 13:51, Lynn Hutchings escreveu:

I'm very new to R and just finding my way, so be gentle!



I've hit a swift halt doing some summary statistics on a simple continuous data 
field, divided into two categories. I'm getting the following error message. I 
am unclear why length(names(tth$Mins.to.hospital)) is zero and how to alter 
this. This is preventing me from carrying the summary data forward to any 
further analyses, which I need to create some new variables to account for the 
missing data points.



I'm sure this is a very simple error, and I apologise for asking!



Lynn







The output is below - I have the epicalc program loaded.


aggregate(tth$Mins.to.hospital, by=list(DIRECT=tth$JR.1st.hospital))

  Note:
   Missing values removed.

   DIRECT count..  sum..mean.. median.. sd.. min.. max.$
1 No  76 202607 2665.8816  630 5297.410   217 26495
2Yes 319  57859  181.3762   70 1314.982 0 23180
Warning messages:
1: In names(y)[length(names(y))] <- paste("count", as.character(substitute(x)), 
 :
   number of items to replace is not a multiple of replacement length
2: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
   number of items to replace is not a multiple of replacement length
3: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
   number of items to replace is not a multiple of replacement length
4: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
   number of items to replace is not a multiple of replacement length
5: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
   number of items to replace is not a multiple of replacement length
6: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
   number of items to replace is not a multiple of replacement length
7: In names(y)[length(names(y))] <- paste(FUN[i], as.character(substitute(x)),  
:
   number of items to replace is not a multiple of replacement length

colnames(tth)

[1] "Time.to.hospital.arrival.present.only" "Mins.to.hospital"  
"JR.1st.hospital"

length(names(tth$Mins.to.hospital))

[1] 0

length(paste("Count", as.character(substitute(tth$JR.1st.hospital

[1] 3

[[alternative HTML version deleted]]

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


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


Re: [R] Extracting data from dataframe with tied rows

2012-08-24 Thread William Dunlap
Or use ave() to compute the within-group ranks (reversed, so max has rank 1) 
and select
the elements whose ranks are 1:
f2 <- function (DATA) 
{
stopifnot(is.data.frame(DATA), all(c("distance", "id", "month") %in% 
names(DATA)))
revRanks <- ave(DATA[["distance"]], DATA[["id"]], DATA[["month"]], 
FUN = function(x) rank(-x, ties = "first"))
DATA[revRanks == 1, ]
}

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Peter Alspach
> Sent: Thursday, August 23, 2012 4:37 PM
> To: rjb; r-help@r-project.org
> Subject: Re: [R] Extracting data from dataframe with tied rows
> 
> Tena koe John
> 
> One way:
> 
> johnData <- data.frame(id=rep(LETTERS[1:5],20), distance=rnorm(1:100, mean = 
> 100),
> bearing=sample(1:360,100,replace=T), month=sample(1:12,100,replace=T))
> johnAgg <- aggregate(johnData[,'distance'], johnData[,c('id','month')], max)
> names(johnAgg)[3] <- 'distance'
> merge(johnAgg, johnData)
> 
> HTH 
> 
> Peter Alspach
> 
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of rjb
> Sent: Friday, 24 August 2012 9:19 a.m.
> To: r-help@r-project.org
> Subject: [R] Extracting data from dataframe with tied rows
> 
> Hi R help,
> 
> I'm a fairly experienced R user but this manipulation has me stumped, please
> help:
> 
> DATA
> id<-rep(LETTERS[1:5],20)
> distance<-rnorm(1:100, mean = 100)
> bearing<-sample(1:360,100,replace=T)
> month<-sample(1:12,100,replace=T)
> 
> I have a dataset with records of individuals (id) , each with a distance
> (distance) & direction (bearing) recorded for each month (month).
> I want to find the largest distance per individual per month, which is easy
> with /tapply/ or /melt/cast (reshape)/,
> head(DATA_m<-melt(DATA,id=c("id","month")))
> cast(DATA_m,id+month~.,max)
> OR
> na.omit(melt(tapply(distance,list(id,month),max)))
> 
> *BUT THE CATCH IS* ,
> I also want the the *corresponding*  bearing for that maximum distance per
> month. I've tried the steps above plus using which.max() and loops, but
> can't solve the problem. The real dataset is about 6000 rows.
> 
> I'm guessing the answer is in finding the row number from the original DATA
> but I can't figure how to do that with tapply or melt.
> 
> Any suggestions would be greatly appreciated.
> 
> John Burnside
> 
> 
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Extracting-data-from-
> dataframe-with-tied-rows-tp4641140.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> 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.
> 
> The contents of this e-mail are confidential and may be subject to legal 
> privilege.
>  If you are not the intended recipient you must not use, disseminate, 
> distribute or
>  reproduce all or any part of this e-mail or attachments.  If you have 
> received this
>  e-mail in error, please notify the sender and delete all material pertaining 
> to this
>  e-mail.  Any opinion or views expressed in this e-mail are those of the 
> individual
>  sender and may not represent those of The New Zealand Institute for Plant and
>  Food Research Limited.
> 
> __
> 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.

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


[R] help with a special variant of balloonplot

2012-08-24 Thread ravi
Hi,
I am interested in implementing a special variant of
balloonplot.  Let me
explain with an example dataset from the reference manual :

library(gplots)
data(Titanic)
dframe<-as.data.frame(Titanic)
survived<-dframe[dframe$Survived=="Yes",]
attach(survived)
balloonplot(x=Class,y=list(Age,Sex),z=Freq,sort=TRUE,show.zeros=TRUE,cum.margins=FALSE,
            main="BalloonPlot : Surviving passengers") # standard 
plot
# Now comes the attempt at something more special
FreqThresh=50 # A threshold level
Freqdev<-Freq-FreqThresh # A new variable
colors=ifelse(Freqdev>0,"green","magenta") 
balloonplot(x=Class,y=list(Age,Sex),z=Freqdev,sort=TRUE,show.zeros=TRUE,cum.margins=FALSE,dotcol=colors,
show.margins=FALSE,main="BalloonPlot : Surviving passengers")
 
I am interested in a table with the
values unchanged from the titanic dataframe. These values should be highlighted
in balloons in two different colours, let’s say, green and magenta. For
positive values of Freqdev, the balloons will be green and have a size
depending on the magnitude of Freqdev. For negative values of Freqdev, the 
balloons
will have a colour of magenta and have a size proportional to the absolute
values of Freqdev.
I am not sure if a simple tweak can lead to a solution.

I will appreciate any help that I can get.
Thanks,
Ravi

[[alternative HTML version deleted]]

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


Re: [R] POSIXct-coerced NA's not considered NA by is.na()

2012-08-24 Thread jim holtman
I think your first problem is the coersion done by 'c' when you are
mixing objects of various types: you have POSIXct and character.  What
were your expections?

> x <- Sys.time()
> str(x)
 POSIXct[1:1], format: "2012-08-24 13:12:31"
> y <- c(x, 'b')
> str(y)
 POSIXct[1:2], format: "2012-08-24 13:12:31" NA
Warning message:
In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
> dput(y)
structure(c("1345828351.75", "b"), class = c("POSIXct", "POSIXt"
))
>

Look at the 'dput' and see that what it is trying to do is to use the
numeric value changed to a character string as a POSIXct value.  So I
am not surprised by the error since it is probably not what you
wanted.  Did you intend to use 'list' instead of 'c'?

On Fri, Aug 24, 2012 at 9:47 AM, Alexander Shenkin  wrote:
> Hello folks,
>
> I found a strangeness while experimenting with POSIXct vectors and
> lists.  It seems that coerced NA's aren't "real" NAs, at least as
> considered by is.na()?
>
>> date_vec = c(as.POSIXct(now()), as.POSIXct(now()+1),NA,"b")
>> date_vec
> [1] "2012-08-22 15:00:46 COT" "2012-08-22 15:00:47 COT" NA
>
> [4] NA
> Warning message:
> In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
>> date_vec[4]
> [1] NA
> Warning message:
> In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
>> is.na(date_vec[4])
> [1] FALSE
>> is.na(date_vec[3])
> [1] TRUE
>> is.POSIXct(date_vec[4])
> [1] TRUE
>
> __
> 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] apply a function separately on each element of a list

2012-08-24 Thread Rui Barradas

Hello,

Your example doesn't run, lmList needs a 'data' argument.

set.seed(8109)
d <- rep(1:10, each=10)
x <- rnorm(100)
e <- rnorm(100)
y <- 2*x + e

dat <- data.frame(x=x, y=y, d=d, e=e)

model <- lmList(y ~ x | d, data = dat)
predict(model)

To the op: if you already have the larger data.farme divided into a list 
of smaller df's, such as the 'lst' below, you can use lapply.



df.lst <- split(dat, dat$d)


model.lst <- lapply(df.lst, function(.data) lm(y ~ x, data = .data))
lapply(model.lst, coef)  # just an example
lapply(model.lst, predict)  # what you want

Hope this helps,

Rui Barradas

Em 24-08-2012 16:05, Daniel Malter escreveu:

The easiest way may be to use lmList in the nlme library:

#simulate data
d<-rep(1:10,each=10)
x<-rnorm(100)
e<-rnorm(100)
y<-2*x+e

require(nlme) #or install and load package

lmList(y~x|d)

#predicted values are obtained with:

predict(lmList(y~x|d)

HTH,
Daniel





jeff6868 wrote

Hi everybody,

I have a question about applying a specific function (with the
calculations I want to do), on a list of elements.

Each elements are like a data.frame (with nrows and ncolumns), and have
the same structure.
At frist, I had a big data.frame that I splitted in all my elements of my
list. They have been splitted by day.
For example, the name of the first element of my list is "2011-01-01", and
is a data.frame corresponding to all my data from this specific date. Then
my second element is "2011-01-02", etc

My question is: how can I apply a function on each element separately (a
bit like a loop)?

For example, if my data from the first element "2011-01-01" is:
element1 <- data.frame(x=rnorm(1:10),data=c(1:10))

I would like to do a regression between "x" and "data (so lm(data ~x) ),
to get the predicted values of the regression, and then to keep the
results in a new object.

And then, do the same with the second element (regression between "x" and
"data" of the second element), keep the results of the predicted values
and keep the results.

... and so one with 200 elements.

Is there any way to do this?

Thanks a lot!





--
View this message in context: 
http://r.789695.n4.nabble.com/apply-a-function-separately-on-each-element-of-a-list-tp4641186p4641204.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] read/write data in libsvm format

2012-08-24 Thread Sam Steingold
How do I read/write libsvm data into/from R?

The libsvm format is sparse data like

[ :]*

e.g.,

1 10:3.4 123:0.5 34567:0.231
0.2 22:1 456:03

The "foreign" library does not seem to provide the necessary functionality.

Any suggestions? Code?

Thanks!

http://stackoverflow.com/questions/12112558/r-read-write-data-in-libsvm-format

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://think-israel.org http://truepeace.org
http://ffii.org http://memri.org http://palestinefacts.org
Any programming language is at its best before it is implemented and used.

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


Re: [R] Concatenating data frames in R versus SAS

2012-08-24 Thread ramoss
I used summary <-rbind.fill(agency,prop) & it worked like a charm. Thanks
everyone.



--
View this message in context: 
http://r.789695.n4.nabble.com/Concatenating-data-frames-in-R-versus-SAS-tp4641138p4641219.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Extracting data from dataframe with tied rows

2012-08-24 Thread Peter Ehlers

Here's another pretty straightforward solution, using the plyr pkg:

 DF <- data.frame(id, month, distance, bearing)
   # variables as defined in the OP

 require(plyr)
 DF1<-ddply(DF, .(id,month), summarize,
   maxdist = max(distance),
   maxbearing = bearing[which.max(distance)])

Peter Ehlers

On 2012-08-24 09:54, William Dunlap wrote:

Or use ave() to compute the within-group ranks (reversed, so max has rank 1) 
and select
the elements whose ranks are 1:
f2 <- function (DATA)
{
 stopifnot(is.data.frame(DATA), all(c("distance", "id", "month") %in%
 names(DATA)))
 revRanks <- ave(DATA[["distance"]], DATA[["id"]], DATA[["month"]],
 FUN = function(x) rank(-x, ties = "first"))
 DATA[revRanks == 1, ]
}

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of Peter Alspach
Sent: Thursday, August 23, 2012 4:37 PM
To: rjb; r-help@r-project.org
Subject: Re: [R] Extracting data from dataframe with tied rows

Tena koe John

One way:

johnData <- data.frame(id=rep(LETTERS[1:5],20), distance=rnorm(1:100, mean = 
100),
bearing=sample(1:360,100,replace=T), month=sample(1:12,100,replace=T))
johnAgg <- aggregate(johnData[,'distance'], johnData[,c('id','month')], max)
names(johnAgg)[3] <- 'distance'
merge(johnAgg, johnData)

HTH 

Peter Alspach

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of rjb
Sent: Friday, 24 August 2012 9:19 a.m.
To: r-help@r-project.org
Subject: [R] Extracting data from dataframe with tied rows

Hi R help,

I'm a fairly experienced R user but this manipulation has me stumped, please
help:

DATA
id<-rep(LETTERS[1:5],20)
distance<-rnorm(1:100, mean = 100)
bearing<-sample(1:360,100,replace=T)
month<-sample(1:12,100,replace=T)

I have a dataset with records of individuals (id) , each with a distance
(distance) & direction (bearing) recorded for each month (month).
I want to find the largest distance per individual per month, which is easy
with /tapply/ or /melt/cast (reshape)/,
head(DATA_m<-melt(DATA,id=c("id","month")))
cast(DATA_m,id+month~.,max)
OR
na.omit(melt(tapply(distance,list(id,month),max)))

*BUT THE CATCH IS* ,
I also want the the *corresponding*  bearing for that maximum distance per
month. I've tried the steps above plus using which.max() and loops, but
can't solve the problem. The real dataset is about 6000 rows.

I'm guessing the answer is in finding the row number from the original DATA
but I can't figure how to do that with tapply or melt.

Any suggestions would be greatly appreciated.

John Burnside


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


Re: [R] POSIXct-coerced NA's not considered NA by is.na()

2012-08-24 Thread Alexander Shenkin
Thanks for your reply, Jim.

On 8/24/2012 12:14 PM, jim holtman wrote:
> I think your first problem is the coersion done by 'c' when you are
> mixing objects of various types: you have POSIXct and character.

Yes, that's something I may have confounded. Still, the warning I'm
getting is "In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion".
 I'm not sure how c()'s coercion works - the warning seems to indicate
that c() is finding as.POSIXct.  That's strange though, since I would
expect to get an error in that case, not just a warning:

> as.POSIXct("b")
Error in as.POSIXlt.character(x, tz, ...) :
  character string is not in a standard unambiguous format

> What were your expections?

I was expecting that the NA resulting from the coercion would result in
a TRUE value when being operated on by is.na().  Instead, I got:

> is.na(date_vec[4])
[1] FALSE

>> x <- Sys.time()
>> str(x)
>  POSIXct[1:1], format: "2012-08-24 13:12:31"
>> y <- c(x, 'b')
>> str(y)
>  POSIXct[1:2], format: "2012-08-24 13:12:31" NA
> Warning message:
> In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
>> dput(y)
> structure(c("1345828351.75", "b"), class = c("POSIXct", "POSIXt"
> ))
>>
> 
> Look at the 'dput' and see that what it is trying to do is to use the
> numeric value changed to a character string as a POSIXct value.  So I
> am not surprised by the error since it is probably not what you
> wanted.  Did you intend to use 'list' instead of 'c'?

I'm a bit confused about how you get that from dput.  Here's what I see:

> dput(date_vec)
structure(c("1345831833", "1345831834", NA, "b"), class = c("POSIXct",
"POSIXt"))

Regardless, I do get the same strange is.na() behavior from the following:

> bad_date = "b"
> class(bad_date) = "POSIXct"
> bad_date
[1] NA
Warning message:
In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
> is.na(bad_date) # shouldn't this be TRUE?
[1] FALSE

As nasty as it may be, shouldn't something showing up as "NA" result in
TRUE when being tested by is.na()?

Just to put some context around this, I was investigating this issue as
I was thinking about converting dataframe columns to dates, and
detecting errors in that conversion.

thanks,
Allie

> 
> On Fri, Aug 24, 2012 at 9:47 AM, Alexander Shenkin  wrote:
>> Hello folks,
>>
>> I found a strangeness while experimenting with POSIXct vectors and
>> lists.  It seems that coerced NA's aren't "real" NAs, at least as
>> considered by is.na()?
>>
>>> date_vec = c(as.POSIXct(now()), as.POSIXct(now()+1),NA,"b")
>>> date_vec
>> [1] "2012-08-22 15:00:46 COT" "2012-08-22 15:00:47 COT" NA
>>
>> [4] NA
>> Warning message:
>> In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
>>> date_vec[4]
>> [1] NA
>> Warning message:
>> In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
>>> is.na(date_vec[4])
>> [1] FALSE
>>> is.na(date_vec[3])
>> [1] TRUE
>>> is.POSIXct(date_vec[4])
>> [1] TRUE

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


[R] if then in R versus SAS

2012-08-24 Thread ramoss
I am new to R and I have the following SAS statements:

if otype='M' and ocond='1' and entry='a.Prop' then MOC=1;
else MOC=0;

How would I translate that into R code?

Thanks in advance
 



--
View this message in context: 
http://r.789695.n4.nabble.com/if-then-in-R-versus-SAS-tp4641225.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] if then in R versus SAS

2012-08-24 Thread Marc Schwartz

On Aug 24, 2012, at 1:03 PM, ramoss  wrote:

> I am new to R and I have the following SAS statements:
> 
> if otype='M' and ocond='1' and entry='a.Prop' then MOC=1;
> else MOC=0;
> 
> How would I translate that into R code?
> 
> Thanks in advance



See ?ifelse and ?Logic, both of which are covered in "An Introduction to R" 
(http://cran.r-project.org/manuals.html).

  MOC <- ifelse((otype == 'M') & (ocond == '1') & (entry == 'a.Prop'), 1, 0)


You might also want to think about getting a copy of:

R for SAS and SPSS Users
Robert Muenchen
http://www.amazon.com/SAS-SPSS-Users-Statistics-Computing/dp/0387094172

Regards,

Marc Schwartz

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


[R] PHP escapeshellcmd() equivalent

2012-08-24 Thread Roebuck,Paul L
[Redirected from R-Devel...]

Not that I recall running across such, but does R (or CRAN package)
provide something equivalent to PHP's escapeshellcmd() function
to escape shell job control, wildcards, etc?

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


Re: [R] if then in R versus SAS

2012-08-24 Thread Daniel Nordlund
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Marc Schwartz
> Sent: Friday, August 24, 2012 12:06 PM
> To: ramoss
> Cc: r-help@r-project.org
> Subject: Re: [R] if then in R versus SAS
> 
> 
> On Aug 24, 2012, at 1:03 PM, ramoss  wrote:
> 
> > I am new to R and I have the following SAS statements:
> >
> > if otype='M' and ocond='1' and entry='a.Prop' then MOC=1;
> > else MOC=0;
> >
> > How would I translate that into R code?
> >
> > Thanks in advance
> 
> 
> 
> See ?ifelse and ?Logic, both of which are covered in "An Introduction to
> R" (http://cran.r-project.org/manuals.html).
> 
>   MOC <- ifelse((otype == 'M') & (ocond == '1') & (entry == 'a.Prop'), 1,
> 0)
> 
> 
> You might also want to think about getting a copy of:
> 
> R for SAS and SPSS Users
> Robert Muenchen
> http://www.amazon.com/SAS-SPSS-Users-Statistics-Computing/dp/0387094172
> 
> Regards,
> 
> Marc Schwartz
> 

I would second Mark's recommendation to carefully work through "An Introduction 
to R" and to get Robert Muenchen's book.  If the variables otype, ocond, and 
entry are scalar values, then the translation from SAS to R is very 
straight-forward:

if(otype=='M' && ocond=='1' && entry=='a.Prop') MOC <- 1 else MOC <- 0


Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA
 

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


[R] 2 (related) problems with RODBC in 64 bit Windows

2012-08-24 Thread Ivan Alves
Hi all,

I am encountering an RODBC problem in R 2.15.1 in windows 64 bit which I do not 
encountered in the same set up in windows 32 bit (the latest binary version of 
RODBC in both cases from the same depository gotten by 
install.packages(‘RODBC’), Oracle ODBC client software installed in 64 and 32 
bit respectively)

1.  The code looks like


library(RODBC)

credentials <- read.csv("~/credentials.csv", head=T, row.names=1)

db <- odbcConnect(dsn="DSN", uid=credentials["DSN", "username"], 
pwd=credentials["DSN", "password"], rows_at_time=1024)


on which the odbcConnect call fails with the following error code

Error in nchar(uid) : 'nchar()' requires a character vector

(

credentials are processed correctly and credentials["DSN", "username"] 
correctly returns – by the way a factor –

[1] _username_

Levels: …

).


When I run the equivalent call with direct arguments


db <- odbcConnect("DSN", uid="_username_", pwd="_password_", rows_at_time=1024)


it works just fine.  Furthermore both work just fine on windows 32 bit, or on 
both systems when the colClasses = "character" option is used. Is this perhaps 
a problem with RODBC in 64 bit when dealing with factors that is not a problem 
in 32 bit?


2.  Furthermore (and as reported in 
http://stackoverflow.com/questions/3407015/querying-oracle-db-from-revolution-r-using-rodbc),
 there are issues with using sqlQuery without the option believeNRows=FALSE, as 
RODBC seems to still have issues with signed vs. unsigned integer (or 
sizeof(long) between 32 and 64 bit.


Any chance the problems have the same source in RODBC code and could be 
addressed in the near future (after apparently years of making difficult the 
transition to 64 bit for work with Oracle servers)? (is there an implicit 
encouragement to use RJDBC when combining 64 bit R use and Oracle databases?)

Many thanks in advance for any guidance.

Ivan
[[alternative HTML version deleted]]

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


Re: [R] PHP escapeshellcmd() equivalent

2012-08-24 Thread R. Michael Weylandt
I don't know PHP, but what does escapeshellcmd() provide over and
above what system() / system2() do?

Cheers,
Michael

On Fri, Aug 24, 2012 at 2:48 PM, Roebuck,Paul L  wrote:
> [Redirected from R-Devel...]
>
> Not that I recall running across such, but does R (or CRAN package)
> provide something equivalent to PHP's escapeshellcmd() function
> to escape shell job control, wildcards, etc?
>
> __
> 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.

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


[R] SparseM buglet

2012-08-24 Thread Sam Steingold
read.matrix.csr does not close the connection:

> library('SparseM')
Package SparseM (0.96) loaded.
> read.matrix.csr(foo)
...
Warning message:
closing unused connection 3 (foo)
>


-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://truepeace.org http://camera.org
http://pmw.org.il http://think-israel.org http://dhimmi.com
My other CAR is a CDR.

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


Re: [R] Please help....normalization by the median of some control genes

2012-08-24 Thread Roebuck,Paul L
On 8/23/12 7:37 AM, "David Lyon"  wrote:

> Can someone show me some code to do normalization by the median of some
> control genes for the example below?
> Many Many Thanks in advance
>
>
> This strategy selects a subset of genes (called ³control genes²) and makes the
> median of their data distribution similar across arrays.
> 

        id1     id2    id3
> control1    0.8    0.7    0.6
>
control2    0.6    0.2    0.4
>
probe1      0.3    0.2    0.5
>
probe2      0.4    0.9    0.7
>
probe3      0.6    0.7    0.4

SuperCurve* has a normalization function that normalizes
by median, variable slope, and housekeeping genes.
But it's geared towards slightly larger problems...
It's used in production by our Core Labs to process their RPPAs.



* Shameless plug

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


Re: [R] PHP escapeshellcmd() equivalent

2012-08-24 Thread Roebuck,Paul L
On 8/24/12 2:59 PM, "R. Michael Weylandt" 
wrote:

> On Fri, Aug 24, 2012 at 2:48 PM, Roebuck,Paul 
> wrote:
>> [Redirected from R-Devel...]
>> 
>> Not that I recall running across such, but does R (or CRAN package)
>> provide something equivalent to PHP's escapeshellcmd() function
>> to escape shell job control, wildcards, etc?
>
> I don't know PHP, but what does escapeshellcmd() provide over and
> above what system() / system2() do?
> 

As before, it escapes job control, etc from the command string.
Assuming such existed in R, it would be used something like this:

R> system(escapeshellcmd(sprintf("somecmd %s", untrustedInput1)))

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


[R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi R-Helpers,

I don't think I need to post a dataset for this question but if I do, I
can.  Anyway, I am having a lot of trouble with the ifelse command.

Here is my code:


vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1,
0 )


And here is my output that doesn't make ANY sense:

  PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0  31403 1
0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0 0
83078 1 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
165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23
1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1 0
2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1

As you can see, there are many instances where PM.EXP > 0 and PM.DIST.TOT =
1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
such as the last line of data.

WWHHH Why why why why why why why? Why?

(Sorry, I've been trying to figure this out for hours and I've devolved to
mumbling in corners and banging my head against the table)

What in the world am I doing wrong?  Or is ifelse not the right function?

Best,

Jen

[[alternative HTML version deleted]]

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 3:22 PM, Jennifer Sabatier
 wrote:
> Hi R-Helpers,
>
> I don't think I need to post a dataset for this question but if I do, I
> can.  Anyway, I am having a lot of trouble with the ifelse command.
>
You probably should have: dput() makes it super easy as well.

> Here is my code:
>
>
> vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1,
> 0 )
>
>
> And here is my output that doesn't make ANY sense:
>
>   PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0  31403 1
> 0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0 0
> 83078 1 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
> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23
> 1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1 0
> 2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1

Indeed it makes no sense to me either because you sent HTML email
which got mangled by the server.

>
> As you can see, there are many instances where PM.EXP > 0 and PM.DIST.TOT =
> 1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
> such as the last line of data.
>
> WWHHH Why why why why why why why? Why?
>
> (Sorry, I've been trying to figure this out for hours and I've devolved to
> mumbling in corners and banging my head against the table)
>
> What in the world am I doing wrong?  Or is ifelse not the right function?

First guess standard problems with equality of floating point
numbers. (See R FAQ 7.31 for the details)

You probably want to change

x == 1

to

abs(x - 1) < 1e-05

or something similar.

Cheers,
Michael

>
> Best,
>
> Jen
>
> [[alternative HTML version deleted]]
>
> __
> 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.

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Oops, sorry, I thought I was in plain text.  I can't tell the
difference because I use so little formatting in my emails.

Try this (a truncated version since I have to hand space everything):

PM.EXP  PM.DIST.TOT PM.DIST_flag
0  00
6417   11
23 10
97691   2   1
0  00
33993   2   1


On Fri, Aug 24, 2012 at 4:36 PM, R. Michael Weylandt
 wrote:
>
> On Fri, Aug 24, 2012 at 3:22 PM, Jennifer Sabatier
>  wrote:
> > Hi R-Helpers,
> >
> > I don't think I need to post a dataset for this question but if I do, I
> > can.  Anyway, I am having a lot of trouble with the ifelse command.
> >
> You probably should have: dput() makes it super easy as well.
>
> > Here is my code:
> >
> >
> > vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0),
> > 1,
> > 0 )
> >
> >
> > And here is my output that doesn't make ANY sense:
> >
> >   PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0
> > 31403 1
> > 0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0
> > 0 0
> > 83078 1 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
> > 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1
> > 23
> > 1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1
> > 0
> > 2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1
>
> Indeed it makes no sense to me either because you sent HTML email
> which got mangled by the server.
>
> >
> > As you can see, there are many instances where PM.EXP > 0 and
> > PM.DIST.TOT =
> > 1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
> > such as the last line of data.
> >
> > WWHHH Why why why why why why why? Why?
> >
> > (Sorry, I've been trying to figure this out for hours and I've devolved
> > to
> > mumbling in corners and banging my head against the table)
> >
> > What in the world am I doing wrong?  Or is ifelse not the right
> > function?
>
> First guess standard problems with equality of floating point
> numbers. (See R FAQ 7.31 for the details)
>
> You probably want to change
>
> x == 1
>
> to
>
> abs(x - 1) < 1e-05
>
> or something similar.
>
> Cheers,
> Michael
>
> >
> > Best,
> >
> > Jen
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > 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.

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Bert Gunter
... and if Michael is correct, there is a lesson here: Think of how
much time and aggravation you would have saved yourself if you had
FIRST made an effort to read the docs. The FAQ's are there for a
reason. As is An Introduction to R, which also should be read before
posting on this list.

If Michael is wrong, then the above homily should be amended to:
If you have not already done so, read the FAQ's and An Introduction to
R. You will save yourself -- and us -- much time and effort by doing
so.

Thus endeth the lesson.

-- Bert

On Fri, Aug 24, 2012 at 1:36 PM, R. Michael Weylandt
 wrote:
> On Fri, Aug 24, 2012 at 3:22 PM, Jennifer Sabatier
>  wrote:
>> Hi R-Helpers,
>>
>> I don't think I need to post a dataset for this question but if I do, I
>> can.  Anyway, I am having a lot of trouble with the ifelse command.
>>
> You probably should have: dput() makes it super easy as well.
>
>> Here is my code:
>>
>>
>> vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1,
>> 0 )
>>
>>
>> And here is my output that doesn't make ANY sense:
>>
>>   PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0  31403 1
>> 0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0 0
>> 83078 1 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
>> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23
>> 1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1 0
>> 2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1
>
> Indeed it makes no sense to me either because you sent HTML email
> which got mangled by the server.
>
>>
>> As you can see, there are many instances where PM.EXP > 0 and PM.DIST.TOT =
>> 1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
>> such as the last line of data.
>>
>> WWHHH Why why why why why why why? Why?
>>
>> (Sorry, I've been trying to figure this out for hours and I've devolved to
>> mumbling in corners and banging my head against the table)
>>
>> What in the world am I doing wrong?  Or is ifelse not the right function?
>
> First guess standard problems with equality of floating point
> numbers. (See R FAQ 7.31 for the details)
>
> You probably want to change
>
> x == 1
>
> to
>
> abs(x - 1) < 1e-05
>
> or something similar.
>
> Cheers,
> Michael
>
>>
>> Best,
>>
>> Jen
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> 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.
>
> __
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] Extracting data from dataframe with tied rows

2012-08-24 Thread William Dunlap
Another strategy is to sort by month, id, and, in reverse order,
distance and select the rows that start each month/id run.  This
can be much faster than the other ways when there are lots of
month/id combinations.

f1 <- function (DATA) 
{
stopifnot(is.data.frame(DATA),
  all(c("distance", "id", "month") %in% names(DATA)))
DATA <- DATA[order(DATA$month, DATA$id, -DATA$distance), ]
ldiff <- function(x) c(TRUE, x[-1] != x[-length(x)])
DATA[ldiff(DATA$month) | ldiff(DATA$id), ]
}

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: Peter Ehlers [mailto:ehl...@ucalgary.ca]
> Sent: Friday, August 24, 2012 10:51 AM
> To: William Dunlap
> Cc: Peter Alspach; rjb; r-help@r-project.org
> Subject: Re: [R] Extracting data from dataframe with tied rows
> 
> Here's another pretty straightforward solution, using the plyr pkg:
> 
>   DF <- data.frame(id, month, distance, bearing)
> # variables as defined in the OP
> 
>   require(plyr)
>   DF1<-ddply(DF, .(id,month), summarize,
> maxdist = max(distance),
> maxbearing = bearing[which.max(distance)])
> 
> Peter Ehlers
> 
> On 2012-08-24 09:54, William Dunlap wrote:
> > Or use ave() to compute the within-group ranks (reversed, so max has rank 
> > 1) and
> select
> > the elements whose ranks are 1:
> > f2 <- function (DATA)
> > {
> >  stopifnot(is.data.frame(DATA), all(c("distance", "id", "month") %in%
> >  names(DATA)))
> >  revRanks <- ave(DATA[["distance"]], DATA[["id"]], DATA[["month"]],
> >  FUN = function(x) rank(-x, ties = "first"))
> >  DATA[revRanks == 1, ]
> > }
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> >> Of Peter Alspach
> >> Sent: Thursday, August 23, 2012 4:37 PM
> >> To: rjb; r-help@r-project.org
> >> Subject: Re: [R] Extracting data from dataframe with tied rows
> >>
> >> Tena koe John
> >>
> >> One way:
> >>
> >> johnData <- data.frame(id=rep(LETTERS[1:5],20), distance=rnorm(1:100, mean 
> >> = 100),
> >> bearing=sample(1:360,100,replace=T), month=sample(1:12,100,replace=T))
> >> johnAgg <- aggregate(johnData[,'distance'], johnData[,c('id','month')], 
> >> max)
> >> names(johnAgg)[3] <- 'distance'
> >> merge(johnAgg, johnData)
> >>
> >> HTH 
> >>
> >> Peter Alspach
> >>
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> >> Of rjb
> >> Sent: Friday, 24 August 2012 9:19 a.m.
> >> To: r-help@r-project.org
> >> Subject: [R] Extracting data from dataframe with tied rows
> >>
> >> Hi R help,
> >>
> >> I'm a fairly experienced R user but this manipulation has me stumped, 
> >> please
> >> help:
> >>
> >> DATA
> >> id<-rep(LETTERS[1:5],20)
> >> distance<-rnorm(1:100, mean = 100)
> >> bearing<-sample(1:360,100,replace=T)
> >> month<-sample(1:12,100,replace=T)
> >>
> >> I have a dataset with records of individuals (id) , each with a distance
> >> (distance) & direction (bearing) recorded for each month (month).
> >> I want to find the largest distance per individual per month, which is easy
> >> with /tapply/ or /melt/cast (reshape)/,
> >> head(DATA_m<-melt(DATA,id=c("id","month")))
> >> cast(DATA_m,id+month~.,max)
> >> OR
> >> na.omit(melt(tapply(distance,list(id,month),max)))
> >>
> >> *BUT THE CATCH IS* ,
> >> I also want the the *corresponding*  bearing for that maximum distance per
> >> month. I've tried the steps above plus using which.max() and loops, but
> >> can't solve the problem. The real dataset is about 6000 rows.
> >>
> >> I'm guessing the answer is in finding the row number from the original DATA
> >> but I can't figure how to do that with tapply or melt.
> >>
> >> Any suggestions would be greatly appreciated.
> >>
> >> John Burnside
> 

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


[R] Hosted R

2012-08-24 Thread Matthew K. Hettinger
I looked in the archives and couldn't find anything that really 
addressed my question so here it is -


Does anyone know of any web sites/environments that hosts R for free, 
web-based, multi-user access to the R engine. My apologies if the 
question is too simplistic for this forum. The reason I ask is that I'm 
looking at the possibility of establishing an R grid if one doesn't 
already exist, and if one does, then I'm looking for interfaces, 
protocols, and guidelines for adding an R node.


--
Matthew K. Hettinger, Enterprise Architect and Systemist
Mathet Consulting, Inc.

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Peter Ehlers

On 2012-08-24 13:22, Jennifer Sabatier wrote:

Hi R-Helpers,

I don't think I need to post a dataset for this question but if I do, I
can.  Anyway, I am having a lot of trouble with the ifelse command.

Here is my code:


vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1,
0 )


And here is my output that doesn't make ANY sense:

   PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0  31403 1
0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0 0
83078 1 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
165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23
1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1 0
2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1

As you can see, there are many instances where PM.EXP > 0 and PM.DIST.TOT =
1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
such as the last line of data.


_Many_ instances?? I see only 4 such cases. Still not good, though.
Here's what you should do:

1. Don't send html mail.
2. use simple variable names (x,y,z would do fine here).
3. either provide the data or at least a part of it with dput() or
   at least provide str(vn).
4. when you're trying to decide between operator error and bug, go
   with the operator error theory. You'll be correct at least 99% of
   the time.

I ran your command on the above (suitably deciphered) data and had no
problem getting what I think you expect (i.e. the four suspect cases
came out just as they should). But what my mailer provides as your
data may not be what you really have.

Oh, and get a bandage for that head bruise.

Peter Ehlers



WWHHH Why why why why why why why? Why?

(Sorry, I've been trying to figure this out for hours and I've devolved to
mumbling in corners and banging my head against the table)

What in the world am I doing wrong?  Or is ifelse not the right function?

Best,

Jen

[[alternative HTML version deleted]]

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



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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Bert,

I will thank you not to condescend to me, as I am too damn old (40) to
be treated that way.  You didn't even offer a solution to my problem.
You only came to chastise me with regards to your assumptions about
me, which is very annoying.

While I am at the beginner level of R, I am not an idiot.  Or an
infant.  I've been a statistician for more than 12 years, mostly
programming in SAS.  I've been moving into R for the past 3 years.

I am EXTENSIVELY familiar with the documentation.  The documentation
is how I've learned to code in R.

I NEVER post to R-help until I've exhausted my own ability to solve
the problem, INCLUDING combing through the documentation.  And looking
at other requests for help to see if the problem has arisen for
someone else.

One of the reason I wait to the last minute to post to R-help is
because it is a very snobby and often unfriendly list, as your comment
illustrates.  You just assumed I hadn't already looked though the
docs.  Nice.

The reality of it is, what Michael pointed out to me wasn't something
I'd discovered in my own search of the docs.  And that, Bert, someone
like me comes to R-help.

Please, Bert, don't we want the whole world to use R?  They won't if
the community is so unwelcoming.

Now, if you have a solution, please post it.  If not, leave off while
I explore Michael's suggestion.

Best,

Jen



On Fri, Aug 24, 2012 at 4:49 PM, Bert Gunter  wrote:
> ... and if Michael is correct, there is a lesson here: Think of how
> much time and aggravation you would have saved yourself if you had
> FIRST made an effort to read the docs. The FAQ's are there for a
> reason. As is An Introduction to R, which also should be read before
> posting on this list.
>
> If Michael is wrong, then the above homily should be amended to:
> If you have not already done so, read the FAQ's and An Introduction to
> R. You will save yourself -- and us -- much time and effort by doing
> so.
>
> Thus endeth the lesson.
>
> -- Bert
>
> On Fri, Aug 24, 2012 at 1:36 PM, R. Michael Weylandt
>  wrote:
>> On Fri, Aug 24, 2012 at 3:22 PM, Jennifer Sabatier
>>  wrote:
>>> Hi R-Helpers,
>>>
>>> I don't think I need to post a dataset for this question but if I do, I
>>> can.  Anyway, I am having a lot of trouble with the ifelse command.
>>>
>> You probably should have: dput() makes it super easy as well.
>>
>>> Here is my code:
>>>
>>>
>>> vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1,
>>> 0 )
>>>
>>>
>>> And here is my output that doesn't make ANY sense:
>>>
>>>   PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0  31403 1
>>> 0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0 0
>>> 83078 1 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
>>> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23
>>> 1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1 0
>>> 2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1
>>
>> Indeed it makes no sense to me either because you sent HTML email
>> which got mangled by the server.
>>
>>>
>>> As you can see, there are many instances where PM.EXP > 0 and PM.DIST.TOT =
>>> 1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
>>> such as the last line of data.
>>>
>>> WWHHH Why why why why why why why? Why?
>>>
>>> (Sorry, I've been trying to figure this out for hours and I've devolved to
>>> mumbling in corners and banging my head against the table)
>>>
>>> What in the world am I doing wrong?  Or is ifelse not the right function?
>>
>> First guess standard problems with equality of floating point
>> numbers. (See R FAQ 7.31 for the details)
>>
>> You probably want to change
>>
>> x == 1
>>
>> to
>>
>> abs(x - 1) < 1e-05
>>
>> or something similar.
>>
>> Cheers,
>> Michael
>>
>>>
>>> Best,
>>>
>>> Jen
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> 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.
>>
>> __
>> 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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Peter,

I'm really sorry, I thought I was in plain text.  I don't use any
formatting in my emails and in Gmail the HTML looks the same as plain
text.

Anyway, I've attached the data (I didn't think we could do that but I
am frequently wrong).

I say many cases because this is just a subset of >300 observations.

The error seems to happen without a pattern I can discern.  I am
assuming I am doing something wrong.

Thanks,

Jen


On Fri, Aug 24, 2012 at 5:17 PM, Peter Ehlers  wrote:
> On 2012-08-24 13:22, Jennifer Sabatier wrote:
>>
>> Hi R-Helpers,
>>
>> I don't think I need to post a dataset for this question but if I do, I
>> can.  Anyway, I am having a lot of trouble with the ifelse command.
>>
>> Here is my code:
>>
>>
>> vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1,
>> 0 )
>>
>>
>> And here is my output that doesn't make ANY sense:
>>
>>PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0  31403
>> 1
>> 0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0
>> 0
>> 83078 1 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
>> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1
>> 23
>> 1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1 0
>> 2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1
>>
>> As you can see, there are many instances where PM.EXP > 0 and PM.DIST.TOT
>> =
>> 1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
>> such as the last line of data.
>
>
> _Many_ instances?? I see only 4 such cases. Still not good, though.
> Here's what you should do:
>
> 1. Don't send html mail.
> 2. use simple variable names (x,y,z would do fine here).
> 3. either provide the data or at least a part of it with dput() or
>at least provide str(vn).
> 4. when you're trying to decide between operator error and bug, go
>with the operator error theory. You'll be correct at least 99% of
>the time.
>
> I ran your command on the above (suitably deciphered) data and had no
> problem getting what I think you expect (i.e. the four suspect cases
> came out just as they should). But what my mailer provides as your
> data may not be what you really have.
>
> Oh, and get a bandage for that head bruise.
>
> Peter Ehlers
>
>>
>> WWHHH Why why why why why why why? Why?
>>
>> (Sorry, I've been trying to figure this out for hours and I've devolved to
>> mumbling in corners and banging my head against the table)
>>
>> What in the world am I doing wrong?  Or is ifelse not the right function?
>>
>> Best,
>>
>> Jen
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> 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.
>>
>
__
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.


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Rui Barradas

Hello,

Michael's standard guess, FAQ 7.31, was also mine, but is wrong. The 
error is in Jennifer's flag column,  not the result of her ifelse. (!)



x <- scan(what="character", text="
 PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0 31403 1
0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0 0
83078 1 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
165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23
1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0 1478 1 0
2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1
")

vn <- matrix(as.numeric(x[-(1:3)]), ncol=3, byrow=TRUE)
vn <- data.frame(vn)
names(vn) <- x[1:3]
str(vn)
vn$flag2 <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1, 0 )

str(vn)
identical(vn$PM.DIST_flag, vn$flag2)  # FALSE
inx <- vn$PM.DIST_flag != vn$flag2
vn[inx, ]

As you can see, there's nothing wrong with ifelse. The second standard 
guess is that Jennifer had something, a variable, in her session messing 
up with the variables envolved in the ifelse.


Also, when the result of a if/else or ifelse is, by this order, 1 or 0, 
the following can be used, with performance benefits.


vn$flag3 <- 1 * (vn$PM.EXP > 0.0 & vn$PM.DIST.TOT != 1.0) # make T/F 
numeric 1/0


Hope this helps,

Rui Barradas
Em 24-08-2012 21:43, Jennifer Sabatier escreveu:

Oops, sorry, I thought I was in plain text.  I can't tell the
difference because I use so little formatting in my emails.

Try this (a truncated version since I have to hand space everything):

PM.EXP  PM.DIST.TOT PM.DIST_flag
0  00
6417   11
23 10
97691   2   1
0  00
33993   2   1


On Fri, Aug 24, 2012 at 4:36 PM, R. Michael Weylandt
 wrote:

On Fri, Aug 24, 2012 at 3:22 PM, Jennifer Sabatier
 wrote:

Hi R-Helpers,

I don't think I need to post a dataset for this question but if I do, I
can.  Anyway, I am having a lot of trouble with the ifelse command.


You probably should have: dput() makes it super easy as well.


Here is my code:


vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0),
1,
0 )


And here is my output that doesn't make ANY sense:

   PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0
31403 1
0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0
0 0
83078 1 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
165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1
23
1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1
0
2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1

Indeed it makes no sense to me either because you sent HTML email
which got mangled by the server.


As you can see, there are many instances where PM.EXP > 0 and
PM.DIST.TOT =
1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
such as the last line of data.

WWHHH Why why why why why why why? Why?

(Sorry, I've been trying to figure this out for hours and I've devolved
to
mumbling in corners and banging my head against the table)

What in the world am I doing wrong?  Or is ifelse not the right
function?

First guess standard problems with equality of floating point
numbers. (See R FAQ 7.31 for the details)

You probably want to change

x == 1

to

abs(x - 1) < 1e-05

or something similar.

Cheers,
Michael


Best,

Jen

 [[alternative HTML version deleted]]

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

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


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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
BTW - no one else who has replied to this topic was snobby or
unfriendly and I thank you very much for trying to help me.

It's just Bert is not the first to respond to my request for help as
such.  As someone looking forward to becoming an advanced R programmer
in my statistical work it is discouraging to be castigated FOR ASKING
FOR HELP.

Thank you, all.

Best,

Jen

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


Re: [R] Hosted R

2012-08-24 Thread Roebuck,Paul L
On 8/24/12 4:02 PM, "Matthew K. Hettinger"  wrote:

> I looked in the archives and couldn't find anything that really
> addressed my question so here it is -
> 
> Does anyone know of any web sites/environments that hosts R for free,
> web-based, multi-user access to the R engine. My apologies if the
> question is too simplistic for this forum. The reason I ask is that I'm
> looking at the possibility of establishing an R grid if one doesn't
> already exist, and if one does, then I'm looking for interfaces,
> protocols, and guidelines for adding an R node.

Roll your own?
 


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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Rui,

Thanks so much for responding but I think with my HTML problem the vn
data you made must not be the same.  I tried running your code on the
data (I uploaded a copy) and I got the same thing I had before.

Jen

On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:
>
> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
Off the wall / wild guess, do you use attach() frequently? Not
entirely sure how it would come up, but it tends to make weird errors
like this occur.

M

On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
 wrote:
> Hi Rui,
>
> Thanks so much for responding but I think with my HTML problem the vn
> data you made must not be the same.  I tried running your code on the
> data (I uploaded a copy) and I got the same thing I had before.
>
> Jen
>
> On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:
>>
>> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23

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


[R] RJSONIO/rjson maximum depth?

2012-08-24 Thread Theodore Van Rooy
Hi All,

has anyone run into maximum depth of nested JSON arrays in either rjson or
RJSONIO ?

I seem to be able to get up to 10 depth levels without problem, but
crossing over to 11 either causes an error or fails to load the nodes
properly.

with RJSONIO I tried:

a = fromJSON('data/myJSON.json', depth=1000)

but I still get this error:

Error in fromJSON(content, handler, default.size, depth, allowComments,  :
  Invalid JSON Node

The JSON file loads correctly until I add this node at the 10th level of an
existing node (note all of my nodes have this exact format:



"node3": {...},
"node4":{
"nodeName":"nodeName4",
"nodeType":"object",
"nodeDeps":["nodeNames"],
"nodeDefaults":["NULL"],
"nodeDef":{
"node4":{
"nodeName":"nodeName5",
"nodeType":"object",
"nodeDeps":["nodeNames"],
"nodeDefaults":["NULL"],
"nodeDef":["a=1"],
"nodeOutput":["a"],
"nodeX":1,
"nodeY":1
}
   },
"node5":{...}

Where {..}  denotes a node structure which has a JSON array at the field
nodeDef, i.e. [item, item, item]

Theo

-- 
Theodore Van Rooy
http://greentheo.scroggles.com

[[alternative HTML version deleted]]

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Michael,

No, I never use attach(), exactly for the reasons you state.  To do
due diligence I did a search of code for the function and it didn't
come up (I would have been shocked because I never us it!).

Now that real data is up, does your suggestion still apply?  I am
reading it now.

Thanks,

Jen

On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
 wrote:
> Off the wall / wild guess, do you use attach() frequently? Not
> entirely sure how it would come up, but it tends to make weird errors
> like this occur.
>
> M
>
> On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
>  wrote:
>> Hi Rui,
>>
>> Thanks so much for responding but I think with my HTML problem the vn
>> data you made must not be the same.  I tried running your code on the
>> data (I uploaded a copy) and I got the same thing I had before.
>>
>> Jen
>>
>> On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:
>>>
>>> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Rui Barradas

No data arrived to me.

Rui Barradas
Em 24-08-2012 22:46, Jennifer Sabatier escreveu:

Hi Michael,

No, I never use attach(), exactly for the reasons you state.  To do
due diligence I did a search of code for the function and it didn't
come up (I would have been shocked because I never us it!).

Now that real data is up, does your suggestion still apply?  I am
reading it now.

Thanks,

Jen

On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
 wrote:

Off the wall / wild guess, do you use attach() frequently? Not
entirely sure how it would come up, but it tends to make weird errors
like this occur.

M

On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
 wrote:

Hi Rui,

Thanks so much for responding but I think with my HTML problem the vn
data you made must not be the same.  I tried running your code on the
data (I uploaded a copy) and I got the same thing I had before.

Jen

On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:

165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23


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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier
 wrote:
> Hi Michael,
>
> No, I never use attach(), exactly for the reasons you state.  To do
> due diligence I did a search of code for the function and it didn't
> come up (I would have been shocked because I never us it!).
>
> Now that real data is up, does your suggestion still apply?  I am
> reading it now.
>

If you mean the data you sent to Peter, it got scrubbed by the list
servers as well (they are somewhat draconian, but appropriately so in
the long run). The absolute best way to send R data via email (esp on
this list) is to use the dput() function which will create a plain
text representation of your data _exactly_ as R sees it. It's a little
hard for the untrained eye to parse (I can usually get about 90% of
what it all means but there's some stuff with rownames = NA I've never
looked into) but it's perfectly reproducible to a different R session.
Then us having the same data is a simple copy+paste away.

For more on dput() and reproducibility generally, see
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

It could be the floating point thing (it's hard to say without knowing
how your data was calculated), but Rui seems to think not.

M

> Thanks,
>
> Jen
>
> On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
>  wrote:
>> Off the wall / wild guess, do you use attach() frequently? Not
>> entirely sure how it would come up, but it tends to make weird errors
>> like this occur.
>>
>> M
>>
>> On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
>>  wrote:
>>> Hi Rui,
>>>
>>> Thanks so much for responding but I think with my HTML problem the vn
>>> data you made must not be the same.  I tried running your code on the
>>> data (I uploaded a copy) and I got the same thing I had before.
>>>
>>> Jen
>>>
>>> On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:

 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 4:50 PM, R. Michael Weylandt
 wrote:
> On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier
>  wrote:
>> Hi Michael,
>>
>> No, I never use attach(), exactly for the reasons you state.  To do
>> due diligence I did a search of code for the function and it didn't
>> come up (I would have been shocked because I never us it!).
>>
>> Now that real data is up, does your suggestion still apply?  I am
>> reading it now.
>>
>
> If you mean the data you sent to Peter, it got scrubbed by the list
> servers as well (they are somewhat draconian, but appropriately so in
> the long run). The absolute best way to send R data via email (esp on
> this list) is to use the dput() function which will create a plain
> text representation of your data _exactly_ as R sees it. It's a little
> hard for the untrained eye to parse (I can usually get about 90% of
> what it all means but there's some stuff with rownames = NA I've never
> looked into) but it's perfectly reproducible to a different R session.
> Then us having the same data is a simple copy+paste away.

Note that the dput() output is to be put into the body of the email,
not in an attachment or we're back where we started ;-)

M

>
> For more on dput() and reproducibility generally, see
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>
> It could be the floating point thing (it's hard to say without knowing
> how your data was calculated), but Rui seems to think not.
>
> M
>
>> Thanks,
>>
>> Jen
>>
>> On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
>>  wrote:
>>> Off the wall / wild guess, do you use attach() frequently? Not
>>> entirely sure how it would come up, but it tends to make weird errors
>>> like this occur.
>>>
>>> M
>>>
>>> On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
>>>  wrote:
 Hi Rui,

 Thanks so much for responding but I think with my HTML problem the vn
 data you made must not be the same.  I tried running your code on the
 data (I uploaded a copy) and I got the same thing I had before.

 Jen

 On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:
>
> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  
> 23

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Oh, sorry, I first though you couldn't post data to the list, but then
I thought I remembered other people doing so, so I tried to post it.

Here is a copy.

Thanks,

Jen

On Fri, Aug 24, 2012 at 5:49 PM, Rui Barradas  wrote:
> No data arrived to me.
>
> Rui Barradas
> Em 24-08-2012 22:46, Jennifer Sabatier escreveu:
>
>> Hi Michael,
>>
>> No, I never use attach(), exactly for the reasons you state.  To do
>> due diligence I did a search of code for the function and it didn't
>> come up (I would have been shocked because I never us it!).
>>
>> Now that real data is up, does your suggestion still apply?  I am
>> reading it now.
>>
>> Thanks,
>>
>> Jen
>>
>> On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
>>  wrote:
>>>
>>> Off the wall / wild guess, do you use attach() frequently? Not
>>> entirely sure how it would come up, but it tends to make weird errors
>>> like this occur.
>>>
>>> M
>>>
>>> On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
>>>  wrote:

 Hi Rui,

 Thanks so much for responding but I think with my HTML problem the vn
 data you made must not be the same.  I tried running your code on the
 data (I uploaded a copy) and I got the same thing I had before.

 Jen

 On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas 
 wrote:
>
> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1
> 23
>
>
__
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.


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Michael,

Thanks for letting me know how to post data.  I will try to upload it
that way in a second.

I can usually use code to make a reproducible dataset but this time
with the ifelse behaving strangely (perhaps, it's probably me) I
didn't think I could do it easily so I figured I would just put my
data up.

I will check out the R FAQ you mentioned.

Thanks, again,

Jen



On Fri, Aug 24, 2012 at 5:50 PM, R. Michael Weylandt
 wrote:
> On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier
>  wrote:
>> Hi Michael,
>>
>> No, I never use attach(), exactly for the reasons you state.  To do
>> due diligence I did a search of code for the function and it didn't
>> come up (I would have been shocked because I never us it!).
>>
>> Now that real data is up, does your suggestion still apply?  I am
>> reading it now.
>>
>
> If you mean the data you sent to Peter, it got scrubbed by the list
> servers as well (they are somewhat draconian, but appropriately so in
> the long run). The absolute best way to send R data via email (esp on
> this list) is to use the dput() function which will create a plain
> text representation of your data _exactly_ as R sees it. It's a little
> hard for the untrained eye to parse (I can usually get about 90% of
> what it all means but there's some stuff with rownames = NA I've never
> looked into) but it's perfectly reproducible to a different R session.
> Then us having the same data is a simple copy+paste away.
>
> For more on dput() and reproducibility generally, see
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>
> It could be the floating point thing (it's hard to say without knowing
> how your data was calculated), but Rui seems to think not.
>
> M
>
>> Thanks,
>>
>> Jen
>>
>> On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
>>  wrote:
>>> Off the wall / wild guess, do you use attach() frequently? Not
>>> entirely sure how it would come up, but it tends to make weird errors
>>> like this occur.
>>>
>>> M
>>>
>>> On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
>>>  wrote:
 Hi Rui,

 Thanks so much for responding but I think with my HTML problem the vn
 data you made must not be the same.  I tried running your code on the
 data (I uploaded a copy) and I got the same thing I had before.

 Jen

 On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:
>
> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  
> 23

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


[R] mgcv package, problems with NAs in gam

2012-08-24 Thread grace
Hi there,

I'm using presence-absence data in a gam (i.e. 0 or 1 as values)
I am trying to run a gam with 'dummy covariates' i.e. 1~1
unfortunately my model:
*
model<-gam(1~1, data=bats, family=negbin)*

keeps putting out:

*
Error in gam(1 ~ 1, data = bats, family = negbin) : 
  Not enough (non-NA) data to do anything meaningful*

Is there a specific reason it would do this? I have tried using various
actions on NAs, na.pass etc, as well as asking it to turn all NAs to 0 but
to no avail.

I would post the data here but its rather long, basically 28x104 matrix of
0/1 with headers 'v1:v28' .The summary for the data comes up fine, it's just
the model that isn't working. 
However if I run using:

*model<-gam(v1~v2, data=bats, family=negbin)
* 

it tends to work.

Any help is seriously appreciated as I have a deadline and have been trying
this for days,

Thanks!



--
View this message in context: 
http://r.789695.n4.nabble.com/mgcv-package-problems-with-NAs-in-gam-tp4641253.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] RJSONIO/rjson maximum depth?

2012-08-24 Thread Noia Raindrops
Hi,

You missed a close bracket.

node4:{
  ...
  nodeDef:{
node4:{
  ...
# need a close bracket here
  }
},

-- 
Noia Raindrops
noia.raindr...@gmail.com

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Peter Ehlers

I see that you got other responses while I was composing an answer.
Your 'example.csv' did come through for me, but I still can't
replicate your PM.DIST_flag variable. Specifically, observations
30, 33, 36 and 40 are wrong.

I agree with Rui, that there's something else going on. The data
you've sent can't be the data that yielded the 'flag' variable
or you didn't use the ifelse() function in the way that you've
shown.

I would start with a clean R session and I would use the 'convert
logical to numeric' idea (or keep a logical rather than numeric
flag):

  vn <- transform(vn,
  my_flag = ( (PM.EXP > 0) & (PM.DIST.TOT != 1) ) * 1 )

It looks as though your PM.DIST.TOT variable is meant to be
integer. If so, you might want to ensure that it is that type.
Otherwise, you might want to use Michael's suggestion of using
abs(... - 1) < 1e-05.

Peter Ehlers

On 2012-08-24 14:56, Jennifer Sabatier wrote:

Hi Michael,

Thanks for letting me know how to post data.  I will try to upload it
that way in a second.

I can usually use code to make a reproducible dataset but this time
with the ifelse behaving strangely (perhaps, it's probably me) I
didn't think I could do it easily so I figured I would just put my
data up.

I will check out the R FAQ you mentioned.

Thanks, again,

Jen



On Fri, Aug 24, 2012 at 5:50 PM, R. Michael Weylandt
 wrote:

On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier
 wrote:

Hi Michael,

No, I never use attach(), exactly for the reasons you state.  To do
due diligence I did a search of code for the function and it didn't
come up (I would have been shocked because I never us it!).

Now that real data is up, does your suggestion still apply?  I am
reading it now.



If you mean the data you sent to Peter, it got scrubbed by the list
servers as well (they are somewhat draconian, but appropriately so in
the long run). The absolute best way to send R data via email (esp on
this list) is to use the dput() function which will create a plain
text representation of your data _exactly_ as R sees it. It's a little
hard for the untrained eye to parse (I can usually get about 90% of
what it all means but there's some stuff with rownames = NA I've never
looked into) but it's perfectly reproducible to a different R session.
Then us having the same data is a simple copy+paste away.

For more on dput() and reproducibility generally, see
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

It could be the floating point thing (it's hard to say without knowing
how your data was calculated), but Rui seems to think not.

M


Thanks,

Jen

On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
 wrote:

Off the wall / wild guess, do you use attach() frequently? Not
entirely sure how it would come up, but it tends to make weird errors
like this occur.

M

On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
 wrote:

Hi Rui,

Thanks so much for responding but I think with my HTML problem the vn
data you made must not be the same.  I tried running your code on the
data (I uploaded a copy) and I got the same thing I had before.

Jen

On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas  wrote:


165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23


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



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


Re: [R] SparseM buglet

2012-08-24 Thread Roger Koenker
Sam,

Thanks for pointing this out, but I have to point out in turn  that this isn't 
a SparseM function,
it is part of the package e1071,  maintained by David Meyer.

Roger

Roger Koenker
rkoen...@illinois.edu




On Aug 24, 2012, at 3:07 PM, Sam Steingold wrote:

> read.matrix.csr does not close the connection:
> 
>> library('SparseM')
> Package SparseM (0.96) loaded.
>> read.matrix.csr(foo)
> ...
> Warning message:
> closing unused connection 3 (foo)
>> 
> 
> 
> -- 
> Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 
> 11.0.11103000
> http://www.childpsy.net/ http://truepeace.org http://camera.org
> http://pmw.org.il http://think-israel.org http://dhimmi.com
> My other CAR is a CDR.

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


Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
AHHH I GOT IT!!

And I *think* I understand about floating point arithmetic..

In this case vn$PM.DIST.TOT is the sum of proportions.  So, it should
be anywhere 0 and 1.

In our case, if it's anything other than 1 when vn$PM.EXP is greater
than 0  then it means something is wrong with one of the variables
used to sum vn$PM.DIST.TOT.

I was worried making it an integer will cause cases of 0.4 to be 0 and
look legal, when it's not (though it doesn't actually seem to be a
problem).

So, I just did what Michael and Peter suggested, after reading up on
floating points.

fpf <- 1e-05   # fpf = floating point fuzz

vn$PM.DIST_flag<-ifelse(vn$PM.EXP > 0 & abs(vn$PM.DIST.TOT - 1) > fpf , 1, 0)

YAY

Thanks, solved AND I learned something new.

Thanks, alll, and have a GREAT weekend!

Jen


On Fri, Aug 24, 2012 at 6:27 PM, Peter Ehlers  wrote:
> I see that you got other responses while I was composing an answer.
> Your 'example.csv' did come through for me, but I still can't
> replicate your PM.DIST_flag variable. Specifically, observations
> 30, 33, 36 and 40 are wrong.
>
> I agree with Rui, that there's something else going on. The data
> you've sent can't be the data that yielded the 'flag' variable
> or you didn't use the ifelse() function in the way that you've
> shown.
>
> I would start with a clean R session and I would use the 'convert
> logical to numeric' idea (or keep a logical rather than numeric
> flag):
>
>   vn <- transform(vn,
>   my_flag = ( (PM.EXP > 0) & (PM.DIST.TOT != 1) ) * 1 )
>
> It looks as though your PM.DIST.TOT variable is meant to be
> integer. If so, you might want to ensure that it is that type.
> Otherwise, you might want to use Michael's suggestion of using
> abs(... - 1) < 1e-05.
>
> Peter Ehlers
>
>
> On 2012-08-24 14:56, Jennifer Sabatier wrote:
>>
>> Hi Michael,
>>
>> Thanks for letting me know how to post data.  I will try to upload it
>> that way in a second.
>>
>> I can usually use code to make a reproducible dataset but this time
>> with the ifelse behaving strangely (perhaps, it's probably me) I
>> didn't think I could do it easily so I figured I would just put my
>> data up.
>>
>> I will check out the R FAQ you mentioned.
>>
>> Thanks, again,
>>
>> Jen
>>
>>
>>
>> On Fri, Aug 24, 2012 at 5:50 PM, R. Michael Weylandt
>>  wrote:
>>>
>>> On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier
>>>  wrote:

 Hi Michael,

 No, I never use attach(), exactly for the reasons you state.  To do
 due diligence I did a search of code for the function and it didn't
 come up (I would have been shocked because I never us it!).

 Now that real data is up, does your suggestion still apply?  I am
 reading it now.

>>>
>>> If you mean the data you sent to Peter, it got scrubbed by the list
>>> servers as well (they are somewhat draconian, but appropriately so in
>>> the long run). The absolute best way to send R data via email (esp on
>>> this list) is to use the dput() function which will create a plain
>>> text representation of your data _exactly_ as R sees it. It's a little
>>> hard for the untrained eye to parse (I can usually get about 90% of
>>> what it all means but there's some stuff with rownames = NA I've never
>>> looked into) but it's perfectly reproducible to a different R session.
>>> Then us having the same data is a simple copy+paste away.
>>>
>>> For more on dput() and reproducibility generally, see
>>>
>>> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>>>
>>> It could be the floating point thing (it's hard to say without knowing
>>> how your data was calculated), but Rui seems to think not.
>>>
>>> M
>>>
 Thanks,

 Jen

 On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
  wrote:
>
> Off the wall / wild guess, do you use attach() frequently? Not
> entirely sure how it would come up, but it tends to make weird errors
> like this occur.
>
> M
>
> On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier
>  wrote:
>>
>> Hi Rui,
>>
>> Thanks so much for responding but I think with my HTML problem the vn
>> data you made must not be the same.  I tried running your code on the
>> data (I uploaded a copy) and I got the same thing I had before.
>>
>> Jen
>>
>> On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas 
>> wrote:
>>>
>>>
>>> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1
>>> 1  23
>>
>>
>> __
>> 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.
>>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 7:29 PM, Jennifer Sabatier
 wrote:
> AHHH I GOT IT!!
>
> And I *think* I understand about floating point arithmetic..

Well then you're doing much better than the rest of us: it's quite a
difficult subject and only gets trickier as you think about it more.
(Numerical analysis generally, not the definition of an IEEE754 / ISO
6059 double) You even get such fun as

-1 * 0 != 1 * 0.

under some interpretations.

>
> In this case vn$PM.DIST.TOT is the sum of proportions.  So, it should
> be anywhere 0 and 1.
>
> In our case, if it's anything other than 1 when vn$PM.EXP is greater
> than 0  then it means something is wrong with one of the variables
> used to sum vn$PM.DIST.TOT.
>
> I was worried making it an integer will cause cases of 0.4 to be 0 and
> look legal, when it's not (though it doesn't actually seem to be a
> problem).
>
> So, I just did what Michael and Peter suggested, after reading up on
> floating points.
>
> fpf <- 1e-05   # fpf = floating point fuzz

Though I sugested 1e-05 here, usually one uses slightly more stringent
testing: a general rule of thumb is the square root of machine
precision. In R terms,

sqrt(.Machine$double.eps)

>
> vn$PM.DIST_flag<-ifelse(vn$PM.EXP > 0 & abs(vn$PM.DIST.TOT - 1) > fpf , 1, 0)
>
> YAY
>
> Thanks, solved AND I learned something new.
>
> Thanks, alll, and have a GREAT weekend!
>
> Jen

Just for the "macro-take-away": this is the reason we don't really
like console printout instead of dput() to show a problem: if you dput
the original not-yet-ifelse-d numbers, you'll see that they really
aren't 1's, but that they are truncated upon regular printing.

Cheers and don't forget the old adage: 0.1*10 is hardly ever 1,
Michael

>
>
> On Fri, Aug 24, 2012 at 6:27 PM, Peter Ehlers  wrote:
>> I see that you got other responses while I was composing an answer.
>> Your 'example.csv' did come through for me, but I still can't
>> replicate your PM.DIST_flag variable. Specifically, observations
>> 30, 33, 36 and 40 are wrong.
>>
>> I agree with Rui, that there's something else going on. The data
>> you've sent can't be the data that yielded the 'flag' variable
>> or you didn't use the ifelse() function in the way that you've
>> shown.
>>
>> I would start with a clean R session and I would use the 'convert
>> logical to numeric' idea (or keep a logical rather than numeric
>> flag):
>>
>>   vn <- transform(vn,
>>   my_flag = ( (PM.EXP > 0) & (PM.DIST.TOT != 1) ) * 1 )
>>
>> It looks as though your PM.DIST.TOT variable is meant to be
>> integer. If so, you might want to ensure that it is that type.
>> Otherwise, you might want to use Michael's suggestion of using
>> abs(... - 1) < 1e-05.
>>
>> Peter Ehlers
>>
>>
>> On 2012-08-24 14:56, Jennifer Sabatier wrote:
>>>
>>> Hi Michael,
>>>
>>> Thanks for letting me know how to post data.  I will try to upload it
>>> that way in a second.
>>>
>>> I can usually use code to make a reproducible dataset but this time
>>> with the ifelse behaving strangely (perhaps, it's probably me) I
>>> didn't think I could do it easily so I figured I would just put my
>>> data up.
>>>
>>> I will check out the R FAQ you mentioned.
>>>
>>> Thanks, again,
>>>
>>> Jen
>>>
>>>
>>>
>>> On Fri, Aug 24, 2012 at 5:50 PM, R. Michael Weylandt
>>>  wrote:

 On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier
  wrote:
>
> Hi Michael,
>
> No, I never use attach(), exactly for the reasons you state.  To do
> due diligence I did a search of code for the function and it didn't
> come up (I would have been shocked because I never us it!).
>
> Now that real data is up, does your suggestion still apply?  I am
> reading it now.
>

 If you mean the data you sent to Peter, it got scrubbed by the list
 servers as well (they are somewhat draconian, but appropriately so in
 the long run). The absolute best way to send R data via email (esp on
 this list) is to use the dput() function which will create a plain
 text representation of your data _exactly_ as R sees it. It's a little
 hard for the untrained eye to parse (I can usually get about 90% of
 what it all means but there's some stuff with rownames = NA I've never
 looked into) but it's perfectly reproducible to a different R session.
 Then us having the same data is a simple copy+paste away.

 For more on dput() and reproducibility generally, see

 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

 It could be the floating point thing (it's hard to say without knowing
 how your data was calculated), but Rui seems to think not.

 M

> Thanks,
>
> Jen
>
> On Fri, Aug 24, 2012 at 5:38 PM, R. Michael Weylandt
>  wrote:
>>
>> Off the wall / wild guess, do you use attach() frequently? Not
>> entirely sure how it would come up, but it tends to make weird errors
>> li

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hah - I guess I didn't mean I understood it in full as I expect I will
run into it again without anticipating it.

But, now that I know the "old adage" I will look there first when I
run into a problem.

Also, I used the square root of machine precision instead - thanks for
that, too.

Thank you, thank you!  I really appreciate all the help.

Best,

Jen

On Fri, Aug 24, 2012 at 10:31 PM, R. Michael Weylandt
 wrote:
> sqrt(.Machine$double.eps)

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


Re: [R] PHP escapeshellcmd() equivalent

2012-08-24 Thread Yihui Xie
You probably mean shQuote().

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Fri, Aug 24, 2012 at 3:17 PM, Roebuck,Paul L  wrote:
> On 8/24/12 2:59 PM, "R. Michael Weylandt" 
> wrote:
>
>> On Fri, Aug 24, 2012 at 2:48 PM, Roebuck,Paul 
>> wrote:
>>> [Redirected from R-Devel...]
>>>
>>> Not that I recall running across such, but does R (or CRAN package)
>>> provide something equivalent to PHP's escapeshellcmd() function
>>> to escape shell job control, wildcards, etc?
>>
>> I don't know PHP, but what does escapeshellcmd() provide over and
>> above what system() / system2() do?
>>
>
> As before, it escapes job control, etc from the command string.
> Assuming such existed in R, it would be used something like this:
>
> R> system(escapeshellcmd(sprintf("somecmd %s", untrustedInput1)))

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


[R] date

2012-08-24 Thread Veerappa Chetty
Hi,
I have dates as follows:
 1/4/2006 0:00:00 AM
It is a factor  at present.
How do I find out the day of the week from this? How do I convert to Julian
date format?
Thanks.
Chetty

-- 
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chett...@gmail.com,vche...@bu.edu

[[alternative HTML version deleted]]

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


Re: [R] date

2012-08-24 Thread R. Michael Weylandt
Three steps:

1) as.character to get character representation
2) as.POSIXct to convert to time
3) julian() or strptime() to get Julian date. 

Read the docs (esp on part 2 and 3) to get the format strings just right. 

Cheers,
Michael

On Aug 24, 2012, at 10:30 PM, Veerappa Chetty  wrote:

> Hi,
> I have dates as follows:
> 1/4/2006 0:00:00 AM
> It is a factor  at present.
> How do I find out the day of the week from this? How do I convert to Julian
> date format?
> Thanks.
> Chetty
> 
> -- 
> Professor of Family Medicine
> Boston University
> Tel: 617-414-6221, Fax:617-414-3345
> emails: chett...@gmail.com,vche...@bu.edu
> 
>[[alternative HTML version deleted]]
> 
> __
> 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.

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


Re: [R] plot curve on surface

2012-08-24 Thread David Winsemius


On Aug 24, 2012, at 2:34 AM, Michael Meyer wrote:




Greetings,

I would like to plot a curve (in color red) on a surface in a 3D plot.
Say

x <- as.vector(seq(-1,1,0.2))
dim(x) <- c(length(x),1)
y <- as.vector(seq(-1,1,0.2))
dim(y) <- c(1,length(y))

z <- x%*%y # (x_iy_j)

# 3D plot of z(x,y)=xy:
persp(x,y,z)

Now I would like to plot the curve z=z(x,x) in red on this surface.
How do I do that?



persp(x,y,z) -> res
points( trans3d(x, x, x^2, pmat = res), col = "red")
lines(  trans3d(x, x, x^2, pmat = res), col = "red")

--

David Winsemius, MD
Alameda, CA, USA

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


[R] remove column

2012-08-24 Thread Kate Dresh
*Hi all,*



I'm trying to filter a file through the columns. This file below is a
example of my data frame. My true data frame has seven hundred thousand
columns and 500 hundred lines. I need to identify and to remove all columns
that all elements equal a number 1. In this my case, columns were deleted
are number 1,5 and 10.





file <-read.table(text="

1  0  2  2  1  1  5  1  1  1

1  0  2  2  1  1  5  1  1  1

1  0  2  2  1  2  5  2  2  1

1  0  2  2  1 1  5  1  1  1

1  0 2  2   1  0  5  0  2  1

1  0  2 2   1  1  5  1  0  1

",sep="",header=FALSE)



the result after the filter will be



0  2  2  1  5  1  1

 0  2  2  1  5  1  1

 0  2  2  2  5  2  2

 0  2  2  1  5  1  1

 0  2  2  0  5  0  2

 0  2  2  1  5  1  0



 I used this commands idlength<-sapply(file,function(x) length(unique(x))
),

but came an error message:



caught segfault ***

address 0x4, cause 'memory not mapped'



*My question: is it possible to remove the all columns from above file
to *achieve* the desired result?*

* *

* **Thank you for help*



 Kate Dresh

[[alternative HTML version deleted]]

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


[R] Turning of source echo

2012-08-24 Thread darnold
HI,

I have this code:

BAGA <- c(10,20,20,30,30,30,30,40,
  40,40,40,50,50,50,50,50,
  60,60,60,60,60,70,70,70,
  70,80,80,80,90,90,100)

BAGB <- c(10,10,10,10,10,20,20,20,
   20,30,30,30,40,40,50,60,
   70,70,80,80,80,90,90,90,
   90,100,100,100,100,100)

A <- sample(c(1,2),1)

if (A==1) {
  B <- BAGA[sample(length(BAGA),1)]
} else {
  B <- BAGB[sample(length(BAGB),1)]
}

cat("X = ", B)

In R-studio, when I source the code with Shift-Command-S on the mac, I get
this response in the console window:

> source('~/Documents/classes/trunk/math15/resources/TIFiles/todd.R')
X =  90

How can I turn of the source echo to get just:

X = 90

Thanks.

D.



--
View this message in context: 
http://r.789695.n4.nabble.com/Turning-of-source-echo-tp4641278.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] extract vector elements of unknown range

2012-08-24 Thread Sepp Tannhuber
Dear all,

I have two vectors
  x <- c(1:20)
  y <- c(1,5,10,14)

Now I would like to extract
  x[ (y[n] + 2):(y[n+1] - 1) ]
for all elements except last one in y. This means I want to have
  x[ c( (y[1]+2):(y[2]-1), (y[2]+2):(y[3]-1), (y[3]+2):(y[4]-1) ) ]
How is this possible if y is a vector of unknown length?

Best regards
Joseph

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


Re: [R] mgcv package, problems with NAs in gam

2012-08-24 Thread Bert Gunter
Grace:

Confession: I loved that error message!  -- and it seems pretty clear to me.

What does "to no avail" mean -- in particular, what happened when you
changed your NA's to 0? Presumably you did not get the same error
message, again, but something else, right? What else?

Modulo the above vagueness, I would guess you're stuck -- you can't do
what you'd like with your data. If so, John Tukey's remark from
decades ago seems apropos:

"The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data."
American Statistician 40 (1986)

But if you post with greater clarity -- or get a response from someone
with a greater brain -- maybe there's hope.

Cheers,
Bert


On Fri, Aug 24, 2012 at 2:36 PM, grace  wrote:
> Hi there,
>
> I'm using presence-absence data in a gam (i.e. 0 or 1 as values)
> I am trying to run a gam with 'dummy covariates' i.e. 1~1
> unfortunately my model:
> *
> model<-gam(1~1, data=bats, family=negbin)*
>
> keeps putting out:
>
> *
> Error in gam(1 ~ 1, data = bats, family = negbin) :
>   Not enough (non-NA) data to do anything meaningful*
>
> Is there a specific reason it would do this? I have tried using various
> actions on NAs, na.pass etc, as well as asking it to turn all NAs to 0 but
> to no avail.
>
> I would post the data here but its rather long, basically 28x104 matrix of
> 0/1 with headers 'v1:v28' .The summary for the data comes up fine, it's just
> the model that isn't working.
> However if I run using:
>
> *model<-gam(v1~v2, data=bats, family=negbin)
> *
>
> it tends to work.
>
> Any help is seriously appreciated as I have a deadline and have been trying
> this for days,
>
> Thanks!
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/mgcv-package-problems-with-NAs-in-gam-tp4641253.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] kernlab | ksvm error

2012-08-24 Thread Reza Salimi-Khorshidi
Dear Uwe,
I appreciate that if you let me know why, when using the attached file, the
following script (two lines) doesn't work once in 10s of times.
Best, Reza

svm.pol4 <- ksvm(class.labs ~ ., data = train.data, prob.model = T, scale =
T, kernel = "polydot")

svm.pol.prd4 <- predict(svm.pol4, train.data, type = "probabilities")[,2]
__
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.


[R] How to arrange the GUI's in window in tcltk package???

2012-08-24 Thread punitha
Hi,

  I am new to R, I need your help. I have been said to create a GUI in
R, 
  I started using Tcltk package which was very easy to learn and code,
  but i am unable to arrange the GUI's in proper order in the window
they are always arranged one below the other, please can anyone help me in
solving this problem,
 Is there any links which will help me solve this problem with example.

   Thanks in advance.

with regards,
Punitha




--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-arrange-the-GUI-s-in-window-in-tcltk-package-tp4641279.html
Sent from the R help mailing list archive at Nabble.com.

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