Re: [R] Overview of error and warning messages for teaching + examples

2009-09-30 Thread Tal Galili
It would best be there - I agree.

But since I had no experience with the site - I didn't know the "rules of
use" for it.

Thanks for clarifying.
Tal


--


My contact information:
Tal Galili
E-mail: tal.gal...@gmail.com
Phone number: 972-52-7275845
FaceBook: Tal Galili
My Blogs:
http://www.talgalili.com (Web and general, Hebrew)
http://www.biostatistics.co.il (Statistics, Hebrew)
http://www.r-statistics.com/ (Statistics,R, English)




On Thu, Oct 1, 2009 at 4:14 AM, Ben Bolker  wrote:

> Tal Galili  gmail.com> writes:
>
> >
> > Hi Joris,
> >
> > Good luck with your work.
> >
> > I know how to set up a wiki. But I wouldn't do it for just 1 page. And
> also,
> > if you have little experience with it - I am not sure you would find it
> easy
> > to "jump" into it.
> > I'll have a look around to see what other collaborative tools there are
> out
> > there.
> >
>
>   Remind me why this shouldn't just be done on the official R
> wiki, wiki.r-project.org ??
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Minimum and blanks

2009-09-30 Thread Peter Ehlers

Chris,

What is your definition of the minimum of a *character* vector?

 -Peter Ehlers

Chris Li wrote:

Hi all,

I want to calculate the minimum of a column which contains blanks.

R returns "" as the minimum, which is not I want.

Is there a way to overcome it?

Thanks in advance.
Chris


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


[R] aproximate a titration kurve to the measure data.

2009-09-30 Thread awayguy

Halo

i'm studying chemistry, today we made an experiment and i have to draw a
titration kurve for my mess data. we can do it on a mm paper, or we can also
use a programe. people from chemistry recomend "R"
last year i studied civil eng. and we used Matlab, as I see, R ist very
similar to it, but its got other comands.
But i think R would be a good help for some exercises.

so my main question is: i have some measurement data from my titration, and
I want aproximate a kurve to this data. is it possible to do it with R?

a titration kurve looks like this:

http://www.nabble.com/file/p25685986/acetic-acid-titration-curve.png 

hope you can help me, and yes when its possible, if you know something like
a tutorial then i would be glad if you could post it.

with regards
-- 
View this message in context: 
http://www.nabble.com/aproximate-a-titration-kurve-to-the-measure-data.-tp25685986p25685986.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] re ading and analyzing a word document

2009-09-30 Thread PDXRugger

Considering your instructions:

#Define words to find
to.find <- c( 'the', 'is', 'are' ,'dr') 
#Read in the file... 
file.text <- readLines( 'data/letter.txt' ) 
#Count number of occurnces of deined word in text
line.matches <- unlist( lapply( to.find, grep, x = unlist(file.text[2]) ) ) 

Result:
> line.matches 
[1] 1 1 1

This is not right of course as there are actually four words and secondly
becasue the searched words appear multiple times.  

I think the problem is that the file.text is coming in so that file.text[2]
<-""\tHello sir, I write to you seeking your guidance organizing some data. 
I have a ." So its reading the document its just putting them into this
type of format.  Im stuck, i tried doing it by saving the doc to a csv and
searching strings, tried using a match process.   It would also be useful to
simply get a run down similar to a summary expressing the most common words. 
Ideas? 



cls59 wrote:
> 
> 
> PDXRugger wrote:
>> 
>> Howdy Y'all, 
>> 
>> So i am looking to read a word document in the following formats(.doc) or
>> any type of accessible word processor software (e.g. text .txt, notepad,
>> etc).  Had the ability to search certain words, for instance "banana",
>> "peacock","Weapons" "Mass" "Destruction".  Then i could summarize and
>> view the results.  i looked and the only thing i could find was the below
>> where i want to analyze "letter.doc" and look for the words mentioned in
>> quotes above.  Its aparently wrong but im wondering if this is even
>> possible.  Please advise.  Thanks 
>> 
>> In Solidarity
>> JR
>> 
> 
> Well... you could make a vector of the words you want to find:
> 
> to.find <- c( 'banana', 'peacock', 'Weapons' )
> 
> Read in the file...
> 
> file.text <- readLines( 'myFile.txt' )
> 
> And recursively apply the grep command in order to determine which lines
> contain matches for your words:
> 
> line.matches <- unlist( lapply( to.find, grep, x = file.text ) )
> 
> It may do what you want for plain text files, as for Microsoft Word
> files... well...
> 
> Sometimes there is a price to pay for using a closed proprietary binary
> document format.
> 
> Good luck!
> 
> -Charlie
> 

-- 
View this message in context: 
http://www.nabble.com/reading-and-analyzing-a-word-document-tp25691972p25692751.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] Input format for kcca in kernlab

2009-09-30 Thread Guru Ananda

Hi,

I'm trying to use kcca function from the kernlab package, and it requires 2
input datasets, both of which need to be matrices containing data index by
row.
I have two data frame objects which I converted to matrices using
data.frame(x). Their dimensions are 2264*10 and 2264*4. I then tried running
kcca on the two data matrices, only to get this error: Error in kcca(xm, ym)
: Number of colums in x, y matrixes is not equall
Does anyone know why I'm encountering this error? 
Also, just to make the number of columns equal, I transposed my two data
matrices, and reran kcca, on which I got a different error message: Error in
VK[(n + 1):(2 * n), ] <- Ky : number of items to replace is not a multiple
of replacement length

I'm not sure how to proceed further. Any help would be greatly appreciated.

Thanks,
Guru.
-- 
View this message in context: 
http://www.nabble.com/Input-format-for-kcca-in-kernlab-tp25683222p25683222.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] re ading and analyzing a word document

2009-09-30 Thread PDXRugger

file=("LUSDR/letter.doc")
Howdy Y'all, 


So i am looking to read a word document in the following formats(.doc) or
any type of accessible word processor software (e.g. text .txt, notepad,
etc).  Had the ability to search certain words, for instance "banana",
"peacock","Weapons" "Mass" "Destruction".  Then i could summarize and view
the results.  i looked and the only thing i could find was the below where i
want to analyze "letter.doc" and look for the words mentioned in quotes
above.  Its aparently wrong but im wondering if this is even possible. 
Please advise.  Thanks 

In Solidarity
JR

cat"banana", "peacock","Weapons" "Mass" "Destruction"
file=("letter.doc"),sep="\n")
readLines(file, n=-1)
unlink("letter.doc") # tidy up
## difference in blocking
cat("123\nabc", file = "test1")
readLines("test1") # line with a warning
a=con <- file("test1", "r", blocking = FALSE)
readLines(con) # empty
cat(" def\n", file = "test1", append = TRUE)
readLines(con) # gets both
close(con)
unlink("test1") # tidy up

-- 
View this message in context: 
http://www.nabble.com/reading-and-analyzing-a-word-document-tp25691972p25691972.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] Calling R functions into C# or C++

2009-09-30 Thread fayssal

Hi,

It is possible to call R functions from .NET by using a .NET wrapper over
the R (D)Com server.  http://www.nabble.com/file/p25682136/RFromCsharp.zip
Attached  is a sample C# project that shows how to call R from C#. 

Best Regards,
Fayssal El Moufatich

http://www.nabble.com/file/p25682136/RFromCsharp.zip RFromCsharp.zip 
 

Shubha Vishwanath Karanth wrote:
> 
> Hi R,
> 
>  
> 
> I have a request...
> 
>  
> 
> Can I call R functions/routines from C# or C++? If so, how do I do this?
> Do I need to have some knowledge on DLL to do this?
> 
>  
> 
>  
> 
> Thanks a lot for your help,
> 
> Shubha
> 
> Shubha Karanth | Amba Research
> 
> Ph +91 80 3980 8031 | Mob +91 94 4886 4510 
> 
> Bangalore * Colombo * London * New York * San José * Singapore *
> www.ambaresearch.com
> 
>  
> 
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Calling-R-functions-into-C--or-C%2B%2B-tp17998762p25682136.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] Confidence intervals PLS prediction

2009-09-30 Thread lievelaurens

I have switched from The Unscrambler to R for pls regression analysis and
have been able to calculate scores, coefficients, RMSEP from a large number
of PLS1 and PLS2 models. The ultimate goal is to use these models for
predicting unknown samples, which again is straight-forward with the
built-in predict() function. However, I’m struggling with prediction
uncertainty (i.e. confidence intervals) on predicted values (as an estimate
on the reliability of the predicted values). 

Has anyone looked into and/or developed an algorithm or function that
calculates the prediction uncertainty? In order to report on the accuracy
and reliability of the predicted values, we need to report on the yDeviation
(as in
http://www.camo.com/TheUnscrambler/Appendices/The%20Unscrambler%20Method%20References.pdf
on page 31). I have extensively read and searched the available literature
on plsr, mvr, predict, etc. as well as the Nabble forums but I couldn't find
any reference to this kind of uncertainty values.

I am considering writing my own function for this, but if this has already
been addressed, it would be most helpful and would save me a lot of time.

Thanks,

Lieve Laurens, PhD
National Renewable Energy Laboratory
Golden, CO 80401
-- 
View this message in context: 
http://www.nabble.com/Confidence-intervals-PLS-prediction-tp25691532p25691532.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] Minimum and blanks

2009-09-30 Thread Chris Li

Hi all,

I want to calculate the minimum of a column which contains blanks.

R returns "" as the minimum, which is not I want.

Is there a way to overcome it?

Thanks in advance.
Chris
-- 
View this message in context: 
http://www.nabble.com/Minimum-and-blanks-tp25692189p25692189.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] xyplot key

2009-09-30 Thread Andrewjohnclose

Hi,

I'm having trouble matching the symbols/color of the key to match those
specifiec in the plot.

Here is the code I used:


xyplot(GCR+GCT ~ FRAC, data=RWF, type=c("g","p"),cex=1.2,pch=c(22,21),
xlab=expression(italic("f")),ylab=expression(italic("S")),
key=list(points=list(pch=c(22,21),cex=1.2),
text=list(c("Targeted Deletion","Random Deletion"

I'm, sorry if this is an apparently easy/obvious mistake on my part.

With thanks

Andrew

http://www.nabble.com/file/p25681535/RWF.csv RWF.csv 
-- 
View this message in context: 
http://www.nabble.com/xyplot-key-tp25681535p25681535.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] Missing functions

2009-09-30 Thread Kenny Shen
Hi all,

I'm new to R and have been working hard to get familiarized with it. A
problem I'm facing now is that having installed some packages (psych, doBy),
I can't seem to access the functions even through there was no error
messages when I load them using library(). I get an error telling me the
function doesn't exist. But when I ran e.g. library(help = psych), the
function I want was missing.

I did find that when I load other packages, there will be some
initialisation messages, but loading psych and doBy just brings up the
prompt again with no output.

Any help is greatly appreciated.

Thanks,
Kenny

-- 
-
"A mental model is good. I change mine all the time."

[[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] Off-topic: looking for a categorical, NMAR dataset

2009-09-30 Thread Andrew Robinson
Dear Colleagues,

apologies for this off-topic posting.

A Ph.D. student here at U of Melb. is trying to find a dataset to use
to demonstrate a technique that he is developing.  He needs a binary
response and ideally a categorical predictor, although the latter can
of course be induced from a continuous predictor.  The data should
also have missing values (ideally, NMAR, not missing at random) in the
response and in the predictor.

Of course we could generate such a dataset but it would be preferable
to use a dataset in which handling the missingness is an integral part
of the analysis.

The data set could be in any discipline, ideally already published.

If you have any suggestions, please respond directly to Ken at

Kheang Ken Lim 

Thanks!

Cheers

Andrew

-- 
Andrew Robinson  
Program Manager, ACERA 
Department of Mathematics and StatisticsTel: +61-3-8344-6410
University of Melbourne, VIC 3010 Australia   (prefer email)
http://www.ms.unimelb.edu.au/~andrewpr  Fax: +61-3-8344-4599
http://www.acera.unimelb.edu.au/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Re gression for levels of a factor/xyplot type="r"

2009-09-30 Thread Jorge Ivan Velez
Hi James,
Here is a suggestion:

# Data
set.seed(123)
Factor <- rep(1:4, each = 20)
X <- rnorm(80, 25, 4)
Y <- 5 + 1.5*Factor*X + rnorm(80)
df <- data.frame(X, Y, Factor)

# Splitting df
sdf <- with(df, split(df, Factor))

# betas and R2
do.call(rbind, lapply(sdf, function(miniDF){
 fit <- lm(Y ~ X, data = miniDF)
out <- c(coef(fit), R2 =
summary(fit)$r.squared)
out
}
)
   )

HTH,
Jorge


On Wed, Sep 30, 2009 at 11:10 PM, jimdare <> wrote:

>
> Hi,
>
> I'm sure these are basic problems so I apologise in advance for my
> ignorance.  I have a dataset with X, Y, and a Factor with 4 levels.  I am
> trying to figure out how to use lm() to find the r2 value, slope and
> intercept of an X~Y regression, for each level of the Factor.  Is there a
> way to do this automatically without having to specify different subsets of
> the factor?
>
> my code so far:
>
> Regression<-lm(Y~X, data=dataset, subset=factor(Factor))
>
> Also, when I plot this dataset using:
>
> xyplot(Y~X|factor(Factor), data=dataset, aspect="iso",
> type=c("p","g","r"),pch=21,cex=1)
>
> I get a four panel plot (one for each level of the factor) with a
> regression
> line for each.  How do I figure out the r2 value and coefficients of each
> regression line and add them as text to the plot.
>
> Thanks for your help!
>
> James
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Regression-for-levels-of-a-factor-xyplot-type%3D%22r%22-tp25692526p25692526.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] mvmeta function in GAP package

2009-09-30 Thread Yan Li
Hi,

I am using mvmeta function in GAP package. Could you please tell me the
algorithm applied in this function and the relevant references?

Thanks.

Lee

[[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] Re gression for levels of a factor/xyplot type="r"

2009-09-30 Thread Gabor Grothendieck
See lmList in the lme4 package.  Each component of the result will be
one lm and you can take a summary of each.

On Wed, Sep 30, 2009 at 11:10 PM, jimdare  wrote:
>
> Hi,
>
> I'm sure these are basic problems so I apologise in advance for my
> ignorance.  I have a dataset with X, Y, and a Factor with 4 levels.  I am
> trying to figure out how to use lm() to find the r2 value, slope and
> intercept of an X~Y regression, for each level of the Factor.  Is there a
> way to do this automatically without having to specify different subsets of
> the factor?
>
> my code so far:
>
> Regression<-lm(Y~X, data=dataset, subset=factor(Factor))
>
> Also, when I plot this dataset using:
>
> xyplot(Y~X|factor(Factor), data=dataset, aspect="iso",
> type=c("p","g","r"),pch=21,cex=1)
>
> I get a four panel plot (one for each level of the factor) with a regression
> line for each.  How do I figure out the r2 value and coefficients of each
> regression line and add them as text to the plot.
>
> Thanks for your help!
>
> James
>
>
>
> --
> View this message in context: 
> http://www.nabble.com/Regression-for-levels-of-a-factor-xyplot-type%3D%22r%22-tp25692526p25692526.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] re ading and analyzing a word document

2009-09-30 Thread cls59



PDXRugger wrote:
> 
> Considering your instructions:
> 
> #Define words to find
> to.find <- c( 'the', 'is', 'are' ,'dr') 
> #Read in the file... 
> file.text <- readLines( 'data/letter.txt' ) 
> #Count number of occurnces of deined word in text
> line.matches <- unlist( lapply( to.find, grep, x = unlist(file.text[2]) )
> ) 
> 
> Result:
>> line.matches 
> [1] 1 1 1
> 
> This is not right of course as there are actually four words and secondly
> becasue the searched words appear multiple times.  
> 
> 

The example I gave was only meant to identify those lines on which matches
occurred. Using x = unlist(file.text[2]) only feeds one line of the file
into the matching routine so the result indicates that all the matches were
on line 1-- the only line present for searching.

If you want to count the individual occurrences of the words on each line,
you may need to look at using a function such as gregexpr. grep only
indicates if a match or matches is present in a line of text-- gregexpr
indicates at which positions those matches occur in the line.

However, you may be getting to the point with this where R is no longer an
appropriate tool for this job. R is amazingly flexible it is possible that
it can give you what you want. However, R was not designed to perform text
processing-- Perl comes to mind as being a language that was explicitly
designed to perform these sorts of operations.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/reading-and-analyzing-a-word-document-tp25691972p25692881.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] R package for visualizing/analyzing accelerometry data?

2009-09-30 Thread spencerg

library(sos)
a <- ???accelerometry # no matches
d3 <- ???'3D' # 411 matches;  retrieved 20 pages 400 matches
d3 <- ???'3D'(99)  # retrieved all 411 matches
summary(d3) # first 13 of 144 packages
findFn2xls(d3) # write d3.xls containing sheets PackageSum2, findFn, call
installPackages(d3) # install missing packages with at least 4 matches
findFn2xls(d3) # write d3.xls with a more complete PackageSum2


 I also tried, "p3 <- ???'plot 3d'", which also found 411 matches. 



 Hope this helps. 
 Spencer



Duncan Murdoch wrote:

On 9/29/2009 10:39 PM, Jen Maresh wrote:

Hello All -

Any recommendations or suggestions for neat ways to visualize data
taken from a 3-axis accelerometer? My study species is aquatic, so I
would be interested in movement in the 3 dimensions in addition to
being able to incorporate the time series as well. Is there a package
in R that might be useful for this?


As David mentioned, rgl can draw 3D figures, but the problem of 
visualizing a 3D path in an informative way is not easy.  The new 
cylinder3d function in rgl might give paths that are easier to decode 
visually than line segments would be; it also offers the possibility 
of encoding orientation in the shape of the cylinder.  I'd be 
interested in hearing how this goes.


Duncan Murdoch

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

and provide commented, minimal, self-contained, reproducible code.




--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Re gression for levels of a factor/xyplot type="r"

2009-09-30 Thread jimdare

Hi,  

I'm sure these are basic problems so I apologise in advance for my
ignorance.  I have a dataset with X, Y, and a Factor with 4 levels.  I am
trying to figure out how to use lm() to find the r2 value, slope and
intercept of an X~Y regression, for each level of the Factor.  Is there a
way to do this automatically without having to specify different subsets of
the factor?

my code so far:

Regression<-lm(Y~X, data=dataset, subset=factor(Factor))

Also, when I plot this dataset using:

xyplot(Y~X|factor(Factor), data=dataset, aspect="iso",
type=c("p","g","r"),pch=21,cex=1)

I get a four panel plot (one for each level of the factor) with a regression
line for each.  How do I figure out the r2 value and coefficients of each
regression line and add them as text to the plot.   

Thanks for your help!

James



-- 
View this message in context: 
http://www.nabble.com/Regression-for-levels-of-a-factor-xyplot-type%3D%22r%22-tp25692526p25692526.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] re ading and analyzing a word document

2009-09-30 Thread cls59


PDXRugger wrote:
> 
> Howdy Y'all, 
> 
> So i am looking to read a word document in the following formats(.doc) or
> any type of accessible word processor software (e.g. text .txt, notepad,
> etc).  Had the ability to search certain words, for instance "banana",
> "peacock","Weapons" "Mass" "Destruction".  Then i could summarize and view
> the results.  i looked and the only thing i could find was the below where
> i want to analyze "letter.doc" and look for the words mentioned in quotes
> above.  Its aparently wrong but im wondering if this is even possible. 
> Please advise.  Thanks 
> 
> In Solidarity
> JR
> 

Well... you could make a vector of the words you want to find:

to.find <- c( 'banana', 'peacock', 'Weapons' )

Read in the file...

file.text <- readLines( 'myFile.txt' )

And recursively apply the grep command in order to determine which lines
contain matches for your words:

line.matches <- unlist( lapply( to.find, grep, x = file.text ) )

It may do what you want for plain text files, as for Microsoft Word files...
well...

Sometimes there is a price to pay for using a closed proprietary binary
document format.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/reading-and-analyzing-a-word-document-tp25691972p25692279.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] matrix exponential

2009-09-30 Thread David Winsemius


On Sep 30, 2009, at 10:14 PM, spencerg wrote:


RSiteSearch('exponential of a matrix')

produced 982 matches.

RSiteSearch('{exponential of a matrix}')

produced 13.




Yes, I know.


David Winsemius wrote:


On Sep 30, 2009, at 9:18 PM, Kon Knafelman wrote:



Hi Guys,

Im trying to find the exponential of a matrix.

Can someone please help me do this?



Didn't we just do this one?




--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567



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] Overview of error and warning messages for teaching + examples

2009-09-30 Thread Ben Bolker
Tal Galili  gmail.com> writes:

> 
> Hi Joris,
> 
> Good luck with your work.
> 
> I know how to set up a wiki. But I wouldn't do it for just 1 page. And also,
> if you have little experience with it - I am not sure you would find it easy
> to "jump" into it.
> I'll have a look around to see what other collaborative tools there are out
> there.
> 

  Remind me why this shouldn't just be done on the official R
wiki, wiki.r-project.org ??

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

2009-09-30 Thread spencerg

RSiteSearch('exponential of a matrix')

 produced 982 matches. 



RSiteSearch('{exponential of a matrix}')

 produced 13. 




David Winsemius wrote:


On Sep 30, 2009, at 9:18 PM, Kon Knafelman wrote:



Hi Guys,

Im trying to find the exponential of a matrix.

Can someone please help me do this?



Didn't we just do this one?




--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

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

2009-09-30 Thread cls59


Kon Knafelman wrote:
> 
> 
> Hi Guys,
> 
> Im trying to find the exponential of a matrix.
> 
> Can someone please help me do this?
> 
> Thanks a lot
>   
> 


There was actually a very recent discussion of this, and related operations.
See:

http://www.nabble.com/implementation-of-matrix-logarithm-%28inverse-of-matrix-exponential%29-ts25628876.html

Also, some good advice for finding a function when you don't know it's name
but you do know what job it performs is to have R search all the help pages
in all the packages you have using the ?? command:

??'matrix exponential'

You will see the expm() function in the base package Matrix if you have a
newish version of R.



David Winsemius wrote:
> 
> 
> Didn't we just do this one?
> 
> 

Well, it was matrix logarithms-- but close enough :P



Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/matrix-exponential-tp25691819p25692117.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] matrix exponential

2009-09-30 Thread David Winsemius


On Sep 30, 2009, at 9:18 PM, Kon Knafelman wrote:



Hi Guys,

Im trying to find the exponential of a matrix.

Can someone please help me do this?



Didn't we just do this one?

--

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.


[R] matrix exponential

2009-09-30 Thread Kon Knafelman

Hi Guys,

 

Im trying to find the exponential of a matrix.

 

Can someone please help me do this?

 

Thanks a lot
  
_
View photos of singles in your area Click Here

=1&lage=18&uage=55&cl=14&sl=0&dist=50&po=1&do=2&trackingid=1046138&r2s=1&_t=773166090&_r=WLM_EndText
[[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] Rounding error in seq(...)

2009-09-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk]
> Sent: Wednesday, September 30, 2009 3:58 PM
> To: Nordlund, Dan (DSHS/RDA)
> Cc: Douglas Bates; r help
> Subject: Re: [R] Rounding error in seq(...)
> 
<<>>
> >
> > The first page of this document references:
> http://www.stats.ox.ac.uk/~ruth/RCourse/Numerics.pdf
> >
> >  ‘The Elements of Programming Style’ by Kernighan and Plauger
> 
> Actually, it cites the R FAQ, Q. 7.31 in extenso...
> 
Right you are Peter.  I just Googled the phrase and looked at the immediate 
context of the phrase, and not much else of the document (since I was looking 
for a Kernighan reference).

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] (windows xp) start script on startup / double clicking on the script

2009-09-30 Thread Gabor Grothendieck
Try creating a Windows batch file along these lines:

setlocal
set R_PROFILE_USER=C:\tmp\myscript.R
"C:\Program Files\R\R-2.9.x\bin\Rgui.exe"
endlocal

and double click it.  The set line sets it up to run your script and
the next line runs R.


On Wed, Sep 30, 2009 at 7:12 PM, Martin Batholdy
 wrote:
> hi,
>
> I am still trying to figure out how it is possible to start an R-script via
> the R-GUI directly by double-clicking on the script file in windows xp.
> On Mac OS I have the option "start script in the editor" in the preferences.
>
> But on windows XP I always get the "ARGUMENT  'c:\...\...'   ___ignored___"
> error when I try to associate the .R extension with the R program file.
>
>
> My problem is that I don't have the possibility to install any other
> programs.
> And the people using the script don't know R.
> So its really important to find a way to start a script just by double
> clicking on the file.
>
>
> Now I was wondering if it is possible to make a shortcut of the R script and
> change the start options.
> I am not familiar with windows - does someone know if that is a possible way
> to get R code to the R console (in the R gui) on startup?
>
> Or any other clues / tips?
>
>
>
>
>
> thanks for any help!
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] (windows xp) start script on startup / double clicking on the script

2009-09-30 Thread Martin Batholdy

hi,

I am still trying to figure out how it is possible to start an R- 
script via the R-GUI directly by double-clicking on the script file in  
windows xp.
On Mac OS I have the option "start script in the editor" in the  
preferences.


But on windows XP I always get the "ARGUMENT  'c:\...\...'
___ignored___" error when I try to associate the .R extension with the  
R program file.



My problem is that I don't have the possibility to install any other  
programs.

And the people using the script don't know R.
So its really important to find a way to start a script just by double  
clicking on the file.



Now I was wondering if it is possible to make a shortcut of the R  
script and change the start options.
I am not familiar with windows - does someone know if that is a  
possible way to get R code to the R console (in the R gui) on startup?


Or any other clues / tips?





thanks for any help!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Peter Dalgaard

Nordlund, Dan (DSHS/RDA) wrote:

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Douglas Bates
Sent: Wednesday, September 30, 2009 3:06 PM
To: Peter Dalgaard
Cc: r help; Duncan Murdoch
Subject: Re: [R] Rounding error in seq(...)

On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard
wrote:

Martin Batholdy wrote:

hum,

can you explain that a little more detailed?
Perhaps I miss the background knowledge - but it seems just absurd to me.

0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?

why is
x <- 0.1 + 0.1 +0.1
not equal to
y <- 0.3

Remember that this is in BINARY arithmetic. It's really not any stranger
than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal arithmetic
(0.3 + 0.3 = 0.6 != 0.7).

In an earlier thread on this theme I believe that someone quoted Brian
Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been
able to track down the quote.  Can anyone point us to such a quote?
It summarizes the situation succinctly,



The first page of this document references: 
http://www.stats.ox.ac.uk/~ruth/RCourse/Numerics.pdf

 ‘The Elements of Programming Style’ by Kernighan and Plauger


Actually, it cites the R FAQ, Q. 7.31 in extenso...

--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Erik Iverson
> In an earlier thread on this theme I believe that someone quoted Brian
> Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been
> able to track down the quote.  Can anyone point us to such a quote?
> It summarizes the situation succinctly,

See FAQ 7.31 :)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Douglas Bates
> Sent: Wednesday, September 30, 2009 3:06 PM
> To: Peter Dalgaard
> Cc: r help; Duncan Murdoch
> Subject: Re: [R] Rounding error in seq(...)
> 
> On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard
> wrote:
> > Martin Batholdy wrote:
> >>
> >> hum,
> >>
> >> can you explain that a little more detailed?
> >> Perhaps I miss the background knowledge - but it seems just absurd to me.
> >>
> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
> >>
> >> why is
> >> x <- 0.1 + 0.1 +0.1
> >> not equal to
> >> y <- 0.3
> >
> > Remember that this is in BINARY arithmetic. It's really not any stranger
> > than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal arithmetic
> > (0.3 + 0.3 = 0.6 != 0.7).
> 
> In an earlier thread on this theme I believe that someone quoted Brian
> Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been
> able to track down the quote.  Can anyone point us to such a quote?
> It summarizes the situation succinctly,
> 

The first page of this document references: 
http://www.stats.ox.ac.uk/~ruth/RCourse/Numerics.pdf

 ‘The Elements of Programming Style’ by Kernighan and Plauger

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread David Winsemius


On Sep 30, 2009, at 6:05 PM, Douglas Bates wrote:

On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard> wrote:

Martin Batholdy wrote:


hum,

can you explain that a little more detailed?
Perhaps I miss the background knowledge - but it seems just absurd  
to me.


0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?

why is
x <- 0.1 + 0.1 +0.1
not equal to
y <- 0.3


Remember that this is in BINARY arithmetic. It's really not any  
stranger
than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal  
arithmetic

(0.3 + 0.3 = 0.6 != 0.7).


In an earlier thread on this theme I believe that someone quoted Brian
Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been
able to track down the quote.  Can anyone point us to such a quote?
It summarizes the situation succinctly,


Number 36 according to this example of "way beyond fair-use":

http://cs.boisestate.edu/~amit/teaching/handouts/style.pdf





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] Rounding error in seq(...)

2009-09-30 Thread Douglas Bates
On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard wrote:
> Martin Batholdy wrote:
>>
>> hum,
>>
>> can you explain that a little more detailed?
>> Perhaps I miss the background knowledge - but it seems just absurd to me.
>>
>> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
>>
>> why is
>> x <- 0.1 + 0.1 +0.1
>> not equal to
>> y <- 0.3
>
> Remember that this is in BINARY arithmetic. It's really not any stranger
> than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal arithmetic
> (0.3 + 0.3 = 0.6 != 0.7).

In an earlier thread on this theme I believe that someone quoted Brian
Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been
able to track down the quote.  Can anyone point us to such a quote?
It summarizes the situation succinctly,

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Overview of error and warning messages for teaching + examples

2009-09-30 Thread Tal Galili
Hi Joris,

Good luck with your work.

I know how to set up a wiki. But I wouldn't do it for just 1 page. And also,
if you have little experience with it - I am not sure you would find it easy
to "jump" into it.
I'll have a look around to see what other collaborative tools there are out
there.

Please let me know of your progress.

Tal








--


My contact information:
Tal Galili
E-mail: tal.gal...@gmail.com
Phone number: 972-52-7275845
FaceBook: Tal Galili
My Blogs:
http://www.talgalili.com (Web and general, Hebrew)
http://www.biostatistics.co.il (Statistics, Hebrew)
http://www.r-statistics.com/ (Statistics,R, English)




On Wed, Sep 30, 2009 at 6:02 PM, joris meys  wrote:

> Hi Tal,
>
> The Wiki is a great idea! Alas I'm not that familiar with setting up
> Wikis. Any idea how to practically approach this?
>
> I'm currently a bit in a hurry, as I have to give the introduction
> next monday. I'll have a first, basic introduction ready by the end of
> the week, but I'll continue to develop a more complete document later
> on. Naturally, this will be available for the internet community too.
> I'll keep you updated.
>
>
> On Wed, Sep 30, 2009 at 5:44 PM, Tal Galili  wrote:
> > Hi Joris.
> > This is a wonderlful idea.
> > I never came across such a document, but assembaling it sounds very good.
> > What do you think about organizing the work of collecting (by R members
> and
> > maybe your students) the error massages and code into some wiki page?
> (maybe
> > on the R wiki)
> > It could be a great work to give to students (go around the mailing list,
> > search for "i got this error massage", and write what the
> > code-problem-solution was).
> >
> > Best,
> > Tal
> >
> >
> >
> >
> > --
> >
> >
> > My contact information:
> > Tal Galili
> > E-mail: tal.gal...@gmail.com
> > Phone number: 972-52-7275845
> > FaceBook: Tal Galili
> > My Blogs:
> > http://www.talgalili.com (Web and general, Hebrew)
> > http://www.biostatistics.co.il (Statistics, Hebrew)
> > http://www.r-statistics.com/ (Statistics,R, English)
> >
> >
> >
> >
> > On Wed, Sep 30, 2009 at 2:50 PM, joris meys  wrote:
> >>
> >> Dear all,
> >>
> >> The background: as I didn't find a manual specifically directed
> >> towards debugging R code on a novice and intermediate level, I decided
> >> to write a student manual myself. I have some basic examples of errors
> >> (the classical interpunction and writing mistakes), but have the
> >> feeling that I miss quite some of the frequently occuring mistakes and
> >> messages. Therefore I'm looking around to find a list of these, and if
> >> possible, some examples of wrong R code.
> >>
> >> I have been googling around a bit, but I couldn't find an overview of
> >> the most common error and warning messages in R. Off course this
> >> mailing list is an extensive source of all kind or errors and
> >> examples, but I was wondering if there is a somewhat more structured
> >> overview. All help appreciated.
> >>
> >> Kind regards
> >> Joris Meys
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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] preformatted and '#' in manual pages

2009-09-30 Thread Gábor Csárdi
On Wed, Sep 30, 2009 at 10:51 PM, Duncan Murdoch  wrote:
> On 9/29/2009 7:31 AM, Gábor Csárdi wrote:
>>
>> Uwe, thanks, but this does not help, I still get:
>>
>> LaTeX errors when creating PDF version.
>> This typically indicates Rd problems.
>> LaTeX errors found:
>> ! You can't use `macro parameter character #' in vertical mode.
>>  ...ike the following: \begin {alltt} ##
>>                                                   vertex1name vertex2name
>> [...
>> l.9051 listed one per line on subsequent lines.}
>>
>> * checking PDF version of manual without index ... ERROR
>>
>> In fact, I added the '\' after the package check failed, but it made
>> no visible difference.
>>
>> Best,
>> Gabor
>
>
> I think this is an inconsistency between LaTeX versions.  On my system, the
> version with no \ on the # works fine, and the documentation for alltt (the
> LaTeX environment used for \preformatted) says it should.
>
> However, R 2.9.2 did add an escape on the #, and that also works fine on my
> system, so I'm going to get R 2.10.0 to add the backslash again. Hopefully
> this will fix things on your system, leave them okay on mine, and not break
> someone else's.

Yep, this sound good, thanks for the help. Btw. it is the LaTeX
version on the windows build service server that gives the error
messages, I haven't tried 2.10.0 on my Linux box yet.

Best,
Gabor

> Duncan Murdoch
>
>> 2009/9/29 Uwe Ligges :
>>>
>>> From Writing R Extensions:
>>>
>>> "‘#’, ‘_’ and ‘&’ must not be escaped."
>>>
>>> Uwe Ligges
>>>
>>>
>>>
>>>
>>>
>>> Gábor Csárdi wrote:

 Dear All,

 I have the following in a .Rd file:
 ...
     human readable (not binary) format. The format itself is like
     the following:
     \preformatted{
       \# vertex1name
       vertex2name [optionalWeight]
       vertex3name [optionalWeight]
     }
     Here, the first vertex of an edge is preceded with a pound sign
 ...

 and it is fine with R 2.9.2, but fails on R-devel, when building the
 PDF version of the manual:
 ...
 * checking PDF version of manual ... WARNING
 LaTeX errors when creating PDF version.
 This typically indicates Rd problems.
 LaTeX errors found:
 ! You can't use `macro parameter character #' in vertical mode.
  ...ike the following: \begin {alltt} ##
                                                  vertex1name vertex2name
 [...
 l.9051 listed one per line on subsequent lines.}

 * checking PDF version of manual without index ... ERROR

 To be precise, this is
 * using R version 2.10.0 Under development (unstable) (2009-09-27
 r49847)

 Is there a way to escape the '#' for LaTeX?

 Thanks,
 Gabor

>>>
>>
>>
>>
>
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] preformatted and '#' in manual pages

2009-09-30 Thread Duncan Murdoch

On 9/29/2009 7:31 AM, Gábor Csárdi wrote:

Uwe, thanks, but this does not help, I still get:

LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! You can't use `macro parameter character #' in vertical mode.
 ...ike the following: \begin {alltt} ##
   vertex1name vertex2name [...
l.9051 listed one per line on subsequent lines.}

* checking PDF version of manual without index ... ERROR

In fact, I added the '\' after the package check failed, but it made
no visible difference.

Best,
Gabor



I think this is an inconsistency between LaTeX versions.  On my system, 
the version with no \ on the # works fine, and the documentation for 
alltt (the LaTeX environment used for \preformatted) says it should.


However, R 2.9.2 did add an escape on the #, and that also works fine on 
my system, so I'm going to get R 2.10.0 to add the backslash again. 
Hopefully this will fix things on your system, leave them okay on mine, 
and not break someone else's.


Duncan Murdoch


2009/9/29 Uwe Ligges :

From Writing R Extensions:

"‘#’, ‘_’ and ‘&’ must not be escaped."

Uwe Ligges





Gábor Csárdi wrote:


Dear All,

I have the following in a .Rd file:
...
 human readable (not binary) format. The format itself is like
 the following:
 \preformatted{
   \# vertex1name
   vertex2name [optionalWeight]
   vertex3name [optionalWeight]
 }
 Here, the first vertex of an edge is preceded with a pound sign
...

and it is fine with R 2.9.2, but fails on R-devel, when building the
PDF version of the manual:
...
* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! You can't use `macro parameter character #' in vertical mode.
 ...ike the following: \begin {alltt} ##
  vertex1name vertex2name
[...
l.9051 listed one per line on subsequent lines.}

* checking PDF version of manual without index ... ERROR

To be precise, this is
* using R version 2.10.0 Under development (unstable) (2009-09-27 r49847)

Is there a way to escape the '#' for LaTeX?

Thanks,
Gabor









__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Ted Harding
On 30-Sep-09 19:32:46, Peter Dalgaard wrote:
> Martin Batholdy wrote:
>> hum,
>> 
>> can you explain that a little more detailed?
>> Perhaps I miss the background knowledge - but it seems just absurd to
>> me.
>> 
>> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
>> 
>> why is
>> x <- 0.1 + 0.1 +0.1
>> not equal to
>> y <- 0.3
> 
> Remember that this is in BINARY arithmetic. It's really not any
> stranger than the fact that 1/3 + 1/3 != 2/3 in finite accuracy
> decimal arithmetic (0.3 + 0.3 = 0.6 != 0.7).

Let me perhaps try to spell it out.
Just as in decimal

  1/7 = 0.142857142857142857142857...

with the sequence 142857 recurring for ever (i.e. 1/7 is not
exactly representable in decimal), so

  1/10 = 0.0001100110011001100110011...

in binary, with the sequence 0011 recurring for ever, so 1/10
is not exactly representable in binary (though of course it is
in decimal). When you write (above) "x <- 0.1 + 0.1 +0.1", you
are writing in decimal. R does not do decimal arithmetic (it
could be implemented in a special package perhaps, as it is
in the Unix program 'bc'; but it isn't there), and instead does
its arithmetic internally in binary. Therefore when you enter

  0.1 + 0.1 + 0.1

R will convert each "0.1" into an internal binary representation,
and add these up. On the other hand, when you enter "Y <- 0.3",
R will convert 0.3 into an internal binary representation which
is NOT identical to the result of adding up the three internal
representations of "0.1". These internal representations are to
a fixed number of binary places.

Example in R:
The binary fraction 0.0001100 is (1/2^4 + 1/2^5) (and these are fine
since they are reciprocals of power of 2 and so exactly represented).
The next chunk in the expansion of 1/10 is 0.00011001100 which is
the above, plus 1/16 of itself. And 0.000110011001100 is the above
plus 1/16 plus 1/16^2 of itself, and so on ...

Code:
  M<-1; k<-1/16
  for(i in (1:14)){
print((1/2^4 + 1/2^5)*M, 17)
M<-M+k; k<-k/16
  }
# [1] 0.09375
# [1] 0.099609375
# [1] 0.0999755859375
# [1] 0.0847412109375
# [1] 0.099046325684
# [1] 0.099940395355
# [1] 0.0627471
# [1] 0.09767169
# [1] 0.09985448
# [1] 0.00905
# [1] 0.0943
# [1] 0.09964
# [1] 0.1
# [1] 0.1

(with no further change to 17 decimal places).

Now let's do "0.1 + 0.1 + 0.1" explicitly in binary arithmetic
(to, say, 27 binary places throughout):

  0.000110011001100110011001100 * see below
+ 0.000110011001100110011001100 * see below
---
  0.001100110011001100110011000
+ 0.000110011001100110011001100 * see below
---
  0.010011001100110011001100100
===

which is incorrect, since the last 2 binary digits in the result
should be "10", not "00". The reason is that the next 2 digits in
the truncated representation of 1/10, at the three places marked "*"
above, are "11", and these would get added in if they had been
present. But they are not present, because of truncation, and so
do not get added in. To 27 binary places, the correct representation
of 3/10 (truncated to 27 binary places)is

  0.010011001100110011001100110

Hence (omitting various further details ... )

  3/10 == (1/10+1/10+1/10)
  # [1] FALSE

Because of the cumulative effects of truncation errors like the
above, and rounding errors which can also be introduced along the way,
the method

 (1:9)/10   or 0.1*(1:9)

is better, since each term only acquires error from the specific
arithmetic operation which gives rise to it, and these errors do
not accumulate.

PS: I'm aware of all the grandmothers on the list who do not need
instruction in ovisuction, but this sort of question occurs so
frequently -- and is not spelled out in detail in the docs -- that I
thought it would be useful to actually exhibit an example of the
working for the benefit of people who do wonder just what is going
on then things do not seem to match up as expected!

Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 30-Sep-09   Time: 21:53:25
-- XFMail --

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


Re: [R] A point in a vector?

2009-09-30 Thread David Winsemius


On Sep 30, 2009, at 4:10 PM, Corrado wrote:


Dear list,

I have a strange requirement  I have a vector, for example v<-
c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x<- 4.8.

I would like to understand in which sub interval of v is x. In this  
case, v
would be in the sub interval [4,6] that is in the subinterval  
starting from

element j=7 to the element j+1=8.


sum(x > v)

> v[sum(x > v)]
[1] 4
> v[sum(x > v)+1]
[1] 6



Can we do that with an R command?


--
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] Rounding error in seq(...)

2009-09-30 Thread Duncan Murdoch

On 9/30/2009 3:59 PM, Ista Zahn wrote:

For my own edification more than anything (I never took computer science): is


a = seq(0.1,0.9,by=0.1)
a <- as.character(a)
a[3] == "0.3"

[1] TRUE

safe?


No.  Someone might be in a locale where the comma is used as the decimal 
separator.  Take a look at your code after options(OutDec=",") to see 
the result.


> options(OutDec=",")
> 0.3
[1] 0,3
> a = seq(0.1,0.9,by=0.1)
> a <- as.character(a)
> a[3] == "0.3"
[1] FALSE

You'd have better luck with a[3] == as.character(0.3), but you should 
use all.equal(), that's what it is designed for.


Duncan Murdoch



-Ista

On Wed, Sep 30, 2009 at 3:46 PM, cls59  wrote:



Martin Batholdy wrote:


hum,

can you explain that a little more detailed?
Perhaps I miss the background knowledge - but it seems just absurd to
me.

0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?




Unfortunately this comes as an utter shock to many people who never take a
Computer Science course. I watch it nail engineering students all the time.

Basically, if you have a fraction and the denominator is not equal to 2^n
for some integer n, that fraction will NEVER be stored as an exact "floating
point" number-- instead it will contain some error due to concessions that
must be made in order to use an efficient binary number scheme.

These errors are generally small, but they do propagate-- especially if you
are carrying the same numbers through a large computation. A good example is
large-scale numerical solutions to nonlinear problems where iterative
algorithms are employed repetitively at each solution step. As the
calculation progresses the roundoff error can rot away the computational
soundness of the algorithm.

If this concerns you, I would suggest reading up on common internal
representations of floating point numbers as well as the propagation of
roundoff error.

At the very least I hope this revelation will instill an appropriate sense
of paranoia concerning the numbers calculated by those magic boxes sitting
on our desks.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
--
View this message in context: 
http://www.nabble.com/Rounding-error-in-seq%28...%29-tp25686630p25687626.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] A point in a vector?

2009-09-30 Thread baptiste auguie
Hi,

assuming v is sorted, try this,

v[ findInterval(x,v)+0:1 ]

see ?findInterval and perhaps ?cut

HTH,

baptiste



2009/9/30 Corrado :
> Dear list,
>
> I have a strange requirement  I have a vector, for example v<-
> c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x<- 4.8.
>
> I would like to understand in which sub interval of v is x. In this case, v
> would be in the sub interval [4,6] that is in the subinterval starting from
> element j=7 to the element j+1=8.
>
> Can we do that with an R command?
>
> Regards
> --
> Corrado Topi
>
> Global Climate Change & Biodiversity Indicators
> Area 18,Department of Biology
> University of York, York, YO10 5YW, UK
> Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] A point in a vector?

2009-09-30 Thread Henrique Dallazuanna
Try this:

v[findInterval(x, v) + 0:1]

On Wed, Sep 30, 2009 at 5:10 PM, Corrado  wrote:
> Dear list,
>
> I have a strange requirement  I have a vector, for example v<-
> c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x<- 4.8.
>
> I would like to understand in which sub interval of v is x. In this case, v
> would be in the sub interval [4,6] that is in the subinterval starting from
> element j=7 to the element j+1=8.
>
> Can we do that with an R command?
>
> Regards
> --
> Corrado Topi
>
> Global Climate Change & Biodiversity Indicators
> Area 18,Department of Biology
> University of York, York, YO10 5YW, UK
> Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] A point in a vector?

2009-09-30 Thread Corrado
Dear list,

I have a strange requirement  I have a vector, for example v<-
c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x<- 4.8. 

I would like to understand in which sub interval of v is x. In this case, v 
would be in the sub interval [4,6] that is in the subinterval starting from 
element j=7 to the element j+1=8.

Can we do that with an R command?

Regards
-- 
Corrado Topi

Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 can I use event.chart (Hmisc) to work with a single row of data?

2009-09-30 Thread George Chen
Hi Everyone,

I would like to use event.chart to make an event chart based on a single row of 
data.  It works fine for 2 or more rows, but when I set subset.r to 1 row or 
use a one row data.frame as the data, I get a dimensional error.

Does anyone know a work around or a solution?

Thanks,

George Chen

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

2009-09-30 Thread Frank E Harrell Jr

Hayes, Rachel M wrote:

Hi all,

 


I have a vector of proportions (post_op_prw) such that

 


 >summary(amb$post_op_prw)

 

   Min. 1st Qu.  MedianMean 3rd Qu.Max.NA's 

 0.  0.  0.  0.3985  0.9134  0.9962  1. 

 


summary(cut2(amb$post_op_prw,0.0001))


 

