[R] possible bug with largest.cliques in igraph_0.6-3

2012-10-31 Thread Christos Hatzis
There is a problem with the largest clique computation in the recent version
of igraph.

> library(igraph)
> adj <- matrix(1, nrow=11, ncol=11) - diag(11)
> g <- graph.adjacency(adj)
> largest.cliques(g)
[[1]]
[1] 10  8  1

[[2]]
[1] 9 7 1

[[3]]
[1] 8 7 1

Warning message:
In largest.cliques(g) :
  At cliques.c:958 :directionality of edges is ignored for directed graphs

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C

[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] igraph_0.6-3

--

An older version of igraph gave the correct answer

> library(igraph)
> adj <- matrix(1, nrow=11, ncol=11) - diag(11)
> g <- graph.adjacency(adj)
> largest.cliques(g)
[[1]]
 [1]  0  1  2  3  4  5  6  7  8  9 10

Warning message:
In largest.cliques(g) :
  At cliques.c:801 :directionality of edges is ignored for directed graphs

> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C

[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] igraph_0.5.5-3


Thanks.

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
999 Broadway, Suite 301
Saugus, MA 01906

__
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] remove object

2009-05-29 Thread Christos Hatzis
You can try

rm(list = ls()[!(ls() %in% "index")]).

-Christos  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Luc Villandre
> Sent: Friday, May 29, 2009 2:06 PM
> To: fernando espindola
> Cc: r-help@r-project.org
> Subject: Re: [R] remove object
> 
> 
>fernando espindola wrote:
> 
> Hi list
> 
> I try to remove all object less one, this object is called 
> index. I have many object with different names and pattern 
> option in ls function may not remove this object why any word 
> in index object repeats with other object.
> Anybody can give me one advise for this question
> 
> Thank for all
> 
> fernando
> 
> [[alternative HTML version deleted]]
> 
> __
> [1]r-h...@r-project.org mailing list
> [2]https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> [3]http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
>Hi Fernando,
>Using "grep" is most likely the way to go, but without at 
> least a sample of
>the names of the objects in your workspace, I'm afraid I 
> can't really help
>you more.
>Cheers,
> 
>--
>Luc Villandré
>Biostatistician
>McGill University Health Center -
>Montreal Children's Hospital Research Institute
> 
> References
> 
>1. mailto:R-help@r-project.org
>2. https://stat.ethz.ch/mailman/listinfo/r-help
>3. http://www.R-project.org/posting-guide.html
> __
> 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] functions flagged for debugging

2009-03-27 Thread Christos Hatzis
Hi,
 
Is there a way to find which functions are flagged for debugging in a given
session?
 
Thank you.
-Christos
 
 

[[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] Statistical Tests

2009-03-20 Thread Christos Hatzis
The following site is your friend:

http://www.rseek.org/

-Christos 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of 
> meenu.s...@ingim.com
> Sent: Friday, March 20, 2009 5:47 AM
> To: r-help@r-project.org
> Subject: [R] Statistical Tests
> 
> 
> Dear Members
> 
> Is there an R code for the following statistical tests ?
> 1. marquering_verbeek
> 2.HenrikssonMerton
> 3.cumby&modest
> 
> Regards
> Meenu
> -
> ATTENTION:
> The information in this electronic mail message is 
> priva...{{dropped:18}}
> 
> __
> 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] set size of a plot

2009-03-12 Thread Christos Hatzis
See ?pdf and its width and height arguments.
Also if you want to have the graph centered on a standard page, there are
additional arguments to help you achieve that effect:

> pdf("test.pdf", height=5, width=5, paper="letter", pagecentre=TRUE)
> hist(rcauchy(100))
> dev.off()

-Christos 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Maxl18
> Sent: Thursday, March 12, 2009 10:05 AM
> To: r-help@r-project.org
> Subject: [R] set size of a plot
> 
> 
> Hi,
> I have the following R-code:
> 
> pdf(file="test.pdf")
> hist(rcauchy(100))
> dev.off()
> 
> How can I set the size of the histogram in my pdf?
> I tried to do with par(...) but I didn't find the right parameter yet.
> 
> Thanks, Max
> --
> View this message in context: 
> http://www.nabble.com/set-size-of-a-plot-tp22477083p22477083.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.


Re: [R] popular R packages

2009-03-10 Thread Christos Hatzis
Bioconductor already provides download stats for all packages...

http://bioconductor.org/packages/stats/bioc/affy.html

-Christos 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Max Kuhn
> Sent: Tuesday, March 10, 2009 12:25 PM
> To: r-help@r-project.org
> Subject: Re: [R] popular R packages
> 
> If is easy to get the download numbers, we should do it and 
> deal with the interpretation issues. I'd like to know the 
> numbers so I can understand which (of my) packages have the 
> most usage.
> 
> One other compication about # downloads: I suspect that a 
> package being on teh depends/suggests/imports list of another 
> package might be a big driver with respect to how many times 
> that it was downloaded.
> 
> If I remember correctly, about 5 years ago Bioconductor asked 
> for volunteers to review packages to get detailed, specific 
> feedback by people who use the package (and should be fairly 
> R proficient). I think that this is pretty important and 
> something like Crantastic is a good interface. I personally 
> got a lot out of the comments the a JSS reviewer had for a package.
> 
> -- 
> 
> Max
> 
> __
> 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] Sparse PCA in R

2009-03-10 Thread Christos Hatzis
Take a look at the elasticnet package.

-Christos 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of joris meys
> Sent: Tuesday, March 10, 2009 3:43 PM
> To: R-help Mailing List
> Subject: [R] Sparse PCA in R
> 
> Dear all,
> 
> I would like to perform a sparse PCA, but I didn't find any 
> library offering me this in R. Is there one available, or do 
> I have to write the functions myself?
> 
> Kind regards
> Joris Meys
> 
>   [[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] Numbers

2009-03-06 Thread Christos Hatzis
You can easily write a simple function to do that:

letters2num <- function(x) {
nletters <- 1:length(LETTERS)
names(nletters) <- LETTERS
nletters[x]
}

> x <- c("A", "X", "F", "W", "G", "V", "L")
> letters2num(x)
 A  X  F  W  G  V  L 
 1 24  6 23  7 22 12 

-Christos
 
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Leandro Marino
> Sent: Friday, March 06, 2009 10:06 AM
> To: r-help@r-project.org
> Subject: [R] Numbers
> 
>  Hi,
> 
> I know the function LETTERS, but, now I have some letters to 
> convert it in numbers, like A=1,B=2, etc... Is any function 
> to do that?
> 
> Atenciosamente,
> Leandro Lins Marino
> Centro de Avaliação
> Fundação CESGRANRIO
> Rua Santa Alexandrina, 1011 - 2º andar
> Rio de Janeiro, RJ - CEP: 20261-903
> R (21) 2103-9600 R.:236
> ( (21) 8777-7907
> ( lean...@cesgranrio.org.br
> 
> "Aquele que suporta o peso da sociedade
> é precisamente aquele que obtém
>  as menores vantagens". (SMITH, Adam)
> 
> P  Antes de imprimir pense em sua responsabilidade e 
> compromisso com o MEIO AMBIENTE 
> 
> __
> 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] FW: flow control

2009-03-04 Thread Christos Hatzis
Hi Ken,

The help page for ?"for" says that:

The index seq in a for loop is evaluated at the start of the loop; changing
it subsequently does not affect the loop. The variable var has the same type
as seq, and is read-only: assigning to it does not alter seq.

So you cannot do what you want to do with a for loop.  But you could do what
you want with a while loop:

i <- 0
while(i < 20) {
i <- i + 1
cat(i, "\n")
if(i %% 5 == 0) i <- i + 2
}

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Lo, Ken
> Sent: Wednesday, March 04, 2009 3:53 PM
> To: r-help@r-project.org
> Subject: [R] FW: flow control
> 
> Hi all,
> 
> I need a little help with flow control in R.  What I'd like 
> to do is to advance a for loop by changing its counter.  
> However, what seems obvious to me does not yield the proper 
> results.  An example of my problem is
> 
> 
> for (i in seq(1, some_number, some_increment)){
>   
>   if (some_condition == T) i <- i + 2;  #want to advance 
> the loop by 2 }
> 
> Whenever the counter goes to the next step, the next item in 
> the original sequence seq(1, some_number, some_increment) 
> replaces the counter value.  Is there a way for me to do this?
> 
> Best,
> 
> Ken
> 
>   
> 
> __
> 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] Using gregexpr with multiple search elements

2009-02-25 Thread Christos Hatzis
gregexpr("\\at|\\og", text) 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Corey Sparks
> Sent: Wednesday, February 25, 2009 11:50 AM
> To: R Help
> Subject: [R] Using gregexpr with multiple search elements
> 
> Dear list,
> I am trying to use gregexpr to see if entries in a dataframe 
> have either of two possible values for a string.
> here's an example
> text<-c("fat", "rat", "cat", "dog", "log", "fish")
> 
> If I just wanted to find if any one of the elements in text 
> match the pattern "at" I would do gregexpr("\\at", text)
> 
> which would match on the first three elements, you can do 
> something like ifelse(gregexpr("\\at",text)>-1, 1,0)
> 
> to see if a particular entry in the data "text" is matched.
> My problem is I need to check if either of two patterns match 
> in the data, an example that doesn't work is 
> gregexpr(c("\\at", "\\og"), text)
> 
> which is the basic form of what I'm looking to do, if this 
> would work I would get a match for elements 1 through 5 of 
> text, since either "at" or "og" occurs.
> 
> If anyone might have an idea about this I would greatly appreciate it.
> Best,
> Corey
> 
> Corey Sparks
> Assistant Professor
> Department of Demography and Organization Studies University 
> of Texas at San Antonio One UTSA Circle San Antonio, TX 78249 
> 210 458 6858 corey.spa...@utsa.edu
> 
> __
> 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] Linear Discriminant Analysis

2009-02-25 Thread Christos Hatzis
Maybe as a starter

RSiteSearch("linear discriminant analysis") 

R has tools to help you help yourself with this types of questions.

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Arup
> Sent: Wednesday, February 25, 2009 4:45 AM
> To: r-help@r-project.org
> Subject: [R] Linear Discriminant Analysis
> 
> 
> Kindly let me know the process to carry out a Linear 
> discriminant analysis...thanks in advance
> 
> Arup
> --
> View this message in context: 
> http://www.nabble.com/Linear-Discriminant-Analysis-tp22199424p
> 22199424.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.


Re: [R] regexp capturing group in R

2009-02-24 Thread Christos Hatzis
I don't know if there is a direct, perl-like way to capture the matches, but
here is a solution:

> mdat <- gregexpr("[[:digit:]]{8}", txt)
> dates <- mapply(function(x, y) substr(txt, x, x + y - 1), mdat[[1]],
attr(mdat[[1]], "match.length")) 
> dates
[1] "20080101" "20090224" 

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of 
> pie...@demartines.com
> Sent: Tuesday, February 24, 2009 7:23 PM
> To: r-help@r-project.org
> Subject: [R] regexp capturing group in R
> 
> Hello,
> 
> Newbie question: how do you capture groups in a regexp in R?
> 
> Let's say I have txt="blah blah start=20080101 end=20090224".
> I'd like to get the two dates start and end.
> 
> In Perl, one would say:
> 
> my ($start,$end) = ($txt =~ /start=(\d{8}).*end=(\d{8})/);
> 
> I've tried:
> 
> txt <- "blah blah start=20080101 end=20090224"
> m <- regexpr("start=(\\d{8}).*end=(\\d{8})", filename, 
> perl=T); dates = substring(filename, m, m+attr(m,"match.length")-1);
> 
> but I get the whole matching substring...
> 
> Any idea?
> 
> ~Pierre
> 
> __
> 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] how to NULL multiple variables of a df efficiently?

2009-02-24 Thread Christos Hatzis
You're right.  The help page is somewhat misleading at first read.

?`[<-.data.frame` states that (with added emphasis)

value   A suitable replacement value: it will be repeated a whole number of
times if necessary and it may be coerced: see the Coercion section. *** If
NULL, deletes the column if a single column is selected. ***
  
So I read this to mean that a NULL value works only if a single column is
selected. 
But the Details gives the rest of the story:

For [ the replacement value can be a list: each element of the list is used
to replace (part of) one column, recycling the list as necessary. If columns
specified by number are created, the names (if any) of the corresponding
list elements are used to name the columns. *** If the replacement is not
selecting rows, list values can contain NULL elements which will cause the
corresponding columns to be deleted. ***

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Stavros Macrakis
> Sent: Tuesday, February 24, 2009 4:47 PM
> To: Sean Zhang
> Cc: r-help@r-project.org
> Subject: Re: [R] how to NULL multiple variables of a df efficiently?
> 
> On Tue, Feb 24, 2009 at  3:10 PM, Sean Zhang wrote:
> > ...Want to delete many variables in a dataframe
> > df<-data.frame(var.a=rnorm(10), var.b=rnorm(10),var.c=rnorm(10))
> > df[,'var.a']<-NULL   #this works for one single variable
> > df[,c('var.a','var.b')]<-NULL  #does not work for multiple variables
> 
> Actually, setting to NULL works fine for multiple variables, 
> but you need one NULL per variable:
> 
> > df[,c("var.a","var.b")] <- list(NULL,NULL) df
> var.c
> 1   1.2470314
> 2  -0.7075917
> 3  -1.3959612
> 
> If the variable list is in a variable:
> 
> > vars <- c("var.a","var.c")
> 
> Careful, rep requires a *list* of NULL, not an element:
> 
> > df[,vars] <- rep(list(NULL),length(vars))
> 
> Hope this helps,
> 
>  -s
> 
> __
> 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] how to NULL multiple variables of a df efficiently?

2009-02-24 Thread Christos Hatzis
Setting to NULL works only if a single column is selected.
More generally,

df[, !(colnames(df) %in% c("var.b", "var.c")), drop=FALSE]

