Re: [R] Trading Strategy and Bootstrap

2015-12-15 Thread Joshua Ulrich
On Thu, Dec 10, 2015 at 4:30 PM, Schiele, Erik
 wrote:
> Hi,
>
> I'm beginning to fool around in R for trading strategy purposes. To keep it 
> simple, I have only played with stock data at this point.
>
> I have created a simple trend following strategy (in blue). Given my 
> statistical background, I am attempting to bootstrap the results and table 
> the same parameters highlighted below with no luck (in green). Any ideas on 
> what I could do differently?
>
People will be more likely to respond and help if you provide a more
specific problem statement than, "with no luck".  What's wrong with
your current solution?  What other things have you tried and why
weren't they sufficient?

Also, please do not cross-post.  It's inconsiderate to those who don't
follow both lists: they won't know whether someone has provided a
satisfactory answer on the list/forum they don't follow.

> Really Appreciate your help!!! Thanks
>
> library(quantmod)
> library(PerformanceAnalytics)
>
> b <- get(getSymbols('SPY'))["2011::"]
> s <- get(getSymbols('GLD'))["2011::"]
> b$sma1 <- SMA(Cl(s) , 1)
> s$sma50 <- SMA(Cl(s) , 50)
> s$position <- ifelse(Cl(s) > s$sma50 , 1 , -1)
> myReturn <- lag(s$position) * dailyReturn(s)
>
> table.Drawdowns(s$position, top = 5, digits = 1)
> table.Stats(s$position, ci = 0.95, digits = 2)
> table.SpecificRisk(s$position, b$sma1, Rf = 0, digits = 2)
> table.Correlation(s$position, b$sma1)
>
> charts.PerformanceSummary(cbind(dailyReturn(s),myReturn))
>
> N = 100 # Number of simulations
> Loop  = mat.or.vec(N,2,1,1,1)
> for (i in 1:N){
>
>   # sample with replacement from return distribution of index
>   s.new = (sample(s, length(s), replace = T, prob = NULL))
>   # demeaning returns
>   s.new = s.new-mean(s)
>   # new price series starting at same value as original series
>   prices.new = xts(prices[[1]]*exp(cumsum(s.new)))
>
>   # define strategies
>   # mean reversion
>   s$sma50.new  = SMA(Cl(s.new) , 50)
>
># Create buy/sell signals
># mean reversion
>s$position.new <- ifelse(Cl(s) > s$sma50.new , 1 , -1)
>
># replace missing values with zeros
>s$position.new[is.na(s$position.new)]   = 0
>
>Loop[i,1] = if (mean(s$position.new)  > mean(s$sma50.new)) {1}else{0}
> }
>
> #Loop
>
> # plots simulated series
> returns.new = cbind(s$sma50.new, cumsum(s$sma50.new))
>
>  chart.CumReturns(returns.new,s$sma50.new,geometric=F)
>
> Erik Schiele
> Vice President
> Money Markets Trading, Originations and Sales
> 101 Barclay St, NY NY 10007 3rd Floor
> BNY Mellon Capital Markets, LLC
> Main Desk 212-815-8222
>
> This is for informational purposes only; from sources the Firm believes 
> reliable; may not be accurate or complete; is subject to change;  is not a 
> recommendation or offer to buy/sell a financial instrument or adopt any 
> investment strategy; is not legal, tax, credit or accounting advice.  Do not 
> use e-mail to submit any instructions - acceptances are at your risk. The 
> Firm or its affiliates lends to, borrows from and provides other 
> products/services to issuers and others, receives compensation therefore, and 
> periodically has a direct or indirect financial interest in the financial 
> instruments/transactions indicated.  Additional risks may exist that are not 
> referenced. Past performance is not indicative of future returns. Other than 
> CDs or CDARS, financial instruments: are not FDIC insured; are not deposits 
> or other obligations of and are not guaranteed by the Firm or any bank or 
> non-bank affiliate; and involve investment risk including possible loss of 
> principal. The Firm i!
 s !
>  a wholly owned, indirect non-bank subsidiary of The Bank of New York Mellon 
> Corporation, and a member of FINRA and SIPC, and is solely responsible for 
> its obligations and commitments.
>
>
> The information contained in this e-mail, and any attachment, is confidential 
> and is intended solely for the use of the intended recipient. Access, copying 
> or re-use of the e-mail or any attachment, or any information contained 
> therein, by any other person is not authorized. If you are not the intended 
> recipient please return the e-mail to the sender and delete it from your 
> computer. Although we attempt to sweep e-mail and attachments for viruses, we 
> do not guarantee that either are virus-free and accept no liability for any 
> damage sustained as a result of viruses.
>
> Please refer to http://disclaimer.bnymellon.com/eu.htm for certain 
> disclosures relating to European legal entities.
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

_

Re: [R] Weird behaviour function args in ellipses

2015-12-15 Thread peter dalgaard

> On 11 Dec 2015, at 20:13 , Duncan Murdoch  wrote:
> 
> On 11/12/2015 1:52 PM, Mario José Marques-Azevedo wrote:
>> Hi Duncan and David,
>> 
>> Thank you for explanation. I'm really disappointed with this R "resource".
>> I think that partial match, mainly in function args, must be optional and
>> not default. We can have many problems and lost hours find errors (it occur
>> with me). I tried to find a solution to disable partial match, but it seems
>> that is not possible. Program with hacks for this will be sad.
> 
> Nowadays with smart editors, I agree that partial matching isn't really 
> necessary.  However, R has been around for 20 years, and lots of existing 
> code depends on it.   Eventually you'll get to know the quirks of the design.

Yes, partial matching is largely regretted by its inventors, but it is hard to 
get rid of due to various arcane bits of history. For instance, have you 
noticed that seq() doesn't have a "length" argument? I.e.

> seq(2, length=3)
[1] 2 3 4

actually only works due to partial matching -- the argument is really 
"length.out". Now, looking that the code for seq.default offers a hint at the: 
It uses things like length(by) internally. In ancient times (in S) that would 
give you a type mismatch, but one of the things that R changed was to have 
function lookup disregard non-function objects.

In other places, some argument names have a period added for similar reasons.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

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

Re: [R] problem with Rcpp and boost threadpool

2015-12-15 Thread Bert Gunter
There is a Rcpp-devel mailing list that should be more suitable for this post.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Dec 15, 2015 at 11:44 AM, Ken Gosier via R-help
 wrote:
> I'm having a problem calling a local library through Rcpp with R Studio 
> Server. It's a bit perplexing, since I have no issues when I call it from R 
> at the command line.
>
> I've written an analytics library which uses boost's threadpool functionality 
> for running multiple threads. I've stripped everything down to the bare 
> essentials, the minimum code which will cause the problem -- this code just 
> starts the threads in the threadpool, then exits them:
>
>
> #include 
>
> #include 
> #include 
> #include 
> #include 
> #include 
>
> RcppExport SEXP test_thread()
> {
> BEGIN_RCPP
> double retdbl = 10.4;
>
> boost::shared_ptr threadpool_work;
> boost::asio::io_service threadpool_io_service;
> boost::thread_group threadpool_threads;
>
> threadpool_work.reset(  new
> boost::asio::io_service::work(threadpool_io_service)  );
> for (int i = 0; i < 6; ++i) {
> threadpool_threads.create_thread(
> boost::bind(&boost::asio::io_service::run, 
> &threadpool_io_service));
> }
>
> threadpool_io_service.stop();
> threadpool_work.reset();
> threadpool_threads.join_all();
>
> return(  Rcpp::wrap(retdbl)  );
> END_RCPP
> }
>
>
> When I run from command-line R, there's no problem, I get the double 
> returned. However, when I run through R Studio Server, it either hangs 
> endlessly, or it crashes when it gets to the create_thread statement.
>
> My version info is:
>
> R: R version 3.1.1 (2014-07-10) -- "Sock it to Me"
> R Studio: 0.99.489
> Linux: Linux Debian-Jessie 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 
> (2015-11-09) x86_64 GNU/Linux
> boost: 1.55
>
> Many thanks for any help!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] TIBCO Enterprise Runtime for R

2015-12-15 Thread William Dunlap via R-help
It looks like you are calling TERR from Spotfire.  The Spotfire/TERR interface
can only pass TERR data.frames (eq. to Spotfire tables) back to Spotfire and
XMLInternalDocuments cannot be columns of data.frames (in neither TERR nor
R).

You should contact TIBCO support and/or participate in the forums at
community.tibco.com to see how to solve your problem.


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Dec 15, 2015 at 5:09 AM, Archit Soni  wrote:
> Hi All,
>
> I have the code to print XML tree that is working successfully in R Studio
> but is failing when i try to work it out with TERR:
>
> x<- XML::xmlParse(y)
>
> y is input (Coming from a row only once)
> x is output
>
> The above code is working in R studio but doesnt work in TERR, please
> suggest.
>
> TIBCO Enterprise Runtime for R returned an error: 'Error in
> as.data.frame.default(passed.args[[i]], stringsAsFactors = s : cannot
> coerce class '"XMLInternalDocumentXMLAbstractDocument"' into a data.frame'.
> at
> Spotfire.Dxp.Data.DataFunctions.Executors.LocalFunctionClient.OnExecuting(FunctionClient
> funcClient) at
> Spotfire.Dxp.Data.DataFunctions.Executors.AbstractFunctionClient.d__0.MoveNext()
> at
> Spotfire.Dxp.Data.DataFunctions.Executors.SPlusFunctionExecutor.d__0.MoveNext()
> at
> Spotfire.Dxp.Data.DataFunctions.DataFunctionExecutorService.d__6.MoveNext()
>
> --
> Regards
> Archit
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] close specific graphics device

2015-12-15 Thread Jim Lemon
Hi Dan,
The range of device numbers seems to be 1-63. There doesn't appear to be a
means of explicitly setting the device number when calling dev.new, and
devices are numbered sequentially when they are opened. This means that
even if you did know that the device number was, say, 4 it would be
possible to close that device and open another device with the number 4.

I suppose it would be possible to write wrapper functions for this, but I
have to leave at the moment, so perhaps tomorrow.

Jim

On Wed, Dec 16, 2015 at 7:51 AM, Dalthorp, Daniel 
wrote:

> dev.off(which) can be used to close a specific graphics device where
> "which" is the index of the device, but is there a way to assign a custom
> number (or name) to a windows device so that specific window can be later
> closed via dev.off (or some other method) if it is open?
>
> The following does NOT work. The target device is not open when its dev.off
> is called, and another window that later got assigned the original index
> associated with the target device is closed instead.
>
> plot(0,0,type='n') # target window to close
> text(0,0,"close me")
> targetindex<-dev.cur()
>
> # unbeknownst to the programmer, user closes device by clicking the red "X"
> or...
> dev.off()
>
> # user draws a new graph that he wants to keep open
> plot(1,1,type='n')
> text(1,1,"do not close me")
>
> # now it's time for the program to close the original graphics device (if
> it still happens to be open)
> dev.off(targetindex)
>
> # the wrong device has been closed because the original window had closed
> and the index associated with original graph is now associated with
> something else
>
> 
>
> I'm looking for something like:
>
> dev.off(which = "original figure") or dev.off(which = n), where n is a
> custom index (like 1) that will not be later assigned to a different
> device [unless explicitly assigned that index].
>
> Any help would be greatly appreciated.
>
> Thanks!
>
>
>
> --
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] problem with Rcpp and boost threadpool

2015-12-15 Thread Ken Gosier via R-help
I'm having a problem calling a local library through Rcpp with R Studio Server. 
It's a bit perplexing, since I have no issues when I call it from R at the 
command line. 

I've written an analytics library which uses boost's threadpool functionality 
for running multiple threads. I've stripped everything down to the bare 
essentials, the minimum code which will cause the problem -- this code just 
starts the threads in the threadpool, then exits them: 


#include  

#include  
#include  
#include  
#include  
#include  

RcppExport SEXP test_thread() 
{ 
BEGIN_RCPP 
double retdbl = 10.4; 

boost::shared_ptr threadpool_work; 
boost::asio::io_service threadpool_io_service; 
boost::thread_group threadpool_threads; 

threadpool_work.reset(  new 
boost::asio::io_service::work(threadpool_io_service)  ); 
for (int i = 0; i < 6; ++i) { 
threadpool_threads.create_thread( 
boost::bind(&boost::asio::io_service::run, 
&threadpool_io_service)); 
} 

threadpool_io_service.stop(); 
threadpool_work.reset(); 
threadpool_threads.join_all(); 

return(  Rcpp::wrap(retdbl)  ); 
END_RCPP 
} 


When I run from command-line R, there's no problem, I get the double returned. 
However, when I run through R Studio Server, it either hangs endlessly, or it 
crashes when it gets to the create_thread statement. 

My version info is: 

R: R version 3.1.1 (2014-07-10) -- "Sock it to Me" 
R Studio: 0.99.489 
Linux: Linux Debian-Jessie 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 
(2015-11-09) x86_64 GNU/Linux 
boost: 1.55

Many thanks for any help!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] party package: is cforest really bagging?

2015-12-15 Thread Benjamin
Hi all,

I'm using the "party" package to create random forest of regression trees. I've
created a ForestControl class in order to limit my number of trees (ntree),
of nodes (maxdepth) and of variables I use to fit a tree (mtry). One thing
I'm not sure of is if the cforest algo is using subsets of my training set
for each tree it generates or not.

I've seen in the documentation that it is bagging so I assume it should.
But I'm not sure to understand well what the "subset" input is in that
function.

I'm also puzzled by the results I get using ctree: when plotting the tree,
I see that all my variables of my training set are classified in the
different terminal tree nodes while I would have exepected that it only
uses a subset here too.

So my question is, is cforest doing the same thing as ctree or is it really
bagging my training set?

Thanks in advance for you help!

Ben

[[alternative HTML version deleted]]

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread Jim Lemon
Hi,
My understanding is:

() - parentheses
{} - braces
[] - square brackets
<> - angle brackets

Jim


On Wed, Dec 16, 2015 at 6:17 AM, S Ellison  wrote:

> > It is clear that a ) although is a type of bracket it is called a
> parenthesis, just as ,
> > is called a comma, which is a type of punctuation mark.
>
> These things are called parentheses because of what they do, not what they
> are.
> A parenthesis is any word or phrase inserted as an explanation or
> afterthought into text that would be is grammatically complete without it,
> usually bounded by punctuation. The bounding punctuation marks are then
> called parentheses, and can be round, square, or curly brackets, dashes, or
> just commas.
>
> So (),  [], {}, - ... -  and , ... , are _all_ pairs of parentheses in
> grammatical usage.
>
> Three of them are also kinds of bracket, but not the only kinds.
>
> There's a disturbingly extensive article on it at
> https://en.wikipedia.org/wiki/Bracket#Names_for_various_bracket_symbols
>
> which suggests to me that the terms are unlikely to be standardised
> quickly.
>
> Steve E
>
>
> ***
> This email and any attachments are confidential. Any u...{{dropped:13}}

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


Re: [R] close specific graphics device

2015-12-15 Thread Sarah Goslee
You could keep track of the device number using dev.cur() when you
create the plot, and some combination of
dev.set()
dev.list()
dev.close(which=mydev)

to manage them.

Sarah

On Tue, Dec 15, 2015 at 3:51 PM, Dalthorp, Daniel  wrote:
> dev.off(which) can be used to close a specific graphics device where
> "which" is the index of the device, but is there a way to assign a custom
> number (or name) to a windows device so that specific window can be later
> closed via dev.off (or some other method) if it is open?
>
> The following does NOT work. The target device is not open when its dev.off
> is called, and another window that later got assigned the original index
> associated with the target device is closed instead.
>
> plot(0,0,type='n') # target window to close
> text(0,0,"close me")
> targetindex<-dev.cur()
>
> # unbeknownst to the programmer, user closes device by clicking the red "X"
> or...
> dev.off()
>
> # user draws a new graph that he wants to keep open
> plot(1,1,type='n')
> text(1,1,"do not close me")
>
> # now it's time for the program to close the original graphics device (if
> it still happens to be open)
> dev.off(targetindex)
>
> # the wrong device has been closed because the original window had closed
> and the index associated with original graph is now associated with
> something else
>
> 
>
> I'm looking for something like:
>
> dev.off(which = "original figure") or dev.off(which = n), where n is a
> custom index (like 1) that will not be later assigned to a different
> device [unless explicitly assigned that index].
>
> Any help would be greatly appreciated.
>
> Thanks!
>
>

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] close specific graphics device

2015-12-15 Thread Dalthorp, Daniel
dev.off(which) can be used to close a specific graphics device where
"which" is the index of the device, but is there a way to assign a custom
number (or name) to a windows device so that specific window can be later
closed via dev.off (or some other method) if it is open?

The following does NOT work. The target device is not open when its dev.off
is called, and another window that later got assigned the original index
associated with the target device is closed instead.

plot(0,0,type='n') # target window to close
text(0,0,"close me")
targetindex<-dev.cur()

# unbeknownst to the programmer, user closes device by clicking the red "X"
or...
dev.off()

# user draws a new graph that he wants to keep open
plot(1,1,type='n')
text(1,1,"do not close me")

# now it's time for the program to close the original graphics device (if
it still happens to be open)
dev.off(targetindex)

# the wrong device has been closed because the original window had closed
and the index associated with original graph is now associated with
something else



I'm looking for something like:

dev.off(which = "original figure") or dev.off(which = n), where n is a
custom index (like 1) that will not be later assigned to a different
device [unless explicitly assigned that index].

Any help would be greatly appreciated.

Thanks!



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread S Ellison
> It is clear that a ) although is a type of bracket it is called a 
> parenthesis, just as ,
> is called a comma, which is a type of punctuation mark.

These things are called parentheses because of what they do, not what they are. 
A parenthesis is any word or phrase inserted as an explanation or afterthought 
into text that would be is grammatically complete without it, usually bounded 
by punctuation. The bounding punctuation marks are then called parentheses, and 
can be round, square, or curly brackets, dashes, or just commas.

So (),  [], {}, - ... -  and , ... , are _all_ pairs of parentheses in 
grammatical usage. 

Three of them are also kinds of bracket, but not the only kinds. 

There's a disturbingly extensive article on it at 
https://en.wikipedia.org/wiki/Bracket#Names_for_various_bracket_symbols

which suggests to me that the terms are unlikely to be standardised quickly.

Steve E


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

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


Re: [R] error on multiple "==" in bquote()

2015-12-15 Thread peter dalgaard

> On 15 Dec 2015, at 13:12 , One Two  wrote:
> 
> Hello,
> 
> I noticed that the function bquote throws an error if there are
> multiple "==" in the first argument. E.g.
>> txt.main <- bquote(1 == 2 == 3)
> Error: unexpected '==' in "txt.main <- bquote(1 == 2 =="
> 
> Is this behaviour intended or is it a bug? Because I don't see a
> reason for this behaviour and didn't find anything in the
> documentation either.

It's a consequence of the grammar of R. At some point, it was decided that a == 
b == c would have undesirable semantics[*], so == (and the other relational 
operators) became non-associative. It is a basic design feature of plotmath 
that it uses unevaluated R expressions, which have to be syntactically valid.

-pd

[*] As in

0 == 1 == 2
0 == (1 == 2)
0 == FALSE
0 == 0
TRUE

(which works from the 2nd line onwards, but then you can be assumed that you 
know what you are doing...)
 
> 
> I know that one can use grouping as a workaround like this:
>> txt.main <- bquote({1 == 2} == 3)
> I am rather interested in whether I should file a bug about this
> behaviour or not.
> 
> I'm using RStudio in this environment:
>> sessionInfo()
> R version 3.2.3 (2015-12-10)
> Platform: i386-w64-mingw32/i386 (32-bit)
> Running under: Windows 7 (build 7601) Service Pack 1
> 
> locale:
> [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
> LC_MONETARY=German_Germany.1252
> [4] LC_NUMERIC=CLC_TIME=German_Germany.1252
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> 
> loaded via a namespace (and not attached):
> [1] tools_3.2.3
> 
> Best Regards,
> Martin
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] TIBCO Enterprise Runtime for R

2015-12-15 Thread David Winsemius

