Re: [R] "R CMD check" does not find a mistake

2009-06-09 Thread Martin Maechler
> "CG" == Christophe Genolini 
> on Tue, 09 Jun 2009 16:17:15 +0200 writes:

CG> Hi the list, I build a package. They was a mistake in
CG> it, but R CMD check did not find it. Is that normal ?

CG> Here is what Kurt gets (which is right, I did this
CG> mistake):

CG> --- 8< 
CG> * checking for code/documentation mismatches ... WARNING
CG> S4 class codoc mismatches from documentation object 'LongData-class':
CG> Slots for class 'LongData'
CG> Code: id other time traj varName
CG> Docs: id time traj varName
CG> --- 8< 

Others have already hinted at the solution:

The problem only shows in  "R-devel" (2.10.x).

Note that I had sent an explicit message to this list
*exactly* in order to advise all package authors :

 Subject: [Rd] R-devel:codocClasses() now finds more --> R CMD check warnings
 Date: Wed, 3 Jun 2009 11:45:45 +0200

i.e. only 6 days before you saw the problem

yes, I am sometimes too optimistic, assuming that people
actually read what I write 

Regards anyway!
Martin

--
Martin Maechler, ETH Zurich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 get output from a nested loop

2009-06-09 Thread Linlin Yan
How about like this:
> t1 <- data.frame(row.names=c('c1','c2','c3','c4'), mk1=c(1,1,0,0), 
> mk2=c(0,0,0,1), mk3=c(1,1,1,1), mk4=c(0,0,0,0), mk5=c(0,0,0,1), S=c(4,5,3,2))
> t1
   mk1 mk2 mk3 mk4 mk5 S
c1   1   0   1   0   0 4
c2   1   0   1   0   0 5
c3   0   0   1   0   0 3
c4   0   1   1   0   1 2
> apply(combn(1:5, 2), 2, function(x) t1[,c(x[1], 6, x[2])])
[[1]]
   mk1 S mk2
c1   1 4   0
c2   1 5   0
c3   0 3   0
c4   0 2   1
... ...