-Christos  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Sean Zhang
> Sent: Tuesday, February 24, 2009 3:10 PM
> To: r-help@r-project.org
> Subject: [R] how to NULL multiple variables of a df efficiently?
> 
> Dear R-helpers:
> 
> I am an R novice and would appreciate answer to the following 
> question.
> 
> Want to delete many variables in a dataframe.
> Am able to delete one variable by assigning it as NULL Have a 
> large number of variables and would like to delete them 
> without using a for loop.
> 
> Is there a command/function which does this job?
> 
> Many thanks in advance.
> 
> -Sean
> 
> 
> #Small Example:
> 
> df<-data.frame(var.a=rnorm(10), var.b=rnorm(10),var.c=rnorm(10))
> df[,'var.a']<-NULL   #this works for one single variable
> df[,c('var.a','var.b')]<-NULL  #does not work for multiple variables
> 
>   [[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] Formula that includes previous row values

2009-02-23 Thread Christos Hatzis
Here's a way without a loop:

x <- read.table(textConnection("ID  X2
1.001.00
2.000.00
3.001.00
4.003058
5.000.00
6.006.00"),header=TRUE)
closeAllConnections()

x$X3 <- append(x$X2, 0, 0)[-nrow(x)]
x$X4 <- as.matrix(x[,2:3]) %*% c(1, 0.24)

> x
  ID   X2   X3  X4
1  1101.00
2  2010.24
3  3101.00
4  4 30581 3058.24
5  50 3058  733.92
6  6667.44

-Christos 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Pele
> Sent: Monday, February 23, 2009 4:48 PM
> To: r-help@r-project.org
> Subject: Re: [R] Formula that includes previous row values
> 
> 
> Hi Jorge - many thanks for you suggestion, but I am looking 
> for a way where I don't have to use a loop.  I meant to 
> include that in my description.
> 
> Thanks again!
> 
> 
> Jorge Ivan Velez wrote:
> > 
> > Dear Pele,
> > Probably not the best way to proceed but it works:
> > 
> > X<-read.table(textConnection("ID  X2
> > 1.001.00
> > 2.000.00
> > 3.001.00
> > 4.003058
> > 5.000.00
> > 6.006.00"),header=TRUE)
> > closeAllConnections()
> > X
> > 
> > x3<-0
> > for(i in 2:(nrow(X)+1)) x3<-c(x3, X$X2[i-1]+0.24*x3[i-1]) 
> X$x3<-x3[-1] 
> > X
> > 
> > HTH,
> > 
> > Jorge
> > 
> > 
> > On Mon, Feb 23, 2009 at 3:59 PM, Pele  wrote:
> > 
> >>
> >> Hi R users,
> >>
> >> Is there an easy way in R to generate the results table 
> below using 
> >> table
> >> 1
> >> and the formula (simplified version of the real problem)?  
> It would 
> >> be easy if I knew the R equivalent of SAS's retain function, but 
> >> could not find one.
> >>
> >> Thanks in Advance for any help!
> >>
> >> table1:
> >>
> >> ID  X2 X3
> >> 1.001.00   0
> >> 2.000.00
> >> 3.001.00
> >> 4.003058
> >> 5.000.00
> >> 6.006.00
> >>
> >> Formula: X3 = x2 + (.24 * x3)
> >>
> >> where the values in the x3 column of the result table are retained 
> >> from previous x3 rows.. Also the first x3 value is 
> initialized to 0 
> >> to start
> >>
> >> e.g.
> >>for ID=1 we have  1 + .24(0)= 1.00
> >>for ID=2 we have  0 + .24(1)= 0.24
> >>for ID=3 we have  1 + .24(.24)  = 1.06
> >>for ID=4 we have  3058 + .24(1.06)  = 3058.25
> >>etc.
> >>
> >> Results:
> >> ID  X2  x3
> >> 1.001.001.00
> >> 2.000.000.24
> >> 3.001.001.06
> >> 4.0030583058.25
> >> 5.000.00733.98
> >> 6.006.00182.16
> >> --
> >> View this message in context:
> >> 
> http://www.nabble.com/Formula-that-includes-previous-row-values-tp221
> >> 70010p22170010.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.
> >>
> > 
> > [[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.
> > 
> > 
> 
> --
> View this message in context: 
> http://www.nabble.com/Formula-that-includes-previous-row-value
> s-tp22170010p22170878.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.


Re: [R] trade-off between speed and storage in matrix multiplications

2009-02-23 Thread Christos Hatzis
You might want to compare the performance of your version to the kronecker
method of Matrix (Matrix package) that has appropriate versions for sparse
matrices etc.

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Camarda, 
> Carlo Giovanni
> Sent: Monday, February 23, 2009 1:18 PM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] trade-off between speed and storage in matrix 
> multiplications
> 
> Dear R-users,
> 
>   I coded two equivalent ways to perform (in a simplified 
> version) some matrix multiplications I would like to use in a 
> more general framework.
> In the first case I used Kronecker product and vectorization 
> of a certain matrix. This approach takes less time, but, as 
> you may guess, I run out of memory when dimensions are large.
> In the second approach, I profited of sparseness and 
> structure of the matrices and use outer-functions for 
> performing operations. Here it takes more time, but I have 
> not problem of memory.
> 
> Is there any way to enhance the second approach for 
> speeding-up the whole process? Or, in computing, this is a 
> well-known trade-off between speed and storage-spaces which 
> I'm not aware (sorry for that).
> 
> Please have a look to the example below.
> 
> Needless to say that I'd appreciate any suggestion.
> 
> Best,
> Carlo Giovanni
> 
> 
> # dimensions
> m <- 10
> n <- 15
> # A-matrix
> rnA <- runif(m*m)
> A <- matrix(rnA, m, m)
> # vector
> v <- runif(n)
> # B-matrix
> rnB <- runif(m*n)
> B <- matrix(rnB, m, n)
> 
> # first solution: vectorize B + kronecker product => faster 
> but storage issues system.time( for(i in 1:100){
> b <- c(B)
> vKron.A <- kronecker(diag(v), A)
> SOL1 <- vKron.A %*% b
> })
> 
> # second solution: orig. dims + apply + mapply => slower, but 
> w/o storage issues system.time( for(i in 1:100){
> Av <- outer(A, v, FUN="*")
> Av.df1 <- apply(Av, 3, as.data.frame)
> Av.df2 <- lapply(X=Av.df1, FUN=as.matrix, nrow=m, ncol=m)
> SOL2 <- mapply(FUN="%*%", Av.df2, as.data.frame(B)) # as a matrix
> })
> 
> 
> 
> 
> 
> --
> This mail has been sent through the MPI for Demographic 
> ...{{dropped:10}}
> 
> __
> 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] Source code for nlm()

2009-02-19 Thread Christos Hatzis
It seems to be in optimize.c

Rgonzui has a very nice search facility for source of R or CRAN packages
(however it is against R 2.8.0 source):
http://rgonzui.nakama.ne.jp/R/markup/R-2.8.0/src/main/optimize.c?fm=c&q=nlm#
l378

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Ravi Varadhan
> Sent: Thursday, February 19, 2009 1:00 PM
> To: r-help@r-project.org
> Subject: [R] Source code for nlm()
> 
> Hi,
>  
> Where can I find the source code for nlm()?  I dowloaded the 
> R2.8.1.tar.gz file and looked at all the .c and .f files, but 
> couldn't find either nlm.c or nlm.f
>  
> There is an nlm.r file, but that is not useful.
>  
> Thanks for any help,
> Ravi.
>  
> --
> --
> ---
> 
> Ravi Varadhan, Ph.D.
> 
> Assistant Professor, The Center on Aging and Health
> 
> Division of Geriatric Medicine and Gerontology 
> 
> Johns Hopkins University
> 
> Ph: (410) 502-2619
> 
> Fax: (410) 614-9625
> 
> Email: rvarad...@jhmi.edu
> 
> Webpage:  
> http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
> 
>  
> 
> --
> --
> 
> 
>  
> 
>   [[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] Aggregrate function

2009-02-12 Thread Christos Hatzis
This requires a small modification to use which instead of which.max that
returns only the first maximum:

do.call("rbind", lapply(split(xveg, xveg$loc), function(x) x[which(x$tot ==
max(x$tot)), ]))

 loc sp tot
L1L1  b  60
L2.5  L2  d  25
L2.7  L2  e  25
L3L3  b  68 

-Christos

> -Original Message-
> From: Monica Pisica [mailto:pisican...@hotmail.com] 
> Sent: Thursday, February 12, 2009 4:35 PM
> To: christos.hat...@nuverabio.com; R help project; 
> markle...@verizon.net
> Subject: RE: [R] Aggregrate function
> 
> 
> Hi, 
>  
> Thanks for the solution. Mark Leeds sent me privately a very 
> similar solution. My next question to him was:
>  
> Suppose that for a certain location 2 species have the same 
> maximum total ... (there are ties in the data for a 
> particular location). How do i get all species that have that 
> max. total??
>  
> For this case i have changed the tot as follows:
>  
> tot <-  c(20, 60, 40, 15, 25, 15, 25, 20, 68, 32)
>  
> His sollution is (and does work):
>  
> temp <- lapply(split(xveg,loc), function(.df) {
>   maxindices <- which(.df$tot == .df$tot[which.max(.df$tot)])
>   
> data.frame(loc=.df$loc[1],sp=paste(.df$sp[maxindices],collapse
> =","),tot=max(.df$tot))
> })
> 
> result <- do.call(rbind,temp)
> print(result)
>  
> Thanks so much again,
>  
> Monica 
>  
> 
>  
> > From: christos.hat...@nuverabio.com
> > To: pisican...@hotmail.com; r-help@r-project.org
> > Subject: RE: [R] Aggregrate function
> > Date: Thu, 12 Feb 2009 15:56:38 -0500
> > 
> > I don't have an easy solution with aggregate, because the 
> function in 
> > aggregate needs to return a scalar.
> > But the following should work:
> > 
> > do.call("rbind", lapply(split(xveg, xveg$loc), function(x) 
> > x[which.max(x$tot), ]))
> > 
> > loc sp tot
> > L1 L1 b 60
> > L2 L2 e 30
> > L3 L3 b 68
> > 
> > -Christos
> > 
> >> -Original Message-
> >> From: r-help-boun...@r-project.org
> >> [mailto:r-help-boun...@r-project.org] On Behalf Of Monica Pisica
> >> Sent: Thursday, February 12, 2009 1:58 PM
> >> To: R help project
> >> Subject: [R] Aggregrate function
> >> 
> >> 
> >> Hi,
> >> 
> >> I have to recognize that i don't fully understand the aggregate 
> >> function, but i think it should help me with what i want to do.
> >> 
> >> xveg is a data.frame with location, species, and total for the 
> >> species. Each location is repeated, once for every species 
> present at 
> >> that location. For each location i want to find out which 
> species has 
> >> the maximum total ... so i've tried different ways to do it using 
> >> aggregate.
> >> 
> >> loc <- c(rep("L1", 3), rep("L2", 5), rep("L3", 2)) sp <- 
> c("a", "b", 
> >> "c", "a", "d", "b", "e", "c", "b", "d") tot <- c(20, 60, 
> 40, 15, 25, 
> >> 10, 30, 20, 68, 32) xveg <- data.frame(loc, sp, tot)
> >> 
> >> result desired:
> >> 
> >> L1 b
> >> L2 e
> >> L3 b
> >> 
> >> sp_maj <- aggregate(xveg[,2], list(xveg[,1], function(x)
> >> levels(x)[which.max(table(x))])
> >> 
> >> This is wrong because it gives the first species name in 
> each level 
> >> of location, so i get a, a, b, as species instead of b, e, b.
> >> 
> >> I've tried other few aggregate commands, all with wrong results.
> >> 
> >> I will appreciate any help,
> >> 
> >> Thanks,
> >> 
> >> Monica
> >> 
> >> _
> >> 
> >> the go.
> >> 
> >> __
> >> 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.
> >> 
> >> 
> > 
> > 
> _
> See how Windows connects the people, information, and fun 
> that are part of your life.
> http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/
>

__
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] Aggregrate function

2009-02-12 Thread Christos Hatzis
I don't have an easy solution with aggregate, because the function in
aggregate needs to return a scalar.
But the following should work:

do.call("rbind", lapply(split(xveg, xveg$loc), function(x)
x[which.max(x$tot), ]))

   loc sp tot
L1  L1  b  60
L2  L2  e  30
L3  L3  b  68 

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Monica Pisica
> Sent: Thursday, February 12, 2009 1:58 PM
> To: R help project
> Subject: [R] Aggregrate function
> 
> 
> Hi,
>  
> I have to recognize that i don't fully understand the 
> aggregate function, but i think it should help me with what i 
> want to do.
>  
> xveg is a data.frame with location, species, and total for 
> the species. Each location is repeated, once for every 
> species present at that location. For each location i want to 
> find out which species has the maximum total ... so i've 
> tried different ways to do it using aggregate.
>  
> loc <- c(rep("L1", 3), rep("L2", 5), rep("L3", 2)) sp <- 
> c("a", "b", "c", "a", "d", "b", "e", "c", "b", "d") tot <- 
> c(20, 60, 40, 15, 25, 10, 30, 20, 68, 32) xveg <- 
> data.frame(loc, sp, tot)
>  
> result desired:
>  
> L1   b
> L2   e
> L3   b
>  
> sp_maj <- aggregate(xveg[,2], list(xveg[,1], function(x) 
> levels(x)[which.max(table(x))])
>  
> This is wrong because it gives the first species name in each 
> level of location, so i get a, a, b, as species instead of b, e, b.
>  
> I've tried other few aggregate commands, all with wrong results.
>  
> I will appreciate any help,
>  
> Thanks,
>  
> Monica
>  
> _
> 
>  the go.
> 
> __
> 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] how to perform power analysis and sample sizeestimation/projection using R

2009-02-12 Thread Christos Hatzis
Ok.  So you have a set of features, which when combined in a certain way
predict a binary outcome, i.e. a multi-feature binary predictor.

You have to decide first what is the hypothesis that you want to test
regarding this predictor in the study that you're designing.  E.g. that
prediction accuracy will be greater than a min value, or the positive
predictive value of the test will be greater than the class-prevalence for
the population under study etc.  Having decided that, you will then need to
specify a null level (e.g. accuracy at least A0=70%) and an (expected)
observed level at which the study will have the stated power to reject the
null hypothesis (e.g. A1=80%).  Then you can use the power of a test on
proportions to estimate sample size for a given power, significance , etc.
Several such tests are given in package 'pwr'.

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Waverley
> Sent: Thursday, February 12, 2009 1:19 PM
> To: r-help; r-help@r-project.org
> Subject: [R] how to perform power analysis and sample 
> sizeestimation/projection using R
> 
> Hi,
> 
> I have a question in regarding to how to perform power 
> analysis and sample size estimation/projection using R?
> 
> I know power.t.test.  It works really well with only one 
> feature analysis.
> 
>  I have a set of features which collectively can discriminate 
> binary classes.  I can do power.t.test for each one feature 
> to get a distribution for the sample size estimation to 
> achieve certain power and significance.  But how to evaluate 
> such that this set of features is analyzed simultaneously as 
> "one group" for the power analysis and sample size 
> estimation.  I also knew samr package has some utility you 
> can do this but it seems does not work well in my situation.
> 
> Please advise.
> 
> Thanks a lot in advance for the help.
> 
> --
> Waverley @ Palo Alto
> 
> __
> 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] Efficent way to create an nxn upper triangular matrix of one's

2009-02-11 Thread Christos Hatzis
Here is a way to do this:

round(upper.tri(matrix(1, 9, 9)))

Or if you also need the diagonal of one's

round(upper.tri(matrix(1, 9, 9), diag = TRUE))

-Christos 
 
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Dale Steele
> Sent: Wednesday, February 11, 2009 4:23 PM
> To: R help
> Subject: [R] Efficent way to create an nxn upper triangular 
> matrix of one's
> 
> The code below create an nxn upper triangular matrix of 
> one's.  I'm stuck on finding a more efficient vectorized way 
> - Thanks.  --Dale
> 
> n <- 9
> data <- matrix(data=NA, nrow=n, ncol=n)
> data
> for (i in 1:n) {
> data[,i] <- c(rep(1,i), rep(0,n-i))
> }
> data
> 
> __
> 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] Generating new variable based on values of an existing variable

2009-02-09 Thread Christos Hatzis
One way to do this is through transform, assuming that there is one-to-one
correspondence between regions and elements:

mydf <- data.frame(region=c(rep("North", 5), rep("East", 5), rep("South",
5), rep("West", 5)))
elements <- c("earth", "water", "air", "fire")
transform(mydf, element = factor(region, levels=c("North", "East", "South",
"West"), labels=elements)) 

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Josip Dasovic
> Sent: Monday, February 09, 2009 2:30 PM
> To: r-help@r-project.org
> Subject: [R] Generating new variable based on values of an 
> existing variable
> 
> Dear R Help-Listers:
> 
> I have a problem that seems like it should have a simple 
> solution, but I've spent hours on it (and searching the 
> r-help archives) to no avail. What I'd like to do is to 
> generate a new variable within a data frame, the values of 
> which are dependent upon the values of an existing variable 
> within that data frame. 
> 
> Assume that I have the following data:
> 
> mydf<-data.frame(region=c(rep("North", 5), rep("East", 5), 
> rep("South", 5), rep("West", 5)))
> 
> Assume, in addition, that I have a factor vector with four 
> values (I actually have a factor with almost two-hundred values):
> 
> element<-c("earth", "water", "air", "fire")
> 
> I would like to add a new variable to the data frame (called 
> "element") such that the value of "element" is "earth" in 
> each observation for which mydf$region=="North", etc. In 
> STATA, this was relatively easy; is there a simple way to do 
> this in R? 
> 
> This is what the final result should look like:
> 
> > mydf
>region element
> 1   North   earth
> 2   North   earth
> 3   North   earth
> 4   North   earth
> 5   North   earth
> 6East   water
> 7East   water
> 8East   water
> 9East   water
> 10   East   water
> 11  South air
> 12  South air
> 13  South air
> 14  South air
> 15  South air
> 16   Westfire
> 17   Westfire
> 18   Westfire
> 19   Westfire
> 20   Westfire
> 
> Thanks in advance,
> Josip
> 
> __
> 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] Choosing a random number between x and y

2009-02-09 Thread Christos Hatzis
If you want to chose numbers from your range with uniform probability

runif(1, 0, 0.5) 

See ?runif

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Vie
> Sent: Monday, February 09, 2009 9:41 AM
> To: r-help@r-project.org
> Subject: [R] Choosing a random number between x and y
> 
> 
> Hi,
> 
> Ive been trying to find a function that will allow me to pull 
> out a number between a minimum and maximum threshold.
> 
> I want a random decimal number between, for example, 0 and 
> 0.5 or 0 and 0.7.
> I've been searching everywhere for a function that will allow 
> me to do this in R, but I have yet to be successful. Any help 
> would be much appreciated.
> 
> Thanks in advance
> 
> 
> --
> View this message in context: 
> http://www.nabble.com/Choosing-a-random-number-between-x-and-y
> -tp21914106p21914106.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.


Re: [R] meaning of asymmetric on help page for intersect

2009-01-13 Thread Christos Hatzis
... which is the same as

setdiff(union(x, y), intersect(x, y))

-Christos 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of 
> dav...@rhotrading.com
> Sent: Tuesday, January 13, 2009 10:56 AM
> To: Juliet Hannah; r-help@r-project.org
> Subject: Re: [R] meaning of asymmetric on help page for intersect
> 
> There is also a symmetric set difference = union(setdiff(x, 
> y), setdiff(y, x)) denoted x \Delta y
> 
> -- David
> 
> 
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org]
> On Behalf Of Juliet Hannah
> Sent: Tuesday, January 13, 2009 9:41 AM
> To: r-help@r-project.org
> Subject: [R] meaning of asymmetric on help page for intersect
> 
> Sorry if this is a silly question. What does asymmetric refer 
> to from ?intersect, and are there any aspects of the result 
> that may be different from expected (reason for exclamation point) ?
> 
> As toy data, if needed, here are the examples from the help page.
> 
> (x <- c(sort(sample(1:20, 9)),NA))
> (y <- c(sort(sample(3:23, 7)),NA))
> 
> Thanks,
> 
> Juliet
> 
> __
> 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] extract the digits of a number

2008-12-09 Thread Christos Hatzis
An alternative that works for any base (other than 10) is the following:

> library(sfsmisc)
> digitsBase(1001, 10)
Class 'basedInt'(base = 10) [1:1]
 [,1]
[1,]1
[2,]0
[3,]0
[4,]1

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Gustavo Carvalho
> Sent: Tuesday, December 09, 2008 12:49 PM
> To: r-help@r-project.org
> Subject: [R] extract the digits of a number
> 
> Hello,
> 
> Anyone knows how can I do this in a cleaner way?
> 
> mynumber = 1001
> as.numeric(unlist(strsplit(as.character(mynumber),"")))
> [1] 1 0 0 1
> 
> Thanks in advance,
> 
> Gustavo
> 
> __
> 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] Save a function existing library

2008-10-30 Thread Christos Hatzis
A simple approach would be to start a fresh R session and source your
function.
Then save that workspace as, e.g., myFuncs.RData.

In future sessions all you have to do is
attach("myFuncs.Rdata") 

and your functions will be available for you to use.
-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Douglas M. 
> Hultstrand
> Sent: Thursday, October 30, 2008 1:45 PM
> To: r-help@r-project.org
> Subject: [R] Save a function existing library
> 
> Hello all,
> 
> I am fairly new to R and I have created a function that I use 
> quit frequently.  I was wondering if there is away to save 
> this function in an existing library so I can call it by 
> using the function name once the library is loaded?
> 
> Thanks,
> Doug
> 
> --
> -
> Douglas M. Hultstrand, MS
> Senior Hydrometeorologist
> Metstat, Inc. Windsor, Colorado
> voice: 970.686.1253
> email: [EMAIL PROTECTED]
> web: http://www.metstat.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.


Re: [R] Barplot: Vertical bars with long labels

2008-10-29 Thread Christos Hatzis
Udo,

You can try inserting a newline where you need the break in your labels:

> dd.names <- c('Conduct Disorders','Attention Deficit', 'Eating Disorders',
'Substance Abuse','Developmental Disorders')
> dd.names.2 <- sapply(dd.names, function(x) gsub("\\s", "\\\n", x))
> barplot(dd, names.arg=dd.names.2)

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Udo
> Sent: Wednesday, October 29, 2008 2:43 PM
> To: r-help@r-project.org
> Subject: [R] Barplot: Vertical bars with long labels
> 
> Dear List,
> I need a barplot with vertical bars. Each bar should have a label.
> The problem is, that the labels are too long, so they 
> overlap, or only every seccond label is displayed in the output.
> 
> Here is a little syntax:
> 
> dd <- c(100,110,90,105,95)
> barplot(dd,names.arg=c('Conduct Disorders','Attention Deficit',
>'Eating Disorders',
>'Substance Abuse','Developmental Disorders'))
> 
> My question is, if there is a chance to force a line break in 
> each label.
> 
> The result shoud look like this:
> 
>   Bar1Bar2   Bar3 Bar4 Bar5
> ConductAttentionEating Substance   Developmental
> Disorders  Disorders   Disorders AbuseDisorders
> 
> 
> 
> The result could also look like this:
> 
>   Bar1 Bar2   Bar3 Bar4 Bar5
>||  || |
> Conduct Disorders   |Eating Disordes|
> Developmental Disordes
> |   |
>  Attention deficit   Substance Abuse
> 
> 
> 
> 
> Many thanks in advance
> Udo
> 
> 
> 
> 
> Udo KN G
>   Ö I
> 
> Clinic for Child an Adolescent Psychiatry Philipps University 
> of Marburg / Germany
> 
> __
> 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] using ifelse with surprising results