> On Dec 15, 2015, at 5:09 AM, Archit Soni  wrote:
> 
> Hi All,
> 
> I have the code to print XML tree that is working successfully in R Studio
> but is failing when i try to work it out with TERR:
> 
> x<- XML::xmlParse(y)
> 
> y is input (Coming from a row only once)
> x is output
> 
> The above code is working in R studio but doesnt work in TERR, please
> suggest.
> 
> TIBCO Enterprise Runtime for R returned an error: 'Error in
> as.data.frame.default(passed.args[[i]], stringsAsFactors = s : cannot
> coerce class '"XMLInternalDocumentXMLAbstractDocument"' into a data.frame'.
> at
> Spotfire.Dxp.Data.DataFunctions.Executors.LocalFunctionClient.OnExecuting(FunctionClient
> funcClient) at
> Spotfire.Dxp.Data.DataFunctions.Executors.AbstractFunctionClient.d__0.MoveNext()
> at
> Spotfire.Dxp.Data.DataFunctions.Executors.SPlusFunctionExecutor.d__0.MoveNext()
> at
> Spotfire.Dxp.Data.DataFunctions.DataFunctionExecutorService.d__6.MoveNext()
> 

I think you should be contacting TIBCO.

> -- 
> Regards
> Archit
> 
>   [[alternative HTML version deleted]]

And do read the Posting Guide.

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

David Winsemius
Alameda, CA, USA

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


Re: [R] adding vector values to corresponding components of a list

2015-12-15 Thread David L Carlson
With each post you seem to be changing what you are trying to accomplish. Your 
WRONG way seems pretty close if I understand you at all. Just tag the names to 
the numeric vector instead of the logical vector, eg:

> names(dbv) <- letters[1:8]
> split(dbv,logmat1)
$`FALSE`
   adgh 
1.540183 1.172661 1.038135 1.172661 

$`TRUE`
   bcef 
1.295202 1.038135 1.540183 1.295202

But the other problem is that you may not realize what is happening. Using 
logmat1 (a matrix) as a vector in split means that it is converted by columns:

> logmat1
  [,1]  [,2] [,3]  [,4]
[1,] FALSE  TRUE TRUE FALSE
[2,]  TRUE FALSE TRUE FALSE

> as.vector(logmat1)
[1] FALSE  TRUE  TRUE FALSE  TRUE  TRUE FALSE FALSE

Earlier it seemed you wanted to combine the by rows:

c(logmat1[1,], logmat[2,])
[1] FALSE  TRUE  TRUE FALSE  TRUE FALSE  TRUE FALSE

As you can see, it makes a difference.

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of debra ragland 
via R-help
Sent: Tuesday, December 15, 2015 9:56 AM
To: R-help
Subject: [R] adding vector values to corresponding components of a list

Hello,

I have tried this 2 ways and I keep coming to a dead end as I am not very 
proficient in R.

I have a logical matrix, where I would like to generate every row-wise pair of 
logical values for further testing. That is row1, row2; row 1, row3 etc. 
Ideally, I would like to assign a pre-generated vector of values to each pair 
such that each combination of rows may be split into 2 groups with each 
variable appearing only once. 

This is similar to the WRONG way I've been trying to do this;

vector = runif(4, 1.0, 2.0)
logmat<-matrix(c(rep(c(F,T,F),3), rep(c(T,F,T),3), rep(c(T,T,F),3), 
rep(c(F,F,T),3)), ncol=4)
logmat1 = logmat[1:2,]
dbv=rep(vector, 2)
split(dbv,logmat1)


As you can see there's no proper distinction between what should be absolutely 
assigned to "TRUE" and what should be assigned to "FALSE". --Note my actual 
data is named.

To try and correct this mistake on a subset of my data I've been trying to use 
what I'll call "method 1" where

 a = c(TRUE, TRUE, TRUE, FALSE, FALSE, TRUE)
 names(a)=c(a,b,c,d,e,f)

 b = c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE)
 names(b)=c("a","b","c","d","e","f")

Using this function, I am able to separate which variables are exactly "TRUE" 
or "FALSE

logical_groups = function (a, b) {
r = list()
s = a + b
r$'TRUE' = names(subset(s, s == 2))
r$'FALSE' = names(subset(s, s == 0))
r$'OR' = names(subset(s, s==1))
return(r)
}

> logical_groups(a,b)
$`TRUE`
[1] "a" "b"

$`FALSE`
[1] "d"

$OR
[1] "c" "e" "f"


The return, as you can see is a list. 
I have a vector of values that match the names a-f in a and b above, i.e.
vector=runif(6, 1.0, 2.0)
names(vector) = c("a","b","c","d","e","f")

and I would like to add these values to the corresponding (names in the) list 
so that I may run the wilcox.test correctly using the 'TRUE' and 'FALSE 
elements. But I am not sure how to achieve this.

I have also tried "method 2"-- starting with;
t=rbind(a, b, vector) to give;
>t
abc   def
a  1.00 1.00 1.00 0.0 0.00 1.00
b  1.00 1.00 0.00 0.0 1.00 0.00
vector 1.012097 1.431088 1.832276 1.12801 1.780018 1.682804

where I then try 
t2 =t[1,]+t[2,]
t3=rbind(t2, t[3,]) to give;
> t3
abc   def
t2 2.00 2.00 1.00 0.0 1.00 1.00
   1.012097 1.431088 1.832276 1.12801 1.780018 1.682804

But again, I am not sure how to split the t3 matrix where the first row == 2 or 
== 0.

I have been searching but I think I'm just confusing myself. I am very late in 
my pregnancy and my brain just won't function fully. 

I hope this makes sense. Any help is appreciated.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 on multiple "==" in bquote()

2015-12-15 Thread One Two
Hello,

I noticed that the function bquote throws an error if there are
multiple "==" in the first argument. E.g.
> txt.main <- bquote(1 == 2 == 3)
Error: unexpected '==' in "txt.main <- bquote(1 == 2 =="

Is this behaviour intended or is it a bug? Because I don't see a
reason for this behaviour and didn't find anything in the
documentation either.

I know that one can use grouping as a workaround like this:
> txt.main <- bquote({1 == 2} == 3)
I am rather interested in whether I should file a bug about this
behaviour or not.

I'm using RStudio in this environment:
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=CLC_TIME=German_Germany.1252

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

loaded via a namespace (and not attached):
[1] tools_3.2.3

Best Regards,
Martin

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread John Sorkin
On this side of the Atlantic, the symbols ( or ) are properly called 
parenthesis not brackets. Consider the expression parenthetical expression, 
which means something enclosed in parentheses.
John


> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)


> On Dec 15, 2015, at 12:23 PM, David Winsemius  wrote:
> 
> 
>> On Dec 15, 2015, at 8:54 AM, Clint Bowman  wrote:
>> 
>> Martin,
>> 
>> I grew up in the Midwest of the United States--about as native English 
>> speaker as you could find.  I was taught exactly the same as you have 
>> learned.
> 
> As with your experience, Clint and Martin, but my online experience is that 
> those speaking "English English" often refer to "(" as "brackets". As a 
> result I generally now call them square-brackets to avoid ambiguity.
> 
> -- 
> David.
> 
>> 
>> Clint
>> 
>> Clint BowmanINTERNET:cl...@ecy.wa.gov
>> Air Quality ModelerINTERNET:cl...@math.utah.edu
>> Department of EcologyVOICE:(360) 407-6815
>> PO Box 47600FAX:(360) 407-7534
>> Olympia, WA 98504-7600
>> 
>>   USPS:   PO Box 47600, Olympia, WA 98504-7600
>>   Parcels:300 Desmond Drive, Lacey, WA 98503-1274
>> 
>>> On Tue, 15 Dec 2015, Martin Maechler wrote:
>>> 
>>> 
>>> 
>>> []
>>> 
 You are missing the closing bracket on the boxplot()
 command.  Just finish with a ')'