On Wed, Jun 10, 2009 at 1:10 PM, Scott Hermann wrote:
> Dear all,
>
> I imagine that this is a trival question, but it has perplexed for most of 
> the day.  Any help would be greatly appreciated.
>
> Below is an example of what I'm trying to do.
>
> Essentially I want to produce all unique 1 x 1 combinations of certain 
> columns from a dataframe, and join these to other columns from the same 
> dataframe.  I'm having problems with the nested loop as I can only output 
> data from the last "cycle" of the loop.  I realise that the problem is with 
> the st1[[i]] but I'm not sure how to define it differently.
>
> ##I want to make a list file of all 1x1 combinations of "mk" columns, and add 
> "clone" and "S" to these combinations.
>
> clone<-c("c1","c2","c3","c4")
> mk1<-c(1,1,0,0)
> mk2<-c(0,0,0,1)
> mk3<-c(1,1,1,1)
> mk4<-c(0,0,0,0)
> mk5<-c(0,0,0,1)
> S<-c(4,5,3,2)
> t1<-as.data.frame(cbind(clone,mk1,mk2,mk3,mk4, mk5,S))
> row.names(t1)<-t1$clone
> t1<-t1[,-1]
> t1
>
> ###A nested loop.  I'm trying to get all combinations of columns 1:5 and join 
> each of them with column 7.
>
> st1 <- list()
>  for(i in 1:4) {
>   for(j in (i+1):5){
>       st1[[i]] <- cbind(t1[,c(i,6)],t1[,j])
>       }
>       }
>  st1
>
> Thanks for your help,
>
> Scott
> BSES Limited Disclaimer
>
> 
>
> This email and any files transmitted with it are confide...{{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.


[R] Creating a specific skewed distribution

2009-06-09 Thread David Arnold
All,
Can someone help me create a skewed distribution, mean = 30, with
probability of selecting a random number from the distribution greater
than or equal 60 equal to 10%?

I need the probability density function to equal zero at zero, and
have  a maximum height at or near 30.

Is this possible?

And if it is possible, how can I adjust the distribution so that the
probability of selecting a random number greater than or equal to 60
is p.

Thanks. No idea how to start.

David



[[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] poly regression

2009-06-09 Thread Ning Ma
hi,

I want to do a polynomial regression of y on x of degree 2, as following

> x<-1:10
> y<-x^2
> lm(y~poly(x,2))

Call:
lm(formula = y ~ poly(x, 2))

Coefficients:
(Intercept)  poly(x, 2)1  poly(x, 2)2
  38.5099.9122.98

Which is not what i had expected.

If I wrote the expression in an explicit form, y~1+x+I(x^2), I could
get the expected result:

> lm(y~1+x+I(x^2))

Call:
lm(formula = y ~ 1 + x + I(x^2))

Coefficients:
(Intercept)x   I(x^2)
  001

What is the diff between them?

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


[R] how to get output from a nested loop

2009-06-09 Thread Scott Hermann
Dear all,

I imagine that this is a trival question, but it has perplexed for most of the 
day.  Any help would be greatly appreciated.

Below is an example of what I'm trying to do.

Essentially I want to produce all unique 1 x 1 combinations of certain columns 
from a dataframe, and join these to other columns from the same dataframe.  I'm 
having problems with the nested loop as I can only output data from the last 
"cycle" of the loop.  I realise that the problem is with the st1[[i]] but I'm 
not sure how to define it differently.

##I want to make a list file of all 1x1 combinations of "mk" columns, and add 
"clone" and "S" to these combinations.

clone<-c("c1","c2","c3","c4")
mk1<-c(1,1,0,0)
mk2<-c(0,0,0,1)
mk3<-c(1,1,1,1)
mk4<-c(0,0,0,0)
mk5<-c(0,0,0,1)
S<-c(4,5,3,2)
t1<-as.data.frame(cbind(clone,mk1,mk2,mk3,mk4, mk5,S))
row.names(t1)<-t1$clone
t1<-t1[,-1]
t1

###A nested loop.  I'm trying to get all combinations of columns 1:5 and join 
each of them with column 7.

st1 <- list()
  for(i in 1:4) {
   for(j in (i+1):5){
   st1[[i]] <- cbind(t1[,c(i,6)],t1[,j])
   }
   }
  st1

Thanks for your help,

Scott
BSES Limited Disclaimer



This email and any files transmitted with it are confide...{{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] Unable to load package:lme4 [ Ubuntu 9.04 ]

2009-06-09 Thread Girish A.R.
Hi folks,

When I try to load package 'lme4' on my Linux box (64-bit Ubuntu
9.04), I get the following error:

-
> library(lme4)
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  function 'cholmod_start' not provided by package 'Matrix'
Error: package/namespace load failed for 'lme4'


I removed and re-installed both 'Matrix' and 'lme4', but that doesn't
seem to solve the problem. If this is something for the [R-sig-ME]
mailing list, please let me know.

Thanks,

-Girish


> sessionInfo()
R version 2.8.1 (2008-12-22)
x86_64-pc-linux-gnu

locale:
LC_CTYPE=en_IN;LC_NUMERIC=C;LC_TIME=en_IN;LC_COLLATE=en_IN;LC_MONETARY=C;LC_MESSAGES=en_IN;LC_PAPER=en_IN;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_IN;LC_IDENTIFICATION=C

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

other attached packages:
[1] Matrix_0.999375-17 lattice_0.17-25Design_2.2-0
survival_2.35-4
[5] Hmisc_3.6-0nlme_3.1-92car_1.2-14
MASS_7.2-47

loaded via a namespace (and not attached):
[1] cluster_1.12.0 grid_2.8.1 tools_2.8.1

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] searchpaths

2009-06-09 Thread Ronggui Huang
No. This function is used to get "a list of 'attach'ed _packages_ "
rather than search files in your computer.

2009/6/10  :
> May I use "searchpaths()" with arguments partially matching file names that 
> are found in different directories ?
> My question is whether this is th R function equivalent of Linux "find" or 
> Windows "search".
> Both O.S. calls are given a starting point so that they search all diectories 
> from then downwards looking for files whose
> names match the searching criteria.
> Thank you.
> Maura
>
>
>
> tutti i telefonini TIM!
>
>
>        [[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.
>



-- 
HUANG Ronggui, Wincent
PhD Candidate
Dept of Public and Social Administration
City University of Hong Kong
Home page: http://asrr.r-forge.r-project.org/rghuang.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] R on EC2 and R CMD javareconf

2009-06-09 Thread Saptarshi Guha
Hello,
I am using EC2 to launch several instances. On each instance, I
perform the following commands

yum -y install R (installs R-2.6)
R CMD javareconf
sleep 10
wget rpackage.tgz
R CMD INSTALL rpackage.tgz

Now, rpackage.tgz needs to be built with jni libraries. When the
instance is fully up, i log in and check if  rpackage was successfully
installed and find out it wasn't.

Running
R CMD INSTALL rpackage.tgz
again, i get the response that I should run R CMD javareconf, which I
do and then successfully install rpackage (using R CMD...)

Q: Why doesn't it work the first time? I am using a small instance and
Fedora 8 AMI

Regards
Saptarshi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] searchpaths

2009-06-09 Thread mauede
May I use "searchpaths()" with arguments partially matching file names that are 
found in different directories ?
My question is whether this is th R function equivalent of Linux "find" or 
Windows "search". 
Both O.S. calls are given a starting point so that they search all diectories 
from then downwards looking for files whose 
names match the searching criteria.
Thank you.
Maura



tutti i telefonini TIM!


[[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] Good Programming Practice Question - Functions in Different Files

2009-06-09 Thread Henrik Bengtsson
library("R.utils");
sourceDirectory("C:/appropriatepath/R/", modifiedOnly=TRUE);


On Tue, Jun 9, 2009 at 8:09 PM, spencerg wrote:
> Sundar Dorai-Raj taught me to do the following:
>
>           Rdir <- "c:\appropriatepath\R"
>
>           Rfiles <- dir(Rdir, pattern='\\.R$', full.names=TRUE)
>
>           invisible(lapply(aTR, source))
>
>
>     The "invisible" suppresses the garbage while still displaying error
> messages.
>
>     Hope this helps.     Spencer
>
> Paul Hiemstra wrote:
>>
>> Hi,
>>
>> I always use source for this kinds of things. If you have a lot of code,
>> you could consider wrapping it into an R-package. This would allow you to
>> load all the code by using the library(myPackage) command. But this might be
>> unnecessary for your situation.
>>
>> cheers,
>> Paul
>>
>> Jason Rupert wrote:
>>>
>>> I've gotten to the point wih an R script where I would like to
>>> encapsulate several blocks of codes in R functions.
>>>
>>> In order to keep the top level script simple I would like to put them in
>>> a separate file.  This should help the readability of the top level main
>>> script.
>>>
>>> Is source(...) the best way to load those functions in the top level
>>> script? For example, in the top level script
>>> Line#
>>> 01  source("FunctionsFile.R")
>>> 02
>>> 03  callfunctionfromfunctionfile(...)
>>>
>>> Thanks for any feedback and insights.
>>> Also, I found the following:
>>> http://www.stat.auckland.ac.nz/~paul/ItDT/HTML/node71.html
>>>
>>> But are there other guides out there that speak to good practices when
>>> developing in R?
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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] Good Programming Practice Question - Functions in Different Files

2009-06-09 Thread spencerg
Sundar Dorai-Raj taught me to do the following: 



   Rdir <- "c:\appropriatepath\R"

   Rfiles <- dir(Rdir, pattern='\\.R$', full.names=TRUE)

   invisible(lapply(aTR, source))


 The "invisible" suppresses the garbage while still displaying 
error messages. 



 Hope this helps. 
 Spencer   



Paul Hiemstra wrote:

Hi,

I always use source for this kinds of things. If you have a lot of 
code, you could consider wrapping it into an R-package. This would 
allow you to load all the code by using the library(myPackage) 
command. But this might be unnecessary for your situation.


cheers,
Paul

Jason Rupert wrote:
I've gotten to the point wih an R script where I would like to 
encapsulate several blocks of codes in R functions.


In order to keep the top level script simple I would like to put them 
in a separate file.  This should help the readability of the top 
level main script.


Is source(...) the best way to load those functions in the top level 
script? 
For example, in the top level script

Line#
01  source("FunctionsFile.R")
02
03  callfunctionfromfunctionfile(...)

Thanks for any feedback and insights.
Also, I found the following:
http://www.stat.auckland.ac.nz/~paul/ItDT/HTML/node71.html

But are there other guides out there that speak to good practices 
when developing in R?


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem : solving a equation with R , fail with uniroot function

2009-06-09 Thread Ben Bolker



Peter Alspach wrote:
> 
> Tena koe Yann
> 
> It may not be the only problem, but you are missing an operator between
> (bb0+x+1) and (bb1-x-1).
> 
> 

And fixing that typo and viewing the function shows that it 
is a bit problematic on this interval anyway ...  (diverges
at x = 1, closer look shows it's pretty nasty -- I haven't stopped
to think about its behavior very carefully, but it will clearly
take some effort.  If you're lucky there is a typo and the
real function is better behaved!)

test <- function(x,bb0=-3,bb1=5,c0=2,r0=0) {
   ((exp(c0-r0)*(bb0+x)*(bb1-x))/((bb0+x+1)*(bb1-x-1))-1)}


uniroot(test,c(-100,100))$root
curve(test(x),from=-100,to=100)
curve(test(x),from=1.1,to=10)
abline(h=0,col=2)
-- 
View this message in context: 
http://www.nabble.com/Problem-%3A-solving-a-equation-with-R-%2C-fail-with-uniroot-function-tp23953174p23953614.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Problem : solving a equation with R , fail with uniroot function

2009-06-09 Thread Peter Alspach
Tena koe Yann

It may not be the only problem, but you are missing an operator between
(bb0+x+1) and (bb1-x-1).

HTH 

Peter Alspach

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of yann lancien
> Sent: Wednesday, 10 June 2009 9:31 a.m.
> To: r-help@r-project.org
> Subject: [R] Problem : solving a equation with R , fail with 
> uniroot function
> 
> Hi ,
> I would like to know if a R function have the same behaviour 
> than the matlab solve function.
> I tried something with uniroot but I have some problems:
> The equation I need to solve is :
> exp(c0-r0)*(bb0+x)*(bb1-x)=(bb0+x+1)(bb1-x-1)
> 
> So I tried this:
> 
> STEP 1: my function test
>  test <- function(x,bb0=-3,bb1=5,c0=2,r0=0) {
> + ((exp(c0-r0)*(bb0+x)*(bb1-x))/((bb0+x+1)(bb1-x-1))-1)}
> 
> STEP 2:
> > uniroot(test,c(-100,100))$root*
> Erreur dans f(lower, ...) :
>   tentative d'appliquer un objet qui n'est pas une fonction*
> 
> R tells me that test is not a function ...
> 
> STEP 3:
> > is.function(test)
> [1] TRUE
> 
> 
> Thanks,
> Yann
> 
>   [[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.
> 

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

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


[R] LS graph

2009-06-09 Thread osbacan

Hi all,

I´m new using R. I wanto to print in a unique plot four results of four
different ordinary least squares regressions. You see, I want to plot (on
each box of the for parts of the graph, actual, fitted values and on the
bottom the residuals).

On the other side,if I only want to plot the for different residuals of each
on the four estimations, how I should proceed?Thanks in advance.

Imagine I have called e1,e2,e3,e4 And for titles I want to put (title) on
both x axis and y axis. How should I put a main title on each graph.

I hope I have explainned good. 

Anyway, thanks in advance for your help. 
-- 
View this message in context: 
http://www.nabble.com/LS-graph-tp23951942p23951942.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] Problem : solving a equation with R , fail with uniroot function

2009-06-09 Thread yann lancien
Hi ,
I would like to know if a R function have the same behaviour than the matlab
solve function.
I tried something with uniroot but I have some problems:
The equation I need to solve is :
exp(c0-r0)*(bb0+x)*(bb1-x)=(bb0+x+1)(bb1-x-1)

So I tried this:

STEP 1: my function test
 test <- function(x,bb0=-3,bb1=5,c0=2,r0=0) {
+ ((exp(c0-r0)*(bb0+x)*(bb1-x))/((bb0+x+1)(bb1-x-1))-1)}

STEP 2:
> uniroot(test,c(-100,100))$root*
Erreur dans f(lower, ...) :
  tentative d'appliquer un objet qui n'est pas une fonction*

R tells me that test is not a function ...

STEP 3:
> is.function(test)
[1] TRUE


Thanks,
Yann

[[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] list to data frame; how to store short elements?

2009-06-09 Thread Jim Porzak
This is programming style, best practices type of question.

When converting a list to a data frame (eg to use in ggplot), what is "best"
way to store descriptive elements?

For example, a survfit object mostly maps to a data frame, but I would also
like to carry along the type, call, etc.

I'm inclined to make these attributes of the data frame.

Any better technique?


TIA,
Jim Porzak
TGN.com
San Francisco, CA
www.linkedin.com/in/jimporzak
use R! Group SF: www.meetup.com/R-Users/

[[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] generating new data with for loop

2009-06-09 Thread Ben Bolker



Bugzilla from gordon.holtslan...@usask.ca wrote:
> 
> I'm new at R ...
> I've not done for loops in R - so this is very new to me.
> 
> One of our students has a data frame that contains two columns data
> 
> 1. unixtime time of an event (in unix time - #of seconds)
> 2. duration of event in seconds.
> 
> We need to create new data - the unixtime (seconds) that these events 
> occurred.
> 
> We want to create a for loop  (or nested for loops) that goes through the 
> first column, and then creates a new unixtime value for each second of 
> duration for that event
> 
> In a single row of data -
> if the duration was three seconds one iteration of this loop should create 
> these values
> 
> unixtime
> unixtime = unixtime +1
> unixtime = unixtime +1
> unixtime = unixtime +1
> 
> I need these four data values (and all the successive data values created
> by 
> the loop(s)) saved into a new dataframe
> 
> How do I get R to create a new data object and add data to it on each 
> interation of the for loop.
> 
> My test for loops only save the data from last iteration of the loop.
> 
> Am I missing something really simple?
> 
> Any recommended reference on loop and control structures in R?
> 
> Thanks,
> 

Hard to see what you tried to do, so hard to correct it.

## "data"
d = data.frame(unixtime=5:10,duration=3:8)

## method 1 (magic)
d2 = data.frame(basetime=unlist(apply(d,1,function(x)
 {rep(x["unixtime"],1+x["duration"])})),
   time=unlist(apply(d,1,function(x)
{x["unixtime"]+0:x["duration"]})))

## method 2 (straightforward)
time <- numeric(sum(d$duration)+nrow(d))
count <- 0
for (i in 1:nrow(d)) {
  dur <- d$duration[i]
  time[(count+1):(count+dur+1)] <- d$unixtime[i]+0:dur
  count <- count+dur+1
}

## method 3 (slowest but simplest)
time <- numeric(0)
for (i in 1:nrow(d)) {
  dur <- d$duration[i]
  time <- c(time,d$unixtime[i]+0:dur)
}


-- 
View this message in context: 
http://www.nabble.com/generating-new-data-with-for-loop-tp23951415p23952650.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] RODBC sqlSave does not append the records

2009-06-09 Thread Elaine Jones


I am running R version 2.8.1 on  Windows XP OS.

recs is a one-row, eighteen-column  data.frame I want to insert into a DB2
table.

sqlSave(channel, recs, tablename = "testappend_slt", append = TRUE,
+ rownames = FALSE, colnames = FALSE,
+ verbose = TRUE, oldstyle = FALSE,
+ safer = TRUE, addPK = FALSE,
+   fast = FALSE, test = FALSE, nastring = NULL)

Query: INSERT INTO "testappend_slt" ( "RECORDNO", "HEADERID", "SITE",
"TESTER", "TESTCELL", "PRODUCT", "OPERATION", "OPNUM", "PRODMODE",
"VERSION", "REVISION", "UUT", "MCTL", "OPERATOR", "STARTTIME", "ENDTIME",
"ENDSTATUS", "CREATED" ) VALUES ( 99, 1125080002314, 13, 'nextra14
', 'cell14 ', 'Nextra Gen2', 'IVT Gen2
', 'T710', 'E', 'PNX10.0b  ', '1104a ', 00023, 'FORGETIT', 'Elaine
', 1227627900, 1228685220, 'C', '12/9/2008 11:06:11' )
>

I don't get any error message, but when I check, the record has not been
added to the table.

This observation troubles me:  The third and fourth columns have class &
mode= character  but they are not enclosed in single quotes like the other
character columns. This also applies to the UUT column.  I notice the
values in these columns contain including only numerical digits,


Any suggestions for how to resolve are appreciated!
Sincerely,
 Elaine McGovern Jones 

 ISC Tape and DASD Storage Products
 Characterization and Failure Analysis Engineering
   Phone:  408  707 9588
   jon...@us.ibm.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] calculate effect size from p-value?

2009-06-09 Thread Joseph Kambeitz

Dear R-List!

Is there any function (apparently for BioStat there is!) to calculate 
effect sizes with the p-values and sample sizes?

That would be really useful for meta-analysis!

Thanks for the help!
Jokel

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 data with for loop

2009-06-09 Thread Henrique Dallazuanna
Try this:


x <- data.frame(u=c(1:5), seconds=sample(5))
transform(x[rep(1:nrow(x),x$seconds),], seconds =
unlist(lapply(split(x$seconds, x$u), seq)))


On Tue, Jun 9, 2009 at 6:11 PM, Gordon J Holtslander <
gordon.holtslan...@usask.ca> wrote:

> I'm new at R ...
> I've not done for loops in R - so this is very new to me.
>
> One of our students has a data frame that contains two columns data
>
> 1. unixtime time of an event (in unix time - #of seconds)
> 2. duration of event in seconds.
>
> We need to create new data - the unixtime (seconds) that these events
> occurred.
>
> We want to create a for loop  (or nested for loops) that goes through the
> first column, and then creates a new unixtime value for each second of
> duration for that event
>
> In a single row of data -
> if the duration was three seconds one iteration of this loop should create
> these values
>
> unixtime
> unixtime = unixtime +1
> unixtime = unixtime +1
> unixtime = unixtime +1
>
> I need these four data values (and all the successive data values created
> by
> the loop(s)) saved into a new dataframe
>
> How do I get R to create a new data object and add data to it on each
> interation of the for loop.
>
> My test for loops only save the data from last iteration of the loop.
>
> Am I missing something really simple?
>
> Any recommended reference on loop and control structures in R?
>
> Thanks,
>
> Gord
> --
> Gordon J. Holtslander
> gordon.holtslan...@usask.ca
> Dept. of Biology
> University of Saskatchewan
> tel 306 966-4433
> fax 306 966-4461
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Help with if statements

2009-06-09 Thread Carl Witthoft


> Error in if (ALLRESULTS[i, 16] <= 0.05) significance_count = 
significance_count + :

> missing value where TRUE/FALSE needed
>
> The script is included below
>
> it works if i convert the NA values to zero but this is not 
appropriate as it includes the zero as significant.

>
> ANY SUGGESTIONS
significance.count <- rowSums(ALLRESULTS[,16:22] <= .05, na.rm=TRUE)

?rowSums


Good solution.

I would like to comment on the OP's naivete:  since he knows that zero 
is a value of interest to his algorithm, why the heck replace "NA" with 
zero?  In general, if there is some reason not to use na.rm or na.omit, 
 start out by thinking about what NA values mean to your analysis.  If 
they are the equivalent of "FALSE" conditions, then replace them with a 
numerical value which is "FALSE".  In this example,  replacing NA with 
0.051 would do just fine.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] generating new data with for loop

2009-06-09 Thread Gordon J Holtslander
I'm new at R ...
I've not done for loops in R - so this is very new to me.

One of our students has a data frame that contains two columns data

1. unixtime time of an event (in unix time - #of seconds)
2. duration of event in seconds.

We need to create new data - the unixtime (seconds) that these events 
occurred.

We want to create a for loop  (or nested for loops) that goes through the 
first column, and then creates a new unixtime value for each second of 
duration for that event

In a single row of data -
if the duration was three seconds one iteration of this loop should create 
these values

unixtime
unixtime = unixtime +1
unixtime = unixtime +1
unixtime = unixtime +1

I need these four data values (and all the successive data values created by 
the loop(s)) saved into a new dataframe

How do I get R to create a new data object and add data to it on each 
interation of the for loop.

My test for loops only save the data from last iteration of the loop.

Am I missing something really simple?

Any recommended reference on loop and control structures in R?

Thanks,

Gord
-- 
Gordon J. Holtslander
gordon.holtslan...@usask.ca
Dept. of Biology 
University of Saskatchewan
tel 306 966-4433
fax 306 966-4461

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] IP-Address

2009-06-09 Thread edwin7
Hi Peter,


I hope you could help. I am stuck with this. The last problem I have is:

I have table like:

id rank color status ip
138 29746 yellow yes 162.131.58.1
138 29746 yellow  yes  162.131.58.2
138 29746 yellow yes  162.131.58.3
138 29746 yellow yes  162.131.58.4
138 29746 yellow yes 162.131.58.5
138 29746 yellow yes  162.131.58.6
138 29746 yellow  yes 162.132.58.20
138 29746 yellow yes  162.252.20.21
138 29746 yellow yes  162.254.20.22
138 29746 yellow yes  163.253.7.23
138 29746 yellow yes  163.253.20.25
138 29746 yellow yes  161.138.45.226

How can i make this to a range:

138 29746 yellow yes 162.131.58.1-162.131.58.6
138 29746 yellow  yes 162.132.58.20-163.253.7.23
138 29746 yellow yes  162.252.20.21-162.254.20.22
138 29746 yellow yes  163.253.20.25-161.138.45.226



Kind regards,

Eddie



> edw...@web.de wrote:
> > Hi,
> >
> >
> > Unfortunately, they can't handle NA. Any suggestion? Some row for Ip
> > don't have ip address. This cause an error/ wrong result.
>
> A quick fix could be to substitute "..." or "0.0.0.0" for the "NA"
> entries. (Use something like
>
> ipch <- as.character(df$ip)
> ipch[is.na(df$ip)] <- "..."
> connection <- textConnection(ipch)
>
> )
>
> > Eddie
> >
> >> library(gsubfn)
> >> library(gtools)
> >> library(rbenchmark)
> >>
> >> n <- 1
> >> df <- data.frame(
> >> a = rnorm(n),
> >> b = rnorm(n),
> >> c = rnorm(n),
> >> ip = replicate(n, paste(sample(255, 4), collapse='.'), simplify=TRUE)
> >> )
> >>
> >> res <- benchmark(columns=c('test', 'elapsed'), replications=10,
> >
> > order=NULL,
> >
> >> peda = {
> >> connection <- textConnection(as.character(df$ip))
> >> o <- do.call(order, read.table(connection, sep='.'))
> >> close(connection)
> >> df[o, ]
> >> },
> >>
> >> peda2 = {
> >> connection <- textConnection(as.character(df$ip))
> >> dfT <- read.table(connection, sep='.', colClasses=rep("integer",
> >> 4), quote="", na.strings=NULL, blank.lines.skip=FALSE)
> >> close(connection)
> >> o <- do.call(order, dfT)
> >> df[o, ]
> >> },
> >>
> >> hb = {
> >> ip <- strsplit(as.character(df$ip), split=".", fixed=TRUE)
> >> ip <- unlist(ip, use.names=FALSE)
> >> ip <- as.integer(ip)
> >> dim(ip) <- c(4, nrow(df))
> >> ip <- 256^3*ip[1,] + 256^2*ip[2,] + 256*ip[3,] + ip[4,]
> >> o <- order(ip)
> >> df[o, ]
> >> },
> >>
> >> hb2 = {
> >> ip <- strsplit(as.character(df$ip), split=".", fixed=TRUE)
> >> ip <- unlist(ip, use.names=FALSE)
> >> ip <- as.integer(ip);
> >> dim(ip) <- c(4, nrow(df))
> >> o <- sort.list(ip[4,], method="radix", na.last=TRUE)
> >> for (kk in 3:1) {
> >> o <- o[sort.list(ip[kk,o], method="radix", na.last=TRUE)]
> >> }
> >> df[o, ]
> >> }
> >> )
> >>
> >> print(res)
> >>
> >> test elapsed
> >> 1 peda 4.12
> >> 2 peda2 4.08
> >> 3 hb 0.28
> >> 4 hb2 0.25
> >>
> >>
> >> On Sun, May 31, 2009 at 12:42 AM, Wacek Kusnierczyk
> >>
> >>  wrote:
> >> > edwin Sendjaja wrote:
> >> >> Hi VQ,
> >> >>
> >> >> Thank you. It works like charm. But I think Peter's code is faster.
> >
> > What
> >
> >> >> is the difference?
> >> >
> >> > i think peter's code is more r-elegant, though less generic.  here's a
> >> > quick test, with not so surprising results.  gsubfn is implemented in
> >> > r, not c, and it is painfully slow in this test. i also added gabor's
> >> > suggestion.
> >> >
> >> >library(gsubfn)
> >> >library(gtools)
> >> >library(rbenchmark)
> >> >
> >> >n = 1000
> >> >df = data.frame(
> >> >   a=rnorm(n),
> >> >   b = rnorm(n),
> >> >   c = rnorm(n),
> >> >   ip = replicate(n, paste(sample(255, 4), collapse='.'),
> >> > simplify=TRUE))
> >> >benchmark(columns=c('test', 'elapsed'), replications=10,
> >> > order=NULL, peda={
> >> >  connection = textConnection(as.character(df$ip))
> >> >  o = do.call(order, read.table(connection, sep='.'))
> >> >  close(connection)
> >> >  df[o, ] },
> >> >   waku=df[order(gsubfn(perl=TRUE,
> >> >  '[0-9]+',
> >> >  ~ sprintf('%03d', as.integer(x)),
> >> >  as.character(df$ip))), ],
> >> >   gagr=df[mixedorder(df$ip), ] )
> >> >
> >> ># peda 0.070
> >> ># waku 7.070
> >> ># gagr 4.710
> >> >
> >> >
> >> > vQ
> >> >
> >> > __
> >> > R-help@r-project.org mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/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.



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do rea

Re: [R] Black-Litterman model

2009-06-09 Thread Stefan Grosse
JannaB schrieb:
> Anyone know where I can obtain an R implementation of the Black-
> Litterman portfolio model?
>
>   
There is the BLCOP package.

hth
Stefan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] surveillance package useful for daily surveillance?

2009-06-09 Thread Christopher W. Ryan
The surveillance package (see below) seems to be mainly designed for
weekly or monthly surveillance (although I am still learning about it.)
 Can it be used for daily surveillance? I had hoped to try using it with
respect to daily visits to walk-in clinics in our area.


Package ‘surveillance’
April 19, 2009
Title Outbreak detection algorithms for surveillance data
Version 1.0-2
Date 2009-05-03
Author M. Höhle with contributions from T. Correa, M. Hofmann, C. Lang,
M. Paul, A. Riebler and V. Wimmer


Thanks.
-- 
Christopher W. Ryan, MD
SUNY Upstate Medical University Clinical Campus at Binghamton
40 Arch Street, Johnson City, NY  13790
cryanatbinghamtondotedu

"If you want to build a ship, don't drum up the men to gather wood,
divide the work and give orders. Instead, teach them to yearn for the
vast and endless sea."  [Antoine de St. Exupery]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Cross correlations on many imported files.

2009-06-09 Thread Pur_045

Hello everyone,

I am trying to import all of the csv files from a particular folder and then
run cross correlations on each of them. i.e In the end have a matrix like
structure with cross correlations. 

So far I have been able to import all of the data and run the ccf's but I
need a way to store the data in an array. I know that this could be done in
matlab by using something like both a for and nested for loop with the
results being place in results[i,j]. 

Below I only have tried to create an array and not the entire matrix
structure. 


files <- list.files(pattern=".csv$")
for(i in seq(along=files)) { # start for loop with numeric or character
vector; numeric vector is often more flexible
x <- read.csv(files[i], skip=4,header=TRUE)

assign(paste('in',i,sep=""),x) # generates data frame object 
and names it
after content in variable 'i'
print(paste(files[i],paste('in',i,sep="")), quote=F)
   
}
library(tseries)
x<-get(paste('in',1,sep=""))

for(i in 1:length(files)-1){
y<-get(paste('in',i+1,sep=""))


xy<-ccf(x[[5]],y[[5]],lag.max=NULL,na.action=na.exclude)
  ***  result[i] = xy

}

Any help or advice would be greatly apperciated. Thanks in advance,

Sean

-- 
View this message in context: 
http://www.nabble.com/Cross-correlations-on-many-imported-files.-tp23950345p23950345.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] last.warning and Sweave?

2009-06-09 Thread Romain Francois

Not sure either where the warning gets trapped, but you could use
something like that:

\documentclass{article}

\begin{document}

Test {\tt last.warning}

<<>>=
withCallingHandlers( {
   x <- log(-1)
}, warning = function(w){
   assign( "last.warning", w, env = baseenv() )
})
@

<<>>=
last.warning
@

\end{document}


Romain


Dieter Menne wrote:

Ben Bolker  ufl.edu> writes:

  

  Sweave does something clever with warnings, which I have so far been


...

  

  I thought I could get around this with last.warning , but apparently
that doesn't work -- this file doesn't produce the desired output of
reproducing the last warning ...


\documentclass{article}



Missing \begin{document}
 
  

Test {\tt last.warning}

<<>>=
x <- log(-1)
L <- last.warning
@

<<>>=
L
@

\end{document}
==



No real answer, but I inserted a 

print(exits("last.warning")) 


which gives FALSE when sweaved, but TRUE when the tangled R file is run.


Dieter

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


  



--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Black-Litterman model

2009-06-09 Thread JannaB
Anyone know where I can obtain an R implementation of the Black-
Litterman portfolio model?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] last.warning and Sweave?

2009-06-09 Thread Dieter Menne
Ben Bolker  ufl.edu> writes:

>   Sweave does something clever with warnings, which I have so far been
...

>   I thought I could get around this with last.warning , but apparently
> that doesn't work -- this file doesn't produce the desired output of
> reproducing the last warning ...
> 
> 
> \documentclass{article}

Missing \begin{document}
 
> Test {\tt last.warning}
> 
> <<>>=
> x <- log(-1)
> L <- last.warning
> @
> 
> <<>>=
> L
> @
> 
> \end{document}
> ==

No real answer, but I inserted a 

print(exits("last.warning")) 

which gives FALSE when sweaved, but TRUE when the tangled R file is run.


Dieter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] scatterplot (car) legend modification

2009-06-09 Thread John Fox
Dear Sam,

It's not exactly clear to me what you're doing here, since you appear to be
specifying some of the arguments to scatterplot() (and to other functions)
in the command used to invoke R. I'm not sure why you would want to do that.

That said, you could suppress the legend that scatterplot() produces and use
the legend() command to make your own. Given what you're doing, however, it
would probably be simpler to use plot() rather than scatterplot(). You could
add the ellipses and the points with the data.ellipse() function from the
car package, and use legend() for the legend.

scatterplot() and the other plotting functions in the car package aren't
really meant for making customized graphs, but rather for easily producing
informative plots for exploring data in the context of regression analysis.

Regards,
 John


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
> Behalf Of sam stein
> Sent: June-08-09 11:49 PM
> To: r-help@r-project.org
> Subject: [R] scatterplot (car) legend modification
> 
> hi,
> 
> new to R and using the car package to do some scatterplots with ellipses
> hoping to add the area and center points of each ellipse to the legend?
> 
> looking for some direction / ideas here is the script, the data is
> where
> golf shots end up by club.
> 
>   x (dispersion), y (distance), group (Club)
> 
> thanks, sam
> 
> ## usage: Rscript shotScatter.R infile outfile level1 level2 minX maxX
> minY maxY
> ## load the library
> library(car)
> 
> ## get the args
> args = commandArgs(TRUE);
> 
> ## get the data format is: x, y, group
> Shot_Data <- read.table(args[1],
>   sep = ",",
>   header=T)
> 
> ## setup the pdf file name
> pdf(file = args[2])
> 
> ## do the plot
> scatterplot(y ~ x | Club, data=Shot_Data,
>   ellipse = TRUE,
> levels = c(as.numeric(args[3]), as.numeric(args[4])),
> robust = TRUE,
> boxplots = "",
>   xlab = "Dispersion",
>   ylab = "Distance",
>   xlim = c(as.numeric(args[5]), as.numeric(args[6])),
>   ylim = c(as.numeric(args[7]), as.numeric(args[8])),
>   smooth = FALSE,
>   reg.line = FALSE)
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Convex bounds in the function "arms" of package "HI"

2009-06-09 Thread hu yuan
Dear Sir/Madam,

i am learning to use a statistical sampling-modle(arms in HI)
But i have a problem with the "indFunc"(bounds of the convex support).
I have found a good example of c code using "arms" function and try to
program the example in R.
If you are interested, you can find the c code from arms usage(P.155-162)
But i always get the error message:
error at convex.bounds(y.start,dir=1,indFunc,...): x not in the support of
indFunc

the R code :
simulate intercept mu
#starting values of mu: mu<-c(0,-2,-4,.)
for (k in 1:K){
for (t in 1:25){
if(k==1){
  n_MU[t]<-firmsCCC[t] -used in the density function(Mudens)
  N_MU[t]<-defCCC[t]   -used in the density function(Mudens)
  MUl=mu[2]
  MUr=50
}
  else if(k==2){
  n_MU[t]<-firmsB[t]
  N_MU[t]<-defB[t]
  MUl=mu[3]
 MUr=mu[1]
   }
 else if...
 ...
  }
Muprev<-mu[k]
mu[k]<- arms(Muprev,Mudens,function(xm,...)(xm>MUl)*(xmhttps://stat.ethz.ch/mailman/listinfo/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] OT: a weighted rank-based, non-paired test statistic ?

2009-06-09 Thread Dylan Beaudette
On Tuesday 09 June 2009, Torsten Hothorn wrote:
> > Date: Fri, 5 Jun 2009 16:09:42 -0700 (PDT)
> > From: Thomas Lumley 
> > To: dylan.beaude...@gmail.com
> > Cc: "'r-h...@stat.math.ethz.ch'" 
> > Subject: Re: [R] OT: a weighted rank-based, non-paired test statistic ?
> >
> > On Fri, 5 Jun 2009, Dylan Beaudette wrote:
> >> Is anyone aware of a rank-based, non-paired test such as the
> >> Krustal-Wallis,
> >> that can accommodate weights?
> >
> > You don't say what sort of weights, but basically, no.
> >
> > Whether you have precision weights or sampling weights, the test will no
> > longer be distribution-free.
> >
> >> Alternatively, would it make sense to simulate a dataset by duplicating
> >> observations in proportion to their weight, and then using the
> >> Krustal-Wallis
> >> test?
> >
> > No.
>
> well, if you have case weights, i.e., w[i] == 5 means: there are five
> observations which look exactly like observation i, then there are several
>
> ways to do it:
> > library("coin")
> >
> > set.seed(29)
> > x <- gl(3, 10)
> > y <- rnorm(length(x), mean = c(0, 0, 1)[x])
> > d <- data.frame(y = y, x = x)
> > w <- rep(2, nrow(d)) ### double each obs
> >
> > ### all the same
> > kruskal_test(y ~ x, data = rbind(d, d))
>
>   Asymptotic Kruskal-Wallis Test
>
> data:  y by x (1, 2, 3)
> chi-squared = 12.1176, df = 2, p-value = 0.002337
>
> > kruskal_test(y ~ x, data = d[rep(1:nrow(d), w),])
>
>   Asymptotic Kruskal-Wallis Test
>
> data:  y by x (1, 2, 3)
> chi-squared = 12.1176, df = 2, p-value = 0.002337
>
> > kruskal_test(y ~ x, data = d, weights = ~ w)
>
>   Asymptotic Kruskal-Wallis Test
>
> data:  y by x (1, 2, 3)
> chi-squared = 12.1176, df = 2, p-value = 0.002337
>
> the first two work by duplicating data, the latter one is more memory
> efficient since it computes weighted statistics (and their distribution).
>
> However, as Thomas pointed out, other forms of weights are more difficult
> to deal with.
>
> Best wishes,
>
> Torsten

Thanks Torsten. This looks like the solution I was after.

Cheers,
Dylan

> > -thomas
> >
> > Thomas Lumley   Assoc. Professor, Biostatistics
> > tlum...@u.washington.eduUniversity of Washington, Seattle
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html and provide commented,
> > minimal, self-contained, reproducible code.



-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] reading in multiple files

2009-06-09 Thread Erin Hodgess
Dear R People:

I have about 6000 files to be read in that I'd like to go to one
matrix.  There are two columns, 1 line in each file.

Is there a way to bring them in to produce one matrix or data frame, please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


Re: [R] reading in multiple files

2009-06-09 Thread Sundar Dorai-Raj
You could try:

do.call("rbind", lapply(list.files("path/to/files", full = TRUE), read.csv))

And add more arguments to lapply if the files are not csv, have no header, etc.

--sundar

On Tue, Jun 9, 2009 at 11:18 AM, Erin Hodgess wrote:
> Dear R People:
>
> I have about 6000 files to be read in that I'd like to go to one
> matrix.  There are two columns, 1 line in each file.
>
> Is there a way to bring them in to produce one matrix or data frame, please?
>
> Thanks,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Gabor Grothendieck
This is just to you.

You might want to read r-help through gmane.org or one of the other
online readers or get a gmail or other online email account just
for reading newsgroups to circumvent your thread-challenged
email client.

Regards.


On Tue, Jun 9, 2009 at 1:42 PM, Greg Snow wrote:
> Yes, I already apologized to Wacek for missing that and pointing out what he 
> had already said.
>
> Given everything in this thread (though it is hard to keep track of all of 
> it, my e-mail client does not keep all the parts of the thread together), 
> this is probably one of those few tasks that R is not the best tool for.  
> There is a Perl module called Lingua::DE::Sentence with the description: 
> "Perl extension for tokenizing german texts into their sentences" which seems 
> to be exactly what the original poster was looking for.  So the best option 
> may be to use Perl and the above module to preprocess his texts, then use R 
> for later steps.
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of Gabor Grothendieck
>> Sent: Tuesday, June 09, 2009 11:27 AM
>> To: Greg Snow
>> Cc: Wacek Kusnierczyk; r-help@r-project.org; Mark Heckmann
>> Subject: Re: [R] using regular expressions to retrieve a digit-digit-
>> dot structure from a string
>>
>> Wacek already mentioned that; however, its still
>> arguably more complex to specify delimiters
>> than to specify content.  Aside from having
>> to specify perl = TRUE and ungreedy matching
>> the content-based regexp is entirely straight forward
>> but for lookbehind (including \K) one has the added
>> complexity of distinguishing between matching and returned
>> values.
>>
>> On Tue, Jun 9, 2009 at 12:36 PM, Greg Snow wrote:
>> > You can sometimes fake variable width look behinds with Perl regexs
>> using '\K':
>> >
>> >> gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1. 11.', perl=TRUE)
>> > [[1]]
>> > [1]  5 13
>> > attr(,"match.length")
>> > [1] 1 1
>> >
>> >
>> > --
>> > Gregory (Greg) L. Snow Ph.D.
>> > Statistical Data Center
>> > Intermountain Healthcare
>> > greg.s...@imail.org
>> > 801.408.8111
>> >
>> >
>> >> -Original Message-
>> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> >> project.org] On Behalf Of Wacek Kusnierczyk
>> >> Sent: Tuesday, June 09, 2009 1:05 AM
>> >> To: Gabor Grothendieck
>> >> Cc: r-help@r-project.org; Mark Heckmann
>> >> Subject: Re: [R] using regular expressions to retrieve a digit-
>> digit-
>> >> dot structure from a string
>> >>
>> >> Gabor Grothendieck wrote:
>> >> > On Mon, Jun 8, 2009 at 7:18 PM, Wacek
>> >> > Kusnierczyk wrote:
>> >> >
>> >> >> Gabor Grothendieck wrote:
>> >> >>
>> >> >>> Try this.  See ?regex for more.
>> >> >>>
>> >> >>>
>> >> >>>
>> >>  x <- 'This happened in the 21. century." (the dot behind 21 is'
>> >>  regexpr("(?![0-9]+)[.]", x, perl = TRUE)
>> >> 
>> >> 
>> >> >>> [1] 24
>> >> >>> attr(,"match.length")
>> >> >>> [1] 1
>> >> >>>
>> >> >>>
>> >> >> yes, but
>> >> >>
>> >> >>    gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>> >> >>    # 2 5 9
>> >> >>
>> >> >
>> >> > Yes, it should be:
>> >> >
>> >> >
>> >> >> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRUE)
>> >> >>
>> >> > [[1]]
>> >> > [1] 5 9
>> >> > attr(,"match.length")
>> >> > [1] 1 1
>> >> >
>> >> > which displays the position of every dot that is preceded
>> >> > immediately by a digit.  Or just replace gregexpr with regexpr
>> >> > if its intended that it match only one.
>> >> >
>> >>
>> >> i guess what was needed was something like
>> >>
>> >>     gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>> >>     # 5
>> >>
>> >> which won't work, however, because pcre does not support variable-
>> width
>> >> lookbehinds.
>> >>
>> >> >
>> >> >> which, i guess, is not what you want.  if what you want is to
>> match
>> >> all
>> >> >> and only dots that follow at least one digit preceded by a word
>> >> >> boundary, then the following should do, as far as i can see:
>> >> >>
>> >> >>    gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1.', perl=TRUE)
>> >> >>    # 5
>> >> >>
>> >> >> vQ
>> >> >>
>> >>
>> >> __
>> >> R-help@r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/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
PLEA

Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Gabor Grothendieck
If there were significant advantage to that perl module
I would recommend interfacing R to it rather than
suffer with perl.

For example, see xls2csv (and read.xls) in the gdata package
for an example of interfacing to a perl program.

I don't want to turn this into an R vs. perl thread but there are
certainly many people using R for linguistics and, like perl
which has books on perl and linguistics, there are books
specifically on R and linguistics.  One is mentioned on the
gsubfn site.  Also there are many linguistics packages in
R that could be explored:

   http://cran.r-project.org/web/views/NaturalLanguageProcessing.html

and there would be a big advantage of being able to leverage all
of R's other capabilities.

On Tue, Jun 9, 2009 at 1:42 PM, Greg Snow wrote:
> Yes, I already apologized to Wacek for missing that and pointing out what he 
> had already said.
>
> Given everything in this thread (though it is hard to keep track of all of 
> it, my e-mail client does not keep all the parts of the thread together), 
> this is probably one of those few tasks that R is not the best tool for.  
> There is a Perl module called Lingua::DE::Sentence with the description: 
> "Perl extension for tokenizing german texts into their sentences" which seems 
> to be exactly what the original poster was looking for.  So the best option 
> may be to use Perl and the above module to preprocess his texts, then use R 
> for later steps.
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of Gabor Grothendieck
>> Sent: Tuesday, June 09, 2009 11:27 AM
>> To: Greg Snow
>> Cc: Wacek Kusnierczyk; r-help@r-project.org; Mark Heckmann
>> Subject: Re: [R] using regular expressions to retrieve a digit-digit-
>> dot structure from a string
>>
>> Wacek already mentioned that; however, its still
>> arguably more complex to specify delimiters
>> than to specify content.  Aside from having
>> to specify perl = TRUE and ungreedy matching
>> the content-based regexp is entirely straight forward
>> but for lookbehind (including \K) one has the added
>> complexity of distinguishing between matching and returned
>> values.
>>
>> On Tue, Jun 9, 2009 at 12:36 PM, Greg Snow wrote:
>> > You can sometimes fake variable width look behinds with Perl regexs
>> using '\K':
>> >
>> >> gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1. 11.', perl=TRUE)
>> > [[1]]
>> > [1]  5 13
>> > attr(,"match.length")
>> > [1] 1 1
>> >
>> >
>> > --
>> > Gregory (Greg) L. Snow Ph.D.
>> > Statistical Data Center
>> > Intermountain Healthcare
>> > greg.s...@imail.org
>> > 801.408.8111
>> >
>> >
>> >> -Original Message-
>> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> >> project.org] On Behalf Of Wacek Kusnierczyk
>> >> Sent: Tuesday, June 09, 2009 1:05 AM
>> >> To: Gabor Grothendieck
>> >> Cc: r-help@r-project.org; Mark Heckmann
>> >> Subject: Re: [R] using regular expressions to retrieve a digit-
>> digit-
>> >> dot structure from a string
>> >>
>> >> Gabor Grothendieck wrote:
>> >> > On Mon, Jun 8, 2009 at 7:18 PM, Wacek
>> >> > Kusnierczyk wrote:
>> >> >
>> >> >> Gabor Grothendieck wrote:
>> >> >>
>> >> >>> Try this.  See ?regex for more.
>> >> >>>
>> >> >>>
>> >> >>>
>> >>  x <- 'This happened in the 21. century." (the dot behind 21 is'
>> >>  regexpr("(?![0-9]+)[.]", x, perl = TRUE)
>> >> 
>> >> 
>> >> >>> [1] 24
>> >> >>> attr(,"match.length")
>> >> >>> [1] 1
>> >> >>>
>> >> >>>
>> >> >> yes, but
>> >> >>
>> >> >>    gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>> >> >>    # 2 5 9
>> >> >>
>> >> >
>> >> > Yes, it should be:
>> >> >
>> >> >
>> >> >> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRUE)
>> >> >>
>> >> > [[1]]
>> >> > [1] 5 9
>> >> > attr(,"match.length")
>> >> > [1] 1 1
>> >> >
>> >> > which displays the position of every dot that is preceded
>> >> > immediately by a digit.  Or just replace gregexpr with regexpr
>> >> > if its intended that it match only one.
>> >> >
>> >>
>> >> i guess what was needed was something like
>> >>
>> >>     gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>> >>     # 5
>> >>
>> >> which won't work, however, because pcre does not support variable-
>> width
>> >> lookbehinds.
>> >>
>> >> >
>> >> >> which, i guess, is not what you want.  if what you want is to
>> match
>> >> all
>> >> >> and only dots that follow at least one digit preceded by a word
>> >> >> boundary, then the following should do, as far as i can see:
>> >> >>
>> >> >>    gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1.', perl=TRUE)
>> >> >>    # 5
>> >> >>
>> >> >> vQ
>> >> >>
>> >>
>> >> __
>> >> R-help@r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide http://www.R-project.org/posting-
>> >> guide.html
>> >> and provi

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Tan, Richard wrote:
> Sorry I did not give some examples in my previous posting to make my
> question clear.  It's not exactly 1 digit, but at least one digit.  Here
> are some examples:
>
>   
>> input = c(none='0foo f0oo foo0 foofoofoo0 0foofoofoo TOOL9NGG
>> 
> NONUMBER',all='foob0 fo0o0b 0foob 0foobardo foob4rdoo foobardo0')
>   
>> gsub(x=input, replacement='x', perl=TRUE,pattern=something)
>> 
>
>   none
> all 
> "0foo f0oo foo0 foo00 f0o0o foofoofoo0 0foofoofoo TOOL9NGG NONUMBER"
> "x x x x x x" 
>   

ok, then to my simple mind the following should do:
   
input = c(
none='0foo f0oo foo0 foofoofoo0 0foofoofoo TOOL9NGG NONUMBER',
all='foob0 fo0o0b 0foob 0foobardo foob4rdoo foobardo0 123456789')

gsub('(?=[[:alpha:]]{0,8}[[:digit:]])\\b[[:alnum:]]{5,9}\\b', 'x',
input, perl=TRUE)
# none -> '0foo f0oo foo0 foofoofoo0 0foofoofoo TOOL9NGG NONUMBER',
# all -> 'x x x x x x x')

where the regex reads 'if there is ahead of you a digit following at
most 8 letters, match 5 to 9 alphanumerics (digits and/or letters). 

vQ

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Sweave and accents

2009-06-09 Thread Eduardo Leoni
1) Please send reproducible code. In this case possibly with a link to the
Snw file.

2) Try setting the charset in LaTeX:  \usepackage[utf8]{inputenc}



On Tue, Jun 9, 2009 at 12:07 PM, Arnau Mir Torres  wrote:

> Hello.
>
> I want to write my notes in Sweave in my own language (spanish). But my
> language has accents and when I run Sweave in R to translate my Snw file
> into the tex file the accents are translated into unrecognizable characters.
> For example, the word "camión" (truck) is translated into "camión"
>
> Somebody knows how can I do it?
>
> One solution I don't like is using a perl program to substitute my accented
> letters into "normal" accents in LaTeX in my Snw file before running Sweave.
>  That is:
>
> á -> \'a
> é -> \'e
> ...
>
> The problem is when I run the spelling program, it doesn't work because the
> spelling doesn't recognize the words with "normal" accents.
>
> There is a solution but it is tedious:
>
> 1)  substitute the accented letters letter into "normal" accents in LaTeX.
> 2) run Sweave and create the tex file.
> 3) subtitute the "normal" accents into the accented letters in the tex
> file.
>
>
> My question is:
> Is there another way to do it?
>
>
> Arnau.
>
> 
> Arnau Mir Torres
> Edifici A. Turmeda
> Campus UIB
> Ctra. Valldemossa, km. 7,5
> 07122 Palma de Mca.
> tel: (+34) 971172987
> fax: (+34) 971173003
> email: arnau@uib.es
> URL: http://dmi.uib.es/~arnau 
> 
>
>