2008-10-17 Thread Christos Hatzis
Try the following instead:

vegdata.dd[is.na(vegdata.dd)] <- 0.01

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Friday, October 17, 2008 4:50 PM
> To: [EMAIL PROTECTED]
> Subject: [R] using ifelse with surprising results
> 
> 
> Thanks for the gracious assistance in advance
> 
> I'm working on a non-metric scaling problem and am 
> calculating the distance for input to isoMDS
> 
> Here is the code
> 
> library(MASS)
> vegdata <- tapply(Percent, list(PRIMARY_VE, MASTERID), sum) 
> x.mat <- matrix(x, nrow=40, ncol=2750, byrow=TRUE, dimnames = 
> c(dimnames(x)[1], dimnames(x)[2]))
> 
> 
>  vegdata.dd <- dist(x)
>  vegdata.dd <- ifelse(vegdata.dd==NA, 0.01, x.dd)
>   vegdata.dd
> 
> Everything works as expected until I try to replace the NA 
> values in the distance matrix.
> the ifelse statement converts the entire dataset to NA.
> 
> What am I doing incorrectly?
> 
> Once again, Thanks
> 
> Steve
> 
> 
> Steve Friedman Ph. D.
> Spatial Statistical Analyst
> Everglades and Dry Tortugas National Park 950 N Krome Ave 
> (3rd Floor) Homestead, Florida 33034
> 
> Office (305) 224 - 4282
> [EMAIL PROTECTED]
> 
> __
> 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] Loop avoidance in simulating a vector

2008-10-16 Thread Christos Hatzis
Yes, but the difference is that the looping in mapply is done in C.
There are no interpreted loops in mapply,as far as I can see.

-Christos 

> -Original Message-
> From: Bert Gunter [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, October 16, 2008 4:13 PM
> To: [EMAIL PROTECTED]; 'David Afshartous'; 
> r-help@r-project.org
> Subject: RE: [R] Loop avoidance in simulating a vector
> 
> mapply is still a (disguised) loop (at the interpreted 
> level). So other than improving code readability (always a 
> good thing!), it shouldn't make much of an efficiency difference.
> 
> A longer answer is: if all you're doing is a location-scale 
> family of distributions, then creating a matrix of standard 
> normal (or whatever) distributed data for all 1:N at once and 
> then using matrix operations to multiply and add, say, so 
> each column becomes your different distribution might be 
> faster. This gets the loops down to C code.
> 
> A shorter answer is: it's unlikely that any of this makes 
> enough of a difference to be worth the effort. Random number 
> generation is so efficient in R that "avoiding loops" rarely matters.
> 
> Also see ?replicate for a way to perhaps write cleaner code 
> (but still using hidden interpreted loops).
> 
> -- Bert Gunter
> 
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Christos Hatzis
> Sent: Thursday, October 16, 2008 1:06 PM
> To: 'David Afshartous'; r-help@r-project.org
> Subject: Re: [R] Loop avoidance in simulating a vector
> 
> Have a look at mapply.
> 
> -Christos 
> 
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of David Afshartous
> > Sent: Thursday, October 16, 2008 3:47 PM
> > To: r-help@r-project.org
> > Subject: [R] Loop avoidance in simulating a vector
> > 
> > 
> > 
> > All,
> > 
> > I'd like to simulate a vector that is formed from many distinct 
> > distributions and avoid a loop if possible.  E.g, consider:
> > 
> > mu = c(1, 2, 3)
> > sigma = c(1, 2, 3)
> > n = c(10, 10, 10)
> > 
> > And we simulate a vector of length 30 that consists of N(mu[i], 
> > sigma[i])
> > distributed data, each of length n[i].   Of course for just 
> > three groups we
> > can simply write it out as:
> > 
> > DV = c(rnorm(n[1], mu[1], sigma[1]), rnorm(n[2], mu[2], sigma[2]), 
> > rnorm(n[3], mu[3], sigma[3]) )
> > 
> > For many groups we can use a loop (assuming equal numbers 
> per group):
> > 
> > n = n[1]
> > DV = numeric(N*n)
> > for (i in 1:N) {
> > DV[(n*i - (n-1)): (n*i)] = rnorm(n, mu[i], sigma[i])
> > }
> > 
> > Is there any way to do the general cas without using a loop?
> > 
> > Cheers,
> > 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-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] Loop avoidance in simulating a vector

2008-10-16 Thread Christos Hatzis
Have a look at mapply.

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of David Afshartous
> Sent: Thursday, October 16, 2008 3:47 PM
> To: r-help@r-project.org
> Subject: [R] Loop avoidance in simulating a vector
> 
> 
> 
> All, 
> 
> I'd like to simulate a vector that is formed from many 
> distinct distributions and avoid a loop if possible.  E.g, consider:
> 
> mu = c(1, 2, 3)
> sigma = c(1, 2, 3)
> n = c(10, 10, 10)
> 
> And we simulate a vector of length 30 that consists of 
> N(mu[i], sigma[i])
> distributed data, each of length n[i].   Of course for just 
> three groups we
> can simply write it out as:
> 
> DV = c(rnorm(n[1], mu[1], sigma[1]), rnorm(n[2], mu[2], 
> sigma[2]), rnorm(n[3], mu[3], sigma[3]) )
> 
> For many groups we can use a loop (assuming equal numbers per group):
> 
> n = n[1]
> DV = numeric(N*n)
> for (i in 1:N) {
> DV[(n*i - (n-1)): (n*i)] = rnorm(n, mu[i], sigma[i])
> }
> 
> Is there any way to do the general cas without using a loop?
> 
> Cheers,
> 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-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 book needed

2008-10-09 Thread Christos Hatzis
You might find Robert Gentleman's recent book useful for exposure on many of
the more advanced features of R. 

http://www.bioconductor.org/pub/RBioinf/

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Hua Li
> Sent: Thursday, October 09, 2008 3:13 PM
> To: R-help
> Subject: [R] R book needed
> 
> Hi there,
> 
> I'm looking for advice on a R book that's for somewhat advanced user. 
> 
> I've been using R for a while and can do the basic analysis 
> with no problem. My problem is that for many already existing 
> commands, such as gsub, textconnection, list, etc, I don't 
> use them, simply because I don't know their existence! Can 
> someone recommend a good book that I can refer to and can 
> learn R systematically? 
> 
> Thanks a lot!
> 
> Hua
> 
> __
> 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] vectorized sub, gsub, grep, etc.

2008-10-08 Thread Christos Hatzis
Hi John,

As I mentioned in our private exchange, this is well known in R, i.e.
vectorized versions are not always faster or more efficient than straight
loops.  It is a misconception that loops should be avoided at any cost.  See
John Fox's illuminating article on Rnews (p. 46) on this subject.
http://cran.r-project.org/doc/Rnews/Rnews_2008-1.pdf

To me, unless the application is way too demanding, I take the vectorized
version over the loop any day, as it is much simpler to write, usually a
one-liner, and therefore much easier to maintain in the long run.

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of john
> Sent: Thursday, October 09, 2008 12:38 AM
> To: r-help
> Subject: Re: [R] vectorized sub, gsub, grep, etc.
> 
> Hello Christos,
>   To my surprise, vectorization actually hurt processing speed!
> 
> #Example
> X <- c("ab", "cd", "ef")
> patt <- c("b", "cd", "a")
> repl <- c("B", "CD", "A")
> 
> sub2 <- function(pattern, replacement, x) {
> len <- length(x)
> if (length(pattern) == 1) 
> pattern <- rep(pattern, len)
> if (length(replacement) == 1) 
> replacement <- rep(replacement, len)
> FUN <- function(i, ...) {
> sub(pattern[i], replacement[i], x[i], fixed = TRUE)
> }
> idx <- 1:length(x)
> sapply(idx, FUN)
> }
>  
> system.time(  for(i in 1:1)  sub2(patt, repl, X)  )
>user  system elapsed 
>1.180.071.26 
> 
> system.time(  for(i in 1:1)  mapply(function(p, r, x) 
> sub(p, r, x, fixed = TRUE), p=patt, r=repl, x=X)  )
>user  system elapsed 
>1.420.051.47 
>  
> So much for avoiding loops.
> John Thaden
> 
> === At 2008-10-07, 14:58:10 Christos wrote: ===
> 
> >John,
> >Try the following:
> >
> > mapply(function(p, r, x) sub(p, r, x, fixed = TRUE), 
> p=patt, r=repl, x=X)
> >   b   cda 
> >"aB" "CD" "ef"  
> >
> >-Christos
> 
> >> -My Original Message-
> >> R pattern-matching and replacement functions are
> >> vectorized: they can operate on vectors of targets.
> >> However, they can only use one pattern and replacement.
> >> Here is code to apply a different pattern and replacement 
> for every 
> >> target.  My question: can it be done better?
> >> 
> >> sub2 <- function(pattern, replacement, x) {
> >> len <- length(x)
> >> if (length(pattern) == 1) 
> >> pattern <- rep(pattern, len)
> >> if (length(replacement) == 1) 
> >> replacement <- rep(replacement, len)
> >> FUN <- function(i, ...) {
> >> sub(pattern[i], replacement[i], x[i], fixed = TRUE)
> >> }
> >> idx <- 1:length(x)
> >> sapply(idx, FUN)
> >> }
> >> 
> >> #Example
> >> X <- c("ab", "cd", "ef")
> >> patt <- c("b", "cd", "a")
> >> repl <- c("B", "CD", "A")
> >> sub2(patt, repl, X)
> >> 
> >> -John
> 
> __
> 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] Using grep

2008-10-08 Thread Christos Hatzis
which(A %in% B)

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of mentor_
> Sent: Wednesday, October 08, 2008 11:19 AM
> To: r-help@r-project.org
> Subject: [R] Using grep
> 
> 
> Hi,
> 
> I have a vector A with (200, 201, 202, 203, 204, ... 210) and 
> a vector B with (201, 204, 209).
> Now I would like to get the position in vector A matches with 
> the entries in vector B So what I want to have is the 
> following result:
> [1] 2 5 10
> 
> I tried the following:
> grep(B, A)
> 
> grep(c(B), A)
> 
> A <- as.character(A)
> B <- as.character(B)
> 
> grep(B, A)
> grep(c(B), A)
> 
> and several other combinations. But nothing is giving me the 
> right result?!
> Does anyone know why?
> 
> Cheers,
> Mentor
> --
> View this message in context: 
> http://www.nabble.com/Using-grep-tp19881017p19881017.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.


Re: [R] vectorized sub, gsub, grep, etc.

2008-10-07 Thread Christos Hatzis
John,
Try the following:

> mapply(function(p, r, x) sub(p, r, x, fixed = TRUE), p=patt, r=repl, x=X)
   b   cda 
