[R] Feature or bug?

2015-05-21 Thread Sigbert Klinke
Hi,

if I run

update <- function (newtime) { ginput <<- list(time=newtime)}

server <- function (input) {
  print(paste("Before", input$time))
  update(1)
  print(paste("After:", input$time))
}

ginput <- list(time=0)
server(ginput)

then I get as result

[1] "Before 0"
[1] "After: 0"

If I uncomment the first print

update <- function (newtime) { ginput <<- list(time=newtime) }

server <- function (input) {
  #print(paste("Before", input$time))
  update(1)
  print(paste("After:", input$time))
}

ginput <- list(time=0)
server(ginput)

then I get

[1] "After: 1"

Even when I use a side effect (by assign some new value to a global
variable) I would have expected the same behaviour in both cases.

Sigbert

-- 
http://u.hu-berlin.de/sk
__
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] Feature or bug?

2015-05-21 Thread Berwin A Turlach
G'day Sigbert,

long time no see :)
How is Berlin these days?

On Thu, 21 May 2015 11:45:26 +0200
Sigbert Klinke  wrote:

It is a feature.

> if I run
> 
> update <- function (newtime) { ginput <<- list(time=newtime)}
> 
> server <- function (input) {
>   print(paste("Before", input$time))
>   update(1)
>   print(paste("After:", input$time))
> }
> 
> ginput <- list(time=0)
> server(ginput)
> 
> then I get as result
> 
> [1] "Before 0"
> [1] "After: 0"

The first print command evaluates input and after this the function
server has an object named "input" in its local environment.  The
second print command reuses this object and extracts the component time
from it (which has not changed).  The change of the global variable has
no effect.

> If I uncomment the first print
> 
> update <- function (newtime) { ginput <<- list(time=newtime) }
> 
> server <- function (input) {
>   #print(paste("Before", input$time))
>   update(1)
>   print(paste("After:", input$time))
> }
> 
> ginput <- list(time=0)
> server(ginput)
> 
> then I get
> 
> [1] "After: 1"

Because the global variable is changed before input is evaluated.  R
has lazy argument evaluation, arguments are only evaluated once they
are needed.  You are essentially getting bitten by R's lazy evaluation
plus "pass by value" syntax.

> Even when I use a side effect (by assign some new value to a global
> variable) I would have expected the same behaviour in both cases.

To get the behaviour that you expect, you would have to write your code
along the following lines:

R> update <- function (newtime) { ginput <<- list(time=newtime)}
R> server <- function(input){
+ inp <- as.name(deparse(substitute(input)))
+ print(paste("Before", eval(substitute(XXX$time, list(XXX=inp)
+ update(1)
+ print(paste("After:", eval(substitute(XXX$time, list(XXX=inp)
+ }
R> ginput <- list(time=0)
R> server(ginput)
[1] "Before 0"
[1] "After: 1"


A cleaner way is perhaps to use environments, as these are passed by
reference:

R> update <- function(env, newtime) env$time <- newtime
R> server <- function(input){
+ print(paste("Before", input$time))
+ update(input, 1)
+ print(paste("After:", input$time))
+ }
R> ginput <- new.env()
R> ginput$time <- 0
R> server(ginput)
[1] "Before 0"
[1] "After: 1"

HTH.

Cheers,

Berwin

== Full address 
A/Prof Berwin A Turlach   Tel.: +61 (8) 6488 3338 (secr)
School of Maths and Stats (M019)+61 (8) 6488 3383 (self)
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway   
Crawley WA 6009 e-mail: berwin.turl...@gmail.com
Australiahttp://www.maths.uwa.edu.au/~berwin
 http://www.researcherid.com/rid/A-4995-2008

__
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] The R Foundation announces new mailing list 'R-package-devel'

2015-05-21 Thread Martin Maechler
New Mailing list:  R-package-devel -- User R Packages Development

At last week's monthly meeting, the R foundation has decided to
create a new mailing list in order to help R package authors in
their package development and testing.

The idea is that some experienced R programmers (often those
currently helping on R-devel or also R-help) will help package
authors and thus unload some of the burden of the CRAN team
members.

Please read the detailed description of the mailing list here,
   https://stat.ethz.ch/mailman/listinfo/r-package-devel
or also the more extended announcement of the list on R-devel,
archived at
 https://stat.ethz.ch/pipermail/r-devel/2015-May/071208.html


For the R foundation,
Martin Maechler, Secretary General

___
r-annou...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
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] Vincentizing Reaction Time data in R

2015-05-21 Thread John Kane
In line

John Kane
Kingston ON Canada


> -Original Message-
> From: yishinlin...@gmail.com
> Sent: Thu, 21 May 2015 10:13:54 +0800
> To: gabriel.wein...@gmail.com
> Subject: Re: [R] Vincentizing Reaction Time data in R
> 
> On Wed, 20 May 2015 18:13:17 +0800,
> Hi Gabriel,
> 
> As far as I could recall, there isn't an R package that has explicitly
> implemented "vincentization". You definitively can find some code
> segments/functions that have implemented "vincentize" on the web. But you
> should verify if they do exactly what you wish to do.  If you could look
> at the question from percentile/quantle perspective, it would not take
> you too much time to realise that they are similar.  I would suggest you
> to read, as John Kane suggested, Prof. Ratcliff's 1979 paper.  Another
> paper that may be very helpful is Prof van Zandt's 2000 RT paper.
> 
> However, you should be aware that there are some different implementation
> of "vincentization", and it is debatable, if not problematic, to use it,
> rather than other more general quantile methods. It would help you to
> understand not only how to do vincentization, but also why/why not if you
> could read papers from Jeff Rouder's as well as from Heathcote's and
> Brown's lab.
> 
> Sorry that I hesitate to give you the code, because this looks like part
> of your course works.  It would be more rewarding for you, if you could
> figure out by yourself.
> 
> Yishin
> 
While I agree the exercise is likely to be a good learning experience I don't 
see this as the equivalent of course work. 

If Gabriel (the OP) was tasked with implementing  "vincentization" in R then, 
strictly speaking it is course work but if I understand him the requirement is 
to do his work in R rather than Minitab.  If such a function existed in an 
existing R package than he could have simply plugged in the numbers et voilà, 
done.

The tenor of the question did not suggest this and it would require the stats 
instructor to know that there was no  "vincentization" function anywhere among 
the, what, a thousand or so packages? And if the OP was working on his own data 
as part of the course then the instructor might have little or no idea of 
exactly what functions are needed

The course  strikes me more as an effort to get psychologists away from SPSS 
which often seems to be the only software package anyone knows.


> Gabriel WEINDEL wrote:
>> 
>> Dear all,
>> 
>> For my master thesis, I'm currently working in cognitive neuroscience
>> on executive control through measurement of reaction time and I need
>> to get my data 'vincentized' with an exclusive use of R set by my
>> statistic teacher for a test purpose, for this reason I can't use the
>> python code the lab team usually uses.
>> Despite a dozen hours of research I couldn't find any package or
>> R-code which would allow the use of vincentization, that's why I'm
>> querying help on the R forum.
>> 
>> So has anyone ever used vincentization in R ?
>> 
>> Best regards,
>> 
>> --
>> Gabriel Weindel
>> Master student in Neuropsychology - Aix-Marseille University (France)
>>


Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.

__
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] Feature or bug?

2015-05-21 Thread Bert Gunter
Well..

"Because the global variable is changed before input is evaluated.  R
has lazy argument evaluation, arguments are only evaluated once they
are needed.  You are essentially getting bitten by R's lazy evaluation
plus "pass by value" syntax."

While I may be either wrong or just picking on semantics, I don't
think so. It is merely what you stated previously: input was assigned
a value in the local server function environment, and that assignment
was not affected by the subsequent assignment to the global
environment. So it is a matter of R's semantics -- where it looks for
the values bound to symbols -- rather than lazy evaluation.

Obviously then, a simple way to do what the OP seemed to want would be
to simply assign the updated value in the local function environment,
rather than the global. I get nervous whenever I see constructs with
eval(substitute...)) or global assignments from within a function.
Both have their place, of course, but (the latter especially) can be
dangerous, and my experience both on the list and with my own code, is
that if you think you need them, you probably should rethink what you
need to do.

Corrections and/or criticism of these comments are welcome.

Best,
Bert



Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Thu, May 21, 2015 at 3:50 AM, Berwin A Turlach
 wrote:
> G'day Sigbert,
>
> long time no see :)
> How is Berlin these days?
>
> On Thu, 21 May 2015 11:45:26 +0200
> Sigbert Klinke  wrote:
>
> It is a feature.
>
>> if I run
>>
>> update <- function (newtime) { ginput <<- list(time=newtime)}
>>
>> server <- function (input) {
>>   print(paste("Before", input$time))
>>   update(1)
>>   print(paste("After:", input$time))
>> }
>>
>> ginput <- list(time=0)
>> server(ginput)
>>
>> then I get as result
>>
>> [1] "Before 0"
>> [1] "After: 0"
>
> The first print command evaluates input and after this the function
> server has an object named "input" in its local environment.  The
> second print command reuses this object and extracts the component time
> from it (which has not changed).  The change of the global variable has
> no effect.
>
>> If I uncomment the first print
>>
>> update <- function (newtime) { ginput <<- list(time=newtime) }
>>
>> server <- function (input) {
>>   #print(paste("Before", input$time))
>>   update(1)
>>   print(paste("After:", input$time))
>> }
>>
>> ginput <- list(time=0)
>> server(ginput)
>>
>> then I get
>>
>> [1] "After: 1"
>
> Because the global variable is changed before input is evaluated.  R
> has lazy argument evaluation, arguments are only evaluated once they
> are needed.  You are essentially getting bitten by R's lazy evaluation
> plus "pass by value" syntax.
>
>> Even when I use a side effect (by assign some new value to a global
>> variable) I would have expected the same behaviour in both cases.
>
> To get the behaviour that you expect, you would have to write your code
> along the following lines:
>
> R> update <- function (newtime) { ginput <<- list(time=newtime)}
> R> server <- function(input){
> + inp <- as.name(deparse(substitute(input)))
> + print(paste("Before", eval(substitute(XXX$time, list(XXX=inp)
> + update(1)
> + print(paste("After:", eval(substitute(XXX$time, list(XXX=inp)
> + }
> R> ginput <- list(time=0)
> R> server(ginput)
> [1] "Before 0"
> [1] "After: 1"
>
>
> A cleaner way is perhaps to use environments, as these are passed by
> reference:
>
> R> update <- function(env, newtime) env$time <- newtime
> R> server <- function(input){
> + print(paste("Before", input$time))
> + update(input, 1)
> + print(paste("After:", input$time))
> + }
> R> ginput <- new.env()
> R> ginput$time <- 0
> R> server(ginput)
> [1] "Before 0"
> [1] "After: 1"
>
> HTH.
>
> Cheers,
>
> Berwin
>
> == Full address 
> A/Prof Berwin A Turlach   Tel.: +61 (8) 6488 3338 (secr)
> School of Maths and Stats (M019)+61 (8) 6488 3383 (self)
> The University of Western Australia   FAX : +61 (8) 6488 1028
> 35 Stirling Highway
> Crawley WA 6009 e-mail: berwin.turl...@gmail.com
> Australiahttp://www.maths.uwa.edu.au/~berwin
>  http://www.researcherid.com/rid/A-4995-2008
>
> __
> 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, sel

Re: [R] Feature or bug?

2015-05-21 Thread peter dalgaard

On 21 May 2015, at 16:26 , Bert Gunter  wrote:

> Well..
> 
> "Because the global variable is changed before input is evaluated.  R
> has lazy argument evaluation, arguments are only evaluated once they
> are needed.  You are essentially getting bitten by R's lazy evaluation
> plus "pass by value" syntax."
> 
> While I may be either wrong or just picking on semantics, I don't
> think so. It is merely what you stated previously: input was assigned
> a value in the local server function environment, and that assignment
> was not affected by the subsequent assignment to the global
> environment. So it is a matter of R's semantics -- where it looks for
> the values bound to symbols -- rather than lazy evaluation.
> 
> Obviously then, a simple way to do what the OP seemed to want would be
> to simply assign the updated value in the local function environment,
> rather than the global. I get nervous whenever I see constructs with
> eval(substitute...)) or global assignments from within a function.
> Both have their place, of course, but (the latter especially) can be
> dangerous, and my experience both on the list and with my own code, is
> that if you think you need them, you probably should rethink what you
> need to do.
> 
> Corrections and/or criticism of these comments are welcome.
> 

Berwin is right, or rather: There are two issues. The "input" argument to 
server() is evaluated when first used. The difference between the two examples 
is whether this happens before or after update(), and that is the effect of 
lazy evaluation. The fact that it in the first case the value is unchanged by 
the update is due to scoping: Once evaluate "input" becomes a local variable  
an is unchanged by assignment to the global variable.

-pd


> Best,
> Bert
> 
> 
> 
> Bert Gunter
> Genentech Nonclinical Biostatistics
> (650) 467-7374
> 
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
> Clifford Stoll
> 
> 
> 
> 
> On Thu, May 21, 2015 at 3:50 AM, Berwin A Turlach
>  wrote:
>> G'day Sigbert,
>> 
>> long time no see :)
>> How is Berlin these days?
>> 
>> On Thu, 21 May 2015 11:45:26 +0200
>> Sigbert Klinke  wrote:
>> 
>> It is a feature.
>> 
>>> if I run
>>> 
>>> update <- function (newtime) { ginput <<- list(time=newtime)}
>>> 
>>> server <- function (input) {
>>>  print(paste("Before", input$time))
>>>  update(1)
>>>  print(paste("After:", input$time))
>>> }
>>> 
>>> ginput <- list(time=0)
>>> server(ginput)
>>> 
>>> then I get as result
>>> 
>>> [1] "Before 0"
>>> [1] "After: 0"
>> 
>> The first print command evaluates input and after this the function
>> server has an object named "input" in its local environment.  The
>> second print command reuses this object and extracts the component time
>> from it (which has not changed).  The change of the global variable has
>> no effect.
>> 
>>> If I uncomment the first print
>>> 
>>> update <- function (newtime) { ginput <<- list(time=newtime) }
>>> 
>>> server <- function (input) {
>>>  #print(paste("Before", input$time))
>>>  update(1)
>>>  print(paste("After:", input$time))
>>> }
>>> 
>>> ginput <- list(time=0)
>>> server(ginput)
>>> 
>>> then I get
>>> 
>>> [1] "After: 1"
>> 
>> Because the global variable is changed before input is evaluated.  R
>> has lazy argument evaluation, arguments are only evaluated once they
>> are needed.  You are essentially getting bitten by R's lazy evaluation
>> plus "pass by value" syntax.
>> 
>>> Even when I use a side effect (by assign some new value to a global
>>> variable) I would have expected the same behaviour in both cases.
>> 
>> To get the behaviour that you expect, you would have to write your code
>> along the following lines:
>> 
>> R> update <- function (newtime) { ginput <<- list(time=newtime)}
>> R> server <- function(input){
>> + inp <- as.name(deparse(substitute(input)))
>> + print(paste("Before", eval(substitute(XXX$time, list(XXX=inp)
>> + update(1)
>> + print(paste("After:", eval(substitute(XXX$time, list(XXX=inp)
>> + }
>> R> ginput <- list(time=0)
>> R> server(ginput)
>> [1] "Before 0"
>> [1] "After: 1"
>> 
>> 
>> A cleaner way is perhaps to use environments, as these are passed by
>> reference:
>> 
>> R> update <- function(env, newtime) env$time <- newtime
>> R> server <- function(input){
>> + print(paste("Before", input$time))
>> + update(input, 1)
>> + print(paste("After:", input$time))
>> + }
>> R> ginput <- new.env()
>> R> ginput$time <- 0
>> R> server(ginput)
>> [1] "Before 0"
>> [1] "After: 1"
>> 
>> HTH.
>> 
>> Cheers,
>> 
>>Berwin
>> 
>> == Full address 
>> A/Prof Berwin A Turlach   Tel.: +61 (8) 6488 3338 (secr)
>> School of Maths and Stats (M019)+61 (8) 6488 3383 (self)
>> The University of Western Australia   FAX : +61 (8) 6488 1028
>> 35 Stirling Highway
>> Crawley WA 6009 e-mail: berwin.turl...@gmail.com
>> Austral

Re: [R] Feature or bug?

2015-05-21 Thread William Dunlap
If you add a print statement to trace the evaluation of the input argument
you can see how the lazy evaluation works:

> update <- function (newtime) {
cat("# update() is changing global ginput's time from", ginput$time,
"to", newtime, "\n")
ginput <<- list(time = newtime)
}
> server <- function(input, doFirstPrint) {
if (doFirstPrint) {
cat("# Before calling update(1): input$time=", input$time,
"ginput$time=", ginput$time, "\n")
}
update(1)
cat("# After calling update(1): input$time=", input$time,
"ginput$time=", ginput$time, "\n")
}
> ginput <- list(time=0)
> server({cat("# Evaluating server's 'input' argument\n"); ginput},
doFirstPrint=TRUE)
# Evaluating server's 'input' argument
# Before calling update(1): input$time= 0 ginput$time= 0
# update() is changing global ginput's time from 0 to 1
# After calling update(1): input$time= 0 ginput$time= 1
> ginput <- list(time=0)
> server({cat("# Evaluating server's 'input' argument\n"); ginput},
doFirstPrint=FALSE)
# update() is changing global ginput's time from 0 to 1
# Evaluating server's 'input' argument
# After calling update(1): input$time= 1 ginput$time= 1


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, May 21, 2015 at 7:48 AM, peter dalgaard  wrote:

>
> On 21 May 2015, at 16:26 , Bert Gunter  wrote:
>
> > Well..
> >
> > "Because the global variable is changed before input is evaluated.  R
> > has lazy argument evaluation, arguments are only evaluated once they
> > are needed.  You are essentially getting bitten by R's lazy evaluation
> > plus "pass by value" syntax."
> >
> > While I may be either wrong or just picking on semantics, I don't
> > think so. It is merely what you stated previously: input was assigned
> > a value in the local server function environment, and that assignment
> > was not affected by the subsequent assignment to the global
> > environment. So it is a matter of R's semantics -- where it looks for
> > the values bound to symbols -- rather than lazy evaluation.
> >
> > Obviously then, a simple way to do what the OP seemed to want would be
> > to simply assign the updated value in the local function environment,
> > rather than the global. I get nervous whenever I see constructs with
> > eval(substitute...)) or global assignments from within a function.
> > Both have their place, of course, but (the latter especially) can be
> > dangerous, and my experience both on the list and with my own code, is
> > that if you think you need them, you probably should rethink what you
> > need to do.
> >
> > Corrections and/or criticism of these comments are welcome.
> >
>
> Berwin is right, or rather: There are two issues. The "input" argument to
> server() is evaluated when first used. The difference between the two
> examples is whether this happens before or after update(), and that is the
> effect of lazy evaluation. The fact that it in the first case the value is
> unchanged by the update is due to scoping: Once evaluate "input" becomes a
> local variable  an is unchanged by assignment to the global variable.
>
> -pd
>
>
> > Best,
> > Bert
> >
> >
> >
> > Bert Gunter
> > Genentech Nonclinical Biostatistics
> > (650) 467-7374
> >
> > "Data is not information. Information is not knowledge. And knowledge
> > is certainly not wisdom."
> > Clifford Stoll
> >
> >
> >
> >
> > On Thu, May 21, 2015 at 3:50 AM, Berwin A Turlach
> >  wrote:
> >> G'day Sigbert,
> >>
> >> long time no see :)
> >> How is Berlin these days?
> >>
> >> On Thu, 21 May 2015 11:45:26 +0200
> >> Sigbert Klinke  wrote:
> >>
> >> It is a feature.
> >>
> >>> if I run
> >>>
> >>> update <- function (newtime) { ginput <<- list(time=newtime)}
> >>>
> >>> server <- function (input) {
> >>>  print(paste("Before", input$time))
> >>>  update(1)
> >>>  print(paste("After:", input$time))
> >>> }
> >>>
> >>> ginput <- list(time=0)
> >>> server(ginput)
> >>>
> >>> then I get as result
> >>>
> >>> [1] "Before 0"
> >>> [1] "After: 0"
> >>
> >> The first print command evaluates input and after this the function
> >> server has an object named "input" in its local environment.  The
> >> second print command reuses this object and extracts the component time
> >> from it (which has not changed).  The change of the global variable has
> >> no effect.
> >>
> >>> If I uncomment the first print
> >>>
> >>> update <- function (newtime) { ginput <<- list(time=newtime) }
> >>>
> >>> server <- function (input) {
> >>>  #print(paste("Before", input$time))
> >>>  update(1)
> >>>  print(paste("After:", input$time))
> >>> }
> >>>
> >>> ginput <- list(time=0)
> >>> server(ginput)
> >>>
> >>> then I get
> >>>
> >>> [1] "After: 1"
> >>
> >> Because the global variable is changed before input is evaluated.  R
> >> has lazy argument evaluation, arguments are only evaluated once they
> >> are needed.  You are essentially getting bitten by R's lazy evaluation
> >> plus "pass by value" syntax.
> >>
> >>> Even when I use a side effect (by assign some new value to a glob

[R] Question regarding different R versions on an enterprise network server

2015-05-21 Thread Assaf P. Oron
Hi all,

I represent R users vs. IT dept. at my workplace (yes, an enviable task :)

We've managed to get a workable network-based R application, for people who
work remotely, or don't have a machine (i.e., they use a VDI terminal).
Everything in this organization is staunchly Windows and Microsoft.

We've agreed to upgrade only once yearly, to save IT resources. Now we're
upgrading, and I would like users to be able to keep their old R 3.1.0
directory trees like it's available on a single Windows machine. At least
for a few months, so that people can evaluate back-compatibility if they
need. In fact, we have an even older server-based 3.0.1, which happens to
be  the only R version for which the Tableaux-R connection works (at least
according to my colleagues, I don't use Tableaux).

Anyway, long story short. That was just the motivating example. The problem
I'm dealing with is whether a network application that has several versions
of R (3.1.z, 3.2.z), etc., all available, and each reading and installing
libraries to a different folder tree.

The libraries right now are installed into each user's "personal" share
drive. It's pretty stable. However, obviously the 3.2.z libraries will now
overwrite the 3.1.z.

My IT contact says it's impossible, because the Windows app name is always
just Rgui.exe, and they can only have one set of instructions associated
with the same app name (i.e., what folders to go to, etc.)

I wonder whether anyone has had experience with this, or I should just give
up and alert people that if they want to explore various historical layers
of R and the associated packages, they will have to work around and/or
install and uninstall lots of packages each time.

Thanks!

Assaf

-- 
Assaf P. Oron, Ph.D.
Senior Statistician, Children's Core for Biomedical Statistics
(206)884-1236, assaf.o...@seattlechildrens.org

Consulting statistician, Seattle DEEDS Project
http://www.duwamishdiesel.org/
Instructor, UW Certificate for Statistical Analysis with R
as...@uw.edu

[[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] Vincentizing Reaction Time data in R

2015-05-21 Thread Weindel Gabriel
Bert : Thank you for your advice, it would be a little bit difficult to 
do it for my master thesis but, if I want to go further with a PhD 
thesis (and I do want), I would probably follow your advice and get in 
touch with a statistician.


Yishin : Thank you very much for the references, I will definitively
read the papers you quote. I'm already a little bit aware of the misuses
possible with the vincentization in particular thanks to the paper of
Rouder and Speckman (2004) and it seems to fit with my design. No 
problem if you want to keep the code but I have to tell you that it's 
our first semester using R and the teacher surely didn't thought that we 
will run out of available code with our experiment. Like John guessed 
the purpose of the course was to give a first view of R to get over the 
temptation of SPSS, my bad if I want to avoid biased statistics like 
sample mean ANOVA's on RT.


Dan : Thank you for your tip, this sure will help but I'm quiet at the
beginning of my R skills so I hardly trust myself to do it on my own,
but I can sure give it a try.

John : I had the same assumption but my research director warned me that 
I might run out of time for my first presentation by doing so but fairly 
enough for my master thesis. But again like I said to Dan I'm quiet 
concerned by my actual R skill.


Anyway I have to say that I'm really glad to see how much help you can 
get by using the r-help mailing-list.


Regards,
Gabriel

Le 21/05/2015 15:52, John Kane a écrit :

In line

John Kane
Kingston ON Canada



-Original Message-
From: yishinlin...@gmail.com
Sent: Thu, 21 May 2015 10:13:54 +0800
To: gabriel.wein...@gmail.com
Subject: Re: [R] Vincentizing Reaction Time data in R

On Wed, 20 May 2015 18:13:17 +0800,
Hi Gabriel,

As far as I could recall, there isn't an R package that has explicitly
implemented "vincentization". You definitively can find some code
segments/functions that have implemented "vincentize" on the web. But you
should verify if they do exactly what you wish to do.  If you could look
at the question from percentile/quantle perspective, it would not take
you too much time to realise that they are similar.  I would suggest you
to read, as John Kane suggested, Prof. Ratcliff's 1979 paper.  Another
paper that may be very helpful is Prof van Zandt's 2000 RT paper.

However, you should be aware that there are some different implementation
of "vincentization", and it is debatable, if not problematic, to use it,
rather than other more general quantile methods. It would help you to
understand not only how to do vincentization, but also why/why not if you
could read papers from Jeff Rouder's as well as from Heathcote's and
Brown's lab.

Sorry that I hesitate to give you the code, because this looks like part
of your course works.  It would be more rewarding for you, if you could
figure out by yourself.

Yishin


While I agree the exercise is likely to be a good learning experience I don't 
see this as the equivalent of course work.

If Gabriel (the OP) was tasked with implementing  "vincentization" in R then, 
strictly speaking it is course work but if I understand him the requirement is to do his 
work in R rather than Minitab.  If such a function existed in an existing R package than 
he could have simply plugged in the numbers et voilà, done.

The tenor of the question did not suggest this and it would require the stats instructor 
to know that there was no  "vincentization" function anywhere among the, what, 
a thousand or so packages? And if the OP was working on his own data as part of the 
course then the instructor might have little or no idea of exactly what functions are 
needed

The course  strikes me more as an effort to get psychologists away from SPSS 
which often seems to be the only software package anyone knows.



Gabriel WEINDEL wrote:


Dear all,

For my master thesis, I'm currently working in cognitive neuroscience
on executive control through measurement of reaction time and I need
to get my data 'vincentized' with an exclusive use of R set by my
statistic teacher for a test purpose, for this reason I can't use the
python code the lab team usually uses.
Despite a dozen hours of research I couldn't find any package or
R-code which would allow the use of vincentization, that's why I'm
querying help on the R forum.

So has anyone ever used vincentization in R ?

Best regards,

--
Gabriel Weindel
Master student in Neuropsychology - Aix-Marseille University (France)




Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.
Check it out at http://mysecurelogon.com/manager




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

Re: [R] Subset and 0 replace?

2015-05-21 Thread Vin Cheng
Thanks William/Duncan!
 
Duncan - Yes - I am using the doBy package.
 
running this line on the sample data below gives weights for V5,V44, & V2.  
Ideally I would like 0's for V8 and V10 in the output.
 
So it would look like:
e<-structure(matrix(c("V5", "0.008714910", "V8", "0", "V10", "0", "V44", 
"0.004357455", "V2", "0.008714910"),nrow = 2))
 
 
This is far as I've gotten by subsetting and  summing:
a<-t(summaryBy(Wgt.sum~as.numeric(.id),data=subset(ldply(c,function(x) 
summaryBy(Wgt ~ SPCLORatingValue, data=x, 
FUN=c(sum))),SPCLORatingValue>16),FUN=c(sum),order=FALSE))
 
All help/guidance is much appreciated!  Thanks Vince!
 
Sample data example:
c<-structure(list(V5 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083
), SPCLORatingValue = c(11L, 15L, 14L, 15L, 14L, 14L, 16L, 19L, 
13L, 17L, 11L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
), row.names = 12:22, class = "data.frame"), V8 = structure(list(
WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083), SPCLORatingValue = c(14L, 15L, 15L, 
12L, 15L, 12L, 13L, 15L, 14L, 15L, 14L)), .Names = c("WgtBand", 
"Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"), 
V10 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083
), SPCLORatingValue = c(15L, 13L, 14L, 14L, 13L, 13L, 13L, 
15L, 15L, 13L, 14L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
), row.names = 12:22, class = "data.frame"), V44 = structure(list(
WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt = 
c(0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083), SPCLORatingValue = c(13L, 14L, 
16L, 15L, 14L, 14L, 18L, 13L, 16L, 15L, 11L)), .Names = c("WgtBand", 
"Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"), 
V2 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083
), SPCLORatingValue = c(13L, 14L, 15L, 15L, 15L, 14L, 12L, 
16L, 17L, 15L, 19L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
), row.names = 12:22, class = "data.frame")), .Names = c("V5", 
"V8", "V10", "V44", "V2"))
structure(list(V5 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083
), SPCLORatingValue = c(11L, 15L, 14L, 15L, 14L, 14L, 16L, 19L, 
13L, 17L, 11L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
), row.names = 12:22, class = "data.frame"), V8 = structure(list(
WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083), SPCLORatingValue = c(14L, 15L, 15L, 
12L, 15L, 12L, 13L, 15L, 14L, 15L, 14L)), .Names = c("WgtBand", 
"Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"), 
V10 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083, 
0.0043574552083, 0.0043574552083, 0.0043574552083
), SPCLORatingValue = c(15L, 13L, 14L, 14L, 13L, 13L, 13L, 
15L, 15L, 13L, 14L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
 
 
 
 
 
 
 
 
 
 
 
 

 
From: wdun...@tibco.com
Date: Wed, 20 May 2015 22:12:01 -0700
Subject: Re: [R] Subset and 0 replace?
To: newrnew...@hotmail.com
CC: r-help@r-project.org

Can you show a small self-contained example of you data 

Re: [R] Question regarding different R versions on an enterprise network server

2015-05-21 Thread Duncan Murdoch

On 21/05/2015 12:21 PM, Assaf P. Oron wrote:

Hi all,

I represent R users vs. IT dept. at my workplace (yes, an enviable task :)

We've managed to get a workable network-based R application, for people who
work remotely, or don't have a machine (i.e., they use a VDI terminal).
Everything in this organization is staunchly Windows and Microsoft.

We've agreed to upgrade only once yearly, to save IT resources. Now we're
upgrading, and I would like users to be able to keep their old R 3.1.0
directory trees like it's available on a single Windows machine. At least
for a few months, so that people can evaluate back-compatibility if they
need. In fact, we have an even older server-based 3.0.1, which happens to
be  the only R version for which the Tableaux-R connection works (at least
according to my colleagues, I don't use Tableaux).

Anyway, long story short. That was just the motivating example. The problem
I'm dealing with is whether a network application that has several versions
of R (3.1.z, 3.2.z), etc., all available, and each reading and installing
libraries to a different folder tree.

The libraries right now are installed into each user's "personal" share
drive. It's pretty stable. However, obviously the 3.2.z libraries will now
overwrite the 3.1.z.

My IT contact says it's impossible, because the Windows app name is always
just Rgui.exe, and they can only have one set of instructions associated
with the same app name (i.e., what folders to go to, etc.)


If you are doing the install, you can rename Rgui.exe to something else, 
e.g. rename the old one to Rgui31.exe.


The default setup already installs user packages into a local directory 
with a versioned name, so that shouldn't be a problem.

See ?R_LIBS for details on that.

Duncan Murdoch


I wonder whether anyone has had experience with this, or I should just give
up and alert people that if they want to explore various historical layers
of R and the associated packages, they will have to work around and/or
install and uninstall lots of packages each time.

Thanks!

Assaf



__
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] Question regarding different R versions on an enterprise network server

2015-05-21 Thread Jeff Newmiller
3.2 library is in a different directory than 3.1 library.

You might benefit from reading the discussion about packages in the 
installation manual for R.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 21, 2015 9:21:28 AM PDT, "Assaf P. Oron"  wrote:
>Hi all,
>
>I represent R users vs. IT dept. at my workplace (yes, an enviable task
>:)
>
>We've managed to get a workable network-based R application, for people
>who
>work remotely, or don't have a machine (i.e., they use a VDI terminal).
>Everything in this organization is staunchly Windows and Microsoft.
>
>We've agreed to upgrade only once yearly, to save IT resources. Now
>we're
>upgrading, and I would like users to be able to keep their old R 3.1.0
>directory trees like it's available on a single Windows machine. At
>least
>for a few months, so that people can evaluate back-compatibility if
>they
>need. In fact, we have an even older server-based 3.0.1, which happens
>to
>be  the only R version for which the Tableaux-R connection works (at
>least
>according to my colleagues, I don't use Tableaux).
>
>Anyway, long story short. That was just the motivating example. The
>problem
>I'm dealing with is whether a network application that has several
>versions
>of R (3.1.z, 3.2.z), etc., all available, and each reading and
>installing
>libraries to a different folder tree.
>
>The libraries right now are installed into each user's "personal" share
>drive. It's pretty stable. However, obviously the 3.2.z libraries will
>now
>overwrite the 3.1.z.
>
>My IT contact says it's impossible, because the Windows app name is
>always
>just Rgui.exe, and they can only have one set of instructions
>associated
>with the same app name (i.e., what folders to go to, etc.)
>
>I wonder whether anyone has had experience with this, or I should just
>give
>up and alert people that if they want to explore various historical
>layers
>of R and the associated packages, they will have to work around and/or
>install and uninstall lots of packages each time.
>
>Thanks!
>
>Assaf

__
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] Question regarding different R versions on an enterprise network server

2015-05-21 Thread Assaf P. Oron
Thanks for the quick response.

@Duncan: The IT person says he cannot rename the binary. Naturally that's
the first suggestion I made to him. I found it odd but he's the IT person
not me.
OTOH if I have authoritative word from the R team that it's perfectly
doable, I can get back to him :)

@Jeff: Since it's a network app, on their side it doesn't sit in a 'folder'
so there's no way for the different Rgui.exe's to reference different
folders. If they are called the same, they will all read off of the same
initialization files.

Assaf



On Thu, May 21, 2015 at 9:54 AM, Duncan Murdoch 
wrote:

> On 21/05/2015 12:21 PM, Assaf P. Oron wrote:
>
>> Hi all,
>>
>> I represent R users vs. IT dept. at my workplace (yes, an enviable task :)
>>
>> We've managed to get a workable network-based R application, for people
>> who
>> work remotely, or don't have a machine (i.e., they use a VDI terminal).
>> Everything in this organization is staunchly Windows and Microsoft.
>>
>> We've agreed to upgrade only once yearly, to save IT resources. Now we're
>> upgrading, and I would like users to be able to keep their old R 3.1.0
>> directory trees like it's available on a single Windows machine. At least
>> for a few months, so that people can evaluate back-compatibility if they
>> need. In fact, we have an even older server-based 3.0.1, which happens to
>> be  the only R version for which the Tableaux-R connection works (at least
>> according to my colleagues, I don't use Tableaux).
>>
>> Anyway, long story short. That was just the motivating example. The
>> problem
>> I'm dealing with is whether a network application that has several
>> versions
>> of R (3.1.z, 3.2.z), etc., all available, and each reading and installing
>> libraries to a different folder tree.
>>
>> The libraries right now are installed into each user's "personal" share
>> drive. It's pretty stable. However, obviously the 3.2.z libraries will now
>> overwrite the 3.1.z.
>>
>> My IT contact says it's impossible, because the Windows app name is always
>> just Rgui.exe, and they can only have one set of instructions associated
>> with the same app name (i.e., what folders to go to, etc.)
>>
>
> If you are doing the install, you can rename Rgui.exe to something else,
> e.g. rename the old one to Rgui31.exe.
>
> The default setup already installs user packages into a local directory
> with a versioned name, so that shouldn't be a problem.
> See ?R_LIBS for details on that.
>
> Duncan Murdoch
>
>
>> I wonder whether anyone has had experience with this, or I should just
>> give
>> up and alert people that if they want to explore various historical layers
>> of R and the associated packages, they will have to work around and/or
>> install and uninstall lots of packages each time.
>>
>> Thanks!
>>
>> Assaf
>>
>>
>


-- 
Assaf P. Oron, Ph.D.
Senior Statistician, Children's Core for Biomedical Statistics
(206)884-1236, assaf.o...@seattlechildrens.org

Consulting statistician, Seattle DEEDS Project
http://www.duwamishdiesel.org/
Instructor, UW Certificate for Statistical Analysis with R
as...@uw.edu

[[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] Question regarding different R versions on an enterprise network server

2015-05-21 Thread Jeff Newmiller
Assaf: they are named differently when you run different versions. 3.1 and 3.2 
are different, but 3.1.1 and 3.1.2 are both in the 3.1 directory.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 21, 2015 11:09:25 AM PDT, "Assaf P. Oron"  wrote:
>Thanks for the quick response.
>
>@Duncan: The IT person says he cannot rename the binary. Naturally
>that's
>the first suggestion I made to him. I found it odd but he's the IT
>person
>not me.
>OTOH if I have authoritative word from the R team that it's perfectly
>doable, I can get back to him :)
>
>@Jeff: Since it's a network app, on their side it doesn't sit in a
>'folder'
>so there's no way for the different Rgui.exe's to reference different
>folders. If they are called the same, they will all read off of the
>same
>initialization files.
>
>Assaf
>
>
>
>On Thu, May 21, 2015 at 9:54 AM, Duncan Murdoch
>
>wrote:
>
>> On 21/05/2015 12:21 PM, Assaf P. Oron wrote:
>>
>>> Hi all,
>>>
>>> I represent R users vs. IT dept. at my workplace (yes, an enviable
>task :)
>>>
>>> We've managed to get a workable network-based R application, for
>people
>>> who
>>> work remotely, or don't have a machine (i.e., they use a VDI
>terminal).
>>> Everything in this organization is staunchly Windows and Microsoft.
>>>
>>> We've agreed to upgrade only once yearly, to save IT resources. Now
>we're
>>> upgrading, and I would like users to be able to keep their old R
>3.1.0
>>> directory trees like it's available on a single Windows machine. At
>least
>>> for a few months, so that people can evaluate back-compatibility if
>they
>>> need. In fact, we have an even older server-based 3.0.1, which
>happens to
>>> be  the only R version for which the Tableaux-R connection works (at
>least
>>> according to my colleagues, I don't use Tableaux).
>>>
>>> Anyway, long story short. That was just the motivating example. The
>>> problem
>>> I'm dealing with is whether a network application that has several
>>> versions
>>> of R (3.1.z, 3.2.z), etc., all available, and each reading and
>installing
>>> libraries to a different folder tree.
>>>
>>> The libraries right now are installed into each user's "personal"
>share
>>> drive. It's pretty stable. However, obviously the 3.2.z libraries
>will now
>>> overwrite the 3.1.z.
>>>
>>> My IT contact says it's impossible, because the Windows app name is
>always
>>> just Rgui.exe, and they can only have one set of instructions
>associated
>>> with the same app name (i.e., what folders to go to, etc.)
>>>
>>
>> If you are doing the install, you can rename Rgui.exe to something
>else,
>> e.g. rename the old one to Rgui31.exe.
>>
>> The default setup already installs user packages into a local
>directory
>> with a versioned name, so that shouldn't be a problem.
>> See ?R_LIBS for details on that.
>>
>> Duncan Murdoch
>>
>>
>>> I wonder whether anyone has had experience with this, or I should
>just
>>> give
>>> up and alert people that if they want to explore various historical
>layers
>>> of R and the associated packages, they will have to work around
>and/or
>>> install and uninstall lots of packages each time.
>>>
>>> Thanks!
>>>
>>> Assaf
>>>
>>>
>>

__
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] configure script claims that pkg-config doesn't know about cairo

2015-05-21 Thread Michael Gooch

and yet I checked manually :

pkg-config --print-variables cairo
exec_prefix
prefix
libdir
includedir

something weird is going on with this

__
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] compiling R with tuned BLAS

2015-05-21 Thread Michael Gooch
I am looking at the instructions on 
http://cran.r-project.org/doc/manuals/r-patched/R-admin.html#ATLAS


I have noticed that ATLAS produces two shared libs in addition to the 
*.a files:

http://math-atlas.sourceforge.net/atlas_install/node22.html

contents of the ATLAS lib directory:
libatlas.a  libcblas.a  libf77blas.a  liblapack.a  libptcblas.a 
libptf77blas.a  libsatlas.so  libtatlas.so


The instructions do not appear to match up with the *.a files & *.so 
files as described. (it appears to want me to use shared libs, but the 
names defined are static libs, not shared libs).


should I simply be having it link against libtatlas.so (and pthreads) 
for shared threaded atlas and libsatlas.so for shared sequential atlas?

do I need shared versions of the other static libraries?

I think the help is a bit out of date, or at least unclear as to what it 
intends of me.


M. Gooch

__
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] Subset and 0 replace?

2015-05-21 Thread William Dunlap
I renamed your 'c' to be 'toyData' and your 'e' to be 'desiredResult'.  Do
you
want the following, which uses only base R code?

> vapply(toyData,
  FUN=function(V)with(V, sum(Wgt[SPCLORatingValue>16])),
  FUN.VALUE=0)
 V5  V8 V10 V44  V2
0.008714910 0.0 0.0 0.004357455 0.008714910

It what is in your desired result but in a more useful format (e.g., numbers
instead of character strings for sum).

> desiredResult
 [,1]  [,2] [,3]  [,4]  [,5]
[1,] "V5"  "V8" "V10" "V44" "V2"
[2,] "0.008714910" "0"  "0"   "0.004357455" "0.008714910"


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, May 21, 2015 at 9:50 AM, Vin Cheng  wrote:

> Thanks William/Duncan!
>
> Duncan - Yes - I am using the doBy package.
>
> running this line on the sample data below gives weights for V5,V44, &
> V2.  Ideally I would like 0's for V8 and V10 in the output.
>
> So it would look like:
> e<-structure(matrix(c("V5", "0.008714910", "V8", "0", "V10", "0", "V44",
> "0.004357455", "V2", "0.008714910"),nrow = 2))
>
>
> This is far as I've gotten by subsetting and  summing:
> a<-t(summaryBy(Wgt.sum~as.numeric(.id),data=subset(ldply(c,function(x)
> summaryBy(Wgt ~ SPCLORatingValue, data=x,
> FUN=c(sum))),SPCLORatingValue>16),FUN=c(sum),order=FALSE))
>
> All help/guidance is much appreciated!  Thanks Vince!
>
> Sample data example:
> c<-structure(list(V5 = structure(list(WgtBand = c(2, 2, 2, 2, 2,
> 2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083
> ), SPCLORatingValue = c(11L, 15L, 14L, 15L, 14L, 14L, 16L, 19L,
> 13L, 17L, 11L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
> ), row.names = 12:22, class = "data.frame"), V8 = structure(list(
> WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt =
> c(0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083), SPCLORatingValue = c(14L, 15L, 15L,
> 12L, 15L, 12L, 13L, 15L, 14L, 15L, 14L)), .Names = c("WgtBand",
> "Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"),
> V10 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2,
> 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083
> ), SPCLORatingValue = c(15L, 13L, 14L, 14L, 13L, 13L, 13L,
> 15L, 15L, 13L, 14L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
> ), row.names = 12:22, class = "data.frame"), V44 = structure(list(
> WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt =
> c(0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083), SPCLORatingValue = c(13L, 14L,
> 16L, 15L, 14L, 14L, 18L, 13L, 16L, 15L, 11L)), .Names =
> c("WgtBand",
> "Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"),
> V2 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2,
> 2, 2), Wgt = c(0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083
> ), SPCLORatingValue = c(13L, 14L, 15L, 15L, 15L, 14L, 12L,
> 16L, 17L, 15L, 19L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
> ), row.names = 12:22, class = "data.frame")), .Names = c("V5",
> "V8", "V10", "V44", "V2"))
> structure(list(V5 = structure(list(WgtBand = c(2, 2, 2, 2, 2,
> 2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083
> ), SPCLORatingValue = c(11L, 15L, 14L, 15L, 14L, 14L, 16L, 19L,
> 13L, 17L, 11L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
> ), row.names = 12:22, class = "data.frame"), V8 = structure(list(
> WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt =
> c(0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083, 0.0043574552083, 0.0043574552083,
> 0.0043574552083), SPCLORatingValue = c(14L, 15L, 15L,
> 

Re: [R] Subset and 0 replace?

2015-05-21 Thread Vin Cheng
This is perfect!  Thanks William!!!

Vince

> On May 21, 2015, at 3:36 PM, William Dunlap  wrote:
> 
> I renamed your 'c' to be 'toyData' and your 'e' to be 'desiredResult'.  Do you
> want the following, which uses only base R code?
> 
> > vapply(toyData,
>   FUN=function(V)with(V, sum(Wgt[SPCLORatingValue>16])),
>   FUN.VALUE=0)
>  V5  V8 V10 V44  V2
> 0.008714910 0.0 0.0 0.004357455 0.008714910
> 
> It what is in your desired result but in a more useful format (e.g., numbers
> instead of character strings for sum).
> 
> > desiredResult
>  [,1]  [,2] [,3]  [,4]  [,5]
> [1,] "V5"  "V8" "V10" "V44" "V2"
> [2,] "0.008714910" "0"  "0"   "0.004357455" "0.008714910"
> 
> 
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
> 
>> On Thu, May 21, 2015 at 9:50 AM, Vin Cheng  wrote:
>> Thanks William/Duncan!
>>  
>> Duncan - Yes - I am using the doBy package.
>>  
>> running this line on the sample data below gives weights for V5,V44, & V2.  
>> Ideally I would like 0's for V8 and V10 in the output.
>>  
>> So it would look like:
>> e<-structure(matrix(c("V5", "0.008714910", "V8", "0", "V10", "0", "V44", 
>> "0.004357455", "V2", "0.008714910"),nrow = 2))
>>  
>>  
>> This is far as I've gotten by subsetting and  summing:
>> a<-t(summaryBy(Wgt.sum~as.numeric(.id),data=subset(ldply(c,function(x) 
>> summaryBy(Wgt ~ SPCLORatingValue, data=x, 
>> FUN=c(sum))),SPCLORatingValue>16),FUN=c(sum),order=FALSE))
>>  
>> All help/guidance is much appreciated!  Thanks Vince!
>>  
>> Sample data example:
>> c<-structure(list(V5 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 
>> 2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083
>> ), SPCLORatingValue = c(11L, 15L, 14L, 15L, 14L, 14L, 16L, 19L, 
>> 13L, 17L, 11L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
>> ), row.names = 12:22, class = "data.frame"), V8 = structure(list(
>> WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt = 
>> c(0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083), SPCLORatingValue = c(14L, 15L, 15L, 
>> 12L, 15L, 12L, 13L, 15L, 14L, 15L, 14L)), .Names = c("WgtBand", 
>> "Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"), 
>> V10 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 
>> 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083
>> ), SPCLORatingValue = c(15L, 13L, 14L, 14L, 13L, 13L, 13L, 
>> 15L, 15L, 13L, 14L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
>> ), row.names = 12:22, class = "data.frame"), V44 = structure(list(
>> WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt = 
>> c(0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083), SPCLORatingValue = c(13L, 14L, 
>> 16L, 15L, 14L, 14L, 18L, 13L, 16L, 15L, 11L)), .Names = c("WgtBand", 
>> "Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"), 
>> V2 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 
>> 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083
>> ), SPCLORatingValue = c(13L, 14L, 15L, 15L, 15L, 14L, 12L, 
>> 16L, 17L, 15L, 19L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
>> ), row.names = 12:22, class = "data.frame")), .Names = c("V5", 
>> "V8", "V10", "V44", "V2"))
>> structure(list(V5 = structure(list(WgtBand = c(2, 2, 2, 2, 2, 
>> 2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083, 
>> 0.0043574552083, 0.0043574552083, 0.0043574552083
>> ), SPCLORatingValue = c(11L, 15L, 14L, 15L, 14L, 14L, 16L, 19L, 
>> 13L, 17L, 11L)), .Names = c("WgtBand", "Wgt", "SPCLORatingValue"
>> ), row.names = 12:22, class = "data.frame"), V8 = structure(list(
>> WgtBand = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt = 
>> c(0.0043574552083,