[[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] calibration curve options

2009-06-09 Thread Frank E Harrell Jr

David A.G wrote:

Hi R-users,

can anyone explain me how to play around with the options of the bootstrap 
calibration curve obtained using the calibrate() function in Design package?

I am trying to colour the diagonal, i.e. the ideal curve, in red, and also hide 
the bias-corrected curve.

Thanks,

Dave


The source code is there so you can create a local copy with any 
customizations you want, e.g.,


mycal <- calibrate.default (for every type except psm and cph)
modify mycal

Frank



_
Show them the way! Add maps and directions to your party invites. 


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




--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Greg Snow
Yes, I already apologized to Wacek for missing that and pointing out what he 
had already said.

Given everything in this thread (though it is hard to keep track of all of it, 
my e-mail client does not keep all the parts of the thread together), this is 
probably one of those few tasks that R is not the best tool for.  There is a 
Perl module called Lingua::DE::Sentence with the description: "Perl extension 
for tokenizing german texts into their sentences" which seems to be exactly 
what the original poster was looking for.  So the best option may be to use 
Perl and the above module to preprocess his texts, then use R for later steps.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Gabor Grothendieck
> Sent: Tuesday, June 09, 2009 11:27 AM
> To: Greg Snow
> Cc: Wacek Kusnierczyk; r-help@r-project.org; Mark Heckmann
> Subject: Re: [R] using regular expressions to retrieve a digit-digit-
> dot structure from a string
> 
> Wacek already mentioned that; however, its still
> arguably more complex to specify delimiters
> than to specify content.  Aside from having
> to specify perl = TRUE and ungreedy matching
> the content-based regexp is entirely straight forward
> but for lookbehind (including \K) one has the added
> complexity of distinguishing between matching and returned
> values.
> 
> On Tue, Jun 9, 2009 at 12:36 PM, Greg Snow wrote:
> > You can sometimes fake variable width look behinds with Perl regexs
> using '\K':
> >
> >> gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1. 11.', perl=TRUE)
> > [[1]]
> > [1]  5 13
> > attr(,"match.length")
> > [1] 1 1
> >
> >
> > --
> > Gregory (Greg) L. Snow Ph.D.
> > Statistical Data Center
> > Intermountain Healthcare
> > greg.s...@imail.org
> > 801.408.8111
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> >> project.org] On Behalf Of Wacek Kusnierczyk
> >> Sent: Tuesday, June 09, 2009 1:05 AM
> >> To: Gabor Grothendieck
> >> Cc: r-help@r-project.org; Mark Heckmann
> >> Subject: Re: [R] using regular expressions to retrieve a digit-
> digit-
> >> dot structure from a string
> >>
> >> Gabor Grothendieck wrote:
> >> > On Mon, Jun 8, 2009 at 7:18 PM, Wacek
> >> > Kusnierczyk wrote:
> >> >
> >> >> Gabor Grothendieck wrote:
> >> >>
> >> >>> Try this.  See ?regex for more.
> >> >>>
> >> >>>
> >> >>>
> >>  x <- 'This happened in the 21. century." (the dot behind 21 is'
> >>  regexpr("(?![0-9]+)[.]", x, perl = TRUE)
> >> 
> >> 
> >> >>> [1] 24
> >> >>> attr(,"match.length")
> >> >>> [1] 1
> >> >>>
> >> >>>
> >> >> yes, but
> >> >>
> >> >>    gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
> >> >>    # 2 5 9
> >> >>
> >> >
> >> > Yes, it should be:
> >> >
> >> >
> >> >> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRUE)
> >> >>
> >> > [[1]]
> >> > [1] 5 9
> >> > attr(,"match.length")
> >> > [1] 1 1
> >> >
> >> > which displays the position of every dot that is preceded
> >> > immediately by a digit.  Or just replace gregexpr with regexpr
> >> > if its intended that it match only one.
> >> >
> >>
> >> i guess what was needed was something like
> >>
> >>     gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
> >>     # 5
> >>
> >> which won't work, however, because pcre does not support variable-
> width
> >> lookbehinds.
> >>
> >> >
> >> >> which, i guess, is not what you want.  if what you want is to
> match
> >> all
> >> >> and only dots that follow at least one digit preceded by a word
> >> >> boundary, then the following should do, as far as i can see:
> >> >>
> >> >>    gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1.', perl=TRUE)
> >> >>    # 5
> >> >>
> >> >> vQ
> >> >>
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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] Non-linear regression/Quantile regression