"aB" "CD" "ef"  

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Thaden, John J
> Sent: Tuesday, October 07, 2008 3:59 PM
> To: r-help@r-project.org
> Cc: [EMAIL PROTECTED]
> Subject: [R] vectorized sub, gsub, grep, etc.
> 
> R pattern-matching and replacement functions are
> vectorized: they can operate on vectors of targets.
> However, they can only use one pattern and replacement.
> Here is code to apply a different pattern and replacement for 
> every target.  My question: can it be done better?
> 
> sub2 <- function(pattern, replacement, x) {
> len <- length(x)
> if (length(pattern) == 1) 
> pattern <- rep(pattern, len)
> if (length(replacement) == 1) 
> replacement <- rep(replacement, len)
> FUN <- function(i, ...) {
> sub(pattern[i], replacement[i], x[i], fixed = TRUE)
> }
> idx <- 1:length(x)
> sapply(idx, FUN)
> }
> 
> #Example
> X <- c("ab", "cd", "ef")
> patt <- c("b", "cd", "a")
> repl <- c("B", "CD", "A")
> sub2(patt, repl, X)
> 
> -John
> 
> Confidentiality Notice: This e-mail message, including 
> a...{{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-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] algorithm to create unique identifiers

2008-09-04 Thread Christos Hatzis
It might be an overkill for what you need, but take a look at package Ruuid.

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Ralph S.
> Sent: Thursday, September 04, 2008 11:44 PM
> To: r-help@r-project.org
> Subject: [R] algorithm to create unique identifiers
> 
> 
> Hi all,
> 
> I am trying to create a unique identifier for each row, 
> combining numbers from three columns.
> 
> Do you know if there is a general formula to do this (or some 
> manual where I can read about this)?
> 
> I figure I can use the numeric entries of the columns as 
> "coordinates" and multiply them with different coefficients 
> (different magnitudes) to get the unique ID - but it would be 
> nice to read about such algorithms in general.
> 
> Any links/input would be great -
> 
> Ralph
> 
> _
> 
> e.
> 
>   [[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] sequence with start and stop positions

2008-08-26 Thread Christos Hatzis
Try:

> unlist(mapply(seq, c(1,20,50), c(7,25,53)))
 [1]  1  2  3  4  5  6  7 20 21 22 23 24 25 50 51 52 53

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Chris Oldmeadow
> Sent: Tuesday, August 26, 2008 12:42 AM
> To: r-help@r-project.org
> Subject: [R] sequence with start and stop positions
> 
> Hi,
> 
> I have a vector of start positions, and another vector of 
> stop positions,
> 
> eg start<-c(1,20,50)
>  stop<-c(7,25,53)
> 
> Is there a quick way to create a sequence from these vectors?
> 
> new<-c(1,2,3,4,5,6,7,20,21,22,23,24,25,50,51,52,53)
> 
> the way Im doing it at the moment is
> 
> pos<-seq(start[1],stop[1])
> 
> for (i in 2:length(start)){
>   new<-seq(start[i],stop[i])
>   pos<-c(pos,new)
> }
> 
> This works on small data, but its very inefficient on large 
> vectors, and is taking forever!
> 
> Anybody no a better way?
> 
> many thanks,
> Chris
> 
> __
> 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] paste: multiple collapse arguments?

2008-08-25 Thread Christos Hatzis
Try this:

> paste(paste(x, c(" ","\n"), sep=""), collapse="")
[1] "1 2\n3 4\n5 6\n"

-Christos Hatzis

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of remko duursma
> Sent: Monday, August 25, 2008 7:37 PM
> To: r-help@r-project.org
> Subject: [R] paste: multiple collapse arguments?
> 
> 
> Dear R-helpers,
> 
> I have a numeric vector, like:
> 
> x <- c(1,2,3,4,5,6)
> 
> I make this into a string for output to a text file, separated by \n:
> 
> paste(x, collapse="\n")
> 
> Is there a way to alternate the collapse argument? So between 
> the first two elements of x, I want to separate by " ", then 
> by "\n", and so forth.
> The result should then look like:
> "1 2\n3 4\n5 6"
> 
> (This way I get 2 elements of x on each line using 
> writeLines, instead of one or all).
> I could do this in some ugly loop, but surely there is a better way?
> 
> thanks,
> Remko
> 
> 
> 
> 
> 
> 
> _
> Get thousands of games on your PC, your mobile phone, and the 
> web with Windows..
> 
>   [[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] simple generation of artificial data with defined features

2008-08-22 Thread Christos Hatzis
On the general question on how to create a dataset that matches the
frequencies in a table, function as.data.frame can be useful.  It takes as
argument an object of a class 'table' and returns a data frame of
frequencies.

Consider for example table 6.1 of Fleiss et al (3rd Ed):

> birth.weight <- c(10,15,40,135)
> attr(birth.weight, "class") <- "table"
> attr(birth.weight, "dim") <- c(2,2)
> attr(birth.weight, "dimnames") <- list(c("A", "Ab"), c("B", "Bb"))
> birth.weight
 B  Bb
A   10  40
Ab  15 135
> summary(birth.weight)
Number of cases in table: 200 
Number of factors: 2 
Test for independence of all factors:
Chisq = 3.429, df = 1, p-value = 0.06408
> 
> bw.dt <- as.data.frame(birth.weight)

Observations (rows) in this table can then be replicated according to their
corresponding frequencies to yield the expanded dataset that conforms with
the original table. 

> bw.dt.exp <- bw.dt[rep(1:nrow(bw.dt), bw.dt$Freq), -ncol(bw.dt)]
> dim(bw.dt.exp)
[1] 200   2
> table(bw.dt.exp)
Var2
Var1   B  Bb
  A   10  40
  Ab  15 135 

The above approach is not restricted to 2x2 tables, and should be
straightforward generate datasets that conform to arbitrary nxm frequency
tables.

-Christos Hatzis


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Greg Snow
> Sent: Friday, August 22, 2008 12:41 PM
> To: drflxms; r-help@r-project.org
> Subject: Re: [R] simple generation of artificial data with 
> defined features
> 
> I don't think that the election data is the right data to 
> demonstrate Kappa, you need subjects that are classified by 2 
> or more different raters/methods.  The election data could be 
> considered classifying the voters into which party they voted 
> for, but you only have 1 rater.  Maybe if you had some survey 
> data that showed which party each voter voted for in 2 or 
> more elections, then that may be a good example dataset.  
> Otherwise you may want to stick with the sample datasets.
> 
> There are other packages that compute Kappa values as well (I 
> don't know if others calculate this particular version), but 
> some of those take the summary data as input rather than the 
> raw data, which may be easier if you just have the summary tables.
> 
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [EMAIL PROTECTED]
> (801) 408-8111
> 
> 
> 
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of drflxms
> > Sent: Friday, August 22, 2008 6:12 AM
> > To: r-help@r-project.org
> > Subject: [R] simple generation of artificial data with defined 
> > features
> >
> > Dear R-colleagues,
> >
> > I am quite a newbie to R fighting my stupidity to solve a probably 
> > quite simple problem of generating artificial data with defined 
> > features.
> >
> > I am conducting a study of inter-observer-agreement in 
> > child-bronchoscopy. One of the most important measures is Kappa 
> > according to Fleiss, which is very comfortable available in 
> R through 
> > the irr-package.
> > Unfortunately medical doctors like me don't really 
> understand much of 
> > statistics. Therefore I'd like to give the reader an easy 
> > understandable example of Fleiss-Kappa in the Methods part. 
> To achieve 
> > this, I obtained a table with the results of the German 
> election from 
> > 2005:
> >
> > partynumber of votespercent
> >
> > SPD1619466534,2
> > CDU1313674027,8
> > CSU34943097,4
> > Gruene38383268,1
> > FDP46481449,8
> > PDS41181948,7
> >
> > I want to show the agreement of voters measured by Fleiss-Kappa. To 
> > calculate this with the kappam.fleiss-function of irr, I need a 
> > data.frame like this:
> >
> > (id of 1st voter) (id of 2nd voter)
> >
> > party spd cdu
> >
> > Of course I don't plan to calculate this with the million of cases 
> > mentioned in the table above (I am working on a small laptop). A 
> > division by 1000 would be more than perfect for this example. The 
> > exact format of the table is generally not so important, as I could 
> > reshape nearly every format with the help of the reshape-package.
> >
> > Unfortunately I could not figure out how to create such a 
> > fictive/artificial dataset a

Re: [R] conditional with and operators

2008-08-19 Thread Christos Hatzis
Mark,

It is not clear whether you are dealing with a single list or something more
complex, such as a list of lists or a list of data frames.  In the case of a
single list, you don't really need any of the 'apply' functions.  The main
problem in your code is the use of '&&' instead of '&':

> test.1 <- list(id = 1:50, tick = rnorm(50, 900, 50), tvis = sample(1:100,
50))
> test.1
$id
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29
[30] 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

$tick
 [1]  891.5450  997.4262  884.0224  892.8317  903.7194  862.7283  913.8126
895.6072
 [9]  923.2599  823.0804  828.0575  919.2257  879.8593  833.6082  924.6253
889.6797
[17]  880.2397 1022.9587  898.3806  953.0213  911.8132  932.3018  960.7257
905.0871
[25] 1018.8407  991.3910  931.3846  960.0569  793.5923  899.3268  921.0783
929.6885
[33]  940.9550  882.9791  914.9050  897.7252  970.7575  867.9848  901.2766
912.0851
[41]  856.8671  878.3230  906.9869  903.8044  882.1902  972.3030  923.9107
869.6903
[49]  836.6934  912.6101

$tvis
 [1] 67  8 89 36 91 30 63 38 22 44 18 79 48 90 82  6 81 39 69  7 45 86 32 43
99 23 34 54 37
[30]  1 15  5 14 87 77 27 93 94 71 60 83 62 92 72 26 80 58 98 84 78

> test.1$id > 10 & test.1$tick > 910
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
FALSE FALSE
[15]  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
TRUE  TRUE
[29] FALSE FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE  TRUE
FALSE FALSE
[43] FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE

> test.1$tvis[test.1$id > 10 & test.1$tick > 910]
 [1] 79 82 39  7 45 86 32 99 23 34 54 15  5 14 77 93 60 80 58 78 

If this is not what you have, it would be helpful to provide an example of
the data structure that you are dealing with, as the posting guide suggests.

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Altaweel, Mark R.
> Sent: Tuesday, August 19, 2008 4:10 PM
> To: r-help@r-project.org
> Subject: [R] conditional with and operators
> 
> Hi,
> 
> I have a problem in which I am parsing data from a list.  I 
> am simply trying to return data that has several conditions 
> being true.  Here is my syntax below:
> 
> d<-sapply(res,function(.df){(.df$TimesVisited[.df$Tick>912 && 
> .df$Id>0])})   #res is the list, and I am trying to return a 
> result that has two true conditions (that is the variable 
> Tick should be greate than 912 and Id should be greater than 0
> 
> This returns an array of 10 with integer values of 0. This is 
> the incorrect result
> 
> However, if I do the same syntax except I remove the && 
> statement (i.e. the second conditional), then the result 
> producing something that makes sense, which is all values 
> that are Tick and greater than 912.
> 
> Can someone let me know how I can setup my data to be parsed 
> so I can have 2 or multiple conditionals in my function that 
> is looking at an array.
> 
> Thanks in advance.
> 
> Mark
> 
> __
> 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] Opening a web browser from R?

2008-08-15 Thread Christos Hatzis
Jose,

I think shell.exec should do what you want:

shell.exec("http://www.yahoo.com";)

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Friday, August 15, 2008 6:56 AM
> To: r-help@r-project.org
> Subject: [R] Opening a web browser from R?
> 
> 
> Hi,
> 
> I was wondering if there's a way in R to open a web browser 
> (such as Internet Explorer, or Firefox or whatever).
> I'm doing some analyses that have associated urls, and it 
> would be nice to have the ability to directly open the 
> relevant page from within R.
> I was looking at the help for 'url' and I can see I can 
> probably access the information I need and display it in my 
> own way, but can I somehow just open the given url with my 
> web browser of choice?
> 
> many thanks for any help,
> 
> Jose
> 
> 
> -- 
> Dr. Jose I. de las Heras  Email: 
> [EMAIL PROTECTED]
> The Wellcome Trust Centre for Cell BiologyPhone: +44 
> (0)131 6513374
> Institute for Cell & Molecular BiologyFax:   +44 
> (0)131 6507360
> Swann Building, Mayfield Road
> University of Edinburgh
> Edinburgh EH9 3JR
> UK
> 
> --
> The University of Edinburgh is a charitable body, registered 
> in Scotland, with registration number SC005336.
> 
> __
> 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] help with my sloppy syntax

2008-08-14 Thread Christos Hatzis
Would something like this work?

my.list <- as.list(c(NIM.results$par, a.hat.decision, etc))
do.call("Draw.NIM.POD.curve", my.list) 

-Christos Hatzis

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Charles Annis, P.E.
> Sent: Thursday, August 14, 2008 11:11 AM
> To: r-help@r-project.org
> Cc: [EMAIL PROTECTED]
> Subject: [R] help with my sloppy syntax
> 
> R-ians:
> 
> After some effort I coerced my code to do what I want but my 
> syntax is a kludge.  Suggestions on more elegant syntax?
> 
>   par <- NIM.results$par
>   do.call("Draw.NIM.POD.curve", list(par[1], par[2], 
> par[3], par[4],
>   par[5], a.hat.decision,  et cetera ...
> 
> It seems that I should be able to avoid defining the variable 
> "par" and then specifying each of its elements, but all my 
> attempts resulted in a list whose first element is a list, 
> rather than the elements of the list.  And my attempts at 
> unlist were unsuccessful.
> 
> Thank you.
> 
> Charles Annis, P.E.
> 
> [EMAIL PROTECTED]
> phone: 561-352-9699
> eFax:  614-455-3265
> http://www.StatisticalEngineering.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.


Re: [R] correlation between rows of data.frame

2008-08-01 Thread Christos Hatzis
Eleni,

A way to do this is to group the data first using 'split' and then sapply
the dist function to this list.
The slower step will be the split which took a couple of minutes on my
laptop but sapply should not take more than a minute or so.

size <- 1
df <- data.frame(
id=rep(sample(1:10,size=size),2),
a=sample(c(NA,rnorm(100,0,1)), size=2*size, rep=TRUE),
b=sample(c(NA,rnorm(100,0,1)), size=2*size, rep=TRUE),
c=sample(c(NA,rnorm(100,0,1)), size=2*size, rep=TRUE))

df$id=factor(df$id)

dfp <- split(df, df$id)
sapply(dfp, dist) 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Eleni Rapsomaniki
> Sent: Friday, August 01, 2008 2:45 PM
> To: r-help@r-project.org
> Subject: [R] correlation between rows of data.frame
> 
> Dear R users,
> 
> I need to come up with an efficient method to compute the 
> correlation (or at least, the euclidean distance if that's 
> easier) between specific rows in a data
> frame (46,232 rows,29 columns). The pairs of rows between 
> which I want to
> find the correlation share a common value in one of the 
> columns. So for example, in the following  
> x=data.frame(id=rep(sample(1:10,size=1),2),a=sample(c(
> NA,rnorm(10,0,1)),size=1,
> replace=T),b=sample(c(NA,rnorm(10,0,1)),size=1,
> replace=T),c=sample(c(NA,rnorm(10,0,1)),size=1, replace=T))
> x$id=factor(x$id)
> 
> I would want to compute the correlation between the two rows 
> (for cols a,b,c) that share the same id. Using a for loop and 
> dist() works but takes a long time (>1 hour, my RAM is
> 1Gb):
> p=NULL
>  for(i in levels(x$id)){p[[i]]=dist(x[x$id==i, -1])}
> 
> Is there a more efficient way? I thought about apply/sapply 
> etc but I don't think they'll work for rows and can't think 
> of an intelligent way to make them work!
> The second problem is that I also need to know how many 
> degrees of freedom (ie non missing pairs of values) were used 
> in each correlation. Is there a way to also do this efficiently?
> 
> I hope this makes sense! Thank you all very much in advance!
> 
> Eleni
> 
> __
> 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] cutting out numbers from vectors

2008-07-31 Thread Christos Hatzis
Have a look at gsub:

> x <- "001-010-001-0"
> gsub("^0+", "", x)
[1] "1-010-001-0" 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of calundergrad
> Sent: Thursday, July 31, 2008 4:40 PM
> To: r-help@r-project.org
> Subject: [R] cutting out numbers from vectors
> 
> 
> i have a vector with values similar to the below text [1] 
> 001-010-001-0
> 
> I want to get rid of all leading zeroes.  for example i want 
> to change the values of the vector so that [1] 001-010-001-0 
> becomes [1] 1-010-001-0.  
> 
> Another example
> [1]082-232-232-1 becomes [1] 82-232-232-1
> 
> how do i do this?
> --
> View this message in context: 
> http://www.nabble.com/cutting-out-numbers-from-vectors-tp18763
> 058p18763058.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.


Re: [R] Grouping Index of Matrix Based on Certain Condition

2008-07-31 Thread Christos Hatzis
Try this:

> x <- matrix(runif(20), ncol=2)
> x
[,1]  [,2]
 [1,] 0.33119833 0.4797847
 [2,] 0.01339784 0.5218626
 [3,] 0.78975940 0.8597246
 [4,] 0.60849015 0.5217248
 [5,] 0.91779777 0.9364047
 [6,] 0.88302538 0.3467961
 [7,] 0.87565986 0.4029147
 [8,] 0.51594479 0.9885018
 [9,] 0.87680383 0.7694989
[10,] 0.40761877 0.4661846

> apply(x, 1, function(y) ifelse(diff(y)<0, 1, 2))
 [1] 2 2 2 1 2 1 1 2 1 2

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Gundala Viswanath
> Sent: Thursday, July 31, 2008 11:00 PM
> To: [EMAIL PROTECTED]
> Subject: [R] Grouping Index of Matrix Based on Certain Condition
> 
> Hi,
> 
> I have the following (M x N) matrix, where M = 10 and N =2 
> What I intend to do is to group index of (M) based on this 
> condition of "x_mn" , namely
> 
> For each M,
> If x_m1 > x_m2, assign index of M to Group1 otherwise assign 
> index of M into Group 2
> 
> 
> > x
>[,1]   [,2]
>   [1,] 4.482909e-01 0.55170907
>   [2,] 9.479594e-01 0.05204063
>   [3,] 8.923553e-01 0.10764474
>   [4,] 9.295003e-01 0.07049966
>   [5,] 8.880434e-01 0.11195664
>   [6,] 9.197367e-01 0.08026327
>   [7,] 9.431232e-01 0.05687676
>   [8,] 9.460356e-01 0.05396442
>   [9,] 6.053829e-01 0.39461708
>  [10,] 9.515173e-01 0.04848268
> 
> Is there a simple way to do it in R?
> - Gundala Viswanath
> Jakarta - Indonesia
> 
> __
> 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] Identifying common prefixes from a vector of words, and delete those prefixes

2008-07-31 Thread Christos Hatzis
A more general solution:

strip.fun <- function(x, split=".") {
xx <- strsplit(x, split, fixed=TRUE)
txx <- table(unlist(xx))
nxx <- names(txx)[txx > 1]
setdiff(unlist(xx), nxx)
}

> x <- c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.animal")
> strip.fun(x)
[1] "dog" "cat" "rat"

> y <- c("my_cat_pet", "my_dog_pet", "my_rat_pet")
> strip.fun(y, "_") 
[1] "cat" "dog" "rat"


-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of John Kane
> Sent: Thursday, July 31, 2008 12:48 PM
> To: [EMAIL PROTECTED]; Daren Tan
> Subject: Re: [R] Identifying common prefixes from a vector of 
> words,and delete those prefixes
> 
> There MUST be a better way but this will work. 
> 
> x <- c("dog.is.an.animal", "cat.is.an.animal", 
> "rat.is.an.animal") bb <- strsplit(x, "\\.") myfun <- 
> function(m) m[1] animals  <- unlist(lapply(bb, myfun)) animals
> 
> 
> 
> 
> --- On Thu, 7/31/08, Daren Tan <[EMAIL PROTECTED]> wrote:
> 
> > From: Daren Tan <[EMAIL PROTECTED]>
> > Subject: [R] Identifying common prefixes from a vector of 
> words, and 
> > delete those prefixes
> > To: [EMAIL PROTECTED]
> > Received: Thursday, July 31, 2008, 7:11 AM For example, 
> > c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.animal").
> > How can I identify the common prefix is ".is.an.animal" and 
> delete it 
> > to give c("dog", "cat", "rat") ?
> >  
> > 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.
> 
> 
>   
> __
> [[elided Yahoo spam]]
> 
> __
> 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] john chambers R book

2008-07-30 Thread Christos Hatzis
I just received mine today (had pre-ordered it directly from Springer)

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Wednesday, July 30, 2008 2:27 PM
> To: r-help@r-project.org
> Subject: [R] john chambers R book
> 
> Just to let everyone know: John Chambers R book is no longer 
> at pre-order status on Amazon which is a good thing. The only 
> problem is that now it is temporarily out of stock. There 
> must have been many pre-orders so now I'm kicking myself for 
> not having done that.
> 
>  
> Mark
> 
> __
> 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] finding a faster way to do an iterative computation

2008-07-29 Thread Christos Hatzis
matrix(rep(x, each=13) - xk, nrow=13) 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of dxc13
> Sent: Tuesday, July 29, 2008 2:13 PM
> To: r-help@r-project.org
> Subject: [R] finding a faster way to do an iterative computation
> 
> 
> useR's,
> 
> I am trying trying to find out if there is a faster way to do 
> a certain computation.  I have successfully used FOR loops 
> and the apply function to do this, but it can take some time 
> to fully compute, but I was wondering if anyone may know of a 
> different function or way to do this:
> > x
> [1] 1 2 3 4 5
> > xk
>  [1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
> 
> I want to do: abs(x-xk[i]) where i = 1 to length(xk)=13.  It 
> should result in a 13 by 5 matrix or data frame.  Does anyone 
> have a "quicker" solution than FOR loops or apply()?
> 
> Much appreciation and thanks,
> dxc13
> --
> View this message in context: 
> http://www.nabble.com/finding-a-faster-way-to-do-an-iterative-
> computation-tp18718233p18718233.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.


Re: [R] Fill in NA values in vector with previous character/factor

2008-07-28 Thread Christos Hatzis
Just for the fun of it, here is a recursive solution to the same problem...

rna <- function(z) { 
y <- c(NA, head(z, -1))
z <- ifelse(is.na(z), y, z)
if (any(is.na(z))) Recall(z) else z }

> x
 [1] "A" "B" NA  NA  "C" NA  NA  NA  NA  "D" NA  NA 
> rna(x)
 [1] "A" "B" "B" "B" "C" "C" "C" "C" "C" "D" "D" "D" 

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Bert Gunter
> Sent: Monday, July 28, 2008 4:05 PM
> To: 'Dimitris Rizopoulos'; 'Owen Jones'
> Cc: r-help@r-project.org
> Subject: Re: [R] Fill in NA values in vector with previous 
> character/factor
> 
> Just for the record, a less efficient but certainly simple 
> and maybe adequate way for you to do it in standard R (no zoo 
> package required) is:
> 
> for(i in seq_along(x)[-1])if(is.na(x[i])) x[i] <- x[i-1]
> 
> I tried timing it on my not so fancy Windows desktop for a 
> vector of 10,000 values, but it was instantaneous.
> 
> Loops may be relatively inefficient in R, but how relatively 
> inefficient is ... well, ... relative. (If you didn't have 
> zoo installed, how long does it take to install? -- perhaps a 
> red herring, but ...)
> 
> Cheers,
> 
> Bert Gunter
> Genentech 
> 
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Dimitris Rizopoulos
> Sent: Monday, July 28, 2008 12:26 PM
> To: Owen Jones
> Cc: r-help@r-project.org
> Subject: Re: [R] Fill in NA values in vector with previous 
> character/factor
> 
> try function na.locf() from package 'zoo', i.e.,
> 
> library(zoo)
> x <- c("A","B",NA,NA,"C",NA,NA,NA,NA,"D",NA,NA)
> na.locf(x)
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> 
> 
> Dimitris Rizopoulos
> Biostatistical Centre
> School of Public Health
> Catholic University of Leuven
> 
> Address: Kapucijnenvoer 35, Leuven, Belgium
> Tel: +32/(0)16/336899
> Fax: +32/(0)16/337015
> Web: http://med.kuleuven.be/biostat/
>   http://perswww.kuleuven.be/dimitris_rizopoulos/
> 
> 
> Quoting Owen Jones <[EMAIL PROTECTED]>:
> 
> > I have a vector of data (species names) interspersed with NA values 
> > and I want a function to "fill in the blanks", replacing NA values 
> > with whatever the last species name was.
> >
> > For example the vector:
> >
> >  "A","B",NA,NA,"C",NA,NA,NA,NA,"D",NA,NA.
> >
> > should evaluate to:
> >
> > "A" "B" "B" "B" "C" "C" "C" "C" "C" "D" "D" "D"
> >
> >
> > I tried to use rle() in a function to do this but have hit 
> a brick wall.
> >
> > How would YOU do this?
> >
> > Many thanks,
> >
> > Owen
> >
> > __
> > 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.
> 
> 
> 
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.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.
> 
> __
> 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] split character string in matrix into character vector and numeric vector

2008-05-21 Thread Christos Hatzis
> x <- "B03_MAH 0.2115  0.2087  0.2087  0.2147  0.2115  0.2176"
> strsplit(x, " +")
[[1]]
[1] "B03_MAH" "0.2115"  "0.2087"  "0.2087"  "0.2147"  "0.2115"  "0.2176" 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Kim Milferstedt
> Sent: Wednesday, May 21, 2008 1:11 PM
> To: [EMAIL PROTECTED]
> Subject: [R] split character string in matrix into character 
> vector and numeric vector
> 
> Hello,
> 
> I've got a matrix consisting of one column with n rows. Each 
> field in the matrix is filled with a character vector.
> 
> I would like to convert this matrix into a character vector 
> containing the B03_MAH-type entries from the beginning of 
> each row and a data.frame that contains the numeric data, but 
> I am stuck.
> 
> I have tried to use textConnection with sep = "  " but since 
> there is sometimes more than two spaces separating the 
> entries, I obtain a result with columns full of NAs.
> 
> Then I tried sub() to replace the all multi-spaces to get 
> only one space that separates each entry but that didn't work either.
> 
> Do you know a good way to convert this matrix?
> 
> Thanks already,
> 
> Kim
> 
> taxa.vec "B03_MAH 0.2115  0.2087  0.2087  0.2147  0.2115  0.2176" 
> taxa.vec "F02_SSBH0.2162  0.2191  0.2133  0.2130  0.2220  0.2158" 
> taxa.vec "G04_MAH 0.2083  0.2111  0.2055  0.2115  0.2140  0.2087" 
> taxa.vec "A04_MAH 0.2097  0.2126  0.2069  0.2065  0.2097  0.2037" 
> taxa.vec "E03_MAH 0.2097  0.2069  0.2069  0.2130  0.2155  0.2101"
> 
> __
> 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] A very simple question