>>> 
>>> Hmm... I once learned
>>> 
>>> '()' =: parenthesis/es
>>> '[]' =: bracket(s)
>>> '{}' =: brace(s)
>>> 
>>> Of course, I'm not a native English speaker, and my teacher(s) /
>>> teaching material may have been biased ... but, as all three
>>> symbol pairs play an important role in R, I think it would be
>>> really really helpful,  if we could agree on using the same
>>> precise English here.
>>> 
>>> I'm happy to re-learn, but I'd really like to end up with three
>>> different simple English words, if possible.
>>> (Yes, I know and have seen/heard "curly braces", "round
>>> parentheses", ... but I'd hope we can do without the extra adjective.)
>>> 
>>> Thank you, well versed English (or "American") learned readers
>>> of R-help, for wise guidance on this ...
>>> 
>>> Martin
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius
> Alameda, CA, USA
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Confidentiality Statement:
This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
Any unauthorized use, disclosure or distribution is prohibited. If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message. 
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Hexbin: Counting Bins That Meet Certain Criteria

2015-12-15 Thread David L Carlson
Something like

> library(hexbin)
> set.seed(42)
> xy <- matrix(rnorm(1000), 500)
> xy.hex <- hexbin(xy)
> table(xy.hex@count)

  1   2   3   4   5   6   7   8 
159  60  33  16   6   1   2   1 
> sum(xy.hex@count >= 3)
[1] 59

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sidoti, 
Salvatore A.
Sent: Monday, December 14, 2015 6:49 PM
To: r-help@r-project.org
Subject: [R] Hexbin: Counting Bins That Meet Certain Criteria

Greetings!

Is there a way to count the bins in a hexbin plot that meet certain criteria? 
For instance, what if I wanted to count the bins (hexes) that have a datapoint 
density of some number x?

Thank you!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Fixed effects regression with state-specific trends

2015-12-15 Thread Jake Russ
Dear All,

I am trying to implement a regression with state-specific trends in R. I
can implement this in Stata with ease, but I am hoping to preserve my R
workflow. I suspect there is an "R formula trick" that I'm just not
understanding and I would be grateful to anyone who could help me
understand "the R way."

I posted a similar question to Stackoverflow, but the solution from there
is not playing nice with plm() and I am hoping for a better answer,
http://stackoverflow.com/questions/34232834/fixed-effects-regression-with-state-specific-trends

My panel data looks like the following,

df <- data.frame(state = rep(c("a", "b", "c"), each = 10), time = seq(1,
10, 1), stringsAsFactors = FALSE)

I would like to create state-specific trends that look like these three new
columns

df2 <- cbind(df, model.matrix( ~ state - 1, data = df) * df$time)

To achieve this in Stata, I would simply write

xi: i.state i.state*time
reg y x _I*

The problem I have with the SO model.matrix solution is that I have greater
than 200 "states." Currently, I am generating more than 200 trend columns
with model.matrix and then I am building a very long formula string with
each column by name, I then turn that string into a formula with
as.formula(). Passing the resulting formula to lm() works but it is
cumbersome, and it is also choking the fixed effects version of plm().

Is there an R formula trick to this that I am missing?

Thank you,

Jake

[[alternative HTML version deleted]]

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread David Winsemius

> On Dec 15, 2015, at 9:21 AM, David Winsemius  wrote:
> 
> 
>> On Dec 15, 2015, at 8:54 AM, Clint Bowman  wrote:
>> 
>> Martin,
>> 
>> I grew up in the Midwest of the United States--about as native English 
>> speaker as you could find.  I was taught exactly the same as you have 
>> learned.
> 
> As with your experience, Clint and Martin, but my online experience is that 
> those speaking "English English" often refer to "(" as "brackets". As a 
> result I generally now call them square-brackets to avoid ambiguity.

I intended to say that I call "[" and "]" square-brackets.

-- 
> David.
> 
>> 
>> Clint
>> 
>> Clint Bowman INTERNET:   cl...@ecy.wa.gov
>> Air Quality Modeler  INTERNET:   cl...@math.utah.edu
>> Department of EcologyVOICE:  (360) 407-6815
>> PO Box 47600 FAX:(360) 407-7534
>> Olympia, WA 98504-7600
>> 
>>   USPS:   PO Box 47600, Olympia, WA 98504-7600
>>   Parcels:300 Desmond Drive, Lacey, WA 98503-1274
>> 
>> On Tue, 15 Dec 2015, Martin Maechler wrote:
>> 
>>> 
>>> 
>>> []
>>> 
 You are missing the closing bracket on the boxplot()
 command.  Just finish with a ')'
>>> 
>>> Hmm... I once learned
>>> 
>>> '()' =: parenthesis/es
>>> '[]' =: bracket(s)
>>> '{}' =: brace(s)
>>> 
>>> Of course, I'm not a native English speaker, and my teacher(s) /
>>> teaching material may have been biased ... but, as all three
>>> symbol pairs play an important role in R, I think it would be
>>> really really helpful,  if we could agree on using the same
>>> precise English here.
>>> 
>>> I'm happy to re-learn, but I'd really like to end up with three
>>> different simple English words, if possible.
>>> (Yes, I know and have seen/heard "curly braces", "round
>>> parentheses", ... but I'd hope we can do without the extra adjective.)
>>> 
>>> Thank you, well versed English (or "American") learned readers
>>> of R-help, for wise guidance on this ...
>>> 
>>> Martin
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius
> Alameda, CA, USA
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread Berend Hasselman

> On 15 Dec 2015, at 18:49, John Sorkin  wrote:
> 
> On this side of the Atlantic, the symbols ( or ) are properly called 
> parenthesis not brackets. Consider the expression parenthetical expression, 
> which means something enclosed in parentheses.
> John
> 


According to http://www.oxforddictionaries.com/words/brackets
I gather that to avoid ambiguity and/or confusion one could/would use round 
brackets for () (parentheses).


Berend

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread David Winsemius

> On Dec 15, 2015, at 8:54 AM, Clint Bowman  wrote:
> 
> Martin,
> 
> I grew up in the Midwest of the United States--about as native English 
> speaker as you could find.  I was taught exactly the same as you have learned.

As with your experience, Clint and Martin, but my online experience is that 
those speaking "English English" often refer to "(" as "brackets". As a result 
I generally now call them square-brackets to avoid ambiguity.

-- 
David.

> 
> Clint
> 
> Clint Bowman  INTERNET:   cl...@ecy.wa.gov
> Air Quality Modeler   INTERNET:   cl...@math.utah.edu
> Department of Ecology VOICE:  (360) 407-6815
> PO Box 47600  FAX:(360) 407-7534
> Olympia, WA 98504-7600
> 
>USPS:   PO Box 47600, Olympia, WA 98504-7600
>Parcels:300 Desmond Drive, Lacey, WA 98503-1274
> 
> On Tue, 15 Dec 2015, Martin Maechler wrote:
> 
>> 
>> 
>>  []
>> 
>>   > You are missing the closing bracket on the boxplot()
>>   > command.  Just finish with a ')'
>> 
>> Hmm... I once learned
>> 
>> '()' =: parenthesis/es
>> '[]' =: bracket(s)
>> '{}' =: brace(s)
>> 
>> Of course, I'm not a native English speaker, and my teacher(s) /
>> teaching material may have been biased ... but, as all three
>> symbol pairs play an important role in R, I think it would be
>> really really helpful,  if we could agree on using the same
>> precise English here.
>> 
>> I'm happy to re-learn, but I'd really like to end up with three
>> different simple English words, if possible.
>> (Yes, I know and have seen/heard "curly braces", "round
>> parentheses", ... but I'd hope we can do without the extra adjective.)
>> 
>> Thank you, well versed English (or "American") learned readers
>> of R-help, for wise guidance on this ...
>> 
>> Martin
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread John Sorkin
Just as there are several types of punctuation marks, 
, ; : .
also called comma, semi-colon, colon, period (or full stop on the east side of 
the Atlantic),
so to are there two types of brackets
[   )  
also called square brackets, parenthesis.
 
It is clear that a ) although is a type of bracket it is called a parenthesis, 
just as , is called a comma, which is a type of punctuation mark.
John
 
 
 



John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing) 
>>> Berend Hasselman  12/15/15 12:59 PM >>>

> On 15 Dec 2015, at 18:49, John Sorkin  wrote:
> 
> On this side of the Atlantic, the symbols ( or ) are properly called 
> parenthesis not brackets. Consider the expression parenthetical expression, 
> which means something enclosed in parentheses.
> John
> 


According to http://www.oxforddictionaries.com/words/brackets
I gather that to avoid ambiguity and/or confusion one could/would use round 
brackets for () (parentheses).


Berend
Confidentiality Statement:
This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
Any unauthorized use, disclosure or distribution is prohibited. If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message. 
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Print minified XML in tree format

2015-12-15 Thread Archit Soni
Thanks Giorgio, for the docs! :)

However my main aim was to  make it run in TERR(TIBCO Enterprise Runtime
Engine for R), but it is throwing some different error but was working fine
in R Studio.

Error:Could not execute function call.
TIBCO Enterprise Runtime for R returned an error: 'Error in
as.data.frame.default(passed.args[[i]], stringsAsFactors = s : cannot
coerce class '"XMLInternalDocumentXMLAbstractDocument"' into a data.frame'.
   at
Spotfire.Dxp.Data.DataFunctions.Executors.LocalFunctionClient.OnExecuting(FunctionClient
funcClient)
   at
Spotfire.Dxp.Data.DataFunctions.Executors.AbstractFunctionClient.d__0.MoveNext()
   at
Spotfire.Dxp.Data.DataFunctions.Executors.SPlusFunctionExecutor.d__0.MoveNext()
   at
Spotfire.Dxp.Data.DataFunctions.DataFunctionExecutorService.d__6.MoveNext()

Much thanks for the docs

On Mon, Dec 14, 2015 at 1:54 PM, Giorgio Garziano <
giorgio.garzi...@ericsson.com> wrote:

> I may suggest this quick guide:
>
>
> http://gastonsanchez.com/work/webdata/getting_web_data_r4_parsing_xml_html.pdf
>
> and the following link:
>
> http://www.r-datacollection.com/
>
>
> I apologize for not being more specific.
>
>
> --
> GG
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Regards
Archit

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] TIBCO Enterprise Runtime for R

2015-12-15 Thread Archit Soni
Hi All,

I have the code to print XML tree that is working successfully in R Studio
but is failing when i try to work it out with TERR:

x<- XML::xmlParse(y)

y is input (Coming from a row only once)
x is output

The above code is working in R studio but doesnt work in TERR, please
suggest.