[0.,0.0001) [0.0001,0.9962]NA's 


   19041672  1

 


I want to use post_op_prw as a predictor variable in an OLS model.  I
decided to fit it using a restricted cubic spline.  But, I'm seeing
behavior I don't understand.  See below:

 


rcspline.eval(amb$post_op_prw,nk = 3, knots.only = T)


[1] 0.000 0.6147927 0.9092937 0.9667178

Warning message:

In rcspline.eval(amb$post_op_prw, nk = 3, knots.only = T) :

  could not obtain 3 knots with default algorithm.

 Used alternate algorithm to obtain 4 knots


rcspline.eval(amb$post_op_prw,nk = 4, knots.only = T)


[1] 0.000 0.8476793 0.9783558


rcspline.eval(amb$post_op_prw,nk = 5, knots.only = T)


[1] 0.000 0.9012711 0.9783558

 


Why are the 4 and 5 knot spline requests returning a spline with 3
knots?  I get the best model results using rcs(amb$post_op_prw,3).   I'm
kind of new to using splines.  Does the fact that observations are
clustered at the ends make the spline fit questionable?  


Yes, or at least it makes the choice of knots questionable.  For that 
type of variable with many ties I tend to use a quadratic effect 
(pol(x,2) in Design or rms packages).


Frank



 


Thanks,

 


Rachel Hayes


[[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] Rounding error in seq(...)

2009-09-30 Thread Ista Zahn
For my own edification more than anything (I never took computer science): is

> a = seq(0.1,0.9,by=0.1)
> a <- as.character(a)
> a[3] == "0.3"
[1] TRUE

safe?

-Ista

On Wed, Sep 30, 2009 at 3:46 PM, cls59  wrote:
>
>
> Martin Batholdy wrote:
>>
>> hum,
>>
>> can you explain that a little more detailed?
>> Perhaps I miss the background knowledge - but it seems just absurd to
>> me.
>>
>> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
>>
>>
>
> Unfortunately this comes as an utter shock to many people who never take a
> Computer Science course. I watch it nail engineering students all the time.
>
> Basically, if you have a fraction and the denominator is not equal to 2^n
> for some integer n, that fraction will NEVER be stored as an exact "floating
> point" number-- instead it will contain some error due to concessions that
> must be made in order to use an efficient binary number scheme.
>
> These errors are generally small, but they do propagate-- especially if you
> are carrying the same numbers through a large computation. A good example is
> large-scale numerical solutions to nonlinear problems where iterative
> algorithms are employed repetitively at each solution step. As the
> calculation progresses the roundoff error can rot away the computational
> soundness of the algorithm.
>
> If this concerns you, I would suggest reading up on common internal
> representations of floating point numbers as well as the propagation of
> roundoff error.
>
> At the very least I hope this revelation will instill an appropriate sense
> of paranoia concerning the numbers calculated by those magic boxes sitting
> on our desks.
>
> -Charlie
>
> -
> Charlie Sharpsteen
> Undergraduate
> Environmental Resources Engineering
> Humboldt State University
> --
> View this message in context: 
> http://www.nabble.com/Rounding-error-in-seq%28...%29-tp25686630p25687626.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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Condition to factor (easy to remember)

2009-09-30 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Douglas Bates
> Sent: Wednesday, September 30, 2009 12:42 PM
> To: Dieter Menne
> Cc: r-help@r-project.org
> Subject: Re: [R] Condition to factor (easy to remember)
> 
> On Wed, Sep 30, 2009 at 2:43 AM, Dieter Menne
>  wrote:
> 
> > Dear List,
> 
> > creating factors in a given non-default orders is 
> notoriously difficult to
> > explain in a course. Students love the ifelse construct 
> given below most,
> > but I remember some comment from Martin Mächler (?) that 
> ifelse should be
> > banned from courses.
> 
> > Any better idea? Not necessarily short, easy to remember is 
> important.
> 
> > Dieter
> 
> > data = c(1,7,10,50,70)
> > levs = c("Pre","Post")
> >
> > # Typical C-Programmer style
> > factor(levs[as.integer(data >10)+1], levels=levs)
> >
> > # Easiest to understand
> > factor(ifelse(data <=10, levs[1], levs[2]), levels=levs)
> 
> Why not
> 
> > factor(data > 10, labels = c("Pre", "Post"))
> [1] Pre  Pre  Pre  Post Post
> Levels: Pre Post
> 
> All you have to remember is that FALSE comes before TRUE.

And if you don't  want to remember that order or if you want TRUE to come
before FALSE use the levels argument to factor.  E.g.,
> factor(data>10, levels=c(TRUE,FALSE), labels=c("Post","Pre"))
[1] Pre  Pre  Pre  Post Post
Levels: Post Pre

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.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] Condition to factor (easy to remember)

2009-09-30 Thread Peter Dalgaard

Douglas Bates wrote:

On Wed, Sep 30, 2009 at 2:42 PM, Douglas Bates  wrote:

On Wed, Sep 30, 2009 at 2:43 AM, Dieter Menne
 wrote:


Dear List,
creating factors in a given non-default orders is notoriously difficult to
explain in a course. Students love the ifelse construct given below most,
but I remember some comment from Martin Mächler (?) that ifelse should be
banned from courses.
Any better idea? Not necessarily short, easy to remember is important.
Dieter
data = c(1,7,10,50,70)
levs = c("Pre","Post")

# Typical C-Programmer style
factor(levs[as.integer(data >10)+1], levels=levs)

# Easiest to understand
factor(ifelse(data <=10, levs[1], levs[2]), levels=levs)

Why not


factor(data > 10, labels = c("Pre", "Post"))

[1] Pre  Pre  Pre  Post Post
Levels: Pre Post

All you have to remember is that FALSE comes before TRUE.


And besides, Frank Harrell will soon be weighing in to tell you why
you shouldn't dichotomize in the first place.


And someone might also remind you that it is safest to include 
levels=c(FALSE,TRUE), just in case the condition is always TRUE. (Terry 
Thernau has the scars from the implementation of Surv()...)


--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Condition to factor (easy to remember)

2009-09-30 Thread hadley wickham
On Wed, Sep 30, 2009 at 2:32 PM, Ista Zahn  wrote:
> An extremely verbose, but (in my view) easy to understand approach is:
>
>> data.f <- data; data.f[which(data <= 10)] <- levs[1]; data.f[which(data > 
>> 10)] <- levs[2]; data.f <- factor(data.f)
>

All those which()s are unnecessary.  And if you're going to use this
approach I'd recommend initialising data.f with NA's so you can tell
if you missed any cases.

Hadley


-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread cls59


Martin Batholdy wrote:
> 
> hum,
> 
> can you explain that a little more detailed?
> Perhaps I miss the background knowledge - but it seems just absurd to  
> me.
> 
> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
> 
> 

Unfortunately this comes as an utter shock to many people who never take a
Computer Science course. I watch it nail engineering students all the time.

Basically, if you have a fraction and the denominator is not equal to 2^n
for some integer n, that fraction will NEVER be stored as an exact "floating
point" number-- instead it will contain some error due to concessions that
must be made in order to use an efficient binary number scheme.

These errors are generally small, but they do propagate-- especially if you
are carrying the same numbers through a large computation. A good example is
large-scale numerical solutions to nonlinear problems where iterative
algorithms are employed repetitively at each solution step. As the
calculation progresses the roundoff error can rot away the computational
soundness of the algorithm.

If this concerns you, I would suggest reading up on common internal
representations of floating point numbers as well as the propagation of
roundoff error.

At the very least I hope this revelation will instill an appropriate sense
of paranoia concerning the numbers calculated by those magic boxes sitting
on our desks.

-Charlie 

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Rounding-error-in-seq%28...%29-tp25686630p25687626.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] Condition to factor (easy to remember)

2009-09-30 Thread Douglas Bates
On Wed, Sep 30, 2009 at 2:42 PM, Douglas Bates  wrote:
> On Wed, Sep 30, 2009 at 2:43 AM, Dieter Menne
>  wrote:
>
>> Dear List,
>
>> creating factors in a given non-default orders is notoriously difficult to
>> explain in a course. Students love the ifelse construct given below most,
>> but I remember some comment from Martin Mächler (?) that ifelse should be
>> banned from courses.
>
>> Any better idea? Not necessarily short, easy to remember is important.
>
>> Dieter
>
>> data = c(1,7,10,50,70)
>> levs = c("Pre","Post")
>>
>> # Typical C-Programmer style
>> factor(levs[as.integer(data >10)+1], levels=levs)
>>
>> # Easiest to understand
>> factor(ifelse(data <=10, levs[1], levs[2]), levels=levs)
>
> Why not
>
>> factor(data > 10, labels = c("Pre", "Post"))
> [1] Pre  Pre  Pre  Post Post
> Levels: Pre Post
>
> All you have to remember is that FALSE comes before TRUE.

And besides, Frank Harrell will soon be weighing in to tell you why
you shouldn't dichotomize in the first place.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Gabor Grothendieck
See:

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