2008-05-14 Thread Christos Hatzis
> k <- c(1,1,1,2,2,1,1,1)
> k[k != 1]
[1] 2 2
> k[k != 2]
[1] 1 1 1 1 1 1
> k[k != 3]
[1] 1 1 1 2 2 1 1 1
> 

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Shubha 
> Vishwanath Karanth
> Sent: Wednesday, May 14, 2008 11:16 AM
> To: [EMAIL PROTECTED]
> Subject: [R] A very simple question
> 
> Hi R,
> 
>  
> 
> Suppose
> 
> l=c(1,1,1,2,2,1,1,1)
> 
>  
> 
> k[-which(k==1)]
> 
> [1] 2 2
> 
>  
> 
> k[-which(k==2)]
> 
> [1] 1 1 1 1 1 1
> 
>  
> 
> But,
> 
>  
> 
> k[-which(k==3)]
> 
> numeric(0)
> 
>  
> 
> I do not want this numeric(0), instead the whole k itself 
> should be my result... How do I do this?
> 
>  
> 
>  
> 
> Thanks,
> 
> Shubha
> 
>  
> 
> This e-mail may contain confidential and/or privileged 
> i...{{dropped:13}}
> 
> __
> 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] help with subset

2008-05-02 Thread Christos Hatzis
Try %in%

subset(dat, treatment %in% vec) 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Friday, May 02, 2008 11:41 PM
> To: r-help@r-project.org
> Subject: [R] help with subset
> 
> Dear list:
> 
> I have a problem using the subset function:
> 
> dat<- data.frame(treatment=c("A", "B", "A", "C", "C", "D", 
> "A", "D", "C", "D"), response=rnorm(10))
> 
> I am interested in treatments "A", "B" and "D"
> vec<- c("A", "B", "D")
> 
> But I can only obtain what I want with:
> subset(dat, treatment=="A" | treatment=="B" | treatment=="D")
> 
> What's wrong with
> subset(dat, treatment==vec)
> 
> It would be much more simple to compute the latter in a 
> rather complex dataframe.
> Thanks in advance
> Justin
> -- 
>   
>   [EMAIL PROTECTED]
> 
> --
> 
> __
> 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] data transformation

2008-05-02 Thread Christos Hatzis
Christian,

You need to use reshape to convert to the 'long' format.
Check the help page ?reshape for details.

>dat <- read.table('clipboard', header=TRUE)
>dat
   site lat lon spec1 spec2 spec3 spec4
1 site1  10  11 1 0 1 0
2 site2  20  21 1 1 1 0
3 site3  30  31 0 1 1 1
> dat.long <- reshape(dat, varying = list(names(dat)[4:7]),
timevar="species", 
times=names(dat)[4:7], direction="long")
> dat.long
 site lat lon species spec1 id
1.spec1 site1  10  11   spec1 1  1
2.spec1 site2  20  21   spec1 1  2
3.spec1 site3  30  31   spec1 0  3
1.spec2 site1  10  11   spec2 0  1
2.spec2 site2  20  21   spec2 1  2
3.spec2 site3  30  31   spec2 1  3
1.spec3 site1  10  11   spec3 1  1
2.spec3 site2  20  21   spec3 1  2
3.spec3 site3  30  31   spec3 1  3
1.spec4 site1  10  11   spec4 0  1
2.spec4 site2  20  21   spec4 0  2
3.spec4 site3  30  31   spec4 1  3
> dat.long[dat.long$spec1 == 1, ]
 site lat lon species spec1 id
1.spec1 site1  10  11   spec1 1  1
2.spec1 site2  20  21   spec1 1  2
2.spec2 site2  20  21   spec2 1  2
3.spec2 site3  30  31   spec2 1  3
1.spec3 site1  10  11   spec3 1  1
2.spec3 site2  20  21   spec3 1  2
3.spec3 site3  30  31   spec3 1  3
3.spec4 site3  30  31   spec4 1  3 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Christian Hof
> Sent: Friday, May 02, 2008 5:28 PM
> To: r-help@r-project.org
> Subject: [R] data transformation
> 
> Dear all,
> how can I, with R, transform a presence-absence (0/1) matrix 
> of species occurrences into a presence-only table (3 columns) 
> with the names of the species (1st column), the lat 
> information of the sites (2nd column) and the lon information 
> of the sites (3rd column), as given in the below example?
> Thanks a lot for your help!
> Christian
> 
> 
> my dataframe:
> 
> site  lat lon spec1   spec2   spec3   spec4
> site1 10  11  1   0   1   0
> site2 20  21  1   1   1   0
> site3 30  31  0   1   1   1
> 
> 
> my desired new dataframe:
> 
> species   lat lon
> spec1 10  11
> spec1 20  21
> spec2 20  21
> spec2 30  31
> spec3 10  11
> spec3 20  21
> spec3 30  31
> spec4 30  31
> 
> 
> 
> --
> Christian Hof, PhD student
> 
> Center for Macroecology & Evolution
> University of Copenhagen
> www.macroecology.ku.dk
> &
> Biodiversity & Global Change Lab
> Museo Nacional de Ciencias Naturales, Madrid www.biochange-lab.eu
> 
> mobile ES .. +34 697 508 519
> mobile DE .. +49 176 205 189 27
>   mail .. [EMAIL PROTECTED]
>  mail2 .. [EMAIL PROTECTED]
>   blog .. www.vogelwart.de
> 
> __
> 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] elseif syntax

2008-05-01 Thread Christos Hatzis
Another option in R is to use the vectorized version 'ifelse', which has an
advantage if x is a vector:

> x <- -1:4
> x
[1] -1  0  1  2  3  4
> ifelse(x == 1, 'same', ifelse(x > 1, 'bigger', 'smaller'))
[1] "smaller" "smaller" "same""bigger"  "bigger"  "bigger" 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of jim holtman
> Sent: Thursday, May 01, 2008 11:30 AM
> To: Hyunchul Kim
> Cc: r-help@r-project.org
> Subject: Re: [R] elseif syntax
> 
> Is this what you want:
> 
> x <- 1
> if (x ==1){
> print('same')
> } else if (x > 1){
> print('bigger')
> } else {
> print('smaller')
> }
> 
> 
> On Thu, May 1, 2008 at 10:52 AM, Hyunchul Kim 
> <[EMAIL PROTECTED]> wrote:
> > Hi, all
> >
> > How to use elseif ?
> > For example, like following short python examples.
> >
> > *
> > x = 1
> > if x == 1:
> >  print 'same'
> > *elif* x > 1:
> >  print 'bigger'
> > else:
> >  print 'smaller'
> > *
> >
> > Thanks in advance,
> >
> > Hyunchul Kim
> >
> >[[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
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem you are trying to solve?
> 
> __
> 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] Design and analysis of mixture experiments

2008-04-17 Thread Christos Hatzis
The place to look is the CRAN Task View 'ExperimentalDesign'.
There are several packages there related to design and analysis of
experiments.

The package 'AlgDesign' appears to have a function for generating mixture
designs, and there might be others in other packages.

Good luck!

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Thursday, April 17, 2008 11:45 AM
> To: r-help@r-project.org
> Subject: [R] Design and analysis of mixture experiments
> 
> Hi,
> 
> I'm interested in experimental design and data analysis on 
> mixtures, like cake recipes where the sum of the components 
> is fixed; e.g.
> . 
> 
> I can't believe that R doesn't have facilities to design and 
> analyse such experiments, but I haven't been able to find 
> them (I have looked quite hard!). Can anyone point me in the 
> right direction?
> 
> Thanks in advance,
> 
> Keith Jewell
> mailto:[EMAIL PROTECTED] telephone (direct) +44 (0)1386 
> 842055 Released by Mr. K. Jewell
> 
> 
> 
> 
> 
> _
> The information in this document and attachments is given 
> after the exercise of all reasonable care and skill in its 
> compilation, preparation and issue, but is provided without 
> liability in its application or use.  It may contain 
> privileged information that is exempt from disclosure by law 
> and may be confidential.  If you are not the intended 
> recipient you must not copy, distribute or take any action in 
> reliance on it.  If you have received this document in error 
> please notify us and delete this message from your system immediately.
> 
> Campden & Chorleywood Food Research Association Group; 
> Campden & Chorleywood Food Research Association (company 
> limited by guarantee),registered number 510618); CCFRA Group 
> Services Ltd. (registered number 3841905); and CCFRA 
> Technology Ltd  (registered number 3836922), all registered 
> in England and Wales with the registered office at Station 
> Road, Chipping Campden, Gloucestershire, GL55 6LD.
> 
> The Group may monitor e-mail traffic data and also the 
> content of e-mail for the purposes of security and staff training.
> 
> Any advice given is subject to our normal terms and 
> conditions of trading, a copy of which is available on request.
> 
> __
> __
> This e-mail has been scanned for all viruses by 
> MessageL...{{dropped: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-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] Number of words in a string

2008-04-09 Thread Christos Hatzis
length(unlist(strsplit(C, ' '))) 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Shubha 
> Vishwanath Karanth
> Sent: Wednesday, April 09, 2008 11:21 AM
> To: [EMAIL PROTECTED]
> Subject: [R] Number of words in a string
> 
> Hi R,
> 
>  
> 
> A quick question: How do we find the number of words in a string?
> 
>  
> 
> Example:
> 
> C="Have a nice day"
> 
>  
> 
> And the number of words should be 4. any built in function or?...
> 
>  
> 
> Thanks, Shubha
> 
> Shubha Karanth | Amba Research
> 
> Ph +91 80 3980 8031 | Mob +91 94 4886 4510 
> 
> Bangalore * Colombo * London * New York * San Josi * 
> Singapore * www.ambaresearch.com
> 
>  
> 
> This e-mail may contain confidential and/or privileged 
> i...{{dropped:13}}
> 
>

__
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] A faster way to compute finite-difference gradient of a scalarfunction of a large number of variables

2008-03-27 Thread Christos Hatzis
Here is as solution that calculates derivatives using central differences by
appropriately embedding the vectors:

> grad.1
function(x, fn) {
x <- sort(x)
x.e <- head(embed(x, 2), -1)
y.e <- embed(fn(x), 3)
hh <- abs(diff(x.e[1, ]))
y.e <- apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh))
cbind(x=x.e[, 1], grad=y.e)
}
> myfunc.1
function(x){
(exp(x) - x) / 10
}
> system.time(g.3 <- grad.1(p0, myfunc.1))
   user  system elapsed 
   0.060.000.07 
 
CAVEAT: this assumes that the x-values are equally spaced, i.e. same h
throughout, but this part can be easily modified to accommodate h1, h2 on
either side of x.

Also, your myfunc takes a vector input and returns a scalar.  If this is
what was intended, you will need to find a way to vectorize it.  

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Ravi Varadhan
> Sent: Thursday, March 27, 2008 12:00 PM
> To: [EMAIL PROTECTED]
> Subject: [R] A faster way to compute finite-difference 
> gradient of a scalarfunction of a large number of variables
> 
> Hi All,
> 
>  
> 
> I would like to compute the simple finite-difference 
> approximation to the gradient of a scalar function of a large 
> number of variables (on the order of 1000).  Although a 
> one-time computation using the following function
> grad() is fast and simple enough, the overhead for repeated 
> evaluation of gradient in iterative schemes is quite 
> significant.  I was wondering whether there are better, more 
> efficient ways to approximate the gradient of a large scalar 
> function in R. 
> 
>  
> 
> Here is an example.  
> 
>  
> 
> grad <- function(x, fn=func, eps=1.e-07, ...){
> 
>   npar <- length(x)
> 
>   df <- rep(NA, npar)
> 
>   f <- fn(x, ...)
> 
> for (i in 1:npar) {
> 
> dx <- x
> 
> dx[i] <- dx[i] + eps
> 
> df[i] <- (fn(dx, ...) - f)/eps
> 
> }
> 
>   df 
> 
> }
> 
>  
> 
>  
> 
> myfunc <- function(x){
> 
> nvec <- 1: length(x)
> 
> sum(nvec * (exp(x) - x)) / 10
> 
> }
> 
>  
> 
> myfunc.g <- function(x){
> 
> nvec <- 1: length(x)
> 
> nvec * (exp(x) - 1) / 10
> 
> }
> 
>  
> 
> p0 <- rexp(1000)
> 
> system.time(g.1 <- grad(x=p0, fn=myfunc))[1]
> 
> system.time(g.2 <- myfunc.g(x=p0))[1]
> 
> max(abs(g.2 - g.1))
> 
>  
> 
>  
> 
> Thanks in advance for any help or hints.
> 
>  
> 
> Ravi.
> 
> --
> --
> ---
> 
> Ravi Varadhan, Ph.D.
> 
> Assistant Professor, The Center on Aging and Health
> 
> Division of Geriatric Medicine and Gerontology 
> 
> Johns Hopkins University
> 
> Ph: (410) 502-2619
> 
> Fax: (410) 614-9625
> 
> Email: [EMAIL PROTECTED]
> 
> Webpage:  
> http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
> 
>  
> 
> --
> --
> 
> 
>  
> 
> 
>   [[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] Rule for accessing attributes?

2008-03-27 Thread Christos Hatzis
Yes, indeed.  The help page says that @ extracts the contents of a slot in
S4 objects.  But you mention below that this 'works' for S3 objects because
S4 slots are stored as attributes.  Doesn't this mean that @ is currently
implemented to access attributes of objects in general (attributes of S3
objects or slots of S4 objects that are implemented as attributes)?  I
realize that this might change in the future...

-Christos  

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley
> Sent: Thursday, March 27, 2008 3:17 AM
> To: Christos Hatzis
> Cc: r-help@r-project.org
> Subject: Re: [R] Rule for accessing attributes?
> 
> Oh please don't recommend misuse of @ to those already confused.
> 
> @ is for accessing slots in S4 objects.  This 'works' because 
> they happen to be stored as attributes.  See the help page 
> (and the warning that it does no checking - we may change that).
> 
> Similarly,
> 
> plt$title <- "My Title"
> 
> works because the package maintainer (of ggplot2, 
> unmentioned?) has chosen to set things up that way.  R is 
> very flexible, and there is plenty of scope for package 
> authors to do confusing things.
> 
> On Thu, 27 Mar 2008, Christos Hatzis wrote:
> 
> > You need to use the '@' operator to directly access attributes (not
> > elements) of objects:
> >
> >> [EMAIL PROTECTED]
> > [1] "x" "y" "z"
> >
> > See ?'@' for more details.
> >
> > -Christos
> >
> >> -Original Message-
> >> From: [EMAIL PROTECTED]
> >> [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy
> >> Sent: Thursday, March 27, 2008 12:16 AM
> >> To: r-help@r-project.org
> >> Subject: [R] Rule for accessing attributes?
> >>
> >> Hi !
> >>
> >> I am a new user and quite confused by R-indexing.
> >>
> >> Make a list and get the attributes
> >> lst <- list(x = 1:3, y = 4:6, z = 7:9)
> >> attributes(lst)
> >>
> >> This returns:
> >>
> >> $names
> >> [1] "x" "y" "z"
> >>
> >> I can easily do:
> >>
> >> nm <-names(lst)
> >>
> >> or
> >>
> >> nm <-attr(lst,"names")
> >>
> >> which both return the assigned names of the named list 
> 'lst', but why 
> >> then this doesn't work:
> >>
> >> lst$names
> >>
> >> ?
> >>
> >> I am confused ... Moreover, I noticed that some of the 
> objects (e.g.
> >> plot objects returned by ggplot) also have attributes when 
> queried by 
> >> the 'attributes' function, but they are accessible by the 
> $ notation.
> >> (e.g.
> >>
> >> xydf <- data.frame(x = 1:5, y = 11:15) plt <- ggplot(data = xydf, 
> >> aes(x = x,y = y)) + geom_point()
> >> attributes(plt)
> >>
> >> Now we can change the title:
> >>
> >> plt$title <- "My Title"
> >> plt
> >>
> >> So is it some inconsistency or am I missing something important?
> >>
> >> __
> >> 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.
> >
> 
> -- 
> Brian D. Ripley,  [EMAIL PROTECTED]
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
> 
> __
> 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] Rule for accessing attributes?

2008-03-26 Thread Christos Hatzis
You need to use the '@' operator to directly access attributes (not
elements) of objects:

> [EMAIL PROTECTED]
[1] "x" "y" "z"

See ?'@' for more details.

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy
> Sent: Thursday, March 27, 2008 12:16 AM
> To: r-help@r-project.org
> Subject: [R] Rule for accessing attributes?
> 
> Hi !
> 
> I am a new user and quite confused by R-indexing.
> 
> Make a list and get the attributes
> lst <- list(x = 1:3, y = 4:6, z = 7:9)
> attributes(lst)
> 
> This returns:
> 
> $names
> [1] "x" "y" "z"
> 
> I can easily do:
> 
> nm <-names(lst)
> 
> or
> 
> nm <-attr(lst,"names")
> 
> which both return the assigned names of the named list 'lst', 
> but why then this doesn't work:
> 
> lst$names
> 
> ?
> 
> I am confused ... Moreover, I noticed that some of the objects (e.g.
> plot objects returned by ggplot) also have attributes when 
> queried by the 'attributes' function, but they are accessible 
> by the $ notation.
> (e.g.
> 
> xydf <- data.frame(x = 1:5, y = 11:15)
> plt <- ggplot(data = xydf, aes(x = x,y = y)) + geom_point()
> attributes(plt)
> 
> Now we can change the title:
> 
> plt$title <- "My Title"
> plt
> 
> So is it some inconsistency or am I missing something important?
> 
> __
> 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] peak finding

2008-03-24 Thread Christos Hatzis
John,

There is a peak finding algorithm attributed to Prof. Ripley in the R-help
archive.  It has a span parameter which might give you something close to
what you seem to be looking for.

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/33097.html 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Research Scholar
> Sent: Monday, March 24, 2008 11:24 PM
> To: [EMAIL PROTECTED]
> Cc: r-help@r-project.org
> Subject: Re: [R] peak finding
> 
> Hi
>  Thanks for replying. I meant x[4] is the start of a peak 
> shape and x[14] is the end of that peak and x[9] is the 
> maxima of the peak.
> Thanks,
> John
> 
> 
> 
> 
> On Mon, Mar 24, 2008 at 11:09 PM, <[EMAIL PROTECTED]> wrote:
> 
> > It's hard to see how positions 4 and 14 correspond to 'peaks', they 
> > look like troughs to me.  So perhaps this is what you mean:
> >
> > > x <- c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
> >
> > > y <- which(x == min(x))
> > > y
> > [1]  4 14
> >
> > as a function:
> >
> > somefunction <- function(x) which(x == min(x))
> >
> >
> > Bill Venables
> > CSIRO Laboratories
> > PO Box 120, Cleveland, 4163
> > AUSTRALIA
> > Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely 
> > necessary):  +61 7 3826 7304
> > Mobile: +61 4 8819 4402
> > Home Phone: +61 7 3286 7700
> > mailto:[EMAIL PROTECTED]
> > http://www.cmis.csiro.au/bill.venables/
> >
> > -Original Message-
> > From: [EMAIL PROTECTED] 
> > [mailto:[EMAIL PROTECTED]
> > On Behalf Of Research Scholar
> > Sent: Tuesday, 25 March 2008 12:54 PM
> > To: r-help@r-project.org
> > Subject: [R] peak finding
> >
> > Hi all
> >  Is there a function that can find the start and end 
> position of peaks 
> > in a set of numbers.
> > eg.
> > x <- c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12)
> > y <- somefunction(x)
> >
> > y
> > 4 14
> >
> >
> > Thanks
> > John
> >
> >[[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 > osting-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-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] a more elegant way to get percentages?

2008-03-13 Thread Christos Hatzis
Monica,

You can try the following:

> x.tot <- aggregate(x$val, by=list(total=x$locat), 'sum')
> x.tot
  total  x
1 a  5
2 b 20
3 c 40
4 d 30
> cbind(x, perc=x$val/rep(x.tot$x, table(x$locat)) * 100)
   locat val  perc
1  a   5 100.0
2  b   5  25.0
3  b  15  75.0
4  c   5  12.5
5  c  20  50.0
6  c   5  12.5
7  c  10  25.0
8  d   5  16.7
9  d  15  50.0
10 d  10  33.3

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Monica Pisica
> Sent: Thursday, March 13, 2008 9:36 AM
> To: r-help@r-project.org
> Subject: [R] a more elegant way to get percentages?
> 
> 
> Hi,
> 
> I am trying to get percentages in a more elegant way. I have 
> a data.frame with locations and values (counts) of species at 
> that location. Each location is repeated for each species i 
> have values for and i would like to get percentages of each 
> species at that location. I am not sure if i am clear in my 
> explanations so i will paste my code below:
> 
> #
> 
> > x
>locat val
> 1  a   5
> 2  b   5
> 3  b  15
> 4  c   5
> 5  c  20
> 6  c   5
> 7  c  10
> 8  d   5
> 9  d  15
> 10 d  10
> > loc1 <- x$locat
> > n <- length(loc1)
> > locuniq1 <- unique(loc1)
> > m <- length(locuniq1)
> > counts <- seq(1:m)
> > 
> > for (i in 1:m) {
> + count <- 0
> + for (j in 1:n) {
> + if (loc1[j]==locuniq1[i]) count <- count+1 counts[i] <- count } }
> > 
> > percent1 <- rep(0,n)
> > j <- 0
> > for (i in 1:m) {
> + 
> + b <- x[(j+1):(j+counts[i]),]
> + total <- sum(b$val)
> + percent1[(j+1):(j+counts[i])] <- round(apply(as.matrix(b$val), 1, 
> + function(x) {x*100/total}),2) j = j+counts[i] }
> > x1 <- cbind(x, percent1)# this is the result i want 
> > x1
>locat val percent1
> 1  a   5   100.00
> 2  b   525.00
> 3  b  1575.00
> 4  c   512.50
> 5  c  2050.00
> 6  c   512.50
> 7  c  1025.00
> 8  d   516.67
> 9  d  1550.00
> 10 d  1033.33
> > 
> 
> 
> I am wondering if there is any way to do it more efficiently, 
> much more that the first loop which gives how many times each 
> location is present in the data.frame is slow if you have a 
> larger data.frame and not only 10 rows.
> 
> Thanks for any input and sorry if the email is on the long side,
> 
> Monica
> 
> 
> _
> [[elided Hotmail spam]]
> 
> __
> 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] regular expressions

2008-03-12 Thread Christos Hatzis
Try this one:

> gsub("^(plif)([a-z]*)", "\\1ONE", words)
[1] "plifONE"   "plafboum"  "ploufbang" "plifONE"  

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of GOUACHE David
> Sent: Wednesday, March 12, 2008 12:15 PM
> To: [EMAIL PROTECTED]
> Subject: [R] regular expressions
> 
> Hello all,
>  
> Still fighting with regular expressions and such, I am again stuck:
>  
> Suppose I have a vector of character chains. In this vector, 
> I wish to identify which character chains start with a given 
> pattern, and then replace everything that comes after said pattern.
>  
> Here is a quick example :
>  
> words<-c("plifboum","plafboum","ploufbang","plifplaf")
>  
> I want to end up with something like this:
>  
> "plifONE","plafboum","ploufbang","plifONE"
>  
> All I can produce so far is this :
> gsub("\\bplif.","ONE",words,perl=T)
>  
> which turns out :
> "ONEboum","plafboum","ploufbang","ONEplaf"
>  
> Thanks in advance for your help.
>  
> David Gouache
> 
> Arvalis - Institut du Végétal
> 
> Station de La Minière
> 
> 78280 Guyancourt
> 
> Tel: 01.30.12.96.22 / Port: 06.86.08.94.32
> 
>  
>  
> 
> __
> 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] subset list based on logical within element flag