TIBCO Enterprise Runtime for R returned an error: 'Error in
as.data.frame.default(passed.args[[i]], stringsAsFactors = s : cannot
coerce class '"XMLInternalDocumentXMLAbstractDocument"' into a data.frame'.
at
Spotfire.Dxp.Data.DataFunctions.Executors.LocalFunctionClient.OnExecuting(FunctionClient
funcClient) at
Spotfire.Dxp.Data.DataFunctions.Executors.AbstractFunctionClient.d__0.MoveNext()
at
Spotfire.Dxp.Data.DataFunctions.Executors.SPlusFunctionExecutor.d__0.MoveNext()
at
Spotfire.Dxp.Data.DataFunctions.DataFunctionExecutorService.d__6.MoveNext()

-- 
Regards
Archit

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 plot two variables in a figure using ggplot2

2015-12-15 Thread JimmyGao
Hi everyone,

Now,I want to use the following data to produce a figure.But I don't know how 
to do it.Is anyone have some experiences?

X axis using variable XX and Y axis using variable OA and KA

XX OA KA

1  1243 0.8157 0.7790
2  2486 0.8190 0.7829
3  3729 0.8278 0.7934
4  4972 0.8354 0.8026
5  6215 0.8475 0.8140
6  7458 0.8530 0.8224
7  8701 0.8668 0.8301
8  9944 0.8790 0.8540
9 11187 0.8990 0.8790


Thank you very much.
Jimmy









 





 
[[alternative HTML version deleted]]

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


Re: [R] adding vector values to corresponding components of a list

2015-12-15 Thread Bert Gunter
I as not able to make sense of your post. Maybe others can. However,
you have posted here several times, now. You should therefore know
that providing a reproducible example (providing data by e.g. dput() )
**and showing exactly what output you want** would improve your chance
of a helpful response.

'Nuff said.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Dec 15, 2015 at 7:56 AM, debra ragland via R-help
 wrote:
> Hello,
>
> I have tried this 2 ways and I keep coming to a dead end as I am not very 
> proficient in R.
>
> I have a logical matrix, where I would like to generate every row-wise pair 
> of logical values for further testing. That is row1, row2; row 1, row3 etc. 
> Ideally, I would like to assign a pre-generated vector of values to each pair 
> such that each combination of rows may be split into 2 groups with each 
> variable appearing only once.
>
> This is similar to the WRONG way I've been trying to do this;
>
> vector = runif(4, 1.0, 2.0)
> logmat<-matrix(c(rep(c(F,T,F),3), rep(c(T,F,T),3), rep(c(T,T,F),3), 
> rep(c(F,F,T),3)), ncol=4)
> logmat1 = logmat[1:2,]
> dbv=rep(vector, 2)
> split(dbv,logmat1)
>
>
> As you can see there's no proper distinction between what should be 
> absolutely assigned to "TRUE" and what should be assigned to "FALSE". --Note 
> my actual data is named.
>
> To try and correct this mistake on a subset of my data I've been trying to 
> use what I'll call "method 1" where
>
>  a = c(TRUE, TRUE, TRUE, FALSE, FALSE, TRUE)
>  names(a)=c(a,b,c,d,e,f)
>
>  b = c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE)
>  names(b)=c("a","b","c","d","e","f")
>
> Using this function, I am able to separate which variables are exactly "TRUE" 
> or "FALSE
>
> logical_groups = function (a, b) {
> r = list()
> s = a + b
> r$'TRUE' = names(subset(s, s == 2))
> r$'FALSE' = names(subset(s, s == 0))
> r$'OR' = names(subset(s, s==1))
> return(r)
> }
>
>> logical_groups(a,b)
> $`TRUE`
> [1] "a" "b"
>
> $`FALSE`
> [1] "d"
>
> $OR
> [1] "c" "e" "f"
>
>
> The return, as you can see is a list.
> I have a vector of values that match the names a-f in a and b above, i.e.
> vector=runif(6, 1.0, 2.0)
> names(vector) = c("a","b","c","d","e","f")
>
> and I would like to add these values to the corresponding (names in the) list 
> so that I may run the wilcox.test correctly using the 'TRUE' and 'FALSE 
> elements. But I am not sure how to achieve this.
>
> I have also tried "method 2"-- starting with;
> t=rbind(a, b, vector) to give;
>>t
> abc   def
> a  1.00 1.00 1.00 0.0 0.00 1.00
> b  1.00 1.00 0.00 0.0 1.00 0.00
> vector 1.012097 1.431088 1.832276 1.12801 1.780018 1.682804
>
> where I then try
> t2 =t[1,]+t[2,]
> t3=rbind(t2, t[3,]) to give;
>> t3
> abc   def
> t2 2.00 2.00 1.00 0.0 1.00 1.00
>1.012097 1.431088 1.832276 1.12801 1.780018 1.682804
>
> But again, I am not sure how to split the t3 matrix where the first row == 2 
> or == 0.
>
> I have been searching but I think I'm just confusing myself. I am very late 
> in my pregnancy and my brain just won't function fully.
>
> I hope this makes sense. Any help is appreciated.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread Clint Bowman

Martin,

I grew up in the Midwest of the United States--about as native English 
speaker as you could find.  I was taught exactly the same as you have 
learned.


Clint

Clint BowmanINTERNET:   cl...@ecy.wa.gov
Air Quality Modeler INTERNET:   cl...@math.utah.edu
Department of Ecology   VOICE:  (360) 407-6815
PO Box 47600FAX:(360) 407-7534
Olympia, WA 98504-7600

USPS:   PO Box 47600, Olympia, WA 98504-7600
Parcels:300 Desmond Drive, Lacey, WA 98503-1274

On Tue, 15 Dec 2015, Martin Maechler wrote:




  []

   > You are missing the closing bracket on the boxplot()
   > command.  Just finish with a ')'

Hmm... I once learned

'()' =: parenthesis/es
'[]' =: bracket(s)
'{}' =: brace(s)

Of course, I'm not a native English speaker, and my teacher(s) /
teaching material may have been biased ... but, as all three
symbol pairs play an important role in R, I think it would be
really really helpful,  if we could agree on using the same
precise English here.