2009-06-09 Thread Gabor Grothendieck
The coefficients are different but the predictions are the same.

On Tue, Jun 9, 2009 at 12:41 PM, Greg Snow wrote:
> poly by default uses orthogonal polynomials which work better mathematically 
> but are harder to interpret.  See ?poly
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of despaired
>> Sent: Tuesday, June 09, 2009 9:59 AM
>> To: r-help@r-project.org
>> Subject: Re: [R] Non-linear regression/Quantile regression
>>
>>
>> Hi,
>>
>> thanks, it works :-)
>> But where is the difference between demand ~ Time + I(Time^2) and
>> demand ~
>> poly(Time, 2) ?
>> Or: How do I have to interpret the results? (I get different results
>> for the
>> two methods)
>>
>> Thank you again!
>>
>>
>> Gabor Grothendieck wrote:
>> >
>> > Those are linear in the coefficients so try these:
>> >
>> > library(quantreg)
>> >
>> > rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1
>> >
>> > # or
>> > rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2
>> >
>> >
>> > On Tue, Jun 9, 2009 at 10:55 AM, despaired
>> wrote:
>> >>
>> >> Hi,
>> >>
>> >> I'm relatively new to R and need to do a quantile regression. Linear
>> >> quantile regression works, but for my data I need some quadratic
>> >> function.
>> >> So I guess, I have to use a nonlinear quantile regression. I tried
>> the
>> >> example on the help page for nlrq with my data and it worked. But
>> the
>> >> example there was with a SSlogis model. Trying to write
>> >>
>> >> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE)
>> >>
>> >> or
>> >>
>> >> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25,
>> trace=TRUE)
>> >>
>> >> (I don't know the difference) both gave me the following error
>> message:
>> >>
>> >> error in getInitial.default(func, data, mCall =
>> as.list(match.call(func,
>> >>  :
>> >>  no 'getInitial' method found for "function" objects
>> >>
>> >> Looking in getInitial, it must have to do something with the
>> starting
>> >> parameters or selfStart model. But I have no idea, what this is and
>> how I
>> >> handle this problem. Can anyone please help?
>> >>
>> >> Thanks a lot in advance!
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Non-linear-regression-Quantile-regression-
>> tp23944530p23944530.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.
>> >
>> >
>>
>> --
>> View this message in context: http://www.nabble.com/Non-linear-
>> regression-Quantile-regression-tp23944530p23945900.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] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Gabor Grothendieck
Wacek already mentioned that; however, its still
arguably more complex to specify delimiters
than to specify content.  Aside from having
to specify perl = TRUE and ungreedy matching
the content-based regexp is entirely straight forward
but for lookbehind (including \K) one has the added
complexity of distinguishing between matching and returned
values.

On Tue, Jun 9, 2009 at 12:36 PM, Greg Snow wrote:
> You can sometimes fake variable width look behinds with Perl regexs using 
> '\K':
>
>> gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1. 11.', perl=TRUE)
> [[1]]
> [1]  5 13
> attr(,"match.length")
> [1] 1 1
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of Wacek Kusnierczyk
>> Sent: Tuesday, June 09, 2009 1:05 AM
>> To: Gabor Grothendieck
>> Cc: r-help@r-project.org; Mark Heckmann
>> Subject: Re: [R] using regular expressions to retrieve a digit-digit-
>> dot structure from a string
>>
>> Gabor Grothendieck wrote:
>> > On Mon, Jun 8, 2009 at 7:18 PM, Wacek
>> > Kusnierczyk wrote:
>> >
>> >> Gabor Grothendieck wrote:
>> >>
>> >>> Try this.  See ?regex for more.
>> >>>
>> >>>
>> >>>
>>  x <- 'This happened in the 21. century." (the dot behind 21 is'
>>  regexpr("(?![0-9]+)[.]", x, perl = TRUE)
>> 
>> 
>> >>> [1] 24
>> >>> attr(,"match.length")
>> >>> [1] 1
>> >>>
>> >>>
>> >> yes, but
>> >>
>> >>    gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>> >>    # 2 5 9
>> >>
>> >
>> > Yes, it should be:
>> >
>> >
>> >> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRUE)
>> >>
>> > [[1]]
>> > [1] 5 9
>> > attr(,"match.length")
>> > [1] 1 1
>> >
>> > which displays the position of every dot that is preceded
>> > immediately by a digit.  Or just replace gregexpr with regexpr
>> > if its intended that it match only one.
>> >
>>
>> i guess what was needed was something like
>>
>>     gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>>     # 5
>>
>> which won't work, however, because pcre does not support variable-width
>> lookbehinds.
>>
>> >
>> >> which, i guess, is not what you want.  if what you want is to match
>> all
>> >> and only dots that follow at least one digit preceded by a word
>> >> boundary, then the following should do, as far as i can see:
>> >>
>> >>    gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1.', perl=TRUE)
>> >>    # 5
>> >>
>> >> vQ
>> >>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] calibration curve options

2009-06-09 Thread David Winsemius
It's rather simple to get the code and add modifications. You wanted  
the dashed line to be red? (To find out what the underlying function  
name is, you use methods(plot):


The dashed ideal line plotting function is not set up to accept  
parameters. so you need to alter the code. Use this as a guide:


>plot.calibrate <-
function(

Hi R-users,

can anyone explain me how to play around with the options of the  
bootstrap calibration curve obtained using the calibrate() function  
in Design package?


I am trying to colour the diagonal, i.e. the ideal curve, in red,  
and also hide the bias-corrected curve.


Thanks,

Dave

_
Show them the way! Add maps and directions to your party invites. --


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Tan, Richard
Sorry I did not give some examples in my previous posting to make my
question clear.  It's not exactly 1 digit, but at least one digit.  Here
are some examples:

> input = c(none='0foo f0oo foo0 foofoofoo0 0foofoofoo TOOL9NGG
NONUMBER',all='foob0 fo0o0b 0foob 0foobardo foob4rdoo foobardo0')
> gsub(x=input, replacement='x', perl=TRUE,pattern=something)

  none
all 
"0foo f0oo foo0 foo00 f0o0o foofoofoo0 0foofoofoo TOOL9NGG NONUMBER"
"x x x x x x" 

-Original Message-
From: Wacek Kusnierczyk [mailto:waclaw.marcin.kusnierc...@idi.ntnu.no] 
Sent: Tuesday, June 09, 2009 1:06 PM
To: Greg Snow
Cc: Marc Schwartz; Barry Rowlingson; r-help@r-project.org; Tan, Richard
Subject: Re: [R] Regex question to find a string that contains 5-9
alpha-numeric characters, at least one of which is a number

Greg Snow wrote:
> Here is one way using a single pattern (so can be used in a
substitution), it uses Perl's positive look ahead patters:
>
>   
>> test <- 
>> c("SHRT","5HRT","M1TCH","M1TCH5","LONG3RS","NONUMBER","TOOLNGG","
>> ooops.3")
>>
>> sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'xxx', test, 
>> perl=TRUE)
>> 


yes, but:

sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'x', '12345',
perl=TRUE)
# "x"

which is not what was expected -- as far as i understand, the point was
to match 5-9 character strings with exactly 1 digit.

vQ

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Stavros Macrakis
On Tue, Jun 9, 2009 at 7:44 AM, Mark Heckmann  wrote:

> Thanks for your help. Your answers solved the problem I posted and that is
> just when I noticed that I misspecified the problem ;)
> My problem is to separate a German texts by sentences. Unfortunately I
> haven't found an R package doing this kind of text separation in German, so
> I try it "manually".
>
> Just using the dot as separator fails in occasions like:
> txt <- "One January 1. I saw Rick. He was born in the 19. century."
>

Sentence boundary disambiguation is a non-trivial problem, as you can see in
your above example (cf. "I arrived on January 1. I saw Rick.").  You can get
~95% accuracy fairly straightforwardly, but the last 5% are hard.  Take a
look at http://en.wikipedia.org/wiki/Sentence_boundary_disambiguation, which
points to other good resources.

   -s

[[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] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Greg Snow wrote:
> Here is one way using a single pattern (so can be used in a substitution), it 
> uses Perl's positive look ahead patters:
>
>   
>> test <- 
>> c("SHRT","5HRT","M1TCH","M1TCH5","LONG3RS","NONUMBER","TOOLNGG","ooops.3")
>>
>> sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'xxx', test, perl=TRUE)
>> 


yes, but:

sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'x', '12345',
perl=TRUE)
# "x"

which is not what was expected -- as far as i understand, the point was
to match 5-9 character strings with exactly 1 digit.

vQ

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Non-linear regression/Quantile regression

2009-06-09 Thread Greg Snow
poly by default uses orthogonal polynomials which work better mathematically 
but are harder to interpret.  See ?poly
 
-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of despaired
> Sent: Tuesday, June 09, 2009 9:59 AM
> To: r-help@r-project.org
> Subject: Re: [R] Non-linear regression/Quantile regression
> 
> 
> Hi,
> 
> thanks, it works :-)
> But where is the difference between demand ~ Time + I(Time^2) and
> demand ~
> poly(Time, 2) ?
> Or: How do I have to interpret the results? (I get different results
> for the
> two methods)
> 
> Thank you again!
> 
> 
> Gabor Grothendieck wrote:
> >
> > Those are linear in the coefficients so try these:
> >
> > library(quantreg)
> >
> > rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1
> >
> > # or
> > rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2
> >
> >
> > On Tue, Jun 9, 2009 at 10:55 AM, despaired
> wrote:
> >>
> >> Hi,
> >>
> >> I'm relatively new to R and need to do a quantile regression. Linear
> >> quantile regression works, but for my data I need some quadratic
> >> function.
> >> So I guess, I have to use a nonlinear quantile regression. I tried
> the
> >> example on the help page for nlrq with my data and it worked. But
> the
> >> example there was with a SSlogis model. Trying to write
> >>
> >> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE)
> >>
> >> or
> >>
> >> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25,
> trace=TRUE)
> >>
> >> (I don't know the difference) both gave me the following error
> message:
> >>
> >> error in getInitial.default(func, data, mCall =
> as.list(match.call(func,
> >>  :
> >>  no 'getInitial' method found for "function" objects
> >>
> >> Looking in getInitial, it must have to do something with the
> starting
> >> parameters or selfStart model. But I have no idea, what this is and
> how I
> >> handle this problem. Can anyone please help?
> >>
> >> Thanks a lot in advance!
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Non-linear-regression-Quantile-regression-
> tp23944530p23944530.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.
> >
> >
> 
> --
> View this message in context: http://www.nabble.com/Non-linear-
> regression-Quantile-regression-tp23944530p23945900.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] Sweave and accents

2009-06-09 Thread Duncan Murdoch

On 6/9/2009 12:07 PM, Arnau Mir Torres wrote:

Hello.

I want to write my notes in Sweave in my own language (spanish). But  
my language has accents and when I run Sweave in R to translate my Snw  
file into the tex file the accents are translated into unrecognizable  
characters.

For example, the word "camión" (truck) is translated into "camión"

Somebody knows how can I do it?


That looks as though you are using Latin1 encoding, and Sweave is giving 
you UTF-8.  (If not those two, then a similar sort of problem.)


The handling of encodings is tricky, because it depends on your system 
settings (what sort of locale you are running in).  The l10n_info() and 
 sessionInfo() functions may be helpful in diagnosing the problem.


Duncan Murdoch



One solution I don't like is using a perl program to substitute my  
accented letters into "normal" accents in LaTeX in my Snw file before  
running Sweave.  That is:


á -> \'a
é -> \'e
...

The problem is when I run the spelling program, it doesn't work  
because the spelling doesn't recognize the words with "normal" accents.


There is a solution but it is tedious:

1)  substitute the accented letters letter into "normal" accents in  
LaTeX.

2) run Sweave and create the tex file.
3) subtitute the "normal" accents into the accented letters in the tex  
file.



My question is:
Is there another way to do it?


Arnau.


Arnau Mir Torres
Edifici A. Turmeda
Campus UIB
Ctra. Valldemossa, km. 7,5
07122 Palma de Mca.
tel: (+34) 971172987
fax: (+34) 971173003
email: arnau@uib.es
URL: http://dmi.uib.es/~arnau









__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dependency between packages for Windows-binaries

2009-06-09 Thread Jon Olav Skoien

Hi,