2008-03-12 Thread Christos Hatzis
Try:

> names(which(my_list == 'Fred'))
[1] "name"

You can break down the two nested calls to figure out what is happening.

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Srinivas Iyyer
> Sent: Wednesday, March 12, 2008 6:53 PM
> To: Benilton Carvalho; [EMAIL PROTECTED]
> Cc: R Help
> Subject: Re: [R] subset list based on logical within element flag
> 
> Hi I have the smililar question.
> 
> I have a list:
> my_list <- list(name="Fred", wife="Mary", no.children=3, 
> child.ages=c(4,7,9)) 
> 
> 
> > my_list
> $name
> [1] "Fred"
> 
> $wife
> [1] "Mary"
> 
> $no.children
> [1] 3
> 
> $child.ages
> [1] 4 7 9
> 
> 
> Now I want to search "Fred" and get attribute of that value 
> which is 'name'. 
> 
> how do I get it. 
> 
> > match(my_list,"Fred")
> [1]  1 NA NA NA
> 
> my thinking stops right here... 
> 
> list operations in R is too tough to digest and there is not 
> good documentations. 
> 
> Could any one please help. 
> 
> thanks
> Srini
> 
> 
> 
> 
> 
> 
> 
> --- Benilton Carvalho <[EMAIL PROTECTED]> wrote:
> 
> > gene.pair.tf.lst[sapply(gene.pair.tf.lst, "[[", "sig.cor")]
> > 
> > b
> > 
> > 
> > On Mar 12, 2008, at 5:24 PM, Mark W Kimpel wrote:
> > 
> > > I have a very long list that I'd like to subset
> > based on a logical
> > > value
> > > within each element. Example below. I'd like to
> > get just those list
> > > elements for further study whose $sig.cor slot is
> > TRUE. In this
> > > example,
> > > I'd only want element [[2]].
> > >
> > > Should be simple, I know. How can I do this?
> > Thanks, Mark
> > >
> > >> gene.pair.tf.lst
> > > [[1]]
> > > [[1]]$gene.pair
> > > [1] "Lgals1:Pxmp2"
> > >
> > > [[1]]$sig.cor
> > > [1] FALSE
> > >
> > >
> > > [[2]]
> > > [[2]]$gene.pair
> > > [1] "Lgals1:Pxmp2"
> > >
> > > [[2]]$sig.cor
> > > [1] TRUE
> > >
> > >
> > > [[3]]
> > > [[3]]$gene.pair
> > > [1] "Lgals1:Pxmp2"
> > >
> > > [[3]]$sig.cor
> > > [1] FALSE
> > > --
> > >
> > > Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of
> > Psychiatry
> > > Indiana University School of Medicine
> > >
> > > 15032 Hunter Court, Westfield, IN  46074
> > >
> > > (317) 490-5129 Work, & Mobile & VoiceMail
> > > (317) 204-4202 Home (no voice mail please)
> > >
> > > mwkimpelgmailcom
> > >
> > > __
> > > 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-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] compress data on read, decompress on write

2008-02-28 Thread Christos Hatzis
Ramon,

If you are looking for a solution to your specific application (as opposed
to a general compression/ decompression mechanism), it might be worth
checking out the Matrix package, which has facilities for storing and
manipulating sparse matrices.  The sparseMatrix class stores matrices in the
triplet representation (i.e. only indices and values of the non-zero
elements) and this affords great compression ratios, depending on the size
and degree of sparseness of the matrix.

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Ramon Diaz-Uriarte
> Sent: Thursday, February 28, 2008 1:18 PM
> To: [EMAIL PROTECTED]
> Subject: [R] compress data on read, decompress on write
> 
> Dear All,
> 
> I'd like to be able to have R store (in a list component) a 
> compressed data set, and then write it out uncompressed. 
> gzcon and gzfile work in exactly the opposite direction. What 
> would be a good way to handle this?
> 
> Details:
> --
> 
> We have a package that uses C; part of the C output is a 
> large sparse matrix. This is never manipulated directly by R, 
> but always by the C code. However, we need to store that data 
> somewhere (inside an R
> object) for further calls to the functions in our package. 
> We'd like to store that matrix as part of the R object (say, 
> as an element of a list). Ideally, it would be stored in as 
> compressed a way as possible.
> Then, when we need to use that information, it would be 
> decompressed and passed to the C function.
> 
> I guess one way to do it is to have C deal with the 
> compression and uncompression (e.g., using zlib or the bzip2 
> libraries) and then use readBin, etc, from R. But, if I can, 
> I'd like to avoid our C code having to call zlib, etc, so as 
> to make our package easily portable.
> 
> 
> Thanks,
> 
> R.
> 
> --
> Ramon Diaz-Uriarte
> Statistical Computing Team
> Structural Biology and Biocomputing Programme Spanish 
> National Cancer Centre (CNIO) http://ligarto.org/rdiaz
> 
> __
> 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] 2D kolmogorov

2008-02-27 Thread Christos Hatzis
Googling "MUAC" mentioned in that message will take you to the following
site with information on the algorithm and apparently access to the code.

http://www.acooke.org/jara/muac/index.html

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Máté Maus
> Sent: Thursday, February 28, 2008 12:04 AM
> To: [EMAIL PROTECTED]
> Subject: [R] 2D kolmogorov
> 
> Dear Dr. Rich Grenyer,
> 
> I am a PhD student at the Department of Immunology, ELTE 
> University, Budapest. I try to find a robust approach to 
> compare 2D distribution of signaling molecules in cell cytoplasm.
> 
> I read your message at
> https://stat.ethz.ch/pipermail/r-help/2004-June/052973.html
> about your implementation of 2D Kolmogorov statistics.
> 
> I tryed the links in your message, but I suppose they are not 
> alive by now. I was wondering if you could give me some 
> advices, how to use 2D Kolmogorov statistics for confocal 
> microscopic images.
> 
> Yours faithfuly,
> Mate Maus
> PhD student
> 
> __
> 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 Principal component analysis

2008-02-26 Thread Christos Hatzis
Sorry, it should have been:

col = c("red", "blue")[c(rep(1, 100), rep(2, 15))]

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Christos Hatzis
> Sent: Tuesday, February 26, 2008 4:46 PM
> To: 'SNN'; r-help@r-project.org
> Subject: Re: [R] Plot Principal component analysis
> 
> If your samples are in the specified order (i.e. first 100 
> from group A and remaining from group B) you can try the 
> following in your plot call:
> 
> plot(..., col=c("red", "blue")[c(rep(100, 1), rep(15, 2))])
> 
> -Christos 
> 
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of SNN
> > Sent: Tuesday, February 26, 2008 4:11 PM
> > To: r-help@r-project.org
> > Subject: [R] Plot Principal component analysis
> > 
> > 
> > Hi,
> > 
> > I have matrix of 300,000*115 (snps*individual). I ran the 
> PCA on the 
> > covariance matrix which has a dimention oof 115*115. I have 
> the first 
> > 100 individuals from group A and the rest of
> > 15 individuals from group B. I need to plot the data in two and 3 
> > dimentions with respect to PC1 and PC2 and (in 3D with 
> respect to PC1, 
> > PC2 and PC3). I do not know how to have the plot ploting 
> the first 100 
> > points corresponding to group A in red (for example) and 
> the rest of 
> > the 15 points in Blue? i.e I want the each group in a 
> diffrent color 
> > in the same plot. I appreciate if someone can help.
> > 
> > Thanks,
> > --
> > View this message in context: 
> > http://www.nabble.com/Plot-Principal-component-analysis-tp1570
> > 0123p15700123.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-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 Principal component analysis

2008-02-26 Thread Christos Hatzis
If your samples are in the specified order (i.e. first 100 from group A and
remaining from group B) you can try the following in your plot call:

plot(..., col=c("red", "blue")[c(rep(100, 1), rep(15, 2))])

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of SNN
> Sent: Tuesday, February 26, 2008 4:11 PM
> To: r-help@r-project.org
> Subject: [R] Plot Principal component analysis
> 
> 
> Hi,
> 
> I have matrix of 300,000*115 (snps*individual). I ran the PCA 
> on the covariance matrix which has a dimention oof 115*115. I 
> have the first 100 individuals from group A and the rest of 
> 15 individuals from group B. I need to plot the data in two 
> and 3 dimentions with respect to PC1 and PC2 and (in 3D with 
> respect to PC1, PC2 and PC3). I do not know how to have the 
> plot ploting the first 100 points corresponding to group A in 
> red (for example) and the rest of the 15 points in Blue? i.e 
> I want the each group in a diffrent color in the same plot. I 
> appreciate if someone can help.
> 
> Thanks,
> --
> View this message in context: 
> http://www.nabble.com/Plot-Principal-component-analysis-tp1570
> 0123p15700123.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.


Re: [R] immediate print

2008-02-05 Thread Christos Hatzis
Introduce 

cat(j)
flush.console() 

in your loop.

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Waterman, 
> DG (David)
> Sent: Tuesday, February 05, 2008 11:20 AM
> To: r-help@r-project.org
> Subject: [R] immediate print
> 
> Hi everyone,
>  
> I have a function containing a loop that takes some time to complete.
> Before I enter the loop I want to print a text string to the 
> screen explaining what is being calculated, however, I find 
> that the information is not printed until the function exits. 
> Is there a way of immediately printing a message from within 
> a function as a side effect before it returns?
> 
> code example:
> 
> myFunc <- function(){
>   print.noquote("some message that I want to print before exiting the
> function")
>   j <- 0
>   for (i in 1:100){
> j <- j + 1
>   }
>   j
> }
>  
> Best wishes,
> David
> This e-mail and any 
> attachments may contain confidential, copyright and or 
> privileged material, and are for the use of the intended 
> addressee only. If you are not the intended addressee or an 
> authorised recipient of the addressee please notify us of 
> receipt by returning the e-mail and do not use, copy, retain, 
> distribute or disclose the information in or attached to the e-mail.
> Any opinions expressed within this e-mail are those of the 
> individual and not necessarily of Diamond Light Source Ltd. 
> Diamond Light Source Ltd. cannot guarantee that this e-mail 
> or any attachments are free from viruses and we cannot accept 
> liability for any damage which you may sustain as a result of 
> software viruses which may be transmitted in or with the message.
> Diamond Light Source Limited (company no. 4375679). 
> Registered in England and Wales with its registered office at 
> Diamond House, Harwell Science and Innovation Campus, Didcot, 
> Oxfordshire, OX11 0DE, United Kingdom  
> 
> __
> 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] pivot table in R

2008-01-29 Thread Christos Hatzis
Also, see ?aggregate:

> with(A, aggregate(no_of_accidents, by=list(SEX=sex), FUN='sum'))
  SEX  x
1   F 34
2   M 83 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Attiglah, Mama
> Sent: Tuesday, January 29, 2008 7:21 AM
> To: [EMAIL PROTECTED]; r-help@r-project.org
> Subject: Re: [R] pivot table in R
> 
> A = read.table("clipboard", header=TRUE)
> > A
>   sex   age region no_of_accidents
> 1   F young  north  10
> 2   F young  south  12
> 3   F   old  north   5
> 4   F   old  south   7
> 5   M young  north  24
> 6   M young  south  30
> 7   M   old  north  12
> 8   M   old  south  17
> 
> 
> 
> 
> 
> sum(A$no_of_accidents[which( A$sex=="F")])
> 
> should give you the required sum. 
> 
> You have to remember that sex, age and region are Factors 
> with their respective levels and no_of_accidents is a numeric vector.
> 
> Do str( A) to see their type.
> Hope that helps.
> 
> Mama 
> 
> -
> Mama Attiglah, PhD
> Advanced Research Center
> Quantitative Research Analyst
> State Street Bank
> +44(0)20 7698 6290 (Direct Line)
> +44 (0)207 004 2968 (Direct Fax)
> Please visit our Web site at
> www.ssga.com
> 
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]
> On Behalf Of [EMAIL PROTECTED]
> Sent: 29 January 2008 12:05
> To: r-help@r-project.org
> Subject: [R] pivot table in R
> 
> Hello,
> 
> I'm struggling with an elementary problem with R. I have a 
> simple data frame such as this one giving the number of 
> accidents subdivided by sex,
> 
> age and region.
> 
> sex age region  no_of_accidents
> 
> F   young   north   10
> F   young   south   12
> F   old north   5
> F   old south   7
> M   young   north   24
> M   young   south   30
> M   old north   12
> M   old south   17
> 
> and I would like to build a pivot table, e.g. obtaining the 
> sum of the number of accidents for each sex:
> 
> sex age region  no_of_accidents
> 
> F   (any)   (any)   34
> M   (any)   (any)   83
> 
> but I can't seem to obtain this result simply in R, except by 
> embarking in complicated "for" loops.
> 
> I have checked the documentation on such functions as 
> "table()" and the documentation on "An introduction to R" but 
> couldn't solve the problem. 
> Could you please help me with this?
> 
> Cheers
> 
> Pete
> 
> 
> PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS E-MAIL
> 
> For Aon's standard conditions associated with this e-mail 
> please visit http://www.aon.com/uk/en/email-footer/aon-limited.jsp
> Aon Limited
> Registered Office: 8 Devonshire Square, London EC2M 4PL 
> Registered in London No. 210725 . VAT Registration No. 480 8401 48
> 
> Aon Limited is authorised and regulated by the Financial 
> Services Authority in respect of insurance mediation activities only.
> 
>   [[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] Function for translation of a list into a matrix as used byordination?

2008-01-25 Thread Christos Hatzis
Take a look at ?reshape - it is used to convert between 'long' and 'wide'
formats of data tables (frames). 

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Friday, January 25, 2008 4:30 PM
> To: r-help@r-project.org
> Subject: [R] Function for translation of a list into a matrix 
> as used byordination?
> 
> 
> Hello.
> 
> Does anyone know of an existing function that takes a list in 
> the form of:
> 
> Plot1 Species1Abundance1
> Plot1 Species2Abundance2
> Plot2 Species1Abundance1
> Plot2 Species3Abundance3
> .
> .
> .
> PlotN SpeciesNAbundanceN
> 
> and translates into a matrix in the form of
> 
>   Species1Species2  SpeciesN
> Plot1 Abundance1  Abundance2... AbundanceN
> Plot2 Abundance1  Abundance2... AbundanceN
> .
> .
> 
> .
> PlotN AbundanceN  AbundanceN... AbundanceN
> 
> 
> This is a basic operation used in the initial stages of 
> ordination etc of ecological data (vegetation or other 
> species) that is usually stored in a database or flatfile in 
> the list format above. It is similar to a cross tabulation 
> like the function xtabs(), however its useful to be able to 
> control whether a measured abundance for a taxa is included 
> or a boolean
> (presence/absence) for the taxa in a given plot.
> 
> Im new to such analyses in R, but before writing it myself 
> hope or suspect that such a function or library is out there 
> (although I dont see it after some quick searching in things 
> like Vegan or BiodivesityR or labdsv).
> 
> 
> Thanks
> billy
> 
> __
> 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] Displaying trailing zeroes