I'm happy to re-learn, but I'd really like to end up with three
different simple English words, if possible.
(Yes, I know and have seen/heard "curly braces", "round
parentheses", ... but I'd hope we can do without the extra adjective.)

Thank you, well versed English (or "American") learned readers
of R-help, for wise guidance on this ...

Martin

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread PIKAL Petr
Hi

I do not see any problem. Due to HTML posting we are not able to decipher what 
you are missing. Probably right parentheses.

I would start from beginning by

boxplot(data)

and gradually add required colour and other items to your boxplot.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dmitri
> Leybman
> Sent: Tuesday, December 15, 2015 4:06 PM
> To: peter dalgaard; r-help@r-project.org; dwinsem...@comcast.net
> Subject: Re: [R] Make a box-whiskers plot in R with 5 variables, color
> coded.
>
> Apologies for the HTML.
>
> This is the initial snippet of the values:
>
> Var1 Var2 Var3 Var4 Var5
> 0 0 7 1 0
> 0 0 7 0 0
> 1 1 8 2 0
> 5 5 8 0 0
> 1 4 8 1 0
> 4 5 8 0 0
> 0 1 7 2 1
> 5 1 7 0 0
> 2 4 9 0 1
> 1 2 9 2 NA
> 1 5 7 1 0
> 4 1 8 0 0
> 2 7 7 1 0
> 7 7 6 2 NA
> 5 2 7 0 0
> 0 1 7 0 4
> 1 3 8 1 0
> 1 5 7 2 0
> 7 2 8 0 0
> 7 0 8 2 0
> 7 5 8 2 0
> 2 0 9 1 0
> 1 6 8 1 0
> 3 4 7 0 2
>
>
>
> I have tried:
>
>
>boxplot(data, las = 2, col =
>
>c("red", "blue", "black", "aquamarine1", "darkorange3"),
>
>at = c(1, 2, 3, 4, 5), par(mar = c(12, 5, 4, 2) + 0.1),
>
>names = c("Meeting1", "Meeting2", "Meeting3", "Meeting4","Meeting5")
>
>
> and have gotten a '+' at the end meaning I am missing something.
>
>
> I used a modify version of the code I found on R-Help for Box-Whiskers
> plot formation 
>
>
> The code this blogger used was
>
>boxplot(data, ylab =“Oxigen (%)”, xlab =“Time”, las = 2,
>
>col =
>
> c(“red”,“sienna”,“palevioletred1″,“royalblue2″,“red”,“sienna”,“paleviol
> etred1″,
>
>“royalblue2″,“red”,“sienna”,“palevioletred1″,“royalblue2″),
>
> at = c(1,2,3,4,  6,7,8,9, 11,12,13,14), par(mar = c(12, 5, 4,
> 2) + 0.1),
>
> names = c(“Station 1″,“Station 2″,“Station 3″,“Station
> 4″,“Station
>
>
> 1″,“Station 2″,“Station 3″,“Station 4″,“Station 1″,“Station
> 2″,“Station
>
>  3″,“Station 4″))
>
>
> I am trying to use the code above to create a five different box-and-
> whiskers plots color-coded. I don't need the "Station 1" or "Station 2"
> labels but I used this code as a starting point for the code I wanted
> write.  .
>
>
> I wanted the y-axis to read "Number of People Attended" instead of
> "Oxigen (%)"
>
>
> and the x-axis to refer to the particular meeting in question:
>
>
>Meeting1, Meeting2, Meeting3, Meeting4, Meeting5
>
>
> which corresponds to variables var1, var2, var3, var4, var5.
>
>
> Each of the box and whiskers would show the median number, along with
> interquartile values, of each of these Meetings. The color coding is
> not necessarily but I think would make it a bit easier to read for
> observers.
>
> I apologize again for the convoluted reply and the HTML error.
>
>
> On Mon, Dec 14, 2015 at 5:42 PM, peter dalgaard 
> wrote:
>
> >
> > > On 14 Dec 2015, at 22:54 , David Winsemius 
> > wrote:
> > >
> > >>
> > >> On Dec 14, 2015, at 1:34 PM, Dmitri Leybman 
> wrote:
> > >>
> > >> I have a spreadsheet with five different columns standing for five
> > >> different variables:
> > >>
> > >> Variable 1 Variable 2 Variable 3 Variable 4 Variable 5 0 0 7 1 0 0
> > >> 0 7
> > 0 0 1
> > >> 1 8 2 0 5 5 8 0 0 1 4 8 1 0 4 5 8 0 0 0 1 7 2 1 I am trying to
> > >> create five box and whiskers plots on a single graph
> > with a
> > >> five x-label ticks named for each one of the variables along with
> > >> color coding. The names for the x-label would
> > be
> > >> "Meeting"[ pertains to Variable1] "Meeting2"[pertains to Variable
> > >> 2] Meeting3[pertains to Variable 3], Meeting4[pertains to
> > >> Variable4], Meeting5[pertains to Variable5].
> > >>
> > >> I have tried:
> > >>
> > >> boxplot(data, las = 2, col =
> > >> c("red", "blue", "black", "aquamarine1", "darkorange3") , at =
> c(1,
> > >> 2, 3, 4, 5), par(mar = c(12, 5, 4, 2) + 0.1), names = c("Meeting
> > >> 1", "'Meeting2",
> > > ^
> > > Extra single quote about here
> > >
> >
> > Hmm, at face value, that should just become part of the label...
> >
> > >
> > >> "Meeting3", "Meeting4","Meeting5")
> > >>
> > >>
> > >> Error: unexpected string constant in:
> > >> "boxplot(data, las=2, col= c('red', 'blue', 'red', 'red', red')
> > >> boxplot(data, las=2, col= c('"
> >
> >
> > ...but the error message doesn't match the input, which is lacking a
> > right parenthesis. So is there a previous incomplete command maybe,
> or
> > are we just being shown random snippets of things that didn't work??
> >
> > I think we need to see a full transcript
> >
> >
> > >>
> > >>  [[alternative HTML version deleted]]
> > >>
> >
> >
> > ...and PLEASE in plain text, not HTML.
> >
> > >> __
> > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > >> https://stat.ethz.ch/mailman/listinfo/r-help
> > >> PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > >> and provide

Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread Marc Schwartz

> On Dec 15, 2015, at 9:55 AM, Martin Maechler  
> wrote:
> 
> 
> 
>   []
> 
>> You are missing the closing bracket on the boxplot()
>> command.  Just finish with a ')'
> 
> Hmm... I once learned
> 
> '()' =: parenthesis/es
> '[]' =: bracket(s)
> '{}' =: brace(s)


Martin,

The above is how I would refer to each.

Regards,

Marc


> 
> Of course, I'm not a native English speaker, and my teacher(s) /
> teaching material may have been biased ... but, as all three
> symbol pairs play an important role in R, I think it would be
> really really helpful,  if we could agree on using the same
> precise English here.
> 
> I'm happy to re-learn, but I'd really like to end up with three
> different simple English words, if possible.
> (Yes, I know and have seen/heard "curly braces", "round
> parentheses", ... but I'd hope we can do without the extra adjective.)
> 
> Thank you, well versed English (or "American") learned readers
> of R-help, for wise guidance on this ...
> 
> Martin
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] adding vector values to corresponding components of a list

2015-12-15 Thread debra ragland via R-help
Hello,

I have tried this 2 ways and I keep coming to a dead end as I am not very 
proficient in R.

I have a logical matrix, where I would like to generate every row-wise pair of 
logical values for further testing. That is row1, row2; row 1, row3 etc. 
Ideally, I would like to assign a pre-generated vector of values to each pair 
such that each combination of rows may be split into 2 groups with each 
variable appearing only once. 

This is similar to the WRONG way I've been trying to do this;

vector = runif(4, 1.0, 2.0)
logmat<-matrix(c(rep(c(F,T,F),3), rep(c(T,F,T),3), rep(c(T,T,F),3), 
rep(c(F,F,T),3)), ncol=4)
logmat1 = logmat[1:2,]
dbv=rep(vector, 2)
split(dbv,logmat1)


As you can see there's no proper distinction between what should be absolutely 
assigned to "TRUE" and what should be assigned to "FALSE". --Note my actual 
data is named.

To try and correct this mistake on a subset of my data I've been trying to use 
what I'll call "method 1" where

 a = c(TRUE, TRUE, TRUE, FALSE, FALSE, TRUE)
 names(a)=c(a,b,c,d,e,f)

 b = c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE)
 names(b)=c("a","b","c","d","e","f")

Using this function, I am able to separate which variables are exactly "TRUE" 
or "FALSE

logical_groups = function (a, b) {
r = list()
s = a + b
r$'TRUE' = names(subset(s, s == 2))
r$'FALSE' = names(subset(s, s == 0))
r$'OR' = names(subset(s, s==1))
return(r)
}

> logical_groups(a,b)
$`TRUE`
[1] "a" "b"

$`FALSE`
[1] "d"

$OR
[1] "c" "e" "f"


The return, as you can see is a list. 
I have a vector of values that match the names a-f in a and b above, i.e.
vector=runif(6, 1.0, 2.0)
names(vector) = c("a","b","c","d","e","f")

and I would like to add these values to the corresponding (names in the) list 
so that I may run the wilcox.test correctly using the 'TRUE' and 'FALSE 
elements. But I am not sure how to achieve this.

I have also tried "method 2"-- starting with;
t=rbind(a, b, vector) to give;
>t
abc   def
a  1.00 1.00 1.00 0.0 0.00 1.00
b  1.00 1.00 0.00 0.0 1.00 0.00
vector 1.012097 1.431088 1.832276 1.12801 1.780018 1.682804

where I then try 
t2 =t[1,]+t[2,]
t3=rbind(t2, t[3,]) to give;
> t3
abc   def
t2 2.00 2.00 1.00 0.0 1.00 1.00
   1.012097 1.431088 1.832276 1.12801 1.780018 1.682804

But again, I am not sure how to split the t3 matrix where the first row == 2 or 
== 0.

I have been searching but I think I'm just confusing myself. I am very late in 
my pregnancy and my brain just won't function fully. 

I hope this makes sense. Any help is appreciated.

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread Martin Maechler


   [] 

> You are missing the closing bracket on the boxplot()
> command.  Just finish with a ')'

Hmm... I once learned

 '()' =: parenthesis/es
 '[]' =: bracket(s)
 '{}' =: brace(s)

Of course, I'm not a native English speaker, and my teacher(s) /
teaching material may have been biased ... but, as all three
symbol pairs play an important role in R, I think it would be
really really helpful,  if we could agree on using the same
precise English here.

I'm happy to re-learn, but I'd really like to end up with three
different simple English words, if possible.
(Yes, I know and have seen/heard "curly braces", "round
 parentheses", ... but I'd hope we can do without the extra adjective.)

Thank you, well versed English (or "American") learned readers
of R-help, for wise guidance on this ...

Martin

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


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread S Ellison


 
> I have tried:
> 
>boxplot(data, las = 2, col =
>c("red", "blue", "black", "aquamarine1", "darkorange3"),
>at = c(1, 2, 3, 4, 5), par(mar = c(12, 5, 4, 2) + 0.1),
>names = c("Meeting1", "Meeting2", "Meeting3", "Meeting4","Meeting5")
> 
> and have gotten a '+' at the end meaning I am missing something.

You are missing the closing bracket on the boxplot() command.
Just finish with a ')'

S Ellison


***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Make a box-whiskers plot in R with 5 variables, color coded.

2015-12-15 Thread Dmitri Leybman
Apologies for the HTML.

This is the initial snippet of the values:

Var1 Var2 Var3 Var4 Var5
0 0 7 1 0
0 0 7 0 0
1 1 8 2 0
5 5 8 0 0
1 4 8 1 0
4 5 8 0 0
0 1 7 2 1
5 1 7 0 0
2 4 9 0 1
1 2 9 2 NA
1 5 7 1 0
4 1 8 0 0
2 7 7 1 0
7 7 6 2 NA
5 2 7 0 0
0 1 7 0 4
1 3 8 1 0
1 5 7 2 0
7 2 8 0 0
7 0 8 2 0
7 5 8 2 0
2 0 9 1 0
1 6 8 1 0
3 4 7 0 2



I have tried:


   boxplot(data, las = 2, col =

   c("red", "blue", "black", "aquamarine1", "darkorange3"),

   at = c(1, 2, 3, 4, 5), par(mar = c(12, 5, 4, 2) + 0.1),

   names = c("Meeting1", "Meeting2", "Meeting3", "Meeting4","Meeting5")


and have gotten a '+' at the end meaning I am missing something.


I used a modify version of the code I found on R-Help for Box-Whiskers plot
formation 


The code this blogger used was

   boxplot(data, ylab =“Oxigen (%)”, xlab =“Time”, las = 2,

   col =
 c(“red”,“sienna”,“palevioletred1″,“royalblue2″,“red”,“sienna”,“palevioletred1″,

   “royalblue2″,“red”,“sienna”,“palevioletred1″,“royalblue2″),

at = c(1,2,3,4,  6,7,8,9, 11,12,13,14), par(mar = c(12, 5, 4, 2) +
0.1),

names = c(“Station 1″,“Station 2″,“Station 3″,“Station 4″,“Station


1″,“Station 2″,“Station 3″,“Station 4″,“Station 1″,“Station
2″,“Station

 3″,“Station 4″))


I am trying to use the code above to create a five different
box-and-whiskers plots color-coded. I don't need the "Station 1" or
"Station 2" labels but I used this code as a starting point for the code I
wanted write.  .


I wanted the y-axis to read "Number of People Attended" instead of "Oxigen
(%)"


and the x-axis to refer to the particular meeting in question:


   Meeting1, Meeting2, Meeting3, Meeting4, Meeting5


which corresponds to variables var1, var2, var3, var4, var5.


Each of the box and whiskers would show the median number, along with
interquartile values, of each of these Meetings. The color coding is not
necessarily but I think would make it a bit easier to read for observers.

I apologize again for the convoluted reply and the HTML error.


On Mon, Dec 14, 2015 at 5:42 PM, peter dalgaard  wrote:

>
> > On 14 Dec 2015, at 22:54 , David Winsemius 
> wrote:
> >
> >>
> >> On Dec 14, 2015, at 1:34 PM, Dmitri Leybman  wrote:
> >>
> >> I have a spreadsheet with five different columns standing for five
> >> different variables:
> >>
> >> Variable 1 Variable 2 Variable 3 Variable 4 Variable 5 0 0 7 1 0 0 0 7
> 0 0 1
> >> 1 8 2 0 5 5 8 0 0 1 4 8 1 0 4 5 8 0 0 0 1 7 2 1
> >> I am trying to create five box and whiskers plots on a single graph
> with a
> >> five x-label ticks named for each one of
> >> the variables along with color coding. The names for the x-label would
> be
> >> "Meeting"[ pertains to Variable1] "Meeting2"[pertains to Variable 2]
> >> Meeting3[pertains to Variable 3], Meeting4[pertains to Variable4],
> >> Meeting5[pertains to Variable5].
> >>
> >> I have tried:
> >>
> >> boxplot(data, las = 2, col =
> >> c("red", "blue", "black", "aquamarine1", "darkorange3")
> >> , at = c(1, 2, 3, 4, 5), par(mar = c(12, 5, 4, 2) + 0.1),
> >> names = c("Meeting 1", "'Meeting2",
> > ^
> > Extra single quote about here
> >
>
> Hmm, at face value, that should just become part of the label...
>
> >
> >> "Meeting3", "Meeting4","Meeting5")
> >>
> >>
> >> Error: unexpected string constant in:
> >> "boxplot(data, las=2, col= c('red', 'blue', 'red', 'red', red')
> >> boxplot(data, las=2, col= c('"
>
>
> ...but the error message doesn't match the input, which is lacking a right
> parenthesis. So is there a previous incomplete command maybe, or are we
> just being shown random snippets of things that didn't work??
>
> I think we need to see a full transcript
>
>
> >>
> >>  [[alternative HTML version deleted]]
> >>
>
>
> ...and PLEASE in plain text, not HTML.
>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> > David Winsemius
> > Alameda, CA, USA
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-hel

Re: [R] matrix which results singular but at the same time positive definite

2015-12-15 Thread Paul Gilbert

Stefano

I think in other response to in this thread you got the answer to the 
question you asked, but you may be asking the wrong question. I'm not 
familiar with the specific papers you mention and you have not provided 
enough detail about what you are doing, so I am guessing a bit. The term 
"dynamic linear model" can refer to both linear ARMA/ARIMA models and to 
linear state-space models, however some authors use it to refer 
exclusively to state-space models and from your phrasing I am guessing 
you are doing that. There would be many state-space models equivalent to 
a given ARMA/ARIMA model, but without specifying structural aspects of 
the system you will likely be using one of the innovations form 
state-space models that are equivalent. In an innovations form 
state-space model the state is defined as an expectation. From a 
practical point of view, this is one of the most important differences 
between an innovation form and a non-innovations form state-space model. 
Since the expectation is known exactly, the state-tracking error is 
zero. That means the covariance matrix from the filter or smoother 
should be a zero matrix, which you should not be trying to invert. In a 
non-innovations form the state has a physical interpretation rather than 
being an expectation, so the state tracking error should not be 
degenerate in that case.


I mention all this because your covariance matrix looks very close to zero.

Paul Gilbert

On 12/11/2015 06:00 AM, r-help-requ...@r-project.org wrote:

Dear John, thank you for your considerations. This matrix (which is a
variance matrix) is part of an algorithm for forward-filtering and
backward-sampling of Dynamic Linear Models (West and Harrison, 1997),
applied to DLM representation of ARIMA processes (Petris, Petrone,
Campagnoli).  It is therefore very difficult to explain why this
variance matrix becomes so ill conditioned. This already happens at
the first iteration of the algorithm. I will try to work on initial
conditions and some fixed parameters.

Thank you again Stefano



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


Re: [R] plot several lines programmaticaly

2015-12-15 Thread PIKAL Petr
Hi Gerrit,

Thanks, I tried it and it seems to be viable option. I knew I overlooked 
something pretty simple.

Cheers
Petr


> -Original Message-
> From: Gerrit Eichner [mailto:gerrit.eich...@math.uni-giessen.de]
> Sent: Tuesday, December 15, 2015 12:31 PM
> To: PIKAL Petr
> Cc: r-help@r-project.org
> Subject: Re: [R] plot several lines programmaticaly
>
> Hi, Petr,
>
> from your example it's not doubtlessly clear to me sure how the
> sequence of ifs should really be continued, but couldn't a nested loop
> help?
> Something like:
>
> for (i in 1:npks) {
>   plot(res[[i]]$x, res[[i]]$y, pch=20)
>
>   for (j in 1:i) {
>lines(res[[i]]$x, res[[i]]$fitpk[j,], col=j, lwd=3)}
>}
>   }
>
> (However, this seems too simple ...)
>
>   Hth  --  Gerrit
>
>
> On Tue, 15 Dec 2015, PIKAL Petr wrote:
>
> > Dear all
> >
> > I am stuck with output of some result. Sorry for not providing
> working
> > example but res is quite a big list and I believe you are able to
> > understand my problem.
> >
> > I have npks variable, which can be anything from 1 to let say 5.
> >
> > I get result called here res as a nested list with several components
> > and I want to plot these components based on npks value. I got this
> > far
> >
> > par(mfrow=c(npks,1)) # slit the device for (i in 1:npks) {
> > plot(res[[i]]$x, res[[i]]$y, pch=20)
> >
> > if (i ==1) { #lines in case npks==1
> > lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)}
> >
> > if(i==2) { # lines in case npks ==2
> > lines(res[[i]]$x, res[[i]]$fitpk[1,], col=1, lwd=3) lines(res[[i]]$x,
> > res[[i]]$fitpk[i,], col=i, lwd=3) }
> >
> > I can follow this further and expand lines plotting with ifs but it
> > seems to me that there must be better solution I overlooked.
> >
> > Here is a structure of res
> >
> >> str(res)
> > List of 2
> > $ :List of 15
> >  ..$ intnr  : int 1
> >  ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
> >  .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
> >  ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
> >  ..$ fit: num [1:153] 15.2 15.3 15.4 15.5 15.7 ...
> >  ..$ fitpk  : num [1, 1:153] 2.35 2.49 2.65 2.81 2.99 ...
> >  ..$ basl   : num [1:153] 258 258 258 258 258 ...
> >  ..$ baslchg: num [1:153] 12.8 12.8 12.7 12.7 12.7 ...
> >  ..$ rss: num 1354
> >  ..$ num.ker: int 1
> >  ..$ par: num [1:6] 12.8649 -0.0409 4549.1417 1.9927 66.939 ...
> >  ..$ parbl  : Named num [1:2] 12.86 -4.09  .. ..- attr(*, "names")=
> > chr [1:2] "" "2485"
> >  ..$ parpks : num [1, 1:5] 35.494 4549.142 715.324 0.129 1.993  ..
> ..-
> > attr(*, "dimnames")=List of 2  .. .. ..$ : NULL  .. .. ..$ : chr
> [1:5]
> > "loc" "height" "intens" "FWHM" ...
> >  ..$ accept : logi FALSE
> >  ..$ alpha  : num 0.1
> >  ..$ thresh : Named num 3.81
> >  .. ..- attr(*, "names")= chr "90%"
> > $ :List of 15
> >  ..$ intnr  : int 1
> >  ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
> >  .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
> >  ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
> >  ..$ fit: num [1:153] 15 15 15.1 15.1 15.2 ...
> >  ..$ fitpk  : num [1:2, 1:153] 2.1329 0.0859 2.2666 0.0876 2.4109 ...
> >  ..$ basl   : num [1:153] 258 258 258 258 258 ...
> >  ..$ baslchg: num [1:153] 12.8 12.7 12.6 12.5 12.4 ...
> >  ..$ rss: num 1325
> >  ..$ num.ker: num 2
> >  ..$ par: num [1:10] 12.8649 -0.0942 4540.4742 2.0373 66.9394 ...
> >  ..$ parbl  : Named num [1:2] 12.86 -9.42  .. ..- attr(*, "names")=
> > chr [1:2] "" "2485"
> >  ..$ parpks : num [1:2, 1:5] 35.5 35.9 4540.5 39.4 715.3 ...
> >  .. ..- attr(*, "dimnames")=List of 2
> >  .. .. ..$ : NULL
> >  .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ...
> >  ..$ accept : logi FALSE
> >  ..$ alpha  : num 0.1
> >  ..$ thresh : Named num 3.81
> >  .. ..- attr(*, "names")= chr "90%"
> >>
> >
> > Best Regards
> > Petr


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žád

Re: [R] define number of clusters in kmeans/apcluster analysis

2015-12-15 Thread Ulrich Bodenhofer

Dear Luigi,

As the others have replied already, you cannot expect a clustering 
algorithm to produce exactly the result that you expect intuitively. The 
results of clustering algorithms depend largely on the parameters and, 
even more importantly, on the distance/similarity measure that is used. 
k-means, for instance, uses the Euclidean distance. As a result, it 
works nicely for spherical clusters that have approximately the same 
radius. APCluster, unless you don't choose a different similarity, uses 
negative squared distances which leads to very similar properties. Your 
data set consists of two clusters, one of which is much more spread out. 
That some parts of the larger cluster are being assigned to the other 
cluster looks weird, but it is perfectly explained by the properties of 
the algorithms. There is a lot of literature about the properties of 
clustering algorithms around. That's my 2 cents about this. In your 
case, however, as already pointed out in Bill Dunlap's reply, the 
scaling is the more important issue. k-means and apcluster do not 
perform any scaling of the data. Your two axes differ strongly in terms 
of scaling. Enter the following to see how the two clustering algorithms 
"see" your data (i.e. with two equally scaled axes):


plot(z, xlim=c(0, 50), ylim=c(0, 50))

Given this, it is no longer surprising that both algorithms split the 
data in the way they do.


Actually, if you re-scale the data, apcluster produces the result you 
expect:


   z2 <- scale(z)
   m <- apclusterK(negDistMat(r=2), z2, K=2, verbose=TRUE)
   plot(m, z2)
   plot(m, z) ## it even works to superimpose the clustering result on
   the original data

I hope that helps.

Best regards,
Ulrich

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


Re: [R] plot several lines programmaticaly

2015-12-15 Thread Gerrit Eichner

Hi, Petr,

from your example it's not doubtlessly clear to me sure how the sequence 
of ifs should really be continued, but couldn't a nested loop help? 
Something like:


for (i in 1:npks) {
 plot(res[[i]]$x, res[[i]]$y, pch=20)

 for (j in 1:i) {
  lines(res[[i]]$x, res[[i]]$fitpk[j,], col=j, lwd=3)}
  }
 }

(However, this seems too simple ...)

 Hth  --  Gerrit


On Tue, 15 Dec 2015, PIKAL Petr wrote:


Dear all

I am stuck with output of some result. Sorry for not providing working 
example but res is quite a big list and I believe you are able to 
understand my problem.


I have npks variable, which can be anything from 1 to let say 5.

I get result called here res as a nested list with several components 
and I want to plot these components based on npks value. I got this far


par(mfrow=c(npks,1)) # slit the device
for (i in 1:npks) {
plot(res[[i]]$x, res[[i]]$y, pch=20)

if (i ==1) { #lines in case npks==1
lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)}

if(i==2) { # lines in case npks ==2
lines(res[[i]]$x, res[[i]]$fitpk[1,], col=1, lwd=3)
lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)
}

I can follow this further and expand lines plotting with ifs but it 
seems to me that there must be better solution I overlooked.


Here is a structure of res


str(res)

List of 2
$ :List of 15
 ..$ intnr  : int 1
 ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
 .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
 ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
 ..$ fit: num [1:153] 15.2 15.3 15.4 15.5 15.7 ...
 ..$ fitpk  : num [1, 1:153] 2.35 2.49 2.65 2.81 2.99 ...
 ..$ basl   : num [1:153] 258 258 258 258 258 ...
 ..$ baslchg: num [1:153] 12.8 12.8 12.7 12.7 12.7 ...
 ..$ rss: num 1354
 ..$ num.ker: int 1
 ..$ par: num [1:6] 12.8649 -0.0409 4549.1417 1.9927 66.939 ...
 ..$ parbl  : Named num [1:2] 12.86 -4.09
 .. ..- attr(*, "names")= chr [1:2] "" "2485"
 ..$ parpks : num [1, 1:5] 35.494 4549.142 715.324 0.129 1.993
 .. ..- attr(*, "dimnames")=List of 2
 .. .. ..$ : NULL
 .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ...
 ..$ accept : logi FALSE
 ..$ alpha  : num 0.1
 ..$ thresh : Named num 3.81
 .. ..- attr(*, "names")= chr "90%"
$ :List of 15
 ..$ intnr  : int 1
 ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
 .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
 ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
 ..$ fit: num [1:153] 15 15 15.1 15.1 15.2 ...
 ..$ fitpk  : num [1:2, 1:153] 2.1329 0.0859 2.2666 0.0876 2.4109 ...
 ..$ basl   : num [1:153] 258 258 258 258 258 ...
 ..$ baslchg: num [1:153] 12.8 12.7 12.6 12.5 12.4 ...
 ..$ rss: num 1325
 ..$ num.ker: num 2
 ..$ par: num [1:10] 12.8649 -0.0942 4540.4742 2.0373 66.9394 ...
 ..$ parbl  : Named num [1:2] 12.86 -9.42
 .. ..- attr(*, "names")= chr [1:2] "" "2485"
 ..$ parpks : num [1:2, 1:5] 35.5 35.9 4540.5 39.4 715.3 ...
 .. ..- attr(*, "dimnames")=List of 2
 .. .. ..$ : NULL
 .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ...
 ..$ accept : logi FALSE
 ..$ alpha  : num 0.1
 ..$ thresh : Named num 3.81
 .. ..- attr(*, "names")= chr "90%"




Best Regards
Petr


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


[R] plot several lines programmaticaly

2015-12-15 Thread PIKAL Petr
Dear all

I am stuck with output of some result. Sorry for not providing working example 
but res is quite a big list and I believe you are able to understand my problem.

I have npks variable, which can be anything from 1 to let say 5.

I get result called here res as a nested list with several components and I 
want to plot these components based on npks value. I got this far

par(mfrow=c(npks,1)) # slit the device
for (i in 1:npks) {
plot(res[[i]]$x, res[[i]]$y, pch=20)

if (i ==1) { #lines in case npks==1
lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)}

if(i==2) { # lines in case npks ==2
lines(res[[i]]$x, res[[i]]$fitpk[1,], col=1, lwd=3)
lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)
}

I can follow this further and expand lines plotting with ifs but it seems to me 
that there must be better solution I overlooked.

Here is a structure of res

> str(res)
List of 2
 $ :List of 15
  ..$ intnr  : int 1
  ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
  .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
  ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
  ..$ fit: num [1:153] 15.2 15.3 15.4 15.5 15.7 ...
  ..$ fitpk  : num [1, 1:153] 2.35 2.49 2.65 2.81 2.99 ...
  ..$ basl   : num [1:153] 258 258 258 258 258 ...
  ..$ baslchg: num [1:153] 12.8 12.8 12.7 12.7 12.7 ...
  ..$ rss: num 1354
  ..$ num.ker: int 1
  ..$ par: num [1:6] 12.8649 -0.0409 4549.1417 1.9927 66.939 ...
  ..$ parbl  : Named num [1:2] 12.86 -4.09
  .. ..- attr(*, "names")= chr [1:2] "" "2485"
  ..$ parpks : num [1, 1:5] 35.494 4549.142 715.324 0.129 1.993
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ...
  ..$ accept : logi FALSE
  ..$ alpha  : num 0.1
  ..$ thresh : Named num 3.81
  .. ..- attr(*, "names")= chr "90%"
 $ :List of 15
  ..$ intnr  : int 1
  ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
  .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
  ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
  ..$ fit: num [1:153] 15 15 15.1 15.1 15.2 ...
  ..$ fitpk  : num [1:2, 1:153] 2.1329 0.0859 2.2666 0.0876 2.4109 ...
  ..$ basl   : num [1:153] 258 258 258 258 258 ...
  ..$ baslchg: num [1:153] 12.8 12.7 12.6 12.5 12.4 ...
  ..$ rss: num 1325
  ..$ num.ker: num 2
  ..$ par: num [1:10] 12.8649 -0.0942 4540.4742 2.0373 66.9394 ...
  ..$ parbl  : Named num [1:2] 12.86 -9.42
  .. ..- attr(*, "names")= chr [1:2] "" "2485"
  ..$ parpks : num [1:2, 1:5] 35.5 35.9 4540.5 39.4 715.3 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ...
  ..$ accept : logi FALSE
  ..$ alpha  : num 0.1
  ..$ thresh : Named num 3.81
  .. ..- attr(*, "names")= chr "90%"
>

Best Regards
Petr



Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e

Re: [R] Random selection of a fixed number of values by interval

2015-12-15 Thread Frank S.
Many thanks to David L Carlson, Ben Gunter and David Winsemius for your quick 
and very elegant solutions!!
With your  list answers I am learning sa lot of things that will help me in the 
future to program.
 
Best,
 
Frank S.
 
> Subject: Re: [R] Random selection of a fixed number of values by interval
> From: dwinsem...@comcast.net
> Date: Mon, 14 Dec 2015 13:31:45 -0800
> CC: f_j_...@hotmail.com; r-help@r-project.org
> To: dcarl...@tamu.edu
> 
> 
> > On Dec 14, 2015, at 12:46 PM, David L Carlson  wrote:
> > 
> > There are lots of ways to do this. For example,
> 
> Another method with mapply:
> 
>  mapply(function( n, vals) {sample(vals$id, n)} ,   # no replacement is the 
> default for sample
> vals= split(data, findInterval(data$value, 0:5) )[1:5] , # drops 
> the values at 5 or above
> n=c(10,7,5,5,3)   )
> 
> $`1`
>  [1] 12 64 10 60 70 58 33 50 57 68
> 
> $`2`
> [1] 43  8 15 26 19  3 20
> 
> $`3`
> [1] 55  9 62 17 67
> 
> $`4`
> [1] 61 21 31 24 48
> 
> $`5`
> [1] 44 13 36
> 
> > 
> >> groups <- cut(data$value, include.lowest = T, right = FALSE,
> > +  breaks = 0:ceiling(max(data$value)))
> >> grp <- c("[0,1)", "[1,2)", "[2,3)", "[3,4)", "[4,5)")
> >> size <- c(10, 7, 5, 5, 3)
> >> set.seed(42)
> >> samples <- lapply(1:5, function(x) sample(data$id[groups==grp[x]],
> > +  size[x]))
> >> names(samples) <- grp
> >> samples
> > $`[0,1)`
> > [1] 69 68 33 63 56 46 65 12 50 58
> > 
> > $`[1,2)`
> > [1] 20 34 43  8 15 52 19
> > 
> > $`[2,3)`
> > [1]  7 22 62 28  2
> > 
> > $`[3,4)`
> > [1] 61 53  5 25 21
> > 
> > $`[4,5)`
> > [1] 59 35 40
> > 
> >> 
> >> groups <- cut(data$value, include.lowest = T, right = FALSE,
> > +  breaks = 0:ceiling(max(data$value)))
> >> grp <- c("[0,1)", "[1,2)", "[2,3)", "[3,4)", "[4,5)")
> >> size <- c(10, 7, 5, 5, 3)
> >> set.seed(42)
> >> samples <- lapply(1:5, function(x) sample(data$id[groups==grp[x]],
> > +  size[x]))
> >> names(samples) <- grp
> >> samples
> > $`[0,1)`
> > [1] 69 68 33 63 56 46 65 12 50 58
> > 
> > $`[1,2)`
> > [1] 20 34 43  8 15 52 19
> > 
> > $`[2,3)`
> > [1]  7 22 62 28  2
> > 
> > $`[3,4)`
> > [1] 61 53  5 25 21
> > 
> > $`[4,5)`
> > [1] 59 35 40
> > 
> > 
> > -
> > David L Carlson
> > Department of Anthropology
> > Texas A&M University
> > College Station, TX 77840-4352
> > 
> > 
> > 
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Frank S.
> > Sent: Monday, December 14, 2015 2:02 PM
> > To: r-help@r-project.org
> > Subject: [R] Random selection of a fixed number of values by interval
> > 
> > Dear R users,
> > 
> > I'm writing to this list because I must get a random sample (without 
> > replacement) from a given vector, but the clue is that I need to extract a 
> > fixed number of values by each prespecified 1-unit interval. As an example 
> > I try to say, I have a data frame that looks like this (my real dataframe 
> > is bigger):
> > 
> > data <- data.frame(id = 1:70, value=  c(0.68, 2.96, 1.93, 5.63, 3.08, 3.10, 
> > 2.99, 1.79, 2.96, 0.85, 11.79, 0.06, 4.31, 0.64, 1.43, 0.88, 2.79, 4.67,
> >  1.23, 1.43, 3.05, 2.44, 2.55, 3.82, 3.55, 1.56, 7.25, 2.75, 9.64, 
> > 5.14, 3.54, 3.12, 0.17, 1.07, 4.08, 4.47, 5.58, 7.41, 0.85, 4.30, 7.58,
> >  0.58, 1.40, 4.74, 5.04, 0.14, 1.14, 3.28, 7.84, 0.07, 3.97, 1.02, 
> > 3.47, 0.66, 2.38, 0.06, 0.67, 0.48, 4.48, 0.12, 3.82, 2.27, 0.93, 0.30, 
> >  0.73, 0.33, 2.91, 0.81, 0.18, 0.42))
> > 
> > And I would like to select, in a random manner:
> > 
> > 10 id's whose value belongs to [0,1) interval
> > 7 id's whose value belongs to [1,2)
> > 5 id's whose value belongs to [2,3)
> > 5 id's whose value belongs to [3,4)
> > 3 id's whose value belongs to [4,5)
> > 
> > # I have the following values by each 1-unit interval:
> > table(cut(data$value, include.lowest = T, right = FALSE, breaks = 
> > 0:ceiling(max(data$value
> > 
> > and the size vector:
> > size <- c(10, 7, 5, 5, 3) 
> > 
> > But I'm not able to get it by using sample function. Does anyone have some 
> > idea?
> > 
> > Thank you very much for any suggestions!!
> > 
> > Frank S.
> > 
> > 
> > 
> > 
> >   
> > [[alternative HTML version deleted]]
> > 
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius
> Alameda, CA, USA
>