I have already asked a similar question without response 
(https://stat.ethz.ch/pipermail/r-help/2009-June/200300.html) so I am 
here reformulating in the hope that someone is able to help. If 
something is unclear, please ask.


I am working on the development of two packages, pkg1 and pkg2 (based on 
work in two different projects). pkg1 is quite generic, pkg2 tries to 
solve a particular problem within same field (geostatistics). Therefore, 
there might be users who want to use pkg2 as an add-on package to 
increase the functionality of pkg1. In other words, functions in pkg1 
are based on the S3 class system, and I want pkg2 to offer methods for 
pkg2-objects to functions defined in pkg1, for users having both 
packages installed. Merging the packages or making pkg2 directly 
dependent pkg1 would be the easiest solution, but it is a bad solution 
as most users will only be interested in one of the packages.


I thought this could be solved by including the following in NAMESPACE 
of pkg2:


if ("pkg1" %in% rownames(utils:::installed.packages()) {
importFrom(pkg1, fun1, fun2, fun3)
S3method(fun1, class2)
S3method(fun2, class2)
S3method(fun3, class2)
}

Unfortunately, this doesn't seem to work as I expected, particularly 
when I try to build a binary for Windows-users (R CMD build -binary 
pkg2). It seems for me that the dependency between pkg2 and pkg1 is 
defined at the time of building a binary, not when the package is loaded 
with library(pkg2):


If I have pkg1 installed when I build pkg2, the package will not load 
for users who do not have pkg1 installed:

> install.packages("d:/pkg2_0.1-1.zip", repos=NULL)
> library(pkg2)
(...)
Error : object 'fun1' not found whilst loading namespace 'pkg2'
Error: package/namespace load failed for 'pkg2'

If I remove pkg1 from the library before building pkg2, pkg2 can be 
installed and loaded by everyone, but the new method is not visible for 
those with pkg1 installed:

> install.packages("d:/pkg2_0.1-2.zip", repos=NULL)
> library(pkg1)
> library(pkg2)
> methods(fun1)
[1] fun1.class1*
  Non-visible functions are asterisked

I have tried with and without one of the following:
Suggests: pkg1
Enhances: pkg1
in the DESCRIPTION file of pkg2, but I cannot see that either of them 
make a difference.


I can of course solve this problem temporarily, building two different 
versions of pkg2, with and without having pkg1 installed on my computer. 
But first of all, that seems unnecessary complicated, and more 
important, the plan is also to upload these packages to CRAN where I 
doubt that such a two-version solution is possible or accepted.


Is there a way to build one binary that works both with and without 
having pkg1 installed? I have tried to search in mail archives and 
"Writing R extensions", but either it is not there, or I have missed it.


Thanks,
Jon

BTW, I am using R version 2.9.0 and Rtools version 29 under Windows XP-SP3

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Greg Snow
You can sometimes fake variable width look behinds with Perl regexs using '\K':

> gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1. 11.', perl=TRUE)
[[1]]
[1]  5 13
attr(,"match.length")
[1] 1 1


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Wacek Kusnierczyk
> Sent: Tuesday, June 09, 2009 1:05 AM
> To: Gabor Grothendieck
> Cc: r-help@r-project.org; Mark Heckmann
> Subject: Re: [R] using regular expressions to retrieve a digit-digit-
> dot structure from a string
> 
> Gabor Grothendieck wrote:
> > On Mon, Jun 8, 2009 at 7:18 PM, Wacek
> > Kusnierczyk wrote:
> >
> >> Gabor Grothendieck wrote:
> >>
> >>> Try this.  See ?regex for more.
> >>>
> >>>
> >>>
>  x <- 'This happened in the 21. century." (the dot behind 21 is'
>  regexpr("(?![0-9]+)[.]", x, perl = TRUE)
> 
> 
> >>> [1] 24
> >>> attr(,"match.length")
> >>> [1] 1
> >>>
> >>>
> >> yes, but
> >>
> >>gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
> >># 2 5 9
> >>
> >
> > Yes, it should be:
> >
> >
> >> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRUE)
> >>
> > [[1]]
> > [1] 5 9
> > attr(,"match.length")
> > [1] 1 1
> >
> > which displays the position of every dot that is preceded
> > immediately by a digit.  Or just replace gregexpr with regexpr
> > if its intended that it match only one.
> >
> 
> i guess what was needed was something like
> 
> gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
> # 5
> 
> which won't work, however, because pcre does not support variable-width
> lookbehinds.
> 
> >
> >> which, i guess, is not what you want.  if what you want is to match
> all
> >> and only dots that follow at least one digit preceded by a word
> >> boundary, then the following should do, as far as i can see:
> >>
> >>gregexpr('\\b[0-9]+\\K[.]', 'a. 1. a1.', perl=TRUE)
> >># 5
> >>
> >> vQ
> >>
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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 if statements

2009-06-09 Thread Chuck Cleland
On 6/9/2009 12:17 PM, Amit Patel wrote:
> Hi 
> I am trying to create a column in a data frame which gives a sigificane score 
> from 0-7. It should read values from 7 different colums and add 1 to the 
> counter if the value is <=0.05. I get an error message saying 
> 
> Error in if (ALLRESULTS[i, 16] <= 0.05) significance_count = 
> significance_count +  : 
>   missing value where TRUE/FALSE needed
> 
> The script is included below
> 
> it works if i convert the NA values to zero but this is not appropriate as it 
> includes the zero as significant. 
> 
> ANY SUGGESTIONS

significance.count <- rowSums(ALLRESULTS[,16:22] <= .05, na.rm=TRUE)

?rowSums

> #SCRIPT STARTS
> for (i in 1:length(ALLRESULTS[,1])) {
> significance_count = 0
> 
> if (ALLRESULTS[i,16] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,17] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,18] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,19] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,20] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,21] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,22] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> 
> ALLRESULTS[i,23] <- significance_count}
> 
> 
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 if statements

2009-06-09 Thread Jorge Ivan Velez
Dear Amit,
Try this:

significance_count <- apply( ALLRESULTS[,16:22], 1, function(x) sum( x <=
0.05 ) ) )

HTH,

Jorge


On Tue, Jun 9, 2009 at 12:17 PM, Amit Patel  wrote:

>
> Hi
> I am trying to create a column in a data frame which gives a sigificane
> score from 0-7. It should read values from 7 different colums and add 1 to
> the counter if the value is <=0.05. I get an error message saying
>
> Error in if (ALLRESULTS[i, 16] <= 0.05) significance_count =
> significance_count +  :
>  missing value where TRUE/FALSE needed
>
> The script is included below
>
> it works if i convert the NA values to zero but this is not appropriate as
> it includes the zero as significant.
>
> ANY SUGGESTIONS
>
>
>
> #SCRIPT STARTS
> for (i in 1:length(ALLRESULTS[,1])) {
> significance_count = 0
>
> if (ALLRESULTS[i,16] <= 0.05 )  significance_count = significance_count +1
> else significance_count = significance_count
> if (ALLRESULTS[i,17] <= 0.05 )  significance_count = significance_count +1
> else significance_count = significance_count
> if (ALLRESULTS[i,18] <= 0.05 )  significance_count = significance_count +1
> else significance_count = significance_count
> if (ALLRESULTS[i,19] <= 0.05 )  significance_count = significance_count +1
> else significance_count = significance_count
> if (ALLRESULTS[i,20] <= 0.05 )  significance_count = significance_count +1
> else significance_count = significance_count
> if (ALLRESULTS[i,21] <= 0.05 )  significance_count = significance_count +1
> else significance_count = significance_count
> if (ALLRESULTS[i,22] <= 0.05 )  significance_count = significance_count +1
> else significance_count = significance_count
>
> ALLRESULTS[i,23] <- significance_count}
>
>
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Help with if statements

2009-06-09 Thread Linlin Yan
Try this:
for (i in 1:dim(ALLRESULTS)[1]) {
  ALLRESULTS[i,23] <- length(ALLRESULTS[i,][ALLRESULTS[i,16:22] <= 0.05])
}

On Wed, Jun 10, 2009 at 12:17 AM, Amit Patel wrote:
>
> Hi
> I am trying to create a column in a data frame which gives a sigificane score 
> from 0-7. It should read values from 7 different colums and add 1 to the 
> counter if the value is <=0.05. I get an error message saying
>
> Error in if (ALLRESULTS[i, 16] <= 0.05) significance_count = 
> significance_count +  :
>  missing value where TRUE/FALSE needed
>
> The script is included below
>
> it works if i convert the NA values to zero but this is not appropriate as it 
> includes the zero as significant.
>
> ANY SUGGESTIONS
>
>
>
> #SCRIPT STARTS
> for (i in 1:length(ALLRESULTS[,1])) {
> significance_count = 0
>
> if (ALLRESULTS[i,16] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,17] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,18] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,19] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,20] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,21] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
> if (ALLRESULTS[i,22] <= 0.05 )  significance_count = significance_count +1 
> else significance_count = significance_count
>
> ALLRESULTS[i,23] <- significance_count}
>
>
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Greg Snow
Here is one way using a single pattern (so can be used in a substitution), it 
uses Perl's positive look ahead patters:

> test <- 
> c("SHRT","5HRT","M1TCH","M1TCH5","LONG3RS","NONUMBER","TOOLNGG","ooops.3")
> 
> sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'xxx', test, perl=TRUE)
[1] "SHRT""5HRT""xxx" "xxx" "xxx"
[6] "NONUMBER""TOOLNGG" "ooops.3"
>

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Marc Schwartz
> Sent: Monday, June 08, 2009 6:33 PM
> To: Barry Rowlingson
> Cc: r-help@r-project.org; Tan, Richard
> Subject: Re: [R] Regex question to find a string that contains 5-9
> alpha-numeric characters, at least one of which is a number
> 
> 
> On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote:
> 
> > On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard
> > wrote:
> >> Hi,
> >>
> >> This is not exactly an R question but I am trying to use gsub to
> >> replace
> >> a string that contains 5-9 alpha-numeric characters, at least one of
> >> which is a number.  Is there a good way to write it in a one line
> >> regex?
> >
> > The only way I can think of is to spell out all the possible
> > expressions, somethinglike:
> >
> > [0-9][a-z0-9]{4} | [a-z0-9][0-9][a-z0-9]{3} |
> > [a-z0-9]{2}[0-9][a-z0-9]{2}  and so on. That is, have a regex
> > component for every possible 5, 6, 7, 8, and 9 character expression
> > with [0-9] in each place. I'm not sure this qualifies as 'good',
> > though..
> >
> > Better to do it in two stages, one to check for 5-9 alphanumerics,
> > and then another to check for a number.
> >
> > Here's something on a test vector 's':
> >
> >> cbind(s,grepl("^[A-Z0-9]{5,9}$",s),grepl("[0-9]",s))
> > s
> > [1,] "SHRT""FALSE" "FALSE"
> > [2,] "5HRT""FALSE" "TRUE"
> > [3,] "M1TCH"   "TRUE"  "TRUE"
> > [4,] "M1TCH5"  "TRUE"  "TRUE"
> > [5,] "LONG3RS" "TRUE"  "TRUE"
> > [6,] "NONUMBER""TRUE"  "FALSE"
> > [7,] "TOOLNGG" "FALSE" "FALSE"
> >
> > The ones you want give two TRUE values. Extending to lower-case is
> > left as an exercise...
> >
> > Barry
> 
> 
> I was trying to think of a way to do this with only a single grep(),
> but it has been too long of a day.
> 
> So here is a bit of a simplification on the two stage approach:
> 
>  > vec
> [1] "SHRT""5HRT""M1TCH"   "M1TCH5"
> "LONG3RS" "NONUMBER""TOOLNGG"
> 
> 
>  > grep("[0-9]", vec[grep("^[[:alnum:]]{5,9}$", vec)], value = TRUE)
> [1] "M1TCH"   "M1TCH5"  "LONG3RS"
> 
> 
> HTH,
> 
> Marc Schwartz
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Non-linear regression/Quantile regression

2009-06-09 Thread Ravi Varadhan