2008-01-24 Thread Christos Hatzis
formatC(round(12.01), digits=1, format="f")

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Lucke, Joseph F
> Sent: Thursday, January 24, 2008 4:37 PM
> To: r-help@r-project.org
> Subject: [R] Displaying trailing zeroes
> 
> round(12.01,1) will give the answer 12, not 12.0 or even 12.  
> To make a table look nice, I need to display the trailing 
> zero so that just as
> round(12.05,1) yields 12.1, round(12.01) yields 12.0. I 
> cannot find an answer in print() or format() or options().  
> Any suggestions would be appreciated.
> Joseph F. Lucke, PhD
> Biostatistician
> Center for Clinical Research and Evidence-based Medicine 
> University of Texas Medical School at Houston
> Email: [EMAIL PROTECTED]
>  
> 
> __
> 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] if statement problem

2008-01-01 Thread Christos Hatzis
You need to use '&' instead of '&&':

A shorter version of your code using ifelse:

das$danger <- with(das, ifelse(age>65 & bmi>30, 1, 0))

HTH

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Gerard Smits
> Sent: Tuesday, January 01, 2008 5:04 PM
> To: r-help@r-project.org
> Subject: [R] if statement problem
> 
> Hi All,
> 
> I have a small dataset named das  (43 cases) in which I am 
> trying to create a binary outcome (1/0) based on the following code:
> 
> if (das$age>65 && das$bmi>30) {das$danger<-1} else das$danger<-0
> 
> I am setting a flag called 'danger' to 1 of the subject is 
> over 65 and has a BMI > 30.
> 
> I find that my statement evaluates the first record in the 
> data.frame and then carries that assignment for all. I 
> detected this as I played around with the values and found 
> that the T/F status of the first record was always carried 
> dowqn. I have gotten this to work with an elseif 
> construction, but would like to know what is happening here.
> 
> Thanks,
> 
> Gerard
> 
> Using: Windows Vista and R 2.61
> 
> 
> Code and output:
> 
> das<- sasxport.get("c:\\personal\\r\\das.xpt")
> if (das$age>65 && das$bmi>30) {das$danger<-1} else das$danger<-0
> attach(das)
> das
> 
> 
>  The following object(s) are masked from das ( position 3 ) :
> 
>   age bmi day id male sex status
> 
>id age sex  bmi status day male danger
> 1  33001  35   M 27.5  0 3651  0
> 2  33002  29   M 34.9  1  221  0
> 3  33003  41   F 23.6  0 3650  0
> 4  33004  55   F 27.0  0 3650  0
> 5  42001  37   M 39.0  0 3651  0
> 6  42002  53   M 26.6  1 1241  0
> 7  42003  46   F 45.4  1 2870  0
> 8  42004  35   F 36.2  0 3650  0
> 9  42005  38   F 24.6  0 3650  0
> 10 42006  58   F 28.0  0 3650  0
> 11 42007  27   M 25.0  0 3651  0
> 12 42008  65   F 24.6  0 3650  0
> 13 42009  25   F 28.0  0 3650  0
> 14 43001  66   M 27.8  0 3651  0
> 15 43002  57   F 34.0  0 3650  0
> 16 43003  45   F 38.1  0 3650  0
> 17 43004  33   F 53.3  1  620  0
> 18 43005  56   F 36.5  0 3650  0
> 19 43006  31   F 22.4  1   10  0
> 20 43007  53   F 32.2  1  210  0
> 21 55001  51   M 29.2  0 3651  0
> 22 55002  33   F 18.7  0 3650  0
> 23 55003  40   F 30.3  0 3650  0
> 24 55004  67   M 31.9  0 3651  0 <- Problem case should 
> =1 for danger
> 25 55005  41   F 35.0  0 3650  0
> 26 55006  44   F 37.3  0 3650  0
> 27 55007  67   M 28.4  1   11  0
> 28 55008  65   F 28.8  0 3650  0
> 29 55009  76   M 18.8  1 2251  0
> 30 55010  75   F 21.1  1  390  0
> 31 63001  30   F 24.9  0 3650  0
> 32 63002  36   F 47.2  1 3770  0
> 33 63003  45   F 32.0  0 3650  0
> 34 63004  49   F 32.3  0 3650  0
> 35 63005  41   F 20.2  0 3650  0
> 36 63006  60   F 28.2  0 3650  0
> 37 63007  33   F 24.5  0 3650  0
> 38 63008  36   F 28.4  1  560  0
> 39 63009  31   F 22.1  0 3650  0
> 40 63010  77   M 26.6  1   91  0
> 41 63011  41   F 32.0  0 3650  0
> 42 63012  40   F 38.5  1  920  0
> 43 63013  27   M 20.6  0 3651  0
> 
>   [[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] Recursive solution with for()

2007-12-20 Thread Christos Hatzis
It not entirely clear, but I think that you are looking for

seq(t-1, 1)

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Owe Jessen
> Sent: Thursday, December 20, 2007 1:29 PM
> To: [EMAIL PROTECTED]
> Subject: [R] Recursive solution with for()
> 
> Hello,
> 
> i just ran into the following problem: I wanted to 
> recursively solve equations of the type 
> x_1[t]=x_1[t+1]+beta*x_2[t], and used a for-loop written
> 
> for(j in c(1:t-1, recursive=TRUE){
> ...
> }
> 
> This didn't work, so i resolved to writing for(j in c(10,9,...,1){
> 
> which worked, but is not terribly efficient. So, what did I do wrong?
> 
> Thanks in advance,
> Owe
> 
> --
> Owe Jessen
> Diplom-Volkswirt
> Hanssenstraße 17
> 24106 Kiel
> 
> [EMAIL PROTECTED]
> http://www.econinfo.de
> 
> __
> 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] book on regular expressions

2007-12-11 Thread Christos Hatzis
Great.
Two books were consistently recommended: the pocket guide "Regular
Expressions" and the more extensive "Mastering Regular Expressions", both by
O'Reilly.

Thanks to all those who responded.

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 11, 2007 1:51 PM
> To: [EMAIL PROTECTED]; r-help@r-project.org
> Subject: RE: [R] book on regular expressions
> 
> I've found the O'Reilly pocket reference "Regular Expression" 
> (about USD
> 10.00) quite handy.
> It covers Perl, C, PHP, Python, Java, and .Net.
> 
> David L. Reiner
> Rho Trading Securities, LLC
> 
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]
> On Behalf Of Christos Hatzis
> Sent: Tuesday, December 11, 2007 9:47 AM
> To: r-help@r-project.org
> Subject: [R] book on regular expressions
> 
> Hello,
>  
> Could someone recommend a good book on regular expressions 
> with focus on applications/use as it might relate to R.  I 
> remember there was a mention of such a reference book 
> recently, but I could not locate that message on the archive.
>  
> Thanks.
> -Christos  
>  
> Christos Hatzis, Ph.D.
> Nuvera Biosciences, Inc.
> 400 West Cummings Park
> Suite 5350
> Woburn, MA 01801
> Tel: 781-938-3830
> www.nuverabio.com <http://www.nuverabio.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.
> 
>

__
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] book on regular expressions

2007-12-11 Thread Christos Hatzis
Hello,
 
Could someone recommend a good book on regular expressions with focus on
applications/use as it might relate to R.  I remember there was a mention of
such a reference book recently, but I could not locate that message on the
archive.
 
Thanks.
-Christos  
 
Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com <http://www.nuverabio.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] vector sprintf argument

2007-11-29 Thread Christos Hatzis
According to the help page sprintf will recycle its arguments:

The arguments (including fmt) are recycled if possible a whole number of
times to the length of the longest, and then the formatting is done in
parallel.  

Therefore the following works:

> sprintf("Number: %d", A)
[1] "Number: 3" "Number: 4" "Number: 5"

Another option is to create a character string from A and then print it:

> sprintf("Number: %s", paste(A, collapse=" "))
[1] "Number: 3 4 5"

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Moshe Olshansky
> Sent: Thursday, November 29, 2007 11:45 PM
> To: Tom Sgouros; r-help@r-project.org
> Subject: Re: [R] vector sprintf argument
> 
> The only thing I can think of is:
> 
> > a <- c(1,2.7,5.19)
> > F<-c("numeric:  %d ","%g ","%8.3f")
> > x<-sapply(1:length(a),function(i)
> sprintf(F[i],a[i]))
> > y<-paste(x,sep="",collapse="")
> 
> But I am sure that you will get a better advice elsewhere.
> 
> --- Tom Sgouros <[EMAIL PROTECTED]> wrote:
> 
> > 
> > Hello all:
> > 
> > If I have a vector and a format, I want to do this:
> > 
> >  > A <- c(3,4,5)
> >  > F <- "Number: %d, %d, %d"
> >  > sprintf(F,A)
> > 
> > This doesn't work because A isn't three arguments, it's 
> just one.  Is 
> > there a way to peel the vector members out of A so that sprintf can 
> > get at them?
> > 
> > I would like to do this because I have a large set of 
> variable-length 
> > data that I'd like to print out in fancy formatted form.  
> The vectors 
> > range in length from 2 to 7.  Each row is different, so I had been 
> > hoping to do this with an array of formats, too.
> > 
> > I feel like I'm either overlooking something obvious, or have 
> > determined to do this in an un-R fashion.  Any advice is 
> welcome.  (On 
> > this topic, that is.)
> > 
> > Many thanks,
> > 
> >  -tom
> > 
> > 
> > --
> >  
> >  tomfool at as220 dot org
> >  http://sgouros.com
> >  http://whatcheer.net
> > 
> > __
> > 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] Packages - a great resource, but hard to find the right one.

2007-11-21 Thread Christos Hatzis
Another useful search facility is
http://www.rseek.org

The nice thing is that it categorizes results by help-list items, R function
etc.
It might be closer to what you are looking for.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley
> Sent: Wednesday, November 21, 2007 10:01 AM
> To: John Sorkin
> Cc: [EMAIL PROTECTED]
> Subject: Re: [R] Packages - a great resource, but hard to 
> find the right one.
> 
> On Wed, 21 Nov 2007, John Sorkin wrote:
> 
> > Gabor,
> 
> > The URL you cited is helpful, but it is not searchable. It 
> can not be 
> > used, for example, to easily determine that MASS can be used for 
> > boxcox tranforms.
> 
> It is searchable (use your browser's search facilities), and 
> that is often helpful.  But you can do your search at 
> search.r-project.org (thanks to Jonathan Baron): select 
> 'Complete list of all packages', select a package and browse its help.
> 
> If you are looking for a way to do Box-Cox, or the function 
> boxcox(), search on that site, or for packages you already 
> have installed, use help.search().  One reason we find it 
> useful to have a system with all packages installed (that do 
> install) is to make it easy for our users to search for what 
> they want, and then use it.
> 
> See also http://www.r-project.org/search.html
> 
> > John
> >
> > John Sorkin M.D., Ph.D.
> 
> 
> -- 
> Brian D. Ripley,  [EMAIL PROTECTED]
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
> 
> __
> 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] The "reverse" of do.call("rbind",) on a list

2007-11-12 Thread Christos Hatzis
Try split:

> x <- matrix(letters[1:4], 2)
> x
 [,1] [,2]
[1,] "a"  "c" 
[2,] "b"  "d" 

> split(x, row(x))
$`1`
[1] "a" "c"

$`2`
[1] "b" "d"
 
-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Søren Højsgaard
> Sent: Monday, November 12, 2007 8:08 PM
> To: [EMAIL PROTECTED]
> Subject: [R] The "reverse" of do.call("rbind",) on a list
> 
> Dear List,
> I want to turn the matrix
> > xm
>  [,1] [,2]
> [1,] "a"  "b" 
> [2,] "d"  "e" 
> 
> into a list "by rows" as:
> [[1]]
> [1] "a" "b"
> [[2]]
> [1] "d" "e"
> 
> A (bad?) way of doing this is as
> > unlist(apply(xm,1, list), recursive=F)
> [[1]]
> [1] "a" "b"
> [[2]]
> [1] "d" "e"
>  
> - but there must be a more elegant way. Can anyone help on 
> this? Thanks!
> Søren
>  
> 
> __
> 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] wrapper for coxph with a subset argument

2007-11-09 Thread Christos Hatzis
In terms of recommended approach, I think it would be easier to generate
subsetting conditions as (lists of) logical vectors and use those as
suggested before.  It seems to me more cumbersome to use the data to
generate logical conditions as text strings and then parse those within your
wrapper to get back the logical vector.

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Erik Iverson
> Sent: Friday, November 09, 2007 12:05 PM
> To: '[EMAIL PROTECTED]'
> Subject: [R] wrapper for coxph with a subset argument
> 
> Dear R-help -
> 
> Thanks to those who replied yesterday (Christos H. and Thomas 
> L.) regarding my question on coxph and model formula, the 
> answers worked perfectly.
> 
> My new question involves the following.
> 
> I want to run several coxph models (package survival) with 
> the same dataset, but different subsets of that dataset.
> 
> I have found a way to do this, described below in functions 
> subwrap1 and subwrap2.  These do not use the coxph "subset" 
> argument, however, as you will see.
> 
> My three main questions are :
> 
> 1) When writing a wrapper like this, should I be using the 
> subset argument in coxph(), or alternatively, doing what I am 
> doing in subwrap1 and subwrap2 below?  Is the subset argument 
> in coxph more of a convenience tool for interactive use 
> rather than programs?
> 
> 2) If the approach in subwrap1 and subwrap2 is fine, is there 
> a preference for using 'expressions' or 'strings'?  
> Eventually, my program will create these subset conditions 
> programmatically, so I think strings will be the way I have 
> to go, even though I've seen warnings on this list about 
> using the eval(parse()) construct.
> 
> 3) Is there some approach to do this that I'm overlooking?  
> My goal will be to produce a list of subset conditions 
> (probably a character vector), and then use lapply to run the 
> various cox regressions.
> 
> I can already achieve my goal, I just would like to know more 
> details about how others do things like this.
> 
> I've simplified my code below to focus on where I feel I'm confused. 
> Here is some code along with comments:
> 
>  BEGIN R SAMPLE CODE
> 
> #Function for producing test data
> makeTestDF <- function(n) {
>times  <- sample(1:200, n, replace = TRUE)
>event  <- rbinom(n, 1, prob = .1)
>trt<- rep(c("A","B"), each = n/2)
>sex<- factor(c("M","F"))
>sex<- rep(sex, times = n/2)
>testdf <- data.frame(times,event,trt,sex) }
> 
> # Make test data, n = 200
> testdf <- makeTestDF(200)
> 
> # Cox wrapper function with subset, this one works # Takes 
> subset as expression
> subwrap1 <- function(x, sb) {
>sb <- eval(substitute(sb), x)
>x <- x[sb,]
>coxph(Surv(times,event)~trt, data = x) }
> 
> subwrap1(testdf, sex == 'F')
> 
> # This next one also works, but uses a character variable # 
> instead of an expression as the subset argument
> 
> subwrap2 <- function(x, sb) {
>sb <- eval(parse(text = sb), x)
>x <- x[sb,]
>coxph(Surv(times,event)~trt, data = x) }
> 
> subwrap2(testdf, "sex == 'F'")
> 
> # Neither of the above use the coxph subset argument # If I 
> try using that, I get stuck with expressions, # I've tried 
> many # different things in the subset argument, but none # 
> seem to do the trick.  Is using this argument in a # program 
> even advisable?
> 
> subwrap3 <- function(x, sb) {
>coxph(Surv(times,event)~trt, data = x,
>subset = eval(substitute(sb), x))
> }
> 
> subwrap3(testdf, sex == 'F') #does not work
> 
> # Using a string, this works, however.
> 
> subwrap4 <- function(x, sb) {
>coxph(Surv(times,event)~trt, data = x, subset = 
> eval(parse(text=sb))) }
> 
> subwrap4(testdf, "sex == 'F'")
> 
> ### END R SAMPLE CODE
> 
> Thanks so much,
> Erik Iverson
> [EMAIL PROTECTED]
> 
>  > sessionInfo()
> R version 2.5.1 (2007-06-27)
> i686-pc-linux-gnu
> 
> locale:
> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLA
> TE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8
> ;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC
> _MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] "grDevices" "datasets"  "tcltk" "splines"   
> "graphics"  "utils"
> [7] "stats" "methods"   "base"
> 
> other attached packages:
> debug mvbutils SPLOTS_1.2-6Hmiscchron 
> survival
>   "1.1.0"  "1.1.1"  "1.2-6"  "3.4-2" "2.3-13" 
> "2.32"
> 
> __
> 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/po

Re: [R] wrapper for coxph with a subset argument

2007-11-09 Thread Christos Hatzis
The following variation of what you proposed will allow you to either subset
the dataset outside coxph or to use the subset argument:

subwrap5 <- function(x, sb=NULL) {
   coxph(Surv(times,event)~trt, data = x, subset = sb)
}

subwrap5(testdf, testdf$sex == 'F')
subwrap5(testdf[testdf$sex == 'F', ])