On Wed, Sep 30, 2009 at 2:40 PM, Michael Knudsen  wrote:
> Hi,
>
> Today I was flabbergasted to see something that looks like a rounding
> error in the very basic seq function in R.
>
>> a = seq(0.1,0.9,by=0.1)
>> a
> [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
>> a[1] == 0.1
> [1] TRUE
>> a[2] == 0.2
> [1] TRUE
>> a[3] == 0.3
> [1] FALSE
>
> It turns out that the alternative
>
>> a = (1:9)/10
>
> works just fine. Are there any good guides out there on how to deal
> with issues like this? I am normally aware of rounding errors, but it
> really surprised me to see that an elementary function like seq would
> behave in this way.
>
> Thanks,
> Michael Knudsen
>
> --
> Michael Knudsen
> micknud...@gmail.com
> http://sites.google.com/site/micknudsen/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Condition to factor (easy to remember)

2009-09-30 Thread Douglas Bates
On Wed, Sep 30, 2009 at 2:43 AM, Dieter Menne
 wrote:

> Dear List,

> creating factors in a given non-default orders is notoriously difficult to
> explain in a course. Students love the ifelse construct given below most,
> but I remember some comment from Martin Mächler (?) that ifelse should be
> banned from courses.

> Any better idea? Not necessarily short, easy to remember is important.

> Dieter

> data = c(1,7,10,50,70)
> levs = c("Pre","Post")
>
> # Typical C-Programmer style
> factor(levs[as.integer(data >10)+1], levels=levs)
>
> # Easiest to understand
> factor(ifelse(data <=10, levs[1], levs[2]), levels=levs)

Why not

> factor(data > 10, labels = c("Pre", "Post"))
[1] Pre  Pre  Pre  Post Post
Levels: Pre Post

All you have to remember is that FALSE comes before TRUE.

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


Re: [R] Rounding error in seq(...)

2009-09-30 Thread Greg Snow
Read FAQ 7.31 (no you are not the first to notice this).

In fact this is an issue with most computer programs, not unique or original to 
R.  The FAQ has a link to a general computer science article that goes into 
great detail on this issue.

Reading that article (or something similar) should be a prerequisite to using a 
computer for anything more numerically involved than playing solitare.

-- 
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 Martin Batholdy
> Sent: Wednesday, September 30, 2009 1:18 PM
> To: Duncan Murdoch
> Cc: r help
> Subject: Re: [R] Rounding error in seq(...)
> 
> hum,
> 
> can you explain that a little more detailed?
> Perhaps I miss the background knowledge - but it seems just absurd to
> me.
> 
> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
> 
> why is
> x <- 0.1 + 0.1 +0.1
> not equal to
> y <- 0.3
> 
> ?
> 
> 
> 
> Am 30.09.2009 um 21:04 schrieb Duncan Murdoch:
> 
> > On 9/30/2009 2:50 PM, Michael Knudsen wrote:
> >> On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch
> >>  wrote:
> >>> Why?  You asked for an increment of 1 in the second case (which is
> >>> exactly
> >>> represented in R), then divided by 10, so you'll get the same as
> >>> 0.3 gives
> >>> you.  In the seq() case you asked for an increment of a number
> >>> close to but
> >>> not equal to 1/10 (because 1/10 is not exactly representable in
> >>> R), so you
> >>> got something different.
> >> Well, the problem is that I don't know how seq is implemented. I
> just
> >> assumed that it wouldn't behave like this.
> >
> > It doesn't really matter how it is implemented:  if you ask to start
> > at 0.1 and increment by 0.1, you should expect the result to be the
> > same as
> >
> > 0.1
> > 0.1+0.1
> > 0.1+0.1+0.1
> > etc.
> >
> > and I think it is.  The problem is that 0.1+0.1+0.1 is not the same
> > as 0.3, due to rounding.  Neither 0.1 nor 0.3 can be represented
> > exactly in the standard IEEE floating point formats that R uses.
> >
> > Duncan Murdoch
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread William Dunlap

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Batholdy
> Sent: Wednesday, September 30, 2009 12:18 PM
> To: Duncan Murdoch
> Cc: r help
> Subject: Re: [R] Rounding error in seq(...)
> 
> hum,
> 
> can you explain that a little more detailed?
> Perhaps I miss the background knowledge - but it seems just 
> absurd to  
> me.
> 
> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
> 
> why is
> x <- 0.1 + 0.1 +0.1
> not equal to
> y <- 0.3
> 

Let's do this in base 10, since it is more familiar.  Suppose
we decide, for efficiency reasons to store all numbers to
2 significant decimal digits.  Then 1/3 gets stored as 0.33 and
stored(1/3)+stored(1/3)+stored(1/3) is stored(0.99), not 1.0.
(Here stored() is the function that maps a number to the
2 decimal digit number closest to it.)

For efficiency reasons standard computer representation of
number with fractional part involves 52 significant binary digits.

1/10 in base 10 is like 1/3 in base 2: it cannot be represented
exactly with 52 significant binary digits.  Hence we cannot
expect that
   as.double(1/10)+ <8 reps> +as.double(1/10) will be
exactly 1.0.  (Here, as.double is not the R function but the
mathematical function that maps a number to the double
precision number closest to it.)

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

> ?
> 
> 
> 
> Am 30.09.2009 um 21:04 schrieb Duncan Murdoch:
> 
> > On 9/30/2009 2:50 PM, Michael Knudsen wrote:
> >> On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch  
> >>  wrote:
> >>> Why?  You asked for an increment of 1 in the second case 
> (which is  
> >>> exactly
> >>> represented in R), then divided by 10, so you'll get the same as  
> >>> 0.3 gives
> >>> you.  In the seq() case you asked for an increment of a number  
> >>> close to but
> >>> not equal to 1/10 (because 1/10 is not exactly representable in  
> >>> R), so you
> >>> got something different.
> >> Well, the problem is that I don't know how seq is 
> implemented. I just
> >> assumed that it wouldn't behave like this.
> >
> > It doesn't really matter how it is implemented:  if you ask 
> to start  
> > at 0.1 and increment by 0.1, you should expect the result 
> to be the  
> > same as
> >
> > 0.1
> > 0.1+0.1
> > 0.1+0.1+0.1
> > etc.
> >
> > and I think it is.  The problem is that 0.1+0.1+0.1 is not 
> the same  
> > as 0.3, due to rounding.  Neither 0.1 nor 0.3 can be represented  
> > exactly in the standard IEEE floating point formats that R uses.
> >
> > Duncan Murdoch
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Condition to factor (easy to remember)

2009-09-30 Thread Ista Zahn
An extremely verbose, but (in my view) easy to understand approach is:

> data.f <- data; data.f[which(data <= 10)] <- levs[1]; data.f[which(data > 
> 10)] <- levs[2]; data.f <- factor(data.f)

-Ista

On Wed, Sep 30, 2009 at 8:31 AM, Dieter Menne
 wrote:
>
>
>
> David Winsemius wrote:
>>
>>
>>> # Typical C-Programmer style
>>> factor(levs[as.integer(data >10)+1], levels=levs)
>>
>> In your code the as.integer function is superfluous
>
> Oops... done too much c# lately, getting invalid cast challenged.
>
> Dieter
>
>
> --
> View this message in context: 
> http://www.nabble.com/Condition-to-factor-%28easy-to-remember%29-tp25676411p25680111.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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Peter Dalgaard

Martin Batholdy wrote:

hum,

can you explain that a little more detailed?
Perhaps I miss the background knowledge - but it seems just absurd to me.

0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?

why is
x <- 0.1 + 0.1 +0.1
not equal to
y <- 0.3


Remember that this is in BINARY arithmetic. It's really not any stranger 
than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal 
arithmetic (0.3 + 0.3 = 0.6 != 0.7).


--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Rolf Turner


On 1/10/2009, at 8:17 AM, Martin Batholdy wrote:


hum,

can you explain that a little more detailed?
Perhaps I miss the background knowledge - but it seems just absurd to
me.

0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?

why is
x <- 0.1 + 0.1 +0.1
not equal to
y <- 0.3

?


You have told the answer already, several times.

***FLOATING POINT ARITHMETIC

If you still don't understand, read up on it.  Start by looking at  
the FAQ.


cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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


Re: [R] Rounding error in seq(...)

2009-09-30 Thread Duncan Murdoch

On 9/30/2009 3:17 PM, Martin Batholdy wrote:

hum,

can you explain that a little more detailed?
Perhaps I miss the background knowledge - but it seems just absurd to  
me.


0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?


R uses a binary floating point storage format, which is the standard 
thing to do in most languages.  Numbers which are fractions like 1/2, 
1/4 and 57/128 are all representable exactly, because the denominator is 
a power of 2. Whole numbers are also representable exactly.


However, numbers like 1/10 are not.  So R stores something slightly 
different from 1/10 when you say x <- 0.1.  If you compare it to 1/10, 
then it comes out equal, because you're comparing to the same slightly 
incorrect value.


However, by the time you add up 3 of them, the rounding error 
accumulates, and you get a different answer than you'd get from 3/10, 
which is the same as 0.3.


Duncan Murdoch



why is
x <- 0.1 + 0.1 +0.1
not equal to
y <- 0.3

?



Am 30.09.2009 um 21:04 schrieb Duncan Murdoch:


On 9/30/2009 2:50 PM, Michael Knudsen wrote:
On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch  
 wrote:
Why?  You asked for an increment of 1 in the second case (which is  
exactly
represented in R), then divided by 10, so you'll get the same as  
0.3 gives
you.  In the seq() case you asked for an increment of a number  
close to but
not equal to 1/10 (because 1/10 is not exactly representable in  
R), so you

got something different.

Well, the problem is that I don't know how seq is implemented. I just
assumed that it wouldn't behave like this.


It doesn't really matter how it is implemented:  if you ask to start  
at 0.1 and increment by 0.1, you should expect the result to be the  
same as


0.1
0.1+0.1
0.1+0.1+0.1
etc.

and I think it is.  The problem is that 0.1+0.1+0.1 is not the same  
as 0.3, due to rounding.  Neither 0.1 nor 0.3 can be represented  
exactly in the standard IEEE floating point formats that R uses.


Duncan Murdoch

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Michael Knudsen
On Wed, Sep 30, 2009 at 8:40 PM, Michael Knudsen  wrote:

>> a = seq(0.1,0.9,by=0.1)
>> a
> [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
>> a[1] == 0.1
> [1] TRUE
>> a[2] == 0.2
> [1] TRUE
>> a[3] == 0.3
> [1] FALSE

A friend of mine just pointed out a possible solution:

> a=seq(0.1,0.9,by=0.1)
> a = seq(0.1,0.9,by=0.1)
> a[3]==0.3
[1] FALSE
> all.equal(a[3],0.3)
[1] TRUE

The all.equal function checks if two objects are "nearly" equal.

-- 
Michael Knudsen
micknud...@gmail.com
http://sites.google.com/site/micknudsen/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Martin Batholdy

hum,

can you explain that a little more detailed?
Perhaps I miss the background knowledge - but it seems just absurd to  
me.


0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?

why is
x <- 0.1 + 0.1 +0.1
not equal to
y <- 0.3

?



Am 30.09.2009 um 21:04 schrieb Duncan Murdoch:


On 9/30/2009 2:50 PM, Michael Knudsen wrote:
On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch  
 wrote:
Why?  You asked for an increment of 1 in the second case (which is  
exactly
represented in R), then divided by 10, so you'll get the same as  
0.3 gives
you.  In the seq() case you asked for an increment of a number  
close to but
not equal to 1/10 (because 1/10 is not exactly representable in  
R), so you

got something different.

Well, the problem is that I don't know how seq is implemented. I just
assumed that it wouldn't behave like this.


It doesn't really matter how it is implemented:  if you ask to start  
at 0.1 and increment by 0.1, you should expect the result to be the  
same as


0.1
0.1+0.1
0.1+0.1+0.1
etc.

and I think it is.  The problem is that 0.1+0.1+0.1 is not the same  
as 0.3, due to rounding.  Neither 0.1 nor 0.3 can be represented  
exactly in the standard IEEE floating point formats that R uses.


Duncan Murdoch

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Duncan Murdoch

On 9/30/2009 2:50 PM, Michael Knudsen wrote:

On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch  wrote:


Why?  You asked for an increment of 1 in the second case (which is exactly
represented in R), then divided by 10, so you'll get the same as 0.3 gives
you.  In the seq() case you asked for an increment of a number close to but
not equal to 1/10 (because 1/10 is not exactly representable in R), so you
got something different.


Well, the problem is that I don't know how seq is implemented. I just
assumed that it wouldn't behave like this.


It doesn't really matter how it is implemented:  if you ask to start at 
0.1 and increment by 0.1, you should expect the result to be the same as


0.1
0.1+0.1
0.1+0.1+0.1
etc.

and I think it is.  The problem is that 0.1+0.1+0.1 is not the same as 
0.3, due to rounding.  Neither 0.1 nor 0.3 can be represented exactly in 
the standard IEEE floating point formats that R uses.


Duncan Murdoch

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


Re: [R] Rounding error in seq(...)

2009-09-30 Thread Bert Gunter
Inline Below.

Bert Gunter
Nonclinical Biostatistics
467-7374

http://devo.gene.com/groups/devo/depts/ncb/home.shtml

 

 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Michael Knudsen
Sent: Wednesday, September 30, 2009 11:50 AM
To: Duncan Murdoch
Cc: r help
Subject: Re: [R] Rounding error in seq(...)

On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch 
wrote:

> Why?  You asked for an increment of 1 in the second case (which is exactly
> represented in R), then divided by 10, so you'll get the same as 0.3 gives
> you.  In the seq() case you asked for an increment of a number close to
but
> not equal to 1/10 (because 1/10 is not exactly representable in R), so you
> got something different.

Well, the problem is that I don't know how seq is implemented. I just
assumed that it wouldn't behave like this.

-- This represents common misconceptions about the nature of floating point
computations/finite precision arithmetic. See 7.31 in the R FAQ. You may
wish to Google/Wikipedia on "floating point computation" or something
similar for more info.

-- Bert

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Michael Knudsen
On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch  wrote:

> Why?  You asked for an increment of 1 in the second case (which is exactly
> represented in R), then divided by 10, so you'll get the same as 0.3 gives
> you.  In the seq() case you asked for an increment of a number close to but
> not equal to 1/10 (because 1/10 is not exactly representable in R), so you
> got something different.

Well, the problem is that I don't know how seq is implemented. I just
assumed that it wouldn't behave like this.

-- 
Michael Knudsen
micknud...@gmail.com
http://sites.google.com/site/micknudsen/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)

2009-09-30 Thread Duncan Murdoch

On 9/30/2009 2:40 PM, Michael Knudsen wrote:

Hi,

Today I was flabbergasted to see something that looks like a rounding
error in the very basic seq function in R.


a = seq(0.1,0.9,by=0.1)
a

[1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

a[1] == 0.1

[1] TRUE

a[2] == 0.2

[1] TRUE

a[3] == 0.3

[1] FALSE

It turns out that the alternative


a = (1:9)/10


works just fine. Are there any good guides out there on how to deal
with issues like this? I am normally aware of rounding errors, but it
really surprised me to see that an elementary function like seq would
behave in this way.


Why?  You asked for an increment of 1 in the second case (which is 
exactly represented in R), then divided by 10, so you'll get the same as 
0.3 gives you.  In the seq() case you asked for an increment of a number 
close to but not equal to 1/10 (because 1/10 is not exactly 
representable in R), so you got something different.


Duncan Murdoch

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


[R] Rounding error in seq(...)

2009-09-30 Thread Michael Knudsen
Hi,

Today I was flabbergasted to see something that looks like a rounding
error in the very basic seq function in R.

> a = seq(0.1,0.9,by=0.1)
> a
[1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
> a[1] == 0.1
[1] TRUE
> a[2] == 0.2
[1] TRUE
> a[3] == 0.3
[1] FALSE

It turns out that the alternative

> a = (1:9)/10

works just fine. Are there any good guides out there on how to deal
with issues like this? I am normally aware of rounding errors, but it
really surprised me to see that an elementary function like seq would
behave in this way.

Thanks,
Michael Knudsen

-- 
Michael Knudsen
micknud...@gmail.com
http://sites.google.com/site/micknudsen/

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

2009-09-30 Thread Bond, Stephen
I need to change one of the axis produced by persp by giving it labels for the 
tickmarks.
The dimension has months (a factor) so the default decimals don't look good.

The graph will finally become a pdf  or emf file to be embedded in a document, 
so persp3d will not work, I think.

Thank you all.
Stephen

[[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] start a script directly under windows

2009-09-30 Thread Martin Batholdy

hi,

I try to configure my system so when I click on an .R script, the  
script is executed in the R GUI.
I tried to open .R files with different .exe files that I found in the  
bin-folder of the R folder (R.exe, Rcmd.exe, Rgui.exe ...).


But I always get the message;


ARGUMENT  'c:\...\...'   ___ignored___


(where c:\...\.. is the path to the .R file)



how can I change this behavior?
Sorry I am not so familiar with windows OS (I use windows xp).



thanks for any help!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 visualize gini coefficient in each node in RF?

2009-09-30 Thread Liaw, Andy
You can try to hunt for it in the findbestsplit Fortran subroutine.  It
uses some thing that's equivalent (but easier to compute), not exactly
identical.  Breiman uses whatever computational shortcuts he could find
in his code.
 
Best,
Andy




From: Chrysanthi A. [mailto:chrys...@gmail.com] 
Sent: Tuesday, September 29, 2009 4:55 PM
To: Liaw, Andy
Cc: r-help@r-project.org
Subject: Re: [R] how to visualize gini coefficient in each node
in RF?



Thanks for the reply! However, what is the code that is used in
order to calculate it.. Is it included in the "randomForest" R
function.. Because I am trying to find the code corresponding to the
estimation of the gini coefficient but I am a bit confused. Could you
please help me, by indicating me that? 

thanks a lot,

chrysanthi



2009/9/29 Liaw, Andy 


No.  The forest object is too large as is.  I didn't
think it's worth
the extra memory to store them.  They were never kept
even in the
Fortran/C code.

Andy

From: Chrysanthi A.
> Sent: Monday, September 28, 2009 5:20 PM
> To: r-help@r-project.org
> Subject: [R] how to visualize gini coefficient in each
node in RF?

>
> Dear all,
>
> I am working with randomForest package and I am
interested in
> examining the
> "Gini importance" measures that are used as a general
> indicator of feature
> relevance. Is there a possibility of getting the Gini
measure
> that is being
> estimated in each tree by the output of the getTree()
function?
>
> Thanks a lot,
>
> Chrysanthi
>

>   [[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.
>
Notice:  This e-mail message, together with any
attachments, contains
information of Merck & Co., Inc. (One Merck Drive,
Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may
be known
outside the United States as Merck Frosst, Merck Sharp &
Dohme or
MSD and in Japan, as Banyu - direct contact information
for affiliates is
available at http://www.merck.com/contact/contacts.html)
that may be
confidential, proprietary copyrighted and/or legally
privileged. It is
intended solely for the use of the individual or entity
named on this
message. If you are not the intended recipient, and have
received this
message in error, please notify us immediately by reply
e-mail and
then delete it from your system.




Notice:  This e-mail message, together with any attachme...{{dropped:15}}

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

2009-09-30 Thread Tim Clark
Peter,

Thanks, that did it!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Wed, 9/30/09, Peter Ehlers  wrote:

> From: Peter Ehlers 
> Subject: Re: [R] bwplot scales in alphabetical order
> To: "Tim Clark" 
> Cc: r-help@r-project.org
> Date: Wednesday, September 30, 2009, 2:43 AM
> Tim,
> 
> Add the argument as.table=TRUE to your call:
> 
>   bwplot(y~x|id, horizontal=FALSE, as.table=TRUE)
> 
> Peter Ehlers
> 
> Tim Clark wrote:
> > Dear List,
> > 
> > I know this has been covered before, but I don't seem
> to be able to get it right.  I am constructing a
> boxplot in lattice and can't get the scales in the correct
> alphebetical order.  I have already read that this is
> due to the way factors are treated, and I have to redefine
> the levels of the factors.  However, I have
> failed.  As a simple example:
> > 
> > library(lattice)
> > id<-rep(letters[1:9], each=20)
> > x<-rep(seq(1:10),each=18)
> > y<-rnorm(180,50,20)
> > 
> > #Reverse alphebetical order
> >   bwplot(y~x|id, horizontal=FALSE)
> > 
> > #alphebetical order reading right to left
> >   id<-factor(id,levels =
> sort(id,decreasing = TRUE))
> >   bwplot(y~x|id, horizontal=FALSE)
> > 
> > It appears that bwplot plots scales from the bottom
> left to the top right. If so my factor levels would need to
> be levels=c(7,8,9,4,5,6,1,2,3). I tried that but can't seem
> to get the factor function to work.
> > 
> > #Did not work!
> >
> id<-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9])
> > 
> > Your help would be greatly appreciated.
> > 
> > Tim
> > 
> > 
> > 
> > 
> > 
> > Tim Clark
> > Department of Zoology University of Hawaii
> > 
> > __
> > R-help@r-project.org
> mailing list
> > https://stat.ethz.ch/mailman/listinfo/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] Scaling data

2009-09-30 Thread Henrique Dallazuanna
Try this:

as.data.frame(sapply(sapply(DF, as.character, simplify = FALSE), strsplit, ";"))

On Wed, Sep 30, 2009 at 1:18 PM, Dry, Jonathan R
 wrote:
> Hello all
>
> I am manipulating some data and wish to expand/unmerge (i.e. do the opposite 
> of aggregate) rows in a data matrix based on the values in a particular 
> column and a seperator, e.g.
>
> Col1    Col2
> n1;n2   6
>
> ...separating by ";" becomes
>
> Col1    Col2
> num1    6
> num2    6
>
> Any ideas?
>
> Also can I do this based on values in two columns?  EG:
>
> Col1    Col2    Col3
> n1;n2   ID1;ID2 6
>
> ...becomes
>
> Col1    Col2    Col3
> n1      ID1     6
> n2      ID2     6
> ?
>
> --
> AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:21}}
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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

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

2009-09-30 Thread Marilia Gmail

Dear all,

I am trying to reproduce the example in the vignette "Using lme4 to fit 
Generalized Additive

Mixed Models" with my dataset.
But...

> exemplo <- read.table(exemplo.dat,header=T)
> mod <- amer(pasvig ~ -1 + harvf + tp(dias,by=harvf) + (1 | pac), 
data=exemplo)

Erro em if (from == to) rep.int(from, length.out) else as.vector(c(from,  :
valor ausente onde TRUE/FALSE necessário

A subset of the dataset is below.
No clue about what is wrong.

Thanks a lot!

Marilia
"pasvig" "dias" "harvf" "pac"
124 0 "HRJB" 1
125 473 "HRJB" 1
125 888 "HRJB" 1
136 1272 "HRJB" 1
161 1614 "HRJB" 1
133 0 "HRV" 2
151 716 "HRV" 2
127 850 "HRV" 2
141 1137 "HRV" 2
135 1382 "HRV" 2
168 0 "HRV" 3
140 169 "HRV" 3
140 555 "HRV" 3
137 1259 "HRV" 3
147 1524 "HRV" 3
150 1842 "HRV" 3
133 1982 "HRV" 3
160 0 "HRV" 4
159 417 "HRV" 4
137 790 "HRV" 4
173 1146 "HRV" 4
149 1761 "HRV" 4
165 2135 "HRV" 4
142 2415 "HRV" 4
137 0 "HRV" 5
144 420 "HRV" 5
145 842 "HRV" 5
127 0 "HRJB" 6
124 365 "HRJB" 6
122 762 "HRJB" 6
138 1134 "HRJB" 6
124 1561 "HRJB" 6
133 0 "HRV" 7
116 502 "HRV" 7
142 1474 "HRV" 7
170 0 "HRV" 8
151 400 "HRV" 8
132 577 "HRV" 8
114 1169 "HRV" 8
146 1547 "HRV" 8
110 1904 "HRV" 8
156 0 "HRV" 9
132 1370 "HRV" 9
154 1784 "HRV" 9
148 2318 "HRV" 9
148 0 "HRV" 10
110 520 "HRV" 10
123 924 "HRV" 10
130 1640 "HRV" 10
142 2075 "HRV" 10
158 0 "HRV" 11
166 274 "HRV" 11
159 1059 "HRV" 11
150 0 "HRV" 12
140 333 "HRV" 12
121 704 "HRV" 12
138 1225 "HRV" 12
110 1406 "HRV" 12
151 0 "HRV" 13
179 318 "HRV" 13
167 913 "HRV" 13
181 1261 "HRV" 13
131 0 "HRJB" 14
123 630 "HRJB" 14
136 1038 "HRJB" 14
138 1463 "HRJB" 14
133 1757 "HRJB" 14
119 2158 "HRJB" 14
144 0 "HRV" 15
150 418 "HRV" 15
145 659 "HRV" 15
141 1099 "HRV" 15
133 1336 "HRV" 15
150 1757 "HRV" 15
140 0 "HRV" 16
127 432 "HRV" 16
118 NA "HRV" 16
151 0 "HRV" 17
140 720 "HRV" 17
150 1455 "HRV" 17
156 0 "HRV" 18
144 402 "HRV" 18
152 807 "HRV" 18
139 1163 "HRV" 18
127 1575 "HRV" 18
126 0 "HRV" 19
141 997 "HRV" 19
143 1505 "HRV" 19
153 1843 "HRV" 19
123 2023 "HRV" 19
135 0 "HRV" 20
128 357 "HRV" 20
135 880 "HRV" 20
151 1561 "HRV" 20
153 1952 "HRV" 20
131 2364 "HRV" 20
122 0 "HRJB" 21
141 462 "HRJB" 21
136 1224 "HRJB" 21
132 1757 "HRJB" 21

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


[R] extract clusters from a hclusrt object without cutree

2009-09-30 Thread Larson, TR


Hello,

I am generating an hclust() object and want to extract a subset of 
clusters WITHOUT using cutree().  I see this somehow involves using the 
$merge matrix to associate $labels into their appropriate clusters where 
clusters are split below a given $height threshold.  Can anyone suggest 
a way/code to do this?  I see cutree uses embedded fortran code, so it's 
not obvious how cutree does it




thanks
Tony

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

2009-09-30 Thread Greg Snow
There was a rather in depth article on doing macros in R in the R newsletter a 
couple of years ago.  There is also the defmacro function in the gtools package 
based on that article that can make the job easier for many cases.

See fortune(236) before taking the assign route.

-- 
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 David Young
> Sent: Tuesday, September 29, 2009 9:58 AM
> To: r-help@r-project.org
> Subject: [R] Macro variable substitution
> 
> Hello All,
> 
> I'm a new R user and have a question about what in SAS would be called
> macro variable substitution.  Below is some R code that doesn't work,
> but I think it will illustrate what I'd like to do.
> 
> readfunc<-function(x) {
>   x <<- read.table(paste(x,".csv",sep=""), header=TRUE,sep=",")
> }
> readfunc(TEF)
> 
> What I'd like to do is have the letters "TEF" become the name of the
> new
> R data and also be used in conjunction with ".csv" to read the file
> "TEF.csv".
> 
> So working R code looks like this:
> 
> TEF <- read.table(TEF.csv, header=TRUE,sep=",")
> 
> but I'd like to type the changing letter sequence just once.
> 
> Any suggestions would be appreciated.
> 
> --
> Best regards,
> 
> David Young
> Marketing and Statistical Consultant
> Madrid, Spain
> +34 913 540 381
> http://www.linkedin.com/in/europedavidyoung
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Scaling data

2009-09-30 Thread Dry, Jonathan R
Hello all

I am manipulating some data and wish to expand/unmerge (i.e. do the opposite of 
aggregate) rows in a data matrix based on the values in a particular column and 
a seperator, e.g.

Col1Col2
n1;n2   6

...separating by ";" becomes

Col1Col2
num16
num26

Any ideas?

Also can I do this based on values in two columns?  EG:

Col1Col2Col3
n1;n2   ID1;ID2 6

...becomes

Col1Col2Col3
n1  ID1 6
n2  ID2 6
?

--
AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:21}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Managing random number generating, while using Condor parallel computing

2009-09-30 Thread Tal Galili
Thanks/Sorry Dirk.

After some more searches I found:
http://cran.r-project.org/web/packages/rsprng/index.html
With a nice explenation about it here:
http://wiki.r-project.org/rwiki/doku.php?id=packages:cran:rsprng


Thanks/Sorry again,
Tal




--


My contact information:
Tal Galili
E-mail: tal.gal...@gmail.com
Phone number: 972-52-7275845
FaceBook: Tal Galili
My Blogs:
http://www.talgalili.com (Web and general, Hebrew)
http://www.biostatistics.co.il (Statistics, Hebrew)
http://www.r-statistics.com/ (Statistics,R, English)




On Wed, Sep 30, 2009 at 5:56 PM, Dirk Eddelbuettel  wrote:

> On Wed, Sep 30, 2009 at 05:02:15PM +0200, Tal Galili wrote:
> > Might someone advice me about the following question:
> > How should I handle the RNG (random number generation) in the running of
> > parallel instances of R on different machines.
> >
>
> http://lmgtfy.com/?q=site%3Ar-project.org+parallel+RNG
>
> --
> Three out of two people have difficulties with fractions.
>

[[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] Overview of error and warning messages for teaching + examples

2009-09-30 Thread joris meys
Hi Tal,

The Wiki is a great idea! Alas I'm not that familiar with setting up
Wikis. Any idea how to practically approach this?

I'm currently a bit in a hurry, as I have to give the introduction
next monday. I'll have a first, basic introduction ready by the end of
the week, but I'll continue to develop a more complete document later
on. Naturally, this will be available for the internet community too.
I'll keep you updated.


On Wed, Sep 30, 2009 at 5:44 PM, Tal Galili  wrote:
> Hi Joris.
> This is a wonderlful idea.
> I never came across such a document, but assembaling it sounds very good.
> What do you think about organizing the work of collecting (by R members and
> maybe your students) the error massages and code into some wiki page? (maybe
> on the R wiki)
> It could be a great work to give to students (go around the mailing list,
> search for "i got this error massage", and write what the
> code-problem-solution was).
>
> Best,
> Tal
>
>
>
>
> --
>
>
> My contact information:
> Tal Galili
> E-mail: tal.gal...@gmail.com
> Phone number: 972-52-7275845
> FaceBook: Tal Galili
> My Blogs:
> http://www.talgalili.com (Web and general, Hebrew)
> http://www.biostatistics.co.il (Statistics, Hebrew)
> http://www.r-statistics.com/ (Statistics,R, English)
>
>
>
>
> On Wed, Sep 30, 2009 at 2:50 PM, joris meys  wrote:
>>
>> Dear all,
>>
>> The background: as I didn't find a manual specifically directed
>> towards debugging R code on a novice and intermediate level, I decided
>> to write a student manual myself. I have some basic examples of errors
>> (the classical interpunction and writing mistakes), but have the
>> feeling that I miss quite some of the frequently occuring mistakes and
>> messages. Therefore I'm looking around to find a list of these, and if
>> possible, some examples of wrong R code.
>>
>> I have been googling around a bit, but I couldn't find an overview of
>> the most common error and warning messages in R. Off course this
>> mailing list is an extensive source of all kind or errors and
>> examples, but I was wondering if there is a somewhat more structured
>> overview. All help appreciated.
>>
>> Kind regards
>> Joris Meys
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Managing random number generating, while using Condor parallel computing

2009-09-30 Thread Dirk Eddelbuettel
On Wed, Sep 30, 2009 at 05:02:15PM +0200, Tal Galili wrote:
> Might someone advice me about the following question:
> How should I handle the RNG (random number generation) in the running of
> parallel instances of R on different machines.
> 

http://lmgtfy.com/?q=site%3Ar-project.org+parallel+RNG

-- 
Three out of two people have difficulties with fractions.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Overview of error and warning messages for teaching + examples

2009-09-30 Thread Tal Galili
Hi Joris.

This is a wonderlful idea.
I never came across such a document, but assembaling it sounds very good.

What do you think about organizing the work of collecting (by R members and
maybe your students) the error massages and code into some wiki page? (maybe
on the R wiki)

It could be a great work to give to students (go around the mailing list,
search for "i got this error massage", and write what the
code-problem-solution was).


Best,
Tal





--


My contact information:
Tal Galili
E-mail: tal.gal...@gmail.com
Phone number: 972-52-7275845
FaceBook: Tal Galili
My Blogs:
http://www.talgalili.com (Web and general, Hebrew)
http://www.biostatistics.co.il (Statistics, Hebrew)
http://www.r-statistics.com/ (Statistics,R, English)




On Wed, Sep 30, 2009 at 2:50 PM, joris meys  wrote:

> Dear all,
>
> The background: as I didn't find a manual specifically directed
> towards debugging R code on a novice and intermediate level, I decided
> to write a student manual myself. I have some basic examples of errors
> (the classical interpunction and writing mistakes), but have the
> feeling that I miss quite some of the frequently occuring mistakes and
> messages. Therefore I'm looking around to find a list of these, and if
> possible, some examples of wrong R code.
>
> I have been googling around a bit, but I couldn't find an overview of
> the most common error and warning messages in R. Off course this
> mailing list is an extensive source of all kind or errors and
> examples, but I was wondering if there is a somewhat more structured
> overview. All help appreciated.
>
> Kind regards
> Joris Meys
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] Openning multiple (writing) connections to a single file - possible ?

2009-09-30 Thread Tal Galili
Hello members of the R-help group.

I am trying to run multiple occurences of R (through the distributed
computing of Condor), and have all of them write their output into one
source.

It is similar (I believe), to running R several time on the same machine,
and running on each instance of R the same script. In that script there is a
line saying "write some text into a file", and I wish it to be the same
file. So at the end of the running I will have a single results file.

Here is the code I tried to run (which didn't work) :

con <- file("output.txt", open = "w")
cat("write me", file=con, append = T)
close(con)


Any suggestions?
Is it possible ? (or should I just write the output to many files, and at
the end combine them to one big file)

Thanks,
Tal










--


My contact information:
Tal Galili
E-mail: tal.gal...@gmail.com
Phone number: 972-52-7275845
FaceBook: Tal Galili
My Blogs:
http://www.talgalili.com (Web and general, Hebrew)
http://www.biostatistics.co.il (Statistics, Hebrew)
http://www.r-statistics.com/ (Statistics,R, English)

[[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] Read header csv file

2009-09-30 Thread Don MacQueen

Lucas,

Although I can't answer all your questions, I can give some suggestions.

I will assume you know how many years of data you 
have. Suppose it is 2004 through 2009.
In each input file, the columns must have names, 
so I will assume there is a column named "Month".
I am not sure if you want all of your output in 
one file, or if you want one output file for each 
year.

I am going to assume you want a separate output file for each year.
I am going to assume that when you do the 
calculations for each month within each year, the 
results

include two variables named "r1" and "pvalue" (as in your example).

Here is some example R code:


## make sure that R is working in the directory that contains the files
## this can be done from a menu in the R window, 
if you are using R in Windows or Macintosh,

## or by using the setwd() command
setwd( "directory where my files are" )

years <- 2004:2009

for (yr in years) {

  infile <- paste(yr,'.csv',sep='')
  outfile <- paste(yr,'.txt',sep='')

  clima <- read.csv2(infile,nrows=7)

  ## open the output file for the current year
  sink(outfile)

  for (mn in unique(clima$Month)) {
 ## do calculations for the current month
 cat('Year: ', yr, '  Month:', mn, ' R1:', r1,' Pvalue:', pvalue,'\n')
 ## end of loop through months (in the current year)
}

  ## close the output file.
  sink()

## end of loop through years
}


If you want all the output, including all the 
years, in a single file, then put the sink() 
commands outside the loop. Like this:


years <- 2004:2009

 ## open the output file for writing
sink("MyOutput.txt")

for (yr in years) {

  infile <- paste(yr,'.csv',sep='')
   clima <- read.csv(infile,nrows=7)

  for (mn in unique(clima$Month)) {
 ## do calculations for the current month
 ## some results are in variables named r1 and pvalue
 cat('Year: ', yr, '  Month:', mn, ' R1:', r1,' Pvalue:', pvalue,'\n')
 ## end of loop through months (in the current year)
}

## end of loop through years
}

## close the output file.
sink()



A few comments:
The sink() command must be given a file name, not a directory name. You had
sink("directore where my text file is")

You can try it first without the sink() commands, 
and see the results on your computer screen. This 
is a good way to make sure they are correct.


Since you already know your file names, 2004.csv, 
2005.csv, and so on, it is not necessary to use 
the dir() command to get them. And actually, 
better to use list.files(), not dir().


If you do use the list.files() or dir() command, 
try not to use it repeatedly inside a loop. It 
should be sufficient to it once outside the loop, 
for example:


   myfiles <- list.files("directory where my files are")
   nfiles <- length(myfiles)
   for (year in 1:nfiles) {
 filename <- myfiles[[year]]   ## and I'm 
pretty sure it should be myfiles[year], not 
[[year]]

}

Also, the way you did it assumes that the dir() 
command lists the files in the correct order, and 
it also assumes that there are no other files in 
the directory.


If you want to run R in a different directory 
than the data files are in, you can change a few 
things.


datadir <- "directory my files are in"
infiles <- list.files( datadir, full.names=TRUE)
nfiles <- length(infiles)

for ( i in 1:nfiles ) {
  clima <- read.csv2(infiles[1], nrow=7)
  sink( paste('outfile',i,'.txt',sep='')
  ## loop over months
## do calculations
## do the cat() commands
  sink()
}

At 1:10 PM + 9/30/09, Lucas Sevilla García wrote:

Hi R community,

First of all, I want to thank everybody to share 
their time solving R questions, You are great. 
Ok, for my questions, I've been looking for a 
solutions by myself, in forums but I'm just a 
little bit desesperate so I hope somebody can 
help me. I have built a code to read files from 
a directory. These files are named by a year 
(2004.csv, 2005.csv,...). When the code reads 
first file (2004.csv), inside this file, there 
is information about precipitation of every 
months and I calculate different variables like 
R square adjusted, p value or formula fit to the 
data from linear regression. The code do more 
things but for my question, to explain what I 
need, that part of the code is enough. I want to 
export to the text file, year and month apart of 
some other variables, something like this:


Year: 2004   Month: January  R1: 0.98   Pvalue: 0.03 ...
Year: 2004   Month: February  R1:0.78   Pvalue:0.12 ...

I've seen that I can use order sink() and cat(), 
so I would put those orders in my code, like 
this:


nfiles<- length(dir("directory where my files are"))   #Count file number

for(year in 1:nfiles)#Read first file
{
filename<-dir()[[year]] 
#take first file and read filename, so if year 
is 1, then filename will be 2004, is year is 2, 
filename will be 2005,...
  
clima<-read.csv2(filename, nrows=7) #open 2004.csv



So, if want to export year to my te

Re: [R] AsciiDoc and R

2009-09-30 Thread Steve Lianoglou

Hi,

On Sep 30, 2009, at 7:57 AM, johannes rara wrote:


I would like to learn AsciiDoc. Is there any good examples how to use
AsciiDoc with R? I know that there is packages called ascii to do
this, but it would be nice to see some examples how AsciiDoc works
with R. Is there an AsciiDoc distribution for Max OS X?


Perhaps this might help, too:

http://learnr.wordpress.com/2009/09/29/wordpress-blogging-with-r-in-3-steps/

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] k-modes (Huang) in package klaR?

2009-09-30 Thread Uwe Ligges



Uwe Ligges wrote:



Kim Vanselow wrote:

Dear R-Users and Developers,
I want to calculate something like k-means clustering, but with 
ordinal data (Braun-Blanquet) to combine this classification technique 
with a NMDS-Ordination.
I found an algorithm especially developed for categorical data: 
k-modes (Huang 1998). Is there a function implemented in R which can 
calculate with this algorithm. I found a hint on a poster-abstract 
from Gero Szepannek, Uwe Ligges and Claus Weihs. There it is stated 
that the algorithm is implemented in their package klaR. But I cannot 
find anything about k-modes in the klaR-Tutorial.

Could you please help me.


Dear Kim,

well, maybe you start writing a message to the authors of that 
poster-abstract at first who might be able to help?
Since I am one of those: Where can I find this abstract or poster (at 
least in order to remind Gero who does no longer work at the university 
to finally implement the feature, if it is not yet there)?


Some news on this:

Gero never presented it in his talk at the useR!2008 and we all forgot 
that he announced it in his abstract. He is working for a bank these 
days and is going to send his code within a few days. Will take a look 
if it is easy to add the existing code to klaR then.


Best wishes,
Uwe Ligges



Best wishes,
Uwe Ligges




Thanks
Kim




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Managing random number generating, while using Condor parallel computing

2009-09-30 Thread Tal Galili
Hello all,

Recently I started playing with running R scripts on the Condor system in my
institute.
(For more on this, have a look at:
 Running Long R Jobs with Condor DAG
by Xianhong Xie
link: http://cran.r-project.org/doc/Rnews/Rnews_2005-2.pdf
)

Might someone advice me about the following question:
How should I handle the RNG (random number generation) in the running of
parallel instances of R on different machines.

For example, Let's say I wish to run 10 times a script that generates 100
normal variables and return their mean.
The script itself is easy to write. What I am not sure about is what should
I do with the seed.
Should I let the program choose one for itself ?
Should I set a seed according to some function of the current process ?
Is there an outside source I should get the numbers from?

Thanks,
Tal






--


My contact information:
Tal Galili
E-mail: tal.gal...@gmail.com
Phone number: 972-52-7275845
FaceBook: Tal Galili
My Blogs:
http://www.talgalili.com (Web and general, Hebrew)
http://www.biostatistics.co.il (Statistics, Hebrew)
http://www.r-statistics.com/ (Statistics,R, English)

[[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] Re cursive regression

2009-09-30 Thread manta

Hi there, I'm in desperate need to figure out how to solve this issue.
I need to estimate a recursive model for a time series data of asset
returns. The dependent variable is the asset return and then I have a set of
k variables, a lagged value of the dependent variable (plus an intercept) as
regressors. My sample period (monthly observations) starts on Jan 1972. What
I need to do is the following:

1)use a moving window regression (window of 60 observations, i.e. 5 years)
2)estimate all the possible model (Jan 1972 Dec 1977) using a subset of the
k variables (intercept and lagged values always present) and choose the best
model according to thee AIC criterion
3)once the best model is chosen, make one-step ahead prediction with that
model
4)go back to step 2 shifting the sample period one month ahead (i.e. Feb
1972, Jan 1978) and then repeat step 2 and 3
5)keep going until the end of the sample (May 2009)

Hope it helps
-- 
View this message in context: 
http://www.nabble.com/Recursive-regression-tp25682804p25682804.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] Optim(...) estimate of stDev far too low

2009-09-30 Thread Peter Ehlers

Luis,

I don't think that you want log() in fn. Try it with

  pdf=-sum(dnorm(x, media, st, TRUE))

(and note the x, rather than xx).

-Peter Ehlers

Luis Ridao Cruz wrote:

R-help,

I'm just trying to find the ML (maximum likelihood) estimates
of the mean and standard deviation of a set of observations:


xx=c(2.5,3.5,4,6,6.5,7.5)



fn<-function(params,x=xx)
{
media<-params[1]
st   <-params[2]
pdf=-sum(dnorm(log(xx),log(media),st,TRUE))
return(pdf)
}

optim(c(mu,stdev),fn,method="L-BFGS-B",lower=c(0.001, 0.001)
,upper = rep(Inf, 2), hessian=TRUE, control=list(trace=1))

iter0 value 3.011784
final  value 2.802694 
converged

$par
[1] 4.6597779 0.3860387

$value
[1] 2.802694

$counts
function gradient 
  17   17 


$convergence
[1] 0

$message
[1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"

WHich gives an estimate of stDev = 0.38
while the empirical stDev = 1.94

Is there anything wrong above in the code?

Thanks in advance

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] k-modes (Huang) in package klaR?

2009-09-30 Thread Uwe Ligges



Kim Vanselow wrote:

Dear R-Users and Developers,
I want to calculate something like k-means clustering, but with ordinal data 
(Braun-Blanquet) to combine this classification technique with a 
NMDS-Ordination.
I found an algorithm especially developed for categorical data: k-modes (Huang 
1998). Is there a function implemented in R which can calculate with this 
algorithm. I found a hint on a poster-abstract from Gero Szepannek, Uwe Ligges 
and Claus Weihs. There it is stated that the algorithm is implemented in their 
package klaR. But I cannot find anything about k-modes in the klaR-Tutorial.
Could you please help me.


Dear Kim,

well, maybe you start writing a message to the authors of that 
poster-abstract at first who might be able to help?
Since I am one of those: Where can I find this abstract or poster (at 
least in order to remind Gero who does no longer work at the university 
to finally implement the feature, if it is not yet there)?


Best wishes,
Uwe Ligges




Thanks
Kim


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Condition to factor (easy to remember)

2009-09-30 Thread Gabor Grothendieck
1. A common way of doing this is cut:

  > cut(data, c(-Inf, 10, Inf), lab = levs, right = TRUE)
  [1] Pre  Pre  Pre  Post Post
  Levels: Pre Post

We don't actually need right=TRUE as its the default but if you omit
it then it can be hard to remember whether the right end of intervals
are included or excluded in the subdivision so I would recommend
including it as a matter of course.  Slightly less safe but if you
knew the values were  integral then another approach that would allow
dropping the right= argument would be to use 10.5 as the breakpoint in
which case the setting of right= does not matter anyways.

2. Similar to cut is findInterval so the subscripting of your first
solution could be done via findInterval:

   > levs[ findInterval(data, c(-Inf, 10), right = TRUE) ]
   [1] "Pre"  "Pre"  "Pre"  "Post" "Post"

The same comment regarding 10.5 applies.  I've omitted the factor(...)
part to focus on the difference and in the remaining examples have
done that too.

3. Either of these could replace the ifelse.  Both work by vectorizing
an ordinary if but sapply is a more common way to do it so is likely
preferable from the viewpoint of clarity.

   > # 3a
   > sapply(data, function(x) if (x <= 10) levs[1] else levs[2])
   [1] "Pre"  "Pre"  "Pre"  "Post" "Post"

   > # 3b
   > Vectorize(function(x) if (x <= 10) levs[1] else levs[2])(data)
   [1] "Pre"  "Pre"  "Pre"  "Post" "Post"

4. The subscripting in your first solution could be done like this
which is a bit longer but is arguably easier to understand:

   > levs[ 1 * (data <=10) + 2 * (data > 10) ]
   [1] "Pre"  "Pre"  "Pre"  "Post" "Post"


On Wed, Sep 30, 2009 at 3:43 AM, Dieter Menne
 wrote:
>
> Dear List,
>
> creating factors in a given non-default orders is notoriously difficult to
> explain in a course. Students love the ifelse construct given below most,
> but I remember some comment from Martin Mächler (?) that ifelse should be
> banned from courses.
>
> Any better idea? Not necessarily short, easy to remember is important.
>
> Dieter
>
>
> data = c(1,7,10,50,70)
> levs = c("Pre","Post")
>
> # Typical C-Programmer style
> factor(levs[as.integer(data >10)+1], levels=levs)
>
> # Easiest to understand
> factor(ifelse(data <=10, levs[1], levs[2]), levels=levs)
>
> --
> View this message in context: 
> http://www.nabble.com/Condition-to-factor-%28easy-to-remember%29-tp25676411p25676411.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] How to calculate KMO?

2009-09-30 Thread G. Jay Kerns
Dear Moumita,



On Wed, Sep 30, 2009 at 10:03 AM, Moumita Das
 wrote:
> Hi All,
> How do i calculate KMO for a dataset?
>
> *Dataset:-*
>
>    m1 m2 m3 m4 m5 m6 m7 m8
> 1       2 20 20  2  1  4 14 12
> 2       9 16  3  5  2  5  5 15
> 3      18 18 18 13 17  9  2  4
> 4       7  7  2 12  2 11 11 11
> 5       7  8  5 19  5  2 20 18
> 6       7  4  7  4  7  9  3  3
> 7       5  5  5 12  5 13 13 12
> 8       6  6  4  3  5 17 17 16
> 9      12 12  4  2  4  4 14 14
> 10      5 14  6 19  6  2 20 20
> 11     13 13 13 20 10 10 10  9
> 12      3  3  3 11  6 15 15 12
> 13      2  2  2  7  5  5  6 16
> 14     11 11 10  4 10 10 10 10
> 15      1  1  1  8  4 16 16 17
> 16     23 23  3  4  3  3  3  3
> 17      4  4  6  9  8 17  8 18
> 18      8  8  5  9  7  7  7  9
> 19      6  7  8  3  8  4  4  7
> 20      8 11  9  3  2  2  2  3
>
> **
> *SPSS results for the above dataset:*
>
> Kaiser-Meyer-Olkin Measure of Sampling Adequacy.(KMO)
> 0.350911931549742
>
> *Got a R-function:-* (
> http://www.opensubscriber.com/message/r-h...@stat.math.ethz.ch/2776549.html)
> kmo.test <- function(df){
> ###
> ## Calculate the Kaiser-Meyer-Olkin Measure of Sampling Adequacy.
> ## Input should be a data frame or matrix, output is the KMO statistic.
> ## Formula derived from Hutcheson et al, 1999,
> ## "The multivariate social scientist," page 224, ISBN 0761952012
> ## see 
> 
> ###
> cor.sq = cor(df)^2
> cor.sumsq = (sum(cor.sq)-dim(cor.sq)[1])/2
> library(corpcor)
> pcor.sq = cor2pcor(cor(df))^2
> pcor.sumsq = (sum(pcor.sq)-dim(pcor.sq)[1])/2
> kmo = sus.cor.ss/(sus.cor.ss+sus.pcor.ss)
> return(kmo)
> }
>
> What is this object "*sus.cor.ss*"?I get errors
>> sus.cor.ss
> Error: object "sus.cor.ss" not found
>
>
> Thanks in advance
> Moumita
>


I gave the solution to this in the next message in the thread:

http://www.opensubscriber.com/message/r-h...@stat.math.ethz.ch/7315408.html

If you simply copy-paste the function I wrote there into your R
session it gives the same answer as SPSS;  I just checked it myself.

This may save you some time:

D <-
structure(list(m1 = c(2L, 9L, 18L, 7L, 7L, 7L, 5L, 6L, 12L, 5L,
13L, 3L, 2L, 11L, 1L, 23L, 4L, 8L, 6L, 8L), m2 = c(20L, 16L,
18L, 7L, 8L, 4L, 5L, 6L, 12L, 14L, 13L, 3L, 2L, 11L, 1L, 23L,
4L, 8L, 7L, 11L), m3 = c(20L, 3L, 18L, 2L, 5L, 7L, 5L, 4L, 4L,
6L, 13L, 3L, 2L, 10L, 1L, 3L, 6L, 5L, 8L, 9L), m4 = c(2L, 5L,
13L, 12L, 19L, 4L, 12L, 3L, 2L, 19L, 20L, 11L, 7L, 4L, 8L, 4L,
9L, 9L, 3L, 3L), m5 = c(1L, 2L, 17L, 2L, 5L, 7L, 5L, 5L, 4L,
6L, 10L, 6L, 5L, 10L, 4L, 3L, 8L, 7L, 8L, 2L), m6 = c(4L, 5L,
9L, 11L, 2L, 9L, 13L, 17L, 4L, 2L, 10L, 15L, 5L, 10L, 16L, 3L,
17L, 7L, 4L, 2L), m7 = c(14L, 5L, 2L, 11L, 20L, 3L, 13L, 17L,
14L, 20L, 10L, 15L, 6L, 10L, 16L, 3L, 8L, 7L, 4L, 2L), m8 = c(12L,
15L, 4L, 11L, 18L, 3L, 12L, 16L, 14L, 20L, 9L, 12L, 16L, 10L,
17L, 3L, 18L, 9L, 7L, 3L)), .Names = c("m1", "m2", "m3", "m4",
"m5", "m6", "m7", "m8"), class = "data.frame", row.names = c(NA,
-20L))

kmo(D)



HTH,
Jay



***
G. Jay Kerns, Ph.D.
Associate Professor
Department of Mathematics & Statistics
Youngstown State University
Youngstown, OH 44555-0002 USA
Office: 1035 Cushwa Hall
Phone: (330) 941-3310 Office (voice mail)
-3302 Department
-3170 FAX
VoIP: gjke...@ekiga.net
E-mail: gke...@ysu.edu
http://people.ysu.edu/~gkerns/

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

2009-09-30 Thread David Winsemius
Wrong mailing list. Suggest reposting on R-SIG-Mac but only after re- 
reading the Posting Guide.



On Sep 30, 2009, at 10:03 AM, Bunny, lautloscrew.com wrote:


Dear all,

i am trying to get PL / R running on Mac OS X. PostgreSQL is already  
running and connects just smoothly to R via DBI / RPostgreSQL .


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] Change directory to implement same programes

2009-09-30 Thread Paul Hiemstra

Hi,

You can use list.files() of Sys.glob to get a listing of all the files 
in a certain directory, e.g. to get all ".R" files and source them:


for(f in Sys.glob("C:/Documents and Settings/lma/*.R")) source(f)

cheers,
Paul

Tammy Ma wrote:

How do I source a bunch of files in different directories in R?

  

From: metal_lical...@live.com
To: r-help@r-project.org
Date: Wed, 30 Sep 2009 13:45:34 +0300
Subject: [R] Change directory to implement same programes


HI, R-Users,

I have one problem:

I have written the the programs which process all file in one directory: for 
example:

setwd("C:/Documents and Settings/lma/My Documents/Vappu-saved/Log") as the 
start.
..

But I have many folders like "Vappu-saved" and there are a lot of files in each 
directory. What I want is using the same program what I write for the above directory
 to autimatically change directory address to implement the above programs what 
I wrote. How do I realize it?

Thanks a lot.

Regards,
Lingyi
 		 	   		  
_

Windows Live™: Keep your life in sync. Check it out!
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
[[alternative HTML version deleted]]


 		 	   		  
_
Show them the way! Add maps and directions to your party invites. 
http://www.microsoft.com/windows/windowslive/products/events.aspx

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



--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] k-modes (Huang) in package klaR?

2009-09-30 Thread Kim Vanselow
Dear R-Users and Developers,
I want to calculate something like k-means clustering, but with ordinal data 
(Braun-Blanquet) to combine this classification technique with a 
NMDS-Ordination.
I found an algorithm especially developed for categorical data: k-modes (Huang 
1998). Is there a function implemented in R which can calculate with this 
algorithm. I found a hint on a poster-abstract from Gero Szepannek, Uwe Ligges 
and Claus Weihs. There it is stated that the algorithm is implemented in their 
package klaR. But I cannot find anything about k-modes in the klaR-Tutorial.
Could you please help me.

Thanks
Kim
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!

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

2009-09-30 Thread Moumita Das
Hi All,
How do i calculate KMO for a dataset?

*Dataset:-*

m1 m2 m3 m4 m5 m6 m7 m8
1   2 20 20  2  1  4 14 12
2   9 16  3  5  2  5  5 15
3  18 18 18 13 17  9  2  4
4   7  7  2 12  2 11 11 11
5   7  8  5 19  5  2 20 18
6   7  4  7  4  7  9  3  3
7   5  5  5 12  5 13 13 12
8   6  6  4  3  5 17 17 16
9  12 12  4  2  4  4 14 14
10  5 14  6 19  6  2 20 20
11 13 13 13 20 10 10 10  9
12  3  3  3 11  6 15 15 12
13  2  2  2  7  5  5  6 16
14 11 11 10  4 10 10 10 10
15  1  1  1  8  4 16 16 17
16 23 23  3  4  3  3  3  3
17  4  4  6  9  8 17  8 18
18  8  8  5  9  7  7  7  9
19  6  7  8  3  8  4  4  7
20  8 11  9  3  2  2  2  3

**
*SPSS results for the above dataset:*

Kaiser-Meyer-Olkin Measure of Sampling Adequacy.(KMO)
0.350911931549742

*Got a R-function:-* (
http://www.opensubscriber.com/message/r-h...@stat.math.ethz.ch/2776549.html)
kmo.test <- function(df){
###
## Calculate the Kaiser-Meyer-Olkin Measure of Sampling Adequacy.
## Input should be a data frame or matrix, output is the KMO statistic.
## Formula derived from Hutcheson et al, 1999,
## "The multivariate social scientist," page 224, ISBN 0761952012
## see 

###
cor.sq = cor(df)^2
cor.sumsq = (sum(cor.sq)-dim(cor.sq)[1])/2
library(corpcor)
pcor.sq = cor2pcor(cor(df))^2
pcor.sumsq = (sum(pcor.sq)-dim(pcor.sq)[1])/2
kmo = sus.cor.ss/(sus.cor.ss+sus.pcor.ss)
return(kmo)
}

What is this object "*sus.cor.ss*"?I get errors
> sus.cor.ss
Error: object "sus.cor.ss" not found


Thanks in advance
Moumita

[[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] R/PL : cannot build PL/R

2009-09-30 Thread Bunny, lautloscrew.com

Dear all,

i am trying to get PL / R running on Mac OS X. PostgreSQL is already  
running and connects just smoothly to R via DBI / RPostgreSQL .
Despite finding a couple of posts of people with the same problem  
(i.e. error message) i could not get it done for me.

I use Mac OS 10.5.7 and PostgreSQL 8.3.7 as well as R 2.9.2

I put the untared plr to my /Library/Frameworks/R.framework/Resources/

If i just add the path mentioned above to the Makefile and run  
USE_PGXS=1 make :


i get the following error message:

make: pg_config: Command not found
make: *** No targets.  Stop.

If simply run make inside the plr directory i get the following:

Makefile:41: ../../src/Makefile.global: No such file or directory
Makefile:42: /contrib/contrib-global.mk: No such file or directory
make: *** No rule to make target `/contrib/contrib-global.mk'.  Stop.


If I change R_HOME in the makefile to Users/myname (which is supposed  
to be my R home and initial working directory) I get the following  
error message:



*** Cannot build PL/R because libR is not a shared library.
*** You might have to rebuild your R installation.  Refer to
*** the documentation for details.

This is a message i found already on several posts. Some answers  
suggest to recompile R with the shared lib option enabled. Anyway,  
some posts suggests that it is possible without recompiling.
Simon Urbanek for example said on a markmail.org post, it was possible  
without recompiling. I´d really like to know how...


Thx in advance for any suggestions !

Best regards

matt

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

2009-09-30 Thread Hayes, Rachel M
Hi all,

 

I have a vector of proportions (post_op_prw) such that

 

 >summary(amb$post_op_prw)

 

   Min. 1st Qu.  MedianMean 3rd Qu.Max.NA's 

 0.  0.  0.  0.3985  0.9134  0.9962  1. 

 

> summary(cut2(amb$post_op_prw,0.0001))

 

[0.,0.0001) [0.0001,0.9962]NA's 

   19041672  1

 

I want to use post_op_prw as a predictor variable in an OLS model.  I
decided to fit it using a restricted cubic spline.  But, I'm seeing
behavior I don't understand.  See below:

 

> rcspline.eval(amb$post_op_prw,nk = 3, knots.only = T)

[1] 0.000 0.6147927 0.9092937 0.9667178

Warning message:

In rcspline.eval(amb$post_op_prw, nk = 3, knots.only = T) :

  could not obtain 3 knots with default algorithm.

 Used alternate algorithm to obtain 4 knots

> rcspline.eval(amb$post_op_prw,nk = 4, knots.only = T)

[1] 0.000 0.8476793 0.9783558

> rcspline.eval(amb$post_op_prw,nk = 5, knots.only = T)

[1] 0.000 0.9012711 0.9783558

 

Why are the 4 and 5 knot spline requests returning a spline with 3
knots?  I get the best model results using rcs(amb$post_op_prw,3).   I'm
kind of new to using splines.  Does the fact that observations are
clustered at the ends make the spline fit questionable?  

 

Thanks,

 

Rachel Hayes


[[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] Optim(...) estimate of stDev far too low

2009-09-30 Thread Luis Ridao Cruz
R-help,

I'm just trying to find the ML (maximum likelihood) estimates
of the mean and standard deviation of a set of observations:

>xx=c(2.5,3.5,4,6,6.5,7.5)


fn<-function(params,x=xx)
{
media<-params[1]
st   <-params[2]
pdf=-sum(dnorm(log(xx),log(media),st,TRUE))
return(pdf)
}

optim(c(mu,stdev),fn,method="L-BFGS-B",lower=c(0.001, 0.001)
,upper = rep(Inf, 2), hessian=TRUE, control=list(trace=1))

iter0 value 3.011784
final  value 2.802694 
converged
$par
[1] 4.6597779 0.3860387

$value
[1] 2.802694

$counts
function gradient 
  17   17 

$convergence
[1] 0

$message
[1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"

WHich gives an estimate of stDev = 0.38
while the empirical stDev = 1.94

Is there anything wrong above in the code?

Thanks in advance

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 compile R with command completion?

2009-09-30 Thread Martin Morgan
Peng Yu wrote:
> On Tue, Sep 29, 2009 at 10:39 PM, Martin Morgan  wrote:
>> Peng Yu wrote:
>>> On Tue, Sep 29, 2009 at 3:47 PM, Tobias Verbeke
>>>  wrote:
 Peng Yu wrote:

> I want to compile R with command completion. But I don't find such an
> option in configure. Can somebody let me know how to enable command
> completion in an R session?
 AFAIK this is not an option you set when compiling.
 Did you try to type a letter (say 'l') and press the
 TAB key ?

 If you are not satisfied, you might want to use
 other R editors or development environments (such
 as StatET for Eclipse or ESS) which implement
 command completion in their idiosyncratic ways.
>>> I have an older version of R where I can do command completion (after
>>> typing TAB, it will list variables that are starting with the already
>>> typed letter. I compiled a newer version R with the default compile
>>> options, which does not do command completion.
>>>
>>> Since the old version can do completion, I believe that there must be
>>> a way to configure the new version also do so. Can somebody share your
>>> insights with me? Thank you!
>> On linux this facility is provided by the readline system library; this
>> should be configured to be true by default and when available; look at
>> the end of the configure output, and check that you have the readline
>> headers installed.
> 
> I get the following configure output that is related to readline. Why
> 'rl_completion_matches' doesn't exist? What should I do with it?
> 
> checking readline/history.h usability... yes
> checking readline/history.h presence... yes
> checking for readline/history.h... yes
> checking readline/readline.h usability... yes
> checking readline/readline.h presence... yes
> checking for readline/readline.h... yes
> checking for rl_callback_read_char in -lreadline... no
> checking for main in -lncurses... yes
> checking for rl_callback_read_char in -lreadline... yes
> checking for history_truncate_file... yes
> checking whether rl_completion_matches exists and is declared... no

I don't know. Ask on the R-devel mailing list. Include the output of R's
sessionInfo(), your operating system version, and the version of
readline (e.g., from /usr/include/readline/readline.h)

Martin

> 
> 
> checking readline/history.h usability... yes
> checking readline/history.h presence... yes
> checking for readline/history.h... yes
> checking readline/readline.h usability... yes
> checking readline/readline.h presence... yes
> checking for readline/readline.h... yes
> checking for rl_callback_read_char in -lreadline... no
> checking for main in -lncurses... yes
> checking for rl_callback_read_char in -lreadline... yes
> checking for history_truncate_file... yes
> checking whether rl_completion_matches exists and is declared... no
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

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


[R] Read header csv file

2009-09-30 Thread Lucas Sevilla García

Hi R community, 

First of all, I want to thank everybody to share their time solving R 
questions, You are great. Ok, for my questions, I've been looking for a 
solutions by myself, in forums but I'm just a little bit desesperate so I hope 
somebody can help me. I have built a code to read files from a directory. These 
files are named by a year (2004.csv, 2005.csv,...). When the code reads first 
file (2004.csv), inside this file, there is information about precipitation of 
every months and I calculate different variables like R square adjusted, p 
value or formula fit to the data from linear regression. The code do more 
things but for my question, to explain what I need, that part of the code is 
enough. I want to export to the text file, year and month apart of some other 
variables, something like this:

Year: 2004   Month: January  R1: 0.98   Pvalue: 0.03 ...
Year: 2004   Month: February  R1:0.78   Pvalue:0.12 ...

I've seen that I can use order sink() and cat(), so I would put those orders in 
my code, like this:

nfiles<- length(dir("directory where my files are"))   #Count file number

for(year in 1:nfiles)#Read first file 
{
filename<-dir()[[year]]#take first file and read 
filename, so if year is 1, then filename will be 2004, is year is 2, filename 
will be 2005,...
   
clima<-read.csv2(filename, nrows=7) #open 2004.csv


So, if want to export year to my text file I would do


  for(year in 1:nfiles)#Read first file 

{
sink("directore where my text file is")

filename<-dir()[[year]]#take first file and
read filename, so if year is 1, then filename will be 2004, is year is
2, filename will be 2005,...

cat(" Year: ",filename)
sink()

clima<-read.csv2(filename, nrows=7) #open 2004.csv

And in my text file would read

Year: 2004

Now, I want to the same to months. (I have built a for loop to read months 
inside for loop to read years). When I import a csv file I get something like 
this

 JanurayFebruary 
13.0 4.1
21.4  3.7
3 0.2 1.5
4 6.7  4.1
.
.
.

I can use commands like clima$Januray or clima[[1]] but I just get 
precipitation values. However, I am not able to get the header of the column. 
If I would able to do that I could do the same as for years and export those 
headers to my text file. Does anyone know how I could do that? or does anyone 
know another way to do what I need? Would anyone use sink() and cat() commands 
to create a summary text like the one I need to do?. Probably my for loop is 
not the best, I am still a beginner with R, and probably there are some better 
forms to express in R what I need but I am working alone so there is nobody in 
person to help me so I apologize for my simple questions. Thanks in advance.

Lucas



  
_


[[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] Overview of error and warning messages for teaching + examples

2009-09-30 Thread joris meys
Dear all,

The background: as I didn't find a manual specifically directed
towards debugging R code on a novice and intermediate level, I decided
to write a student manual myself. I have some basic examples of errors
(the classical interpunction and writing mistakes), but have the
feeling that I miss quite some of the frequently occuring mistakes and
messages. Therefore I'm looking around to find a list of these, and if
possible, some examples of wrong R code.

I have been googling around a bit, but I couldn't find an overview of
the most common error and warning messages in R. Off course this
mailing list is an extensive source of all kind or errors and
examples, but I was wondering if there is a somewhat more structured
overview. All help appreciated.

Kind regards
Joris Meys

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

2009-09-30 Thread David Winsemius


On Sep 30, 2009, at 7:57 AM, johannes rara wrote:


I would like to learn AsciiDoc. Is there any good examples how to use
AsciiDoc with R? I know that there is packages called ascii to do
this, but it would be nice to see some examples how AsciiDoc works
with R. Is there an AsciiDoc distribution for Max OS X?


http://lmgtfy.com/?q=asciidoc+mac+os+x

(Google even gives you informative links if you misspell it (as I did)  
as ascidocs the first time.)


--
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] bwplot scales in alphabetical order

2009-09-30 Thread Peter Ehlers

Tim,

Add the argument as.table=TRUE to your call:

  bwplot(y~x|id, horizontal=FALSE, as.table=TRUE)

Peter Ehlers

Tim Clark wrote:

Dear List,

I know this has been covered before, but I don't seem to be able to get it right.  I am constructing a boxplot in lattice and can't get the scales in the correct alphebetical order.  I have already read that this is due to the way factors are treated, and I have to redefine the levels of the factors.  However, I have failed.  
As a simple example:


library(lattice)
id<-rep(letters[1:9], each=20)
x<-rep(seq(1:10),each=18)
y<-rnorm(180,50,20)

#Reverse alphebetical order
  bwplot(y~x|id, horizontal=FALSE)

#alphebetical order reading right to left
  id<-factor(id,levels = sort(id,decreasing = TRUE))
  bwplot(y~x|id, horizontal=FALSE)

It appears that bwplot plots scales from the bottom left to the top right. If 
so my factor levels would need to be levels=c(7,8,9,4,5,6,1,2,3). I tried that 
but can't seem to get the factor function to work.

#Did not work!
id<-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9])

Your help would be greatly appreciated.

Tim





Tim Clark
Department of Zoology 
University of Hawaii


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


  1   2   >