Try  `poly(Time, 2, raw=TRUE)'

Here is an example:

Time <- runif(100)

demand <- 1 + 0.5 * Time - 1.2 * Time^2 + rt(100, df=4)

rq1 <- rq(demand ~ Time + I(Time^2), tau = 1:3/4) 

rq2 <- rq(demand ~ poly(Time, 2, raw=TRUE), tau = 1:3/4) 

all.equal(c(rq1$coef), c(rq2$coef))


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_personal_pages/Varadhan.h
tml







-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of despaired
Sent: Tuesday, June 09, 2009 11:59 AM
To: r-help@r-project.org
Subject: Re: [R] Non-linear regression/Quantile regression


Hi,

thanks, it works :-)
But where is the difference between demand ~ Time + I(Time^2) and demand ~
poly(Time, 2) ?
Or: How do I have to interpret the results? (I get different results for the
two methods)

Thank you again!


Gabor Grothendieck wrote:
> 
> Those are linear in the coefficients so try these:
> 
> library(quantreg)
> 
> rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1
> 
> # or
> rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2
> 
> 
> On Tue, Jun 9, 2009 at 10:55 AM, despaired wrote:
>>
>> Hi,
>>
>> I'm relatively new to R and need to do a quantile regression. Linear 
>> quantile regression works, but for my data I need some quadratic 
>> function.
>> So I guess, I have to use a nonlinear quantile regression. I tried 
>> the example on the help page for nlrq with my data and it worked. But 
>> the example there was with a SSlogis model. Trying to write
>>
>> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE)
>>
>> or
>>
>> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, 
>> trace=TRUE)
>>
>> (I don't know the difference) both gave me the following error message:
>>
>> error in getInitial.default(func, data, mCall = 
>> as.list(match.call(func,
>>  :
>>  no 'getInitial' method found for "function" objects
>>
>> Looking in getInitial, it must have to do something with the starting 
>> parameters or selfStart model. But I have no idea, what this is and 
>> how I handle this problem. Can anyone please help?
>>
>> Thanks a lot in advance!
>> --
>> View this message in context:
>> http://www.nabble.com/Non-linear-regression-Quantile-regression-tp239
>> 44530p23944530.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.
> 
> 

--
View this message in context:
http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p2
3945900.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] Isolating a single plot from plots produced simultaneously

2009-06-09 Thread Thomas Lumley

On Tue, 9 Jun 2009, Laura Bonnett wrote:


I'd like to isolate the second plot produced (the estimated functional
form of the influence of age on the log relative hazard) so that I can
use the 'points' function to add the linear predictors for the
untransformed and the log-transformed models.  In the usual situation
one would produce a plot and then type:



I think predict(, type="terms") does what you want.

-thomas


Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

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


[R] Help with if statements

2009-06-09 Thread Amit Patel

Hi 
I am trying to create a column in a data frame which gives a sigificane score 
from 0-7. It should read values from 7 different colums and add 1 to the 
counter if the value is <=0.05. I get an error message saying 

Error in if (ALLRESULTS[i, 16] <= 0.05) significance_count = significance_count 
+  : 
  missing value where TRUE/FALSE needed

The script is included below

it works if i convert the NA values to zero but this is not appropriate as it 
includes the zero as significant. 

ANY SUGGESTIONS



#SCRIPT STARTS
for (i in 1:length(ALLRESULTS[,1])) {
significance_count = 0

if (ALLRESULTS[i,16] <= 0.05 )  significance_count = significance_count +1 else 
significance_count = significance_count
if (ALLRESULTS[i,17] <= 0.05 )  significance_count = significance_count +1 else 
significance_count = significance_count
if (ALLRESULTS[i,18] <= 0.05 )  significance_count = significance_count +1 else 
significance_count = significance_count
if (ALLRESULTS[i,19] <= 0.05 )  significance_count = significance_count +1 else 
significance_count = significance_count
if (ALLRESULTS[i,20] <= 0.05 )  significance_count = significance_count +1 else 
significance_count = significance_count
if (ALLRESULTS[i,21] <= 0.05 )  significance_count = significance_count +1 else 
significance_count = significance_count
if (ALLRESULTS[i,22] <= 0.05 )  significance_count = significance_count +1 else 
significance_count = significance_count

ALLRESULTS[i,23] <- significance_count}




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] quantile of a mixture of bivriate normal distributions

2009-06-09 Thread li li
Hi,
   Does anyone know how to compute the quantile of a mixture of  four
bivariate normal distriutions?
   Many thanks!
 Hannah

[[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] Comparing R and SAs

2009-06-09 Thread Vadlamani, Satish {FLNA}
Hi:
For those of you who are adept at both SAS and R, I have the following 
questions:

a) What are some reasons / tasks for which you would use R over SAS and vice 
versa?
b) What are some things for which R is a must have that SAS cannot fulfill the 
requirements?

I am on the ramp up on both of them. The general feeling that I am getting by 
following this group is that R updates to the product are at a much faster pace 
and therefore, this would be better for someone who wants the bleeding edge 
(correct me if I am wrong). But I am also interested in what is inherently 
better in R that SAS cannot offer perhaps because of the design.

Thanks.
Satish

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] calibration curve options

2009-06-09 Thread David A.G

Hi R-users,

can anyone explain me how to play around with the options of the bootstrap 
calibration curve obtained using the calibrate() function in Design package?

I am trying to colour the diagonal, i.e. the ideal curve, in red, and also hide 
the bias-corrected curve.

Thanks,

Dave

_
Show them the way! Add maps and directions to your party invites. 

[[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] Sweave and accents

2009-06-09 Thread Arnau Mir Torres

Hello.

I want to write my notes in Sweave in my own language (spanish). But  
my language has accents and when I run Sweave in R to translate my Snw  
file into the tex file the accents are translated into unrecognizable  
characters.

For example, the word "camión" (truck) is translated into "camión"

Somebody knows how can I do it?

One solution I don't like is using a perl program to substitute my  
accented letters into "normal" accents in LaTeX in my Snw file before  
running Sweave.  That is:


á -> \'a
é -> \'e
...

The problem is when I run the spelling program, it doesn't work  
because the spelling doesn't recognize the words with "normal" accents.


There is a solution but it is tedious:

1)  substitute the accented letters letter into "normal" accents in  
LaTeX.

2) run Sweave and create the tex file.
3) subtitute the "normal" accents into the accented letters in the tex  
file.



My question is:
Is there another way to do it?


Arnau.


Arnau Mir Torres
Edifici A. Turmeda
Campus UIB
Ctra. Valldemossa, km. 7,5
07122 Palma de Mca.
tel: (+34) 971172987
fax: (+34) 971173003
email: arnau@uib.es
URL: http://dmi.uib.es/~arnau









__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Gabor Grothendieck
Another way to handle is to match the contents rather than the
delimiters using strapply in gsubfn (http://gsubfn.googlecode.com).

Below a sentence is defined as starting with a non-space followed by
anything followed by an alpha followed by dot, question mark or
exclamation mark.

The (?U) means that we use ungreedy matching so that the first
sentence terminator matches rather than the last.

This is an arguably simpler regexp as it does not involve lookbehind.

> txt <-  "One January 1. I saw Rick. He was born in the 19. century."

> library(gsubfn)
> strapply(txt, "(?U)([^ ].*[[:alpha:]][.?!])", c, perl = TRUE)
[[1]]
[1] "One January 1. I saw Rick."  "He was born in the 19. century."

This won't be as fast as the other solutions but typically speed is
not a real consideration unless you have huge amounts of text.  Also
note that the development version of strapply runs 5x faster than
the production version on certain sample problems.

On Tue, Jun 9, 2009 at 10:40 AM, Mark Heckmann wrote:
>
> Thanks,
>
> Now it works great. I modified it a bit so the sentences will be split by
> questionmarks (.?!:), etc. as well.
>
> strsplit(gsub("([[:alpha:]][\\.\\?\\!\\:])", "\\1*", txt), "\\* *") [[1]]
>
> e.g.
>
>> strsplit(gsub("([[:alpha:]][\\.\\?\\!\\:])", "\\1*", txt), "\\* *") [[1]]
> [1] "One January 1. I saw Rick?"      "He was born in the 19. century."
>
> ---
>
> Mark Heckmann
> + 49 (0) 421 - 1614618
> www.markheckmann.de
> R-Blog: http://ryouready.wordpress.com
>
>
>
>
> -Ursprüngliche Nachricht-
> Von: Marc Schwartz [mailto:marc_schwa...@me.com]
> Gesendet: Dienstag, 9. Juni 2009 14:17
> An: Mark Heckmann
> Cc: r-help@r-project.org; 'Gabor Grothendieck';
> waclaw.marcin.kusnierc...@idi.ntnu.no
> Betreff: Re: AW: [R] using regular expressions to retrieve a digit-digit-dot
> structure from a string
>
> On Jun 9, 2009, at 6:44 AM, Mark Heckmann wrote:
>
>> Hey all,
>>
>> Thanks for your help. Your answers solved the problem I posted and
>> that is
>> just when I noticed that I misspecified the problem ;)
>> My problem is to separate a German texts by sentences. Unfortunately I
>> haven't found an R package doing this kind of text separation in
>> German, so
>> I try it "manually".
>>
>> Just using the dot as separator fails in occasions like:
>> txt <- "One January 1. I saw Rick. He was born in the 19. century."
>>
>> Here I want the algorithm to separate the string only at the
>> positions where
>> the dot is not preceded by a digit. The R-snippets posted pick out
>> "1." and
>> "19."
>>
>> txt <- "One January 1. I saw Rick. He was born in the 19. century."
>>> gregexpr('(?<=[0-9])[.]',txt, perl=T)
>> [[1]]
>> [1] 14 49
>> attr(,"match.length")
>> [1] 1 1
>>
>> But I just need it the other way round. So I tried:
>>
>>> strsplit(txt, "[[:alpha:]]\\." , perl=T)
>> [[1]]
>> [1] "One January 1. I saw Ric"       " He was born in the 19. centur"
>>
>> But this erases the last letter from each sentence. Does someone
>> know a
>> solution?
>>
>> TIA
>> Mark
>
> 
>
> This is one of those rare? times where it might be nice for strsplit()
> to have an option to retain the split regex at the end of each parsed
> segment, rather than removing it.
>
> There may be a better way, but trying to both avoid a loop over vector
> indices and trying to stay with R functions that use .Internal() for
> speed, you may be able to use something like this:
>
>  > strsplit(gsub("([[:alpha:]]\\.)", "\\1*", txt), "\\* *")
> [[1]]
> [1] "One January 1. I saw Rick."      "He was born in the 19. century."
>
> What I am essentially doing is to add an "*" to the ending of each
> sentence (you can use other characters) such that strsplit() can split
> on that character without affecting the rest of the sentence.  So as
> an intermediate result, you get:
>
>  > gsub("([[:alpha:]]\\.)", "\\1*", txt)
> [1] "One January 1. I saw Rick.* He was born in the 19. century.*"
>
> which then makes the strsplit() parsing a bit easier. Since both
> strsplit() and grep() use .Internal()s, hopefully this would still be
> reasonably fast. Note that I have strsplit() split on the "*" possibly
> followed by one or more " ", which is required for mid-line splits.
>
> HTH,
>
> Marc Schwartz
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Non-linear regression/Quantile regression

2009-06-09 Thread despaired

Hi,

thanks, it works :-)
But where is the difference between demand ~ Time + I(Time^2) and demand ~
poly(Time, 2) ?
Or: How do I have to interpret the results? (I get different results for the
two methods)

Thank you again!


Gabor Grothendieck wrote:
> 
> Those are linear in the coefficients so try these:
> 
> library(quantreg)
> 
> rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1
> 
> # or
> rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2
> 
> 
> On Tue, Jun 9, 2009 at 10:55 AM, despaired wrote:
>>
>> Hi,
>>
>> I'm relatively new to R and need to do a quantile regression. Linear
>> quantile regression works, but for my data I need some quadratic
>> function.
>> So I guess, I have to use a nonlinear quantile regression. I tried the
>> example on the help page for nlrq with my data and it worked. But the
>> example there was with a SSlogis model. Trying to write
>>
>> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE)
>>
>> or
>>
>> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, trace=TRUE)
>>
>> (I don't know the difference) both gave me the following error message:
>>
>> error in getInitial.default(func, data, mCall = as.list(match.call(func,
>>  :
>>  no 'getInitial' method found for "function" objects
>>
>> Looking in getInitial, it must have to do something with the starting
>> parameters or selfStart model. But I have no idea, what this is and how I
>> handle this problem. Can anyone please help?
>>
>> Thanks a lot in advance!
>> --
>> View this message in context:
>> http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23944530.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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23945900.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Splicing factors without losing levels

2009-06-09 Thread Stavros Macrakis
On Tue, Jun 9, 2009 at 11:16 AM, Titus von der Malsburg
wrote:

> On Tue, Jun 09, 2009 at 11:04:03AM -0400, Stavros Macrakis wrote:
> > This may seem like a minor point, but I think it is worthwhile using
> > descriptive names for functions.
>
> Makes sense.  I thought I've seen this use somewhere else (probably in
> Lisp?).  What better name do you suggest for this operation?
>

The two meanings I can think of in Lisp for splicing are

1) The backquote operator ,@X, which means to insert the value of X as part
of the surrounding list rather than as an element of the list, e.g.   `(a b
,@'(c d) e f) == (append '(a b) '(c d) '(e f)) =>  (a b c d e f), as opposed
to `(a b ,'(c d) e f) == (append '(a b) (list '(c d)) '(e f)) => (a b (c d)
e f).

2) The notion of inserting (typically destructively) one list in the middle
of another.

I would suggest a name like 'intersperse' or 'alternate'.

-s

[[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] using regular expressions to retrieve a digit-digit-dotstructure from a string

2009-06-09 Thread William Dunlap

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Heckmann
> Sent: Tuesday, June 09, 2009 4:45 AM
> To: r-help@r-project.org
> Cc: waclaw.marcin.kusnierc...@idi.ntnu.no; marc_schwa...@me.com
> Subject: Re: [R] using regular expressions to retrieve a 
> digit-digit-dotstructure from a string
> 
> Hey all,
> 
> Thanks for your help. Your answers solved the problem I 
> posted and that is
> just when I noticed that I misspecified the problem ;) 
> My problem is to separate a German texts by sentences. Unfortunately I
> haven't found an R package doing this kind of text separation 
> in German, so
> I try it "manually". 
> 
> Just using the dot as separator fails in occasions like:
> txt <- "One January 1. I saw Rick. He was born in the 19. century."
> 
> Here I want the algorithm to separate the string only at the 
> positions where
> the dot is not preceded by a digit. The R-snippets posted 
> pick out "1." and
> "19."
> 
> txt <- "One January 1. I saw Rick. He was born in the 19. century."
> > gregexpr('(?<=[0-9])[.]',txt, perl=T)
> [[1]]
> [1] 14 49
> attr(,"match.length")
> [1] 1 1
> 
> But I just need it the other way round. So I tried:
> 
> > strsplit(txt, "[[:alpha:]]\\." , perl=T)
> [[1]]
> [1] "One January 1. I saw Ric"   " He was born in the 19. centur"
> 
> But this erases the last letter from each sentence. Does 
> someone know a
> solution?

In S+ strsplit() has an argument called subpattern that lets you
specify which parenthesized part of the regular expression
to use as the split point.  It is the akin to the \\ used in the
replacement argument of sub and gsub.  E.g., to split the string
at the sequence of spaces after a period, but not after period preceded
by a digit do:
   > txt <- "One January 1. I saw Rick. He was born in the 19. century."
   > strsplit(txt, "[^[:digit:]]\\.([[:space:]]+)", subpattern=1)
   [[1]]:
   [1] "One January 1. I saw Rick."  "He was born in the 19. century."
subpattern=0, the default, means text matched by the entire regular
expression.  regexpr has the same argument.  Would such an argument
solve your problem?

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 
 
> TIA
> Mark
> 
> ---
> 
> Mark Heckmann
> + 49 (0) 421 - 1614618
> www.markheckmann.de
> R-Blog: http://ryouready.wordpress.com
> 
> 
> 
> 
> -Ursprüngliche Nachricht-
> Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] 
> Gesendet: Dienstag, 9. Juni 2009 12:48
> An: Wacek Kusnierczyk
> Cc: Mark Heckmann; r-help@r-project.org
> Betreff: Re: [R] using regular expressions to retrieve a 
> digit-digit-dot
> structure from a string
> 
> On Tue, Jun 9, 2009 at 3:04 AM, Wacek
> Kusnierczyk wrote:
> > Gabor Grothendieck wrote:
> >> On Mon, Jun 8, 2009 at 7:18 PM, Wacek
> >> Kusnierczyk wrote:
> >>
> >>> Gabor Grothendieck wrote:
> >>>
>  Try this.  See ?regex for more.
> 
> 
> 
> > x <- 'This happened in the 21. century." (the dot behind 21 is'
> > regexpr("(?![0-9]+)[.]", x, perl = TRUE)
> >
> >
>  [1] 24
>  attr(,"match.length")
>  [1] 1
> 
> 
> >>> yes, but
> >>>
> >>>    gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
> >>>    # 2 5 9
> >>>
> >>
> >> Yes, it should be:
> >>
> >>
> >>> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRU
> E)
> >>>
> >> [[1]]
> >> [1] 5 9
> >> attr(,"match.length")
> >> [1] 1 1
> >>
> >> which displays the position of every dot that is preceded
> >> immediately by a digit.  Or just replace gregexpr with regexpr
> >> if its intended that it match only one.
> >>
> >
> > i guess what was needed was something like
> >
> >    gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
> >    # 5
> >
> > which won't work, however, because pcre does not support 
> variable-width
> > lookbehinds.
> 
> No, what I wrote was what I intended.   I don't think we are
> discussing the answer
> at this point but just the interpretation of what was intended.  You
> are including
> the word boundary in the question and I am not.  I think its 
> also possible
> that
> regexpr is what is wanted, not gregexpr, but at this point I think the
> poster has
> enough answers that he can complete it himself by considering 
> what he wants
> and using one of ours or a suitable modification.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Isolating a single plot from plots produced simultaneously

2009-06-09 Thread David Winsemius
This is almost certainly a device-dependent issue, which is the reason  
the Posting Guide requests that you include such details.


On a Mac using the GUI interface, one can scroll backwards through the  
graphics windows with -. With the plot of interest as  
the focus one can then issue additonal plotting function calls such as  
lines() or points() and then save the plots as pdf if the default  
Qartz device has been used.


I suspect there are equivalent facilities for Windows and Linux  
installations and encourage you to try reading the help pages:


?Devices #should bring up useful (installation-specific)  
information


--
David
On Jun 9, 2009, at 10:36 AM, Laura Bonnett wrote:


Dear R-Help,

I am using the 'mfp' package.  It produces three plots (as I am using
the Cox model) simultaneously which can be viewed together using the
following code:

fit <- mfp(Surv(rem.Remtime,rem.Rcens)~fp(age) 
+strata(rpa),family=cox,data=nearma,select=0.05,verbose=TRUE)

par(mfrow=c(2,2))
plot(fit)

They can be viewed separately but the return key must be pressed after
each graph appears (Click or hit ENTER for next page).

I'd like to isolate the second plot produced (the estimated functional
form of the influence of age on the log relative hazard) so that I can
use the 'points' function to add the linear predictors for the
untransformed and the log-transformed models.  In the usual situation
one would produce a plot and then type:

coxfitu <- coxph(Surv(rem.Remtime,rem.Rcens)~age 
+strata(rpa),data=nearma)

points(coxfitu$linear.predictor,col=2)
coxfitl <- coxph(Surv(rem.Remtime,rem.Rcens)~log(age) 
+strata(rpa),data=nearma)

points(coxfitl$linear.predictor,col=3)

Can anyone tell me how to isolate just the second plot produced?

Thank you for your help,

Laura

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Non-linear regression/Quantile regression

2009-06-09 Thread Gabor Grothendieck
Those are linear in the coefficients so try these:

library(quantreg)

rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1

# or
rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2


On Tue, Jun 9, 2009 at 10:55 AM, despaired wrote:
>
> Hi,
>
> I'm relatively new to R and need to do a quantile regression. Linear
> quantile regression works, but for my data I need some quadratic function.
> So I guess, I have to use a nonlinear quantile regression. I tried the
> example on the help page for nlrq with my data and it worked. But the
> example there was with a SSlogis model. Trying to write
>
> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE)
>
> or
>
> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, trace=TRUE)
>
> (I don't know the difference) both gave me the following error message:
>
> error in getInitial.default(func, data, mCall = as.list(match.call(func,  :
>  no 'getInitial' method found for "function" objects
>
> Looking in getInitial, it must have to do something with the starting
> parameters or selfStart model. But I have no idea, what this is and how I
> handle this problem. Can anyone please help?
>
> Thanks a lot in advance!
> --
> View this message in context: 
> http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23944530.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] Splicing factors without losing levels

2009-06-09 Thread Titus von der Malsburg
On Tue, Jun 09, 2009 at 11:04:03AM -0400, Stavros Macrakis wrote:
> This may seem like a minor point, but I think it is worthwhile using
> descriptive names for functions.

Makes sense.  I thought I've seen this use somewhere else (probably in
Lisp?).  What better name do you suggest for this operation?

  Titus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Splicing factors without losing levels

2009-06-09 Thread Stavros Macrakis
Various people have provided technical solutions to your problem.

May I suggest, though, that 'splice' isn't quite the right word for this
operation?  Splicing two pieces of rope / movie film / audio tape / wires /
etc. means connecting them at their ends, either at an extremity or in the
middle, e.g.

X:  
Y:  
Extremity splice: xx  or
yyxx
Middle splice: xxxyyyx or
yyyxxx

The splice itself is the point of connection (xy or yx) between two things.

In normal English, splicing never refers to interspersing alternate members
of X and Y.

This may seem like a minor point, but I think it is worthwhile using
descriptive names for functions.

 -s


On Tue, Jun 9, 2009 at 5:12 AM, Titus von der Malsburg
wrote:

> An operation that I often need is splicing two vectors:
>
>  > splice(1:3, 4:6)
>  [1] 1 4 2 5 3 6
>

[[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] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Mark Heckmann
Hey all,

Thanks for your help. Your answers solved the problem I posted and that is
just when I noticed that I misspecified the problem ;) 
My problem is to separate a German texts by sentences. Unfortunately I
haven't found an R package doing this kind of text separation in German, so
I try it "manually". 

Just using the dot as separator fails in occasions like:
txt <- "One January 1. I saw Rick. He was born in the 19. century."

Here I want the algorithm to separate the string only at the positions where
the dot is not preceded by a digit. The R-snippets posted pick out "1." and
"19."

txt <- "One January 1. I saw Rick. He was born in the 19. century."
> gregexpr('(?<=[0-9])[.]',txt, perl=T)
[[1]]
[1] 14 49
attr(,"match.length")
[1] 1 1

But I just need it the other way round. So I tried:

> strsplit(txt, "[[:alpha:]]\\." , perl=T)
[[1]]
[1] "One January 1. I saw Ric"   " He was born in the 19. centur"

But this erases the last letter from each sentence. Does someone know a
solution?

TIA
Mark

---

Mark Heckmann
+ 49 (0) 421 - 1614618
www.markheckmann.de
R-Blog: http://ryouready.wordpress.com




-Ursprüngliche Nachricht-
Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] 
Gesendet: Dienstag, 9. Juni 2009 12:48
An: Wacek Kusnierczyk
Cc: Mark Heckmann; r-help@r-project.org
Betreff: Re: [R] using regular expressions to retrieve a digit-digit-dot
structure from a string

On Tue, Jun 9, 2009 at 3:04 AM, Wacek
Kusnierczyk wrote:
> Gabor Grothendieck wrote:
>> On Mon, Jun 8, 2009 at 7:18 PM, Wacek
>> Kusnierczyk wrote:
>>
>>> Gabor Grothendieck wrote:
>>>
 Try this.  See ?regex for more.



> x <- 'This happened in the 21. century." (the dot behind 21 is'
> regexpr("(?![0-9]+)[.]", x, perl = TRUE)
>
>
 [1] 24
 attr(,"match.length")
 [1] 1


>>> yes, but
>>>
>>>    gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>>>    # 2 5 9
>>>
>>
>> Yes, it should be:
>>
>>
>>> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRU
E)
>>>
>> [[1]]
>> [1] 5 9
>> attr(,"match.length")
>> [1] 1 1
>>
>> which displays the position of every dot that is preceded
>> immediately by a digit.  Or just replace gregexpr with regexpr
>> if its intended that it match only one.
>>
>
> i guess what was needed was something like
>
>    gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>    # 5
>
> which won't work, however, because pcre does not support variable-width
> lookbehinds.

No, what I wrote was what I intended.   I don't think we are
discussing the answer
at this point but just the interpretation of what was intended.  You
are including
the word boundary in the question and I am not.  I think its also possible
that
regexpr is what is wanted, not gregexpr, but at this point I think the
poster has
enough answers that he can complete it himself by considering what he wants
and using one of ours or a suitable modification.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Using ADF.Test

2009-06-09 Thread ehxpieterse

Hi,

I am quite new to R and would appreciate some guidance, if possible.

I have imported a csv file: spread <- read.csv("Spread.csv")

I get the following error when I try to run adf.test:
> adf.test(spread,alternative = c("stationary", "explosive"),0)
Error in embed(y, k) : 'x' is not a vector or matrix

Why is this?
-- 
View this message in context: 
http://www.nabble.com/Using-ADF.Test-tp23940824p23940824.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Mark Heckmann

Thanks,

Now it works great. I modified it a bit so the sentences will be split by
questionmarks (.?!:), etc. as well.

strsplit(gsub("([[:alpha:]][\\.\\?\\!\\:])", "\\1*", txt), "\\* *") [[1]]

e.g.

> strsplit(gsub("([[:alpha:]][\\.\\?\\!\\:])", "\\1*", txt), "\\* *") [[1]]
[1] "One January 1. I saw Rick?"  "He was born in the 19. century."

---

Mark Heckmann
+ 49 (0) 421 - 1614618
www.markheckmann.de
R-Blog: http://ryouready.wordpress.com




-Ursprüngliche Nachricht-
Von: Marc Schwartz [mailto:marc_schwa...@me.com] 
Gesendet: Dienstag, 9. Juni 2009 14:17
An: Mark Heckmann
Cc: r-help@r-project.org; 'Gabor Grothendieck';
waclaw.marcin.kusnierc...@idi.ntnu.no
Betreff: Re: AW: [R] using regular expressions to retrieve a digit-digit-dot
structure from a string

On Jun 9, 2009, at 6:44 AM, Mark Heckmann wrote:

> Hey all,
>
> Thanks for your help. Your answers solved the problem I posted and  
> that is
> just when I noticed that I misspecified the problem ;)
> My problem is to separate a German texts by sentences. Unfortunately I
> haven't found an R package doing this kind of text separation in  
> German, so
> I try it "manually".
>
> Just using the dot as separator fails in occasions like:
> txt <- "One January 1. I saw Rick. He was born in the 19. century."
>
> Here I want the algorithm to separate the string only at the  
> positions where
> the dot is not preceded by a digit. The R-snippets posted pick out  
> "1." and
> "19."
>
> txt <- "One January 1. I saw Rick. He was born in the 19. century."
>> gregexpr('(?<=[0-9])[.]',txt, perl=T)
> [[1]]
> [1] 14 49
> attr(,"match.length")
> [1] 1 1
>
> But I just need it the other way round. So I tried:
>
>> strsplit(txt, "[[:alpha:]]\\." , perl=T)
> [[1]]
> [1] "One January 1. I saw Ric"   " He was born in the 19. centur"
>
> But this erases the last letter from each sentence. Does someone  
> know a
> solution?
>
> TIA
> Mark



This is one of those rare? times where it might be nice for strsplit()  
to have an option to retain the split regex at the end of each parsed  
segment, rather than removing it.

There may be a better way, but trying to both avoid a loop over vector  
indices and trying to stay with R functions that use .Internal() for  
speed, you may be able to use something like this:

 > strsplit(gsub("([[:alpha:]]\\.)", "\\1*", txt), "\\* *")
[[1]]
[1] "One January 1. I saw Rick."  "He was born in the 19. century."

What I am essentially doing is to add an "*" to the ending of each  
sentence (you can use other characters) such that strsplit() can split  
on that character without affecting the rest of the sentence.  So as  
an intermediate result, you get:

 > gsub("([[:alpha:]]\\.)", "\\1*", txt)
[1] "One January 1. I saw Rick.* He was born in the 19. century.*"

which then makes the strsplit() parsing a bit easier. Since both  
strsplit() and grep() use .Internal()s, hopefully this would still be  
reasonably fast. Note that I have strsplit() split on the "*" possibly  
followed by one or more " ", which is required for mid-line splits.

HTH,

Marc Schwartz

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


[R] adonis formula

2009-06-09 Thread Benjamin Gosney

Hello,

	I have a pretty large data set of insect community data from a tree  
plantation. There are 14 subraces (fixed) of tree, each with 10  
families fixed within subrace.  There are then 10 reps (random) of  
each family, which are in specific part of the plantation.  I am  
trying to determine the proper formula for adonis for testing for  
differences in communities within and between rep, subrace and family  
fixed in subrace.  Please let me know id you can help.  Also, does  
adonis support unbalanced designs?  Thanks for your help.


Ben

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Writing Reports from R in Office Open XML format (ooxmlWeave?)

2009-06-09 Thread Ronggui Huang
Wow, It sounds great. Looking forward to it.


2009/6/9 Duncan Temple Lang :
> Yes. We will release a version in the next few weeks
> when I have time to wrap it all up.
> There is also a Docbook-based version that uses
> R extensions to Docbook for authoring structured
> documents.
>
>  D.
>
> Tobias Sing wrote:
>>
>> Dear all,
>>
>> has someone implemented functionality for writing reports from R in
>> Office Open XML format (*), similar to what odfWeave does for the ODF
>> format of OpenOffice? It would be great to have a kind of
>> "ooxmlWeave" at least for those of us who are forced to work in an
>> MS ecosystem.
>>
>> (*) Office Open XML is the default, XML-based, file format for MS
>> Word: http://en.wikipedia.org/wiki/Office_Open_XML
>>
>> Kind regards,
>>  Tobias
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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.
>



-- 
HUANG Ronggui, Wincent
PhD Candidate
Dept of Public and Social Administration
City University of Hong Kong
Home page: http://asrr.r-forge.r-project.org/rghuang.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] Non-linear regression/Quantile regression

2009-06-09 Thread despaired

Hi,

I'm relatively new to R and need to do a quantile regression. Linear
quantile regression works, but for my data I need some quadratic function.
So I guess, I have to use a nonlinear quantile regression. I tried the
example on the help page for nlrq with my data and it worked. But the
example there was with a SSlogis model. Trying to write 

dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE)

or 

dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, trace=TRUE)

(I don't know the difference) both gave me the following error message:

error in getInitial.default(func, data, mCall = as.list(match.call(func,  : 
  no 'getInitial' method found for "function" objects

Looking in getInitial, it must have to do something with the starting
parameters or selfStart model. But I have no idea, what this is and how I
handle this problem. Can anyone please help?

Thanks a lot in advance!
-- 
View this message in context: 
http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23944530.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Cairo Package Installation

2009-06-09 Thread Uwe Ligges
Install the cairo headers? Probably in some cairo or cairo-devel package 
for your OS.


Uwe Ligges



Douglas M. Hultstrand wrote:
I am trying to install the Cairo package on a linux machine, the Cairo 
package did not install correctly (could not find cairo.h), I am new to 
R and linux any help on the installation would be great.  Below are 
output from trying to install the Cairo package, thought this might help.


 > install.packages("Cairo")
Warning in install.packages("Cairo") :
 argument 'lib' is missing: using 
'/home/tyep/R/x86_64-unknown-linux-gnu-library/2.8'
trying URL 
'http://streaming.stat.iastate.edu/CRAN/src/contrib/Cairo_1.4-4.tar.gz'

Content type 'application/x-gzip' length 75200 bytes (73 Kb)
opened URL
==
downloaded 73 Kb

* Installing *source* package 'Cairo' ...
checking for gcc... gcc -std=gnu99
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for pkg-config... /usr/bin/pkg-config
checking whether pkg-config knows about cairo... no
configure: CAIRO_LIBS is unset, attempting to guess it.
configure: CAIRO_CFLAGS=
checking if R was compiled with the RConn patch... no
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h! Please install cairo 
(http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS

correspondingly.
ERROR: configuration failed for package 'Cairo'
** Removing '/home/tyep/R/x86_64-unknown-linux-gnu-library/2.8/Cairo'

The downloaded packages are in
   /tmp/RtmpILmmXw/downloaded_packages
Warning message:
In install.packages("Cairo") :
 installation of package 'Cairo' had non-zero exit status
 >

Thanks,
Doug



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 CMD check" does not find a mistake

2009-06-09 Thread Uwe Ligges



Henrik Bengtsson wrote:

"using R version 2.9.0 beta (2009-04-04 r48290)"

As a start, Kurt et al. are for sure using a much more recent version
(probably also the very latest patched version).


and if not only then at least also R-devel.

Uwe








/H

On Tue, Jun 9, 2009 at 7:17 AM, Christophe
Genolini wrote:

Hi the list,

I build a package. They was a mistake in it, but R CMD check did not find
it. Is that normal ?

Here is what Kurt gets (which is right, I did this mistake):

--- 8< 
* checking for code/documentation mismatches ... WARNING
S4 class codoc mismatches from documentation object 'LongData-class':
Slots for class 'LongData'
 Code: id other time traj varName
 Docs: id time traj varName
--- 8< 

But here is what I get :

--- 8< 
R CMD check longitudinalData
* checking for working pdflatex ... OK
* using log directory 'C:/Documents and Settings/Christophe/Mes
documents/Recher
che/Trajectoires/kmeal/longitudinalData.Rcheck'
* using R version 2.9.0 beta (2009-04-04 r48290)
* using session charset: ISO8859-1
* checking for file 'longitudinalData/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'longitudinalData' version '0.5'
* package encoding: latin1
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for .dll and .exe files ... OK
* checking whether package 'longitudinalData' can be installed ... OK
* checking package directory ... OK
* checking for portable file names ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking for unstated dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd files against version 2 parser ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking examples ... OK
* checking PDF version of manual ... OK


R CMD build longitudinalData
* checking for file 'longitudinalData/DESCRIPTION' ... OK
* preparing 'longitudinalData':
* checking DESCRIPTION meta-information ... OK
* removing junk files
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building 'longitudinalData_0.5.tar.gz'
--- 8< 

Christophe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] "R CMD check" does not find a mistake

2009-06-09 Thread Ingmar Visser


try issueing this before calling R CMD check

export _R_CHECK_CODOC_S4_METHODS_=true

hth, Ingmar

On 9 Jun 2009, at 16:17, Christophe Genolini wrote:


Hi the list,

I build a package. They was a mistake in it, but R CMD check did not  
find it. Is that normal ?


Here is what Kurt gets (which is right, I did this mistake):

--- 8< 
* checking for code/documentation mismatches ... WARNING
S4 class codoc mismatches from documentation object 'LongData-class':
Slots for class 'LongData'
Code: id other time traj varName
Docs: id time traj varName
--- 8< 

But here is what I get :

--- 8< 
R CMD check longitudinalData
* checking for working pdflatex ... OK
* using log directory 'C:/Documents and Settings/Christophe/Mes  
documents/Recher

che/Trajectoires/kmeal/longitudinalData.Rcheck'
* using R version 2.9.0 beta (2009-04-04 r48290)
* using session charset: ISO8859-1
* checking for file 'longitudinalData/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'longitudinalData' version '0.5'
* package encoding: latin1
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for .dll and .exe files ... OK
* checking whether package 'longitudinalData' can be installed ... OK
* checking package directory ... OK
* checking for portable file names ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated  
dependencies ... OK

* checking for unstated dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd files against version 2 parser ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking examples ... OK
* checking PDF version of manual ... OK


R CMD build longitudinalData
* checking for file 'longitudinalData/DESCRIPTION' ... OK
* preparing 'longitudinalData':
* checking DESCRIPTION meta-information ... OK
* removing junk files
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building 'longitudinalData_0.5.tar.gz'
--- 8< 

Christophe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Cairo Package Installation

2009-06-09 Thread Douglas M. Hultstrand
I am trying to install the Cairo package on a linux machine, the Cairo 
package did not install correctly (could not find cairo.h), I am new to 
R and linux any help on the installation would be great.  Below are 
output from trying to install the Cairo package, thought this might help.


> install.packages("Cairo")
Warning in install.packages("Cairo") :
 argument 'lib' is missing: using 
'/home/tyep/R/x86_64-unknown-linux-gnu-library/2.8'
trying URL 
'http://streaming.stat.iastate.edu/CRAN/src/contrib/Cairo_1.4-4.tar.gz'

Content type 'application/x-gzip' length 75200 bytes (73 Kb)
opened URL
==
downloaded 73 Kb

* Installing *source* package 'Cairo' ...
checking for gcc... gcc -std=gnu99
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for pkg-config... /usr/bin/pkg-config
checking whether pkg-config knows about cairo... no
configure: CAIRO_LIBS is unset, attempting to guess it.
configure: CAIRO_CFLAGS=
checking if R was compiled with the RConn patch... no
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h! Please install cairo 
(http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS

correspondingly.
ERROR: configuration failed for package 'Cairo'
** Removing '/home/tyep/R/x86_64-unknown-linux-gnu-library/2.8/Cairo'

The downloaded packages are in
   /tmp/RtmpILmmXw/downloaded_packages
Warning message:
In install.packages("Cairo") :
 installation of package 'Cairo' had non-zero exit status
>

Thanks,
Doug

--
-
Douglas M. Hultstrand, MS
Senior Hydrometeorologist
Metstat, Inc. Windsor, Colorado
voice: 970.686.1253
email: dmhul...@metstat.com
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.


Re: [R] "R CMD check" does not find a mistake

2009-06-09 Thread Henrik Bengtsson
"using R version 2.9.0 beta (2009-04-04 r48290)"

As a start, Kurt et al. are for sure using a much more recent version
(probably also the very latest patched version).

/H

On Tue, Jun 9, 2009 at 7:17 AM, Christophe
Genolini wrote:
> Hi the list,
>
> I build a package. They was a mistake in it, but R CMD check did not find
> it. Is that normal ?
>
> Here is what Kurt gets (which is right, I did this mistake):
>
> --- 8< 
> * checking for code/documentation mismatches ... WARNING
> S4 class codoc mismatches from documentation object 'LongData-class':
> Slots for class 'LongData'
>  Code: id other time traj varName
>  Docs: id time traj varName
> --- 8< 
>
> But here is what I get :
>
> --- 8< 
> R CMD check longitudinalData
> * checking for working pdflatex ... OK
> * using log directory 'C:/Documents and Settings/Christophe/Mes
> documents/Recher
> che/Trajectoires/kmeal/longitudinalData.Rcheck'
> * using R version 2.9.0 beta (2009-04-04 r48290)
> * using session charset: ISO8859-1
> * checking for file 'longitudinalData/DESCRIPTION' ... OK
> * checking extension type ... Package
> * this is package 'longitudinalData' version '0.5'
> * package encoding: latin1
> * checking package dependencies ... OK
> * checking if this is a source package ... OK
> * checking for .dll and .exe files ... OK
> * checking whether package 'longitudinalData' can be installed ... OK
> * checking package directory ... OK
> * checking for portable file names ... OK
> * checking DESCRIPTION meta-information ... OK
> * checking top-level files ... OK
> * checking index information ... OK
> * checking package subdirectories ... OK
> * checking R files for non-ASCII characters ... OK
> * checking R files for syntax errors ... OK
> * checking whether the package can be loaded ... OK
> * checking whether the package can be loaded with stated dependencies ... OK
> * checking for unstated dependencies in R code ... OK
> * checking S3 generic/method consistency ... OK
> * checking replacement functions ... OK
> * checking foreign function calls ... OK
> * checking R code for possible problems ... OK
> * checking Rd files ... OK
> * checking Rd files against version 2 parser ... OK
> * checking Rd cross-references ... OK
> * checking for missing documentation entries ... OK
> * checking for code/documentation mismatches ... OK
> * checking Rd \usage sections ... OK
> * checking examples ... OK
> * checking PDF version of manual ... OK
>
>
> R CMD build longitudinalData
> * checking for file 'longitudinalData/DESCRIPTION' ... OK
> * preparing 'longitudinalData':
> * checking DESCRIPTION meta-information ... OK
> * removing junk files
> * checking for LF line-endings in source and make files
> * checking for empty or unneeded directories
> * building 'longitudinalData_0.5.tar.gz'
> --- 8< 
>
> Christophe
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] is it possible to combine multiple barplots?

2009-06-09 Thread Titus von der Malsburg
On Tue, Jun 09, 2009 at 04:39:29PM +0200, Titus von der Malsburg wrote:
> > is there a way to plot both of them in one plot, so that the bars for
> > value "1" (dataA: 3, dataB: 5) would appear side by side, followed by
> > the bars for value 2 etc.?

Oh, I see you want something different.  I should've read your message
more closely.

I found this example in the gallery:

http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=54

Maybe it's close enough to what you want to do.

  Titus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] is it possible to combine multiple barplots?

2009-06-09 Thread Titus von der Malsburg

You can use barchart in package lattice.  Here's a rough sketch:

library(lattice)

dataA <- rep(1:4, c(3,2,2,4))
dataB <- rep(1:4, c(5,4,3,2))

da <- data.frame(table(dataA))
db <- data.frame(table(dataB))

da$cond <- "a"
db$cond <- "b"

colnames(da)[1] <- "data"
colnames(db)[1] <- "data"

d <- rbind(da, db)
barchart(Freq~data|cond, d)

Titus

On Tue, Jun 09, 2009 at 04:23:32PM +0200, Philipp Schmidt wrote:
> i am working with two sets of likert scale type (4 distinct values) data:
> 
> dataA <- rep(1:4, c(3,2,2,4))
> dataB <- rep(1:4, c(5,4,3,2))
> 
> i can now (bar)plot both of these separately and compare the distributions.
> 
> plot(table(dataA), type='h')
> plot(table(dataB), type='h')
> 
> is there a way to plot both of them in one plot, so that the bars for
> value "1" (dataA: 3, dataB: 5) would appear side by side, followed by
> the bars for value 2 etc.?
> 
> thanks!
> 
> best - P
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Isolating a single plot from plots produced simultaneously

2009-06-09 Thread Laura Bonnett
Dear R-Help,

I am using the 'mfp' package.  It produces three plots (as I am using
the Cox model) simultaneously which can be viewed together using the
following code:

fit <- 
mfp(Surv(rem.Remtime,rem.Rcens)~fp(age)+strata(rpa),family=cox,data=nearma,select=0.05,verbose=TRUE)
par(mfrow=c(2,2))
plot(fit)

They can be viewed separately but the return key must be pressed after
each graph appears (Click or hit ENTER for next page).

I'd like to isolate the second plot produced (the estimated functional
form of the influence of age on the log relative hazard) so that I can
use the 'points' function to add the linear predictors for the
untransformed and the log-transformed models.  In the usual situation
one would produce a plot and then type:

coxfitu <- coxph(Surv(rem.Remtime,rem.Rcens)~age+strata(rpa),data=nearma)
points(coxfitu$linear.predictor,col=2)
coxfitl <- coxph(Surv(rem.Remtime,rem.Rcens)~log(age)+strata(rpa),data=nearma)
points(coxfitl$linear.predictor,col=3)

Can anyone tell me how to isolate just the second plot produced?

Thank you for your help,

Laura

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] is it possible to combine multiple barplots?

2009-06-09 Thread Philipp Schmidt
i am working with two sets of likert scale type (4 distinct values) data:

dataA <- rep(1:4, c(3,2,2,4))
dataB <- rep(1:4, c(5,4,3,2))

i can now (bar)plot both of these separately and compare the distributions.

plot(table(dataA), type='h')
plot(table(dataB), type='h')

is there a way to plot both of them in one plot, so that the bars for
value "1" (dataA: 3, dataB: 5) would appear side by side, followed by
the bars for value 2 etc.?

thanks!

best - P

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Writing Reports from R in Office Open XML format (ooxmlWeave?)

2009-06-09 Thread Duncan Temple Lang

Yes. We will release a version in the next few weeks
when I have time to wrap it all up.
There is also a Docbook-based version that uses
R extensions to Docbook for authoring structured
documents.

 D.

Tobias Sing wrote:

Dear all,

has someone implemented functionality for writing reports from R in
Office Open XML format (*), similar to what odfWeave does for the ODF
format of OpenOffice? It would be great to have a kind of
"ooxmlWeave" at least for those of us who are forced to work in an
MS ecosystem.

(*) Office Open XML is the default, XML-based, file format for MS
Word: http://en.wikipedia.org/wiki/Office_Open_XML

Kind regards,
  Tobias

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] "R CMD check" does not find a mistake

2009-06-09 Thread Christophe Genolini

Hi the list,

I build a package. They was a mistake in it, but R CMD check did not 
find it. Is that normal ?


Here is what Kurt gets (which is right, I did this mistake):

--- 8< 
* checking for code/documentation mismatches ... WARNING
S4 class codoc mismatches from documentation object 'LongData-class':
Slots for class 'LongData'
 Code: id other time traj varName
 Docs: id time traj varName
--- 8< 

But here is what I get :

--- 8< 
R CMD check longitudinalData
* checking for working pdflatex ... OK
* using log directory 'C:/Documents and Settings/Christophe/Mes 
documents/Recher

che/Trajectoires/kmeal/longitudinalData.Rcheck'
* using R version 2.9.0 beta (2009-04-04 r48290)
* using session charset: ISO8859-1
* checking for file 'longitudinalData/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'longitudinalData' version '0.5'
* package encoding: latin1
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for .dll and .exe files ... OK
* checking whether package 'longitudinalData' can be installed ... OK
* checking package directory ... OK
* checking for portable file names ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking for unstated dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd files against version 2 parser ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking examples ... OK
* checking PDF version of manual ... OK


R CMD build longitudinalData
* checking for file 'longitudinalData/DESCRIPTION' ... OK
* preparing 'longitudinalData':
* checking DESCRIPTION meta-information ... OK
* removing junk files
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building 'longitudinalData_0.5.tar.gz'
--- 8< 

Christophe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Writing Reports from R in Office Open XML format (ooxmlWeave?)

2009-06-09 Thread Tobias Sing
Dear all,

has someone implemented functionality for writing reports from R in
Office Open XML format (*), similar to what odfWeave does for the ODF
format of OpenOffice? It would be great to have a kind of
"ooxmlWeave" at least for those of us who are forced to work in an
MS ecosystem.

(*) Office Open XML is the default, XML-based, file format for MS
Word: http://en.wikipedia.org/wiki/Office_Open_XML

Kind regards,
  Tobias

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rpart - the xval argument in rpart.control and in xpred.rpart

2009-06-09 Thread Paolo Radaelli
Usually 10-fold cross validation is performed more than once to get an 
estimate of the misclassification rate thus I thought "number of 
cross-validations" was different from the "number of cross-validation 
groups". So, if I want to perform 10-fold cross-validation more than once 
(say 5) in order to estimate the miscalssification rate I have to run 
xpred.rpart 5 times ?

Thanks
Paolo



I have some problems in understanding the meaning of the xval argument in
the two functions rpart.control and xpred.rpart. In the former it is 
defined
as the number of cross-validations while in the latter it is defined as 
the

number of cross-validation groups.
 It is the same thing.  If xval=10 then the data is divided into 10 
disjoint
groups.  A model is fit with group 1 left out and that model is used to 
predict
the observations in group 1; then a model is fit with group 2 left out; 
then

group 3, ...
  So 10 groups = 10 fits of the model.




Actually I thought that in rpart.control





  Terry Therneau




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rpart - the xval argument in rpart.control and in xpred.rpart

2009-06-09 Thread Terry Therneau
> I have some problems in understanding the meaning of the xval argument in 
> the two functions rpart.control and xpred.rpart. In the former it is defined 
> as the number of cross-validations while in the latter it is defined as the 
> number of cross-validation groups. 

  It is the same thing.  If xval=10 then the data is divided into 10 disjoint 
groups.  A model is fit with group 1 left out and that model is used to predict 
the observations in group 1; then a model is fit with group 2 left out; then 
group 3, ...
   So 10 groups = 10 fits of the model.
   
   
   
Terry Therneau

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] removing elements from a "unit" vector

2009-06-09 Thread Duncan Murdoch

On 6/9/2009 9:02 AM, baptiste auguie wrote:

Dear list,

I'm quite surprised by this,

unit(1:5,"char")[-c(1:2)]
#4char 3char # what's going on??

while I expected something like,


c(1:5)[-c(1:2)]

# 3 4 5

Note that,

unit(1:5,"char")[c(1:2)]

# 1char 2char  # fine

?unit warns about unit.c for concatenating, but also says,

It is possible to subset unit objects in the normal way (e.g., 
unit(1:5,"npc")[2:4])

Am I missing something obvious?


No, I think the grid:::unit.[ method has a bug.  It does the indexing of 
an object x by making sure the indices are integers, then


 class(x) <- NULL
 x <- x[(index - 1)%%this.length + 1]

which assumes that index has positive entries.

Duncan Murdoch



Thanks,

baptiste

sessionInfo()
R version 2.9.0 (2009-04-17) 
i386-apple-darwin8.11.1 


locale:
en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rpart - the xval argument in rpart.control and in xpred.rpart

2009-06-09 Thread Paolo Radaelli

Dear R users,
I'm working with the rpart package and want to evaluate the performance of 
user defined split  functions.
I have some problems in understanding the meaning of the xval argument in 
the two functions rpart.control and xpred.rpart. In the former it is defined 
as the number of cross-validations while in the latter it is defined as the 
number of cross-validation groups. If I am correct this means that for 
xpred.rpart, xval denots the number V of one V-fold cross validation while 
for rpart.control it denotes the number of times that the cross-validation 
is performed. Am I right ? If so, how many subsets compose the learning 
sample when performing one of the xval cross-validations ? Is it a 10-fold 
cross-validation repeated xval=10 times ?

Thank you for your help

Paolo

Paolo Radaelli
Dipartimento di Metodi Quantitativi per le Scienze Economiche ed Aziendali
Facoltà di Economia
Università degli Studi di Milano-Bicocca
Via Bicocca degli Arcimboldi, 8
20126 Milano
Italy
e-mail paolo.radae...@unimib.it
Tel +39 02 6448 3163
Fax +39 02 6448 3105

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 command to join data.frames rows with identical keys?

2009-06-09 Thread Titus von der Malsburg


An example:

> schoolZone1_df <- data.frame(address=101, schoolZone="Sherman")
> schoolZone2_df <- data.frame(address=108, schoolZone="Baker")
> schoolZone_df <- rbind(schoolZone1_df, schoolZone2_df)
> schoolZone_df
  address schoolZone
1 101Sherman
2 108  Baker
> neighborhoodInfo1_df <- data.frame(address=101, squareFootage=2000, 
> lotsize=0.75)
> neighborhoodInfo2_df <- data.frame(address=108, squareFootage=3000, 
> lotsize=1.25)
> neighborhoodInfo_df <- rbind(neighborhoodInfo1_df, neighborhoodInfo2_df)
> neighborhoodInfo_df
  address squareFootage lotsize
1 101  20000.75
2 108  30001.25
> merge(schoolZone_df, neighborhoodInfo_df, by="address")
  address schoolZone squareFootage lotsize
1 101Sherman  20000.75
2 108  Baker  30001.25


  Titus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] removing elements from a "unit" vector

2009-06-09 Thread baptiste auguie

Dear list,

I'm quite surprised by this,

unit(1:5,"char")[-c(1:2)]
#4char 3char # what's going on??

while I expected something like,


c(1:5)[-c(1:2)]

# 3 4 5

Note that,

unit(1:5,"char")[c(1:2)]

# 1char 2char  # fine

?unit warns about unit.c for concatenating, but also says,

It is possible to subset unit objects in the normal way (e.g., 
unit(1:5,"npc")[2:4])

Am I missing something obvious?

Thanks,

baptiste

sessionInfo()
R version 2.9.0 (2009-04-17) 
i386-apple-darwin8.11.1 


locale:
en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 command to join data.frames rows with identical keys?

2009-06-09 Thread Titus von der Malsburg
Have a look at the merge function.

  "Merge two data frames by common columns or row names, or do other
 versions of database _join_ operations."


  Titus

On Tue, Jun 09, 2009 at 05:48:05AM -0700, Jason Rupert wrote:
> 
> I've got two data.frames and, when certain "keys" match,  I would like to add 
> the column values from one data frame to the other data.frame.
> 
> Below I list the two data.frames, i.e. neighborhoodInfo_df, and 
> schoolZone_df.  Based on the "address" key I would like to add the 
> "schoolZone" key to the neighborhoodInfo_df data.frame.  
> 
> By any chance is there an R command to accomplish this in one or two steps.  
> I think I could do this in a "for" loop or something, but think there is 
> might be another way in R to accomplish it smarter.  
> 
> Thanks for any info.  
> 
> 
> neighborhoodInfo1_df<-data.frame(address<-c(101),squareFootage<-c(2000),lotsize<-c(0.75))
> 
> neighborhoodInfo2_df<-data.frame(address<-c(108),squareFootage<-c(3000), 
> lotsize<-c(1.25))
> 
> neighborhoodInfo_df<-rbind(neighborhoodInfo1_df, neighborhoodInfo2_df)
>   
>   
> schoolZone1_df<-data.frame(address<-c(101), schoolZone<-c("Sherman"))
> 
> schoolZone2_df<-data.frame(address<-c(108), schoolZone<-c("Baker"))   
> 
> 
> schoolZone_df<-rbind(schoolZone1_df, schoolZone2_df)
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] (no subject)

2009-06-09 Thread Jason Rupert

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


[R] R command to join data.frames rows with identical keys?

2009-06-09 Thread Jason Rupert

I've got two data.frames and, when certain "keys" match,  I would like to add 
the column values from one data frame to the other data.frame.

Below I list the two data.frames, i.e. neighborhoodInfo_df, and schoolZone_df.  
Based on the "address" key I would like to add the "schoolZone" key to the 
neighborhoodInfo_df data.frame.  

By any chance is there an R command to accomplish this in one or two steps.  I 
think I could do this in a "for" loop or something, but think there is might be 
another way in R to accomplish it smarter.  

Thanks for any info.  


neighborhoodInfo1_df<-data.frame(address<-c(101),squareFootage<-c(2000),lotsize<-c(0.75))

neighborhoodInfo2_df<-data.frame(address<-c(108),squareFootage<-c(3000), 
lotsize<-c(1.25))

neighborhoodInfo_df<-rbind(neighborhoodInfo1_df, neighborhoodInfo2_df)


schoolZone1_df<-data.frame(address<-c(101), schoolZone<-c("Sherman"))
  
schoolZone2_df<-data.frame(address<-c(108), schoolZone<-c("Baker")) 

  
schoolZone_df<-rbind(schoolZone1_df, schoolZone2_df)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Marc Schwartz

On Jun 9, 2009, at 6:44 AM, Mark Heckmann wrote:


Hey all,

Thanks for your help. Your answers solved the problem I posted and  
that is

just when I noticed that I misspecified the problem ;)
My problem is to separate a German texts by sentences. Unfortunately I
haven't found an R package doing this kind of text separation in  
German, so

I try it "manually".

Just using the dot as separator fails in occasions like:
txt <- "One January 1. I saw Rick. He was born in the 19. century."

Here I want the algorithm to separate the string only at the  
positions where
the dot is not preceded by a digit. The R-snippets posted pick out  
"1." and

"19."

txt <- "One January 1. I saw Rick. He was born in the 19. century."

gregexpr('(?<=[0-9])[.]',txt, perl=T)

[[1]]
[1] 14 49
attr(,"match.length")
[1] 1 1

But I just need it the other way round. So I tried:


strsplit(txt, "[[:alpha:]]\\." , perl=T)

[[1]]
[1] "One January 1. I saw Ric"   " He was born in the 19. centur"

But this erases the last letter from each sentence. Does someone  
know a

solution?

TIA
Mark




This is one of those rare? times where it might be nice for strsplit()  
to have an option to retain the split regex at the end of each parsed  
segment, rather than removing it.


There may be a better way, but trying to both avoid a loop over vector  
indices and trying to stay with R functions that use .Internal() for  
speed, you may be able to use something like this:


> strsplit(gsub("([[:alpha:]]\\.)", "\\1*", txt), "\\* *")
[[1]]
[1] "One January 1. I saw Rick."  "He was born in the 19. century."

What I am essentially doing is to add an "*" to the ending of each  
sentence (you can use other characters) such that strsplit() can split  
on that character without affecting the rest of the sentence.  So as  
an intermediate result, you get:


> gsub("([[:alpha:]]\\.)", "\\1*", txt)
[1] "One January 1. I saw Rick.* He was born in the 19. century.*"

which then makes the strsplit() parsing a bit easier. Since both  
strsplit() and grep() use .Internal()s, hopefully this would still be  
reasonably fast. Note that I have strsplit() split on the "*" possibly  
followed by one or more " ", which is required for mid-line splits.


HTH,

Marc Schwartz

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


Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote:
> On Tue, Jun 9, 2009 at 3:04 AM, Wacek
> Kusnierczyk wrote:
>   
>> Gabor Grothendieck wrote:
>> 
>>> On Mon, Jun 8, 2009 at 7:18 PM, Wacek
>>> Kusnierczyk wrote:
>>>
>>>   
 Gabor Grothendieck wrote:

 
> Try this.  See ?regex for more.
>
>
>
>   
>> x <- 'This happened in the 21. century." (the dot behind 21 is'
>> regexpr("(?![0-9]+)[.]", x, perl = TRUE)
>>
>>
>> 
> [1] 24
> attr(,"match.length")
> [1] 1
>
>
>   
 yes, but

gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
# 2 5 9

 
>>> Yes, it should be:
>>>
>>>
>>>   
 gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRU
 
> E)
>   
>>> [[1]]
>>> [1] 5 9
>>> attr(,"match.length")
>>> [1] 1 1
>>>
>>> which displays the position of every dot that is preceded
>>> immediately by a digit.  Or just replace gregexpr with regexpr
>>> if its intended that it match only one.
>>>
>>>   
>> i guess what was needed was something like
>>
>>gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>># 5
>>
>> which won't work, however, because pcre does not support variable-width
>> lookbehinds.
>> 
>
> No, what I wrote was what I intended.   I don't think we are
> discussing the answer
> at this point but just the interpretation of what was intended.  


which amounts to discussing whether the answer is appropriate ;)

> You
> are including
> the word boundary in the question and I am not.  

indeed, and i think this was essential.  but irrespectively of whether
it really was or not, this sort of problem shows the insufficiency of a
lookbehind, and illustrates the use of the \K operator, so it will
hopefully be easier for the op and others to design the right pattern in
similar future cases.

vQ

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Gabor Grothendieck
On Tue, Jun 9, 2009 at 3:04 AM, Wacek
Kusnierczyk wrote:
> Gabor Grothendieck wrote:
>> On Mon, Jun 8, 2009 at 7:18 PM, Wacek
>> Kusnierczyk wrote:
>>
>>> Gabor Grothendieck wrote:
>>>
 Try this.  See ?regex for more.



> x <- 'This happened in the 21. century." (the dot behind 21 is'
> regexpr("(?![0-9]+)[.]", x, perl = TRUE)
>
>
 [1] 24
 attr(,"match.length")
 [1] 1


>>> yes, but
>>>
>>>    gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>>>    # 2 5 9
>>>
>>
>> Yes, it should be:
>>
>>
>>> gregexpr('(?<=[0-9])[.]', 'a. 1. a1.', perl=TRU
E)
>>>
>> [[1]]
>> [1] 5 9
>> attr(,"match.length")
>> [1] 1 1
>>
>> which displays the position of every dot that is preceded
>> immediately by a digit.  Or just replace gregexpr with regexpr
>> if its intended that it match only one.
>>
>
> i guess what was needed was something like
>
>    gregexpr('(?<=\\b[0-9]+)[.]', 'a. 1. a1.', perl=TRUE)
>    # 5
>
> which won't work, however, because pcre does not support variable-width
> lookbehinds.

No, what I wrote was what I intended.   I don't think we are
discussing the answer
at this point but just the interpretation of what was intended.  You
are including
the word boundary in the question and I am not.  I think its also possible that
regexpr is what is wanted, not gregexpr, but at this point I think the
poster has
enough answers that he can complete it himself by considering what he wants
and using one of ours or a suitable modification.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Splicing factors without losing levels

2009-06-09 Thread Titus von der Malsburg
On Tue, Jun 09, 2009 at 11:23:36AM +0200, ONKELINX, Thierry wrote:
> For factors, you better convert them first back to character strings.
> 
>   splice <- function(x, y) {
>   x <- levels(x)[x]
>   y <- levels(y)[y]
>   factor(as.vector(rbind(x, y)))
>   } 

Thank you very much, Thierry!

I failed to mention something important in my last mail: x and y have
the same levels.  (I assume that the integer to level name mapping of
a factor defines its class and that it only makes sense to combine
factors of the same class.)

Say

> x <- factor(c(2,2,4,4), levels=1:4, labels=c("a","b","c","d"))

then

> x
[1] b b d d
Levels: a b c d

> as.integer(x)
[1] 2 2 4 4

but

> splice(x,x)
[1] b b b b d d d d
Levels: b d

> as.integer(splice(x,x))
[1] 1 1 1 1 2 2 2 2

I'd like to have a splice function that retains the level to label
mapping.  One candidate for a solution is:

splice <- function(x,y) {
  xy <- as.vector(rbind(x, y))
  if (is.factor(x) && is.factor(y))
xy <- factor(xy, levels=1:length(levels(x)), labels=levels(x))
  xy
}

However, this relies on assumtions about the implementation of
factors that are neither mentioned nor guaranteed in the man page:
Levels are underlyingly integers starting from one and going to
length(levels).  levels(x) gives me the labels of these integers in an
order corresponding to 1:length(levels(x)).

Without these assumptions I see no way to recover the integer to level
name mapping for levels that are defined in a factor but do not occur.

I'd be happy if somebody could clarify this issue!

  Titus

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


  1   2   >