I'm not sure whether anyone of these would be more efficient with memory
usage - if this is an issue you could test with large datasets.

-Christos
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Erik Iverson
> Sent: Friday, November 09, 2007 12:05 PM
> To: '[EMAIL PROTECTED]'
> Subject: [R] wrapper for coxph with a subset argument
> 
> Dear R-help -
> 
> Thanks to those who replied yesterday (Christos H. and Thomas 
> L.) regarding my question on coxph and model formula, the 
> answers worked perfectly.
> 
> My new question involves the following.
> 
> I want to run several coxph models (package survival) with 
> the same dataset, but different subsets of that dataset.
> 
> I have found a way to do this, described below in functions 
> subwrap1 and subwrap2.  These do not use the coxph "subset" 
> argument, however, as you will see.
> 
> My three main questions are :
> 
> 1) When writing a wrapper like this, should I be using the 
> subset argument in coxph(), or alternatively, doing what I am 
> doing in subwrap1 and subwrap2 below?  Is the subset argument 
> in coxph more of a convenience tool for interactive use 
> rather than programs?
> 
> 2) If the approach in subwrap1 and subwrap2 is fine, is there 
> a preference for using 'expressions' or 'strings'?  
> Eventually, my program will create these subset conditions 
> programmatically, so I think strings will be the way I have 
> to go, even though I've seen warnings on this list about 
> using the eval(parse()) construct.
> 
> 3) Is there some approach to do this that I'm overlooking?  
> My goal will be to produce a list of subset conditions 
> (probably a character vector), and then use lapply to run the 
> various cox regressions.
> 
> I can already achieve my goal, I just would like to know more 
> details about how others do things like this.
> 
> I've simplified my code below to focus on where I feel I'm confused. 
> Here is some code along with comments:
> 
>  BEGIN R SAMPLE CODE
> 
> #Function for producing test data
> makeTestDF <- function(n) {
>times  <- sample(1:200, n, replace = TRUE)
>event  <- rbinom(n, 1, prob = .1)
>trt<- rep(c("A","B"), each = n/2)
>sex<- factor(c("M","F"))
>sex<- rep(sex, times = n/2)
>testdf <- data.frame(times,event,trt,sex) }
> 
> # Make test data, n = 200
> testdf <- makeTestDF(200)
> 
> # Cox wrapper function with subset, this one works # Takes 
> subset as expression
> subwrap1 <- function(x, sb) {
>sb <- eval(substitute(sb), x)
>x <- x[sb,]
>coxph(Surv(times,event)~trt, data = x) }
> 
> subwrap1(testdf, sex == 'F')
> 
> # This next one also works, but uses a character variable # 
> instead of an expression as the subset argument
> 
> subwrap2 <- function(x, sb) {
>sb <- eval(parse(text = sb), x)
>x <- x[sb,]
>coxph(Surv(times,event)~trt, data = x) }
> 
> subwrap2(testdf, "sex == 'F'")
> 
> # Neither of the above use the coxph subset argument # If I 
> try using that, I get stuck with expressions, # I've tried 
> many # different things in the subset argument, but none # 
> seem to do the trick.  Is using this argument in a # program 
> even advisable?
> 
> subwrap3 <- function(x, sb) {
>coxph(Surv(times,event)~trt, data = x,
>subset = eval(substitute(sb), x))
> }
> 
> subwrap3(testdf, sex == 'F') #does not work
> 
> # Using a string, this works, however.
> 
> subwrap4 <- function(x, sb) {
>coxph(Surv(times,event)~trt, data = x, subset = 
> eval(parse(text=sb))) }
> 
> subwrap4(testdf, "sex == 'F'")
> 
> ### END R SAMPLE CODE
> 
> Thanks so much,
> Erik Iverson
> [EMAIL PROTECTED]
> 
>  > sessionInfo()
> R version 2.5.1 (2007-06-27)
> i686-pc-linux-gnu
> 
> locale:
> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLA
> TE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8
> ;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC
> _MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] "grDevices" "datasets"  "tcltk" "splines"   
> "graphics"  "utils"
> [7] "stats" "methods"   "base"
> 
> other attached packages:
> debug mvbutils SPLOTS_1.2-6Hmiscchron 
> survival
>   "1.1.0"  "1.1.1"  "1.2-6"  "3.4-2" "2.3-13" 
> "2.32"
> 
> __
> 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 maili

Re: [R] mapply, coxph, and model formula

2007-11-08 Thread Christos Hatzis
Instead of mapply, use lapply (it is more appropriate in this case anyway as
you have only one list that you need to iterate over):

lapply(df.list, function(x) coxph(form, x))


-Christos 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Erik Iverson
> Sent: Thursday, November 08, 2007 4:43 PM
> To: '[EMAIL PROTECTED]'
> Subject: [R] mapply, coxph, and model formula
> 
> Hello -
> 
> I am wanting to create some Cox PH models with coxph (in package
> survival) using different datasets.
> 
> The code below illustrates my current approach and problem 
> with completing this.
> 
> ### BEGIN R SAMPLE CODE ##
> library(survival)
> 
> #Define a function to make test data
> makeTestDF <- function(n) {
>times  <- sample(1:200, n, replace = TRUE)
>event  <- rbinom(n, 1, prob = .1)
>trt<- rep(c("A","B"), each = n/2)
>testdf <- data.frame(times,event,trt) }
> 
> #Create two sets of test data of different sizes
> testdf1 <- makeTestDF(100)
> testdf2 <- makeTestDF(200)
> 
> #Define a formula and call coxph
> form <- Surv(times, event) ~ trt
> coxph(form, testdf1) #Works
> coxph(form, testdf2) #Works
> 
> #Create a list of the two data.frames
> df.list <- list(testdf1, testdf2)
> 
> #Try to use mapply
> mapply(coxph, form, df.list)
> 
> ### END R SAMPLE CODE ###
> 
> The mapply call generates the following message:
> 
> Error in terms.default(formula, special, data = data) :
>   no terms component
> 
> It appears from debugging that the formula argument passed 
> into coxph is simply `~` in this case, with class "name" 
> instead of "formula".
> 
> Any ideas on how I can get this to work using this approach?
> 
> Best,
> Erik Iverson
> [EMAIL PROTECTED]
> 
>  > sessionInfo()
> R version 2.5.1 (2007-06-27)
> i686-pc-linux-gnu
> 
> locale:
> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLA
> TE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8
> ;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC
> _MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
> 
> attached base packages:
>   [1] "grid"  "grDevices" "datasets"  "tcltk" "splines" 
> "graphics"
>   [7] "utils" "stats" "methods"   "base"
> 
> other attached packages:
>  debug  mvbutils  SPLOTS_1.2-6   reshape SPLOTS_1.3-22
>"1.1.0"   "1.1.1"   "1.2-6"   "0.8.0"  "1.3-22"
>  Hmisc chron  survival
>"3.4-2"  "2.3-13""2.32"
> 
> __
> 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] scoping problem

2007-10-24 Thread Christos Hatzis
Another way to do this without messing with environments is to update the
data and formula locally within the function and re-run the regression on
the updated model/data:

tukey.test <- function(m) {
ud <- data.frame( m$model, pred2=m$fitted.values^2 )
uf <- update.formula(formula(m$terms), ~ . + pred2)
summary(lm(uf, ud))$coef
}

> data(BOD)
> m1 <- lm(demand~Time,BOD)
> tukey.test(m1)
  Estimate Std. Errort value  Pr(>|t|)
(Intercept) 12.5854086  5.0344850  2.4998403 0.0877190
Time 7.5390634  6.1271204  1.2304415 0.3062126
pred2   -0.1096744  0.1148654 -0.9548081 0.4101142
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Sandy Weisberg
> Sent: Wednesday, October 24, 2007 3:44 PM
> To: [EMAIL PROTECTED]
> Subject: [R] scoping problem
> 
> I would like to write a function that computes Tukey's 1 df 
> for nonadditivity.  Here is a simplified version of the 
> function I'd like to
> write:  (m is an object created by lm):
> 
> tukey.test <- function(m) {
>   m1 <- update(m, ~.+I(predict(m)^2))
>   summary(m1)$coef
>   }
> 
> The t-test for the added variable is Tukey's test.  This won't work:
> 
> data(BOD)
> m1 <- lm(demand~Time,BOD)
> tukey.test(m1)
> 
> Error in predict(m) : object "m" not found
> 
> This function doesn't work for two reasons:
>   1. The statement m1 <- update(m, ~.+I(predict(m)^2)) 
> can't see 'm' in the call to predict.
>   2. If in creating m missing values had been present, 
> then predict(m), even if it could be computed, could be of 
> the wrong length.
> 
> Can anyone help?
> 
> 
> 
> --
> Sanford Weisberg, [EMAIL PROTECTED]
> Office and mailing address:
> University of Minnesota, School of Statistics
> 312 Ford Hall, 224 Church St. SE, Minneapolis, MN  55455 
> 612-625-8355, FAX 612-624-8868
> 
> St. Paul office:
> 146 Classroom-Office Building, 612-625-8777
> 
> __
> 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] functions applied to two vectors

2007-10-23 Thread Christos Hatzis
> a <- c(2, 3, 7, 5)
> b <- c(4, 7, 8, 9)
> mapply(seq, from=a, to=b)

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Rolf Turner
> Sent: Tuesday, October 23, 2007 11:29 PM
> To: Anya Okhmatovskaia
> Cc: r-help@r-project.org
> Subject: Re: [R] functions applied to two vectors
> 
> 
> On 24/10/2007, at 4:15 PM, Anya Okhmatovskaia wrote:
> 
> > Hi,
> >
> > I am very new to R, so I apologize if I have missed some 
> trivial thing 
> > in the manuals/archives. I am trying to get rid of for loops in my 
> > code and replace them with R vector magic (with no success).
> >
> > Let's say I have 2 vectors of the same length:
> > a <- c(2, 3, 7, 5)
> > b <- c(4, 7, 8, 9)
> >
> > What I'd like to do is to generate a list(?) of 4 sequences using a 
> > [i] as a start indices, and b[i] as end indices:
> > 2,3,4
> > 3,4,5,6,7
> > 7,8
> > 5,6,7,8,9
> >
> > My first guess: "a:b", of course, does not work - only one sequence 
> > gets generated using the first values from both vectors, plus a 
> > warning.
> > Is there
> > a special syntax I can use to make ":" treat its operands 
> as vectors?
> > More generally, is there a standard way to apply some arbitrary 
> > functions to two or more vectors in an element-by-element 
> fashion? For 
> > instance,
> > sum(a,b)
> > will sum all values in both vectors; how can I make it produce a 
> > vector of pairwise sums instead?
> 
> Cute question!  The first idea that pops into my head is
> 
>   apply(cbind(a,b),1,function(x){x[1]:x[2]})
> 
> This works --- but there may be better ideas.
> 
>   cheers,
> 
>   Rolf Turner
> 
> ##
> Attention:\ This e-mail message is privileged and 
> confid...{{dropped:9}}
> 
> __
> 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] Visualize cox proportional hazards

2007-10-10 Thread Christos Hatzis
Armin,

RSiteSearch("forest plot meta analysis")

will point you to the metaplot function in the rmeta package.
There is also a forestplot function in the same package that offers more
flexibility.
These plots are useful in meta analysis in general (e.g. showing odds ratios
from different studies).

-Christos 

> -Original Message-
> From: Armin Goralczyk [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, October 10, 2007 7:27 AM
> To: [EMAIL PROTECTED]
> Cc: R-help@r-project.org
> Subject: Re: [R] Visualize cox proportional hazards
> 
> On 10/9/07, Christos Hatzis <[EMAIL PROTECTED]> wrote:
> > There are at least a couple of versions of such plots.
> > Search for forest plots:
> >
> > help.search("forest plot")
> >
> 
> Hi Christos
> 
> Could you be more specific? On my system I found nothing:
> 
> > help.search("forest plot")
> No help files found matching 'forest plot' using fuzzy matching
> 
> > version
>_
> platform   powerpc-apple-darwin8.9.1
> arch   powerpc
> os darwin8.9.1
> system powerpc, darwin8.9.1
> status
> major  2
> minor  5.1
> year   2007
> month  06
> day27
> svn rev42083
> language   R
> version.string R version 2.5.1 (2007-06-27)
> 
> Thanks
> --
> Armin Goralczyk
> 
>

__
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] Visualize cox proportional hazards

2007-10-09 Thread Christos Hatzis
There are at least a couple of versions of such plots.
Search for forest plots:

help.search("forest plot") 

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Armin Goralczyk
> Sent: Tuesday, October 09, 2007 4:45 PM
> To: [EMAIL PROTECTED]
> Subject: [R] Visualize cox proportional hazards
> 
> Hello all
> I would like to visualize the hazard ratios of a cox 
> proportional hazards model. I have seen some good examples in 
> the New England Journal of Medicine:
> 
> http://content.nejm.org/cgi/content/short/353/26/2747/F3
> 
> http://content.nejm.org/cgi/content/short/350/26/2654/F2
> 
> (I hope these are open access, but I am not sure)
> 
> And something similar in the book 'R Graphics' by Paul Murrell:
> 
> http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter1.html
> (Fig. 1.8)
> 
> But the code that is needed (to modify) is quite complex:
> 
> http://www.stat.auckland.ac.nz/~paul/RGraphics/examples-table.R
> 
> My question: Is there a simple way to obtain such a plot? and 
> Is there any other good plot to visualize the hazard ratios?
> 
> Thanks in advance.
> --
> Armin Goralczyk
> 
> __
> 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] Factor levels.

2007-10-03 Thread Christos Hatzis
My suggestion was based on the standard sort order of a factor.
What I did as an example was to create a factor having your specified
levels:

> x <- factor(sample(c("Unit","Achievement","Scholarship"), 10, TRUE))
> x
 [1] Achievement UnitAchievement UnitScholarship Achievement
Unit   
 [8] Achievement UnitUnit   
Levels: Achievement Scholarship Unit 

This creates a factor with the default (sorted) order of levels.  Then what
I proposed works, since it is based on the standard behavior of factor.  Now
if you have to override this behavior, you will have to deal with the
sorting problem, as Peter suggested.

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Rolf Turner
> Sent: Wednesday, October 03, 2007 4:12 PM
> To: Peter Dalgaard
> Cc: r-help list
> Subject: Re: [R] Factor levels.
> 
> 
> On 4/10/2007, at 7:50 AM, Peter Dalgaard wrote:
> 
> > Rolf Turner wrote:
> >>> Does it even work? (What if it is the first or the 2nd 
> level that is 
> >>> absent?
> >>
> >> Yes it works.  What's the problem?
> >>
> >> To beat it to death:  if the second level of fff is 
> absent then 
> >> fff will consist entirely of 1's and 3's,
> >> and so c("U","A","S")[fff] will consist entirely of 
> U's and S's.  
> >> I can then set the levels to be
> >> c("U","A","S") and get what I want.
> > You didn't say that fff was numeric.
> 
>   All factors are numeric.
> > If fff is a factor, then we have the problem:
> >
> > > attach(read.table(stdin(),header=T))
> > 0: fff
> > 1: Unit
> > 2: Scholarship
> > 3: Scholarship
> > 4: Unit
> > 5:
> > > c("U","A","S")[fff]
> > [1] "A" "U" "U" "A"
> 
>   My original fff is a factor with levels c 
> ("Unit","Achievement","Scholarship").  If you make that
>   adjustment, you get the ``right answer''.
> > Actually we have another problem too, namely sort order
> 
>   No, there is no sort order problem.  See above.
> 
>   [Given that the original fff has its levels in the 
> order specified  
> then Unit maps to U,
>   Achievement to A, and Scholarship to S.]
> 
>   cheers,
> 
>   Rolf
> 
>   P.S.  ***Are*** there any risks/dangers in following Christos  
> Hatzis' suggestion of simply doing
> 
>   levels(fff) <- c("U","A","S")   ???
> 
> ##
> Attention:\ This e-mail message is privileged and 
> confidenti...{{dropped}}
> 
> __
> 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] Factor levels.

2007-10-02 Thread Christos Hatzis
Would

levels(fff) <- c("A","S","U")

not work?  Can you send an example?

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Rolf Turner
> Sent: Wednesday, October 03, 2007 12:58 AM
> To: r-help list
> Subject: [R] Factor levels.
> 
> 
> I have factors with levels ``Unit", "Achieved", and 
> "Scholarship"; I wish to replace these with "U", "A", and "S".
> 
> So I do
> 
>   fff <- factor(fff,labels=c("U","A","S"))
> 
> This works as long as all of the levels are actually present 
> in the factor.  But if ``Scholarship'' is absent (as if often 
> is) then I get an error.
> 
> I can do a workaround such as
> 
>   fff <- factor(c("U","A","S")[fff],levels=c("U","A","S"))
> 
> but this seems kludgy to me.
> 
> Is there a sexier way?
> 
>   cheers,
> 
>   Rolf Turner
> 
> 
> ##
> Attention:\ This e-mail message is privileged and 
> confidenti...{{dropped}}
> 
> __
> 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] How to modify function for list

2007-10-02 Thread Christos Hatzis
Instead of 

> bmisds(age,gender,bmi)

Try the vectorized version 

> mapply(bmisds, age, gender, bmi)

See ?mapply

-Christos

 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Chung-hong Chan
> Sent: Wednesday, October 03, 2007 12:31 AM
> To: [EMAIL PROTECTED]
> Subject: [R] How to modify function for list
> 
> Dear R Gurus,
> 
> I have a function which calculate the BMI standard deviation 
> score based on the age and gender specific L, M, S value.
> I have written a function like this
> 
> bmisds <- function (age, gender, bmi){
>   if (age ==1 & gender ==1)
> {
>   bmif <- c(-1.013,16.133,0.07656)
> }
>   else if (age ==1 & gender ==0)
> {
>   bmif <- c(-1.79,16.421,0.07149)
> }
>   else if (age == 2 & gender == 1)
> {
>   bmif <- c(-1.403,15.58,0.07342)
> }
>   else if (age == 2 & gender == 0)
> {
>   bmif <- c(-2.045,15.861,0.07116)
> }
> 
> 
>   (((bmi/bmif[2])**bmif[1] -1)/(bmif[1]*bmif[3])) }
> 
> This function work when I supply a single variable, e.g. 
> bmisds(1,0,16)
> 
> When I try it with a list, e.g.
> age <- c(12,13,14)
> gender <- c(0,1,1)
> bmi <- c(14,15,16)
> bmisds(age,gender,bmi)
> 
> This function give me wrong answer and error msg.
> Warning messages:
> 1: the condition has length > 1 and only the first element 
> will be used in: if (age == 1 & gender == 1) {
> 
> 
> How can I midify this function to work with list/vector?
> 
> regards,
> C
> 
> 
> --
> CH Chan
> Research Assistant - KWH
> http://www.macgrass.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.