Re: [R] Fwd: Dynamic regex/sub changes to function

2014-09-22 Thread Rolf Turner

On 23/09/14 12:18, Bert Gunter wrote:




Daniel:

Do you understand what a parse tree is?




Paraphrasing a quote attributed to Feynman:  "If you think you 
understand what a parse tree is, then you don't understand what a parse 
tree is." :-)


cheers,

Rolf


--
Rolf Turner
Technical Editor ANZJS

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Confused by dlnorm - densities do not match histogram

2014-09-22 Thread Terran Melconian
Good evening!  I'm running into some surprising behavior with dlnorm() and
trying to understand it.

To set the stage, I'll plot the density and overlay a normal distribution.
This works exactly as expected; the two graphs align quite closely:

qplot(data=data.frame(x=rnorm(1e5,4,2)),x=x,stat='density',geom='area') +
stat_function(fun=dnorm,args=list(4,2),colour='blue')

but then I change to a log normal distribution and the behaviour gets
odd.  The distribution looks nothing like the density plot:

qplot(data=data.frame(x=rlnorm(1e5,4,2)),x=x,log='x',stat='density',geom='area')
 + stat_function(fun=dlnorm,args=list(4,2),colour='blue')

I thought the issue might be scale transformation - if dlnorm is giving the
density per unit x this is not the same as the density after transforming
to log(x).  So I tried to effect this scale transformation manually by
dividing by the derivative of log(x) - i.e. by multiplying by x - but this
also did not match:

qplot(data=data.frame(x=rlnorm(1e5,4,2)),x=x,log='x',stat='density',geom='area')
 + 
stat_function(fun=function(x,...){dlnorm(x,...)*x},args=list(4,2),colour='blue')

I also tried plotting without the log scale to eliminate that
transformation as a source of discrepancy, and they still don't match:

qplot(data=data.frame(x=rlnorm(1e5,4,2)),x=x,stat='density',geom='area',xlim=c(0,50))
 + stat_function(fun=dlnorm,args=list(4,2),colour='blue')

I'd appreciate any help in understanding what I'm missing.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dynamic regex/sub changes to function

2014-09-22 Thread Duncan Murdoch
On 22/09/2014, 7:38 PM, Daniel Fuka wrote:
> Thanks everyone for the help. I need to step back and refresh my
> memory on expressions as I am still unclear as to why I can not
> directly edit:
> body(nsong)[[2]]
> # Which can be located from a grep:
> body(nsong)[[grep("fuka",body(nsong))]]
> # though I believe
> class(body(nsong)[[2]])
> [1] "="
> # is trying to give me a pretty blatant hint... {: -)

Here's another hint:  everything in R is a function call.  You're
looking at a call to the function named "=".

Duncan Murdoch

> 
> On Mon, Sep 22, 2014 at 1:24 PM, Duncan Murdoch
>  wrote:
>> On 22/09/2014 11:34 AM, Daniel Fuka wrote:
>>>
>>> Howdy Duncan,
>>>
>>> Thanks for the quick reply!  I must be missing something
>>> simple/obvious. I need to have the "sub()" not return quoted and
>>> escaped characters to "just edit the language expression". In my
>>> problem, there is a function that is supported from a different
>>> package. So I always want to use the supported function as my base...
>>> but a url in the supported function needs to be changed dynamically
>>> for my application, which is easiest using "sub()".
>>>
>>> I am trying to do what you correctly indicate I would need to do:
>>> "just edit the language expression that body(fsong) gives you, and
>>> assign it back"
>>> BUT, using sub, I get back a quoted string in my example if I just use
>>> sed:
>>>
 fsong
>>> function(x){
>>>   song=paste("my name is fuka,",x)
>>>   return(song)
>>> }
>>> # Using "sub()" becomes:
 nsong
>>> function (x)
>>> {
>>>  "song = paste(\"my name is muka,\", x)"
>>>  return(song)
>>> }
>>
>>
>> You didn't do it right :-).   With fsong as above, the string to edit is
>> body(fsong)[[c(2,3,2)]].  (Why c(2,3,2)?  Because that's where the string is
>> in the parse tree.  Try looking at variations on body(fsong)[[c(2,3,2)]] to
>> figure it out, e.g.
>> body(fsong)[[c(2,3)]], or body(fsong)[[c(2,3,3)]], etc.)
>>
>> So this code would work:
>>
>> orig <- body(fsong)[[c(2,3,2)]]
>> new <- sub("fuka", "muka", orig)
>>
>> # Now put it back in nsong:
>> nsong <- fsong
>> body(nsong)[[c(2,3,2)]] <- new
>>
>> But as Bill said, this is a really bad idea.  If you just *think* about
>> changing that fsong function, it will break.
>>
>> Duncan Murdoch
>>
>>>
>>> Thanks again for the quick reply and help you are giving me!
>>> dan
>>>
>>> On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
>>>  wrote:
 On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>
> Howdy,
>
> I have searched the lists and can not seem to find a solution to my
> problem. I need to be able to dynamically modify a string inside a
> function to build a new function. "sub" replaces with a quoted
> string... and "parse" of "sub" returns expression... How can I get an
> unquoted string from a regex to stick into a "body" of a function?


 It's possible to do what you want, though you don't want to be using
 parse(), you can just edit the language expression that body(fsong)
 gives
 you, and assign it back.  But that's a messy way to solve your problem.

 Why not create a new function containing the new string?  e.g.

 makefsong <- function(name = "fuka") {
   line1 <- paste("my name is", name)
   function(x) {
 song <- paste(line1, x)
 return(song)
   }
 }

 f1 <- makefsong()
 f1("I live on the second floor")
 f2 <- makefsong("muka")
 f2("I live on the second floor")

 Duncan Murdoch

>
> Thanks for your help!
> dan
>
> # Original Function
> fsong=function(x){
>   song=paste("my name is fuka,",x)
>   return(song)
> }
> fsong("I live on the second floor")
> #
> # Copy and modify using "sub" returns quoted string with escaped quotes
> #   internally... as expected.. which can not be evaluated.
> nsong=fsong
> body(nsong)[[grep("fuka",body(nsong))]]=
> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>
> nsong("I live on the second floor") # broken
>
> #
> # Copy and modify with "parse" of  "sub",  returns expression.. but
> without quotes,
> # o getting closer.
> #
> nsong=fsong
> body(nsong)[[grep("fuka",body(nsong))]]=
>
>
> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


>>
>>

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

[R] Fwd: Dynamic regex/sub changes to function

2014-09-22 Thread Bert Gunter
(failed to cc the list)

Daniel:

Do you understand what a parse tree is?

Try this:

 f <- function(x){
+ y <- x^2
+ z <- sin(y+2)
+ }

> body(f)
{
y <- x^2
z <- sin(y + 2)
}

> as.list(body(f))
[[1]]
`{`

[[2]]
y <- x^2

[[3]]
z <- sin(y + 2)

> body(f)[[c(3,3,1)]]
sin

> class(body(f))
[1] "{"


You should listen to your elders (Bill and Duncan) and **don't do this. **

Cheers,
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 Mon, Sep 22, 2014 at 4:38 PM, Daniel Fuka  wrote:
> Thanks everyone for the help. I need to step back and refresh my
> memory on expressions as I am still unclear as to why I can not
> directly edit:
> body(nsong)[[2]]
> # Which can be located from a grep:
> body(nsong)[[grep("fuka",body(nsong))]]
> # though I believe
> class(body(nsong)[[2]])
> [1] "="
> # is trying to give me a pretty blatant hint... {: -)
>
> On Mon, Sep 22, 2014 at 1:24 PM, Duncan Murdoch
>  wrote:
>> On 22/09/2014 11:34 AM, Daniel Fuka wrote:
>>>
>>> Howdy Duncan,
>>>
>>> Thanks for the quick reply!  I must be missing something
>>> simple/obvious. I need to have the "sub()" not return quoted and
>>> escaped characters to "just edit the language expression". In my
>>> problem, there is a function that is supported from a different
>>> package. So I always want to use the supported function as my base...
>>> but a url in the supported function needs to be changed dynamically
>>> for my application, which is easiest using "sub()".
>>>
>>> I am trying to do what you correctly indicate I would need to do:
>>> "just edit the language expression that body(fsong) gives you, and
>>> assign it back"
>>> BUT, using sub, I get back a quoted string in my example if I just use
>>> sed:
>>>
>>> > fsong
>>> function(x){
>>>   song=paste("my name is fuka,",x)
>>>   return(song)
>>> }
>>> # Using "sub()" becomes:
>>> > nsong
>>> function (x)
>>> {
>>>  "song = paste(\"my name is muka,\", x)"
>>>  return(song)
>>> }
>>
>>
>> You didn't do it right :-).   With fsong as above, the string to edit is
>> body(fsong)[[c(2,3,2)]].  (Why c(2,3,2)?  Because that's where the string is
>> in the parse tree.  Try looking at variations on body(fsong)[[c(2,3,2)]] to
>> figure it out, e.g.
>> body(fsong)[[c(2,3)]], or body(fsong)[[c(2,3,3)]], etc.)
>>
>> So this code would work:
>>
>> orig <- body(fsong)[[c(2,3,2)]]
>> new <- sub("fuka", "muka", orig)
>>
>> # Now put it back in nsong:
>> nsong <- fsong
>> body(nsong)[[c(2,3,2)]] <- new
>>
>> But as Bill said, this is a really bad idea.  If you just *think* about
>> changing that fsong function, it will break.
>>
>> Duncan Murdoch
>>
>>>
>>> Thanks again for the quick reply and help you are giving me!
>>> dan
>>>
>>> On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
>>>  wrote:
>>> > On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>>> >>
>>> >> Howdy,
>>> >>
>>> >> I have searched the lists and can not seem to find a solution to my
>>> >> problem. I need to be able to dynamically modify a string inside a
>>> >> function to build a new function. "sub" replaces with a quoted
>>> >> string... and "parse" of "sub" returns expression... How can I get an
>>> >> unquoted string from a regex to stick into a "body" of a function?
>>> >
>>> >
>>> > It's possible to do what you want, though you don't want to be using
>>> > parse(), you can just edit the language expression that body(fsong)
>>> > gives
>>> > you, and assign it back.  But that's a messy way to solve your problem.
>>> >
>>> > Why not create a new function containing the new string?  e.g.
>>> >
>>> > makefsong <- function(name = "fuka") {
>>> >   line1 <- paste("my name is", name)
>>> >   function(x) {
>>> > song <- paste(line1, x)
>>> > return(song)
>>> >   }
>>> > }
>>> >
>>> > f1 <- makefsong()
>>> > f1("I live on the second floor")
>>> > f2 <- makefsong("muka")
>>> > f2("I live on the second floor")
>>> >
>>> > Duncan Murdoch
>>> >
>>> >>
>>> >> Thanks for your help!
>>> >> dan
>>> >>
>>> >> # Original Function
>>> >> fsong=function(x){
>>> >>   song=paste("my name is fuka,",x)
>>> >>   return(song)
>>> >> }
>>> >> fsong("I live on the second floor")
>>> >> #
>>> >> # Copy and modify using "sub" returns quoted string with escaped quotes
>>> >> #   internally... as expected.. which can not be evaluated.
>>> >> nsong=fsong
>>> >> body(nsong)[[grep("fuka",body(nsong))]]=
>>> >> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>>> >>
>>> >> nsong("I live on the second floor") # broken
>>> >>
>>> >> #
>>> >> # Copy and modify with "parse" of  "sub",  returns expression.. but
>>> >> without quotes,
>>> >> # o getting closer.
>>> >> #
>>> >> nsong=fsong
>>> >> body(nsong)[[grep("fuka",body(nsong))]]=
>>> >>
>>> >>
>>> >> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>>> >>
>>> >> __
>>> >> R-help@r-

Re: [R] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Thanks everyone for the help. I need to step back and refresh my
memory on expressions as I am still unclear as to why I can not
directly edit:
body(nsong)[[2]]
# Which can be located from a grep:
body(nsong)[[grep("fuka",body(nsong))]]
# though I believe
class(body(nsong)[[2]])
[1] "="
# is trying to give me a pretty blatant hint... {: -)

On Mon, Sep 22, 2014 at 1:24 PM, Duncan Murdoch
 wrote:
> On 22/09/2014 11:34 AM, Daniel Fuka wrote:
>>
>> Howdy Duncan,
>>
>> Thanks for the quick reply!  I must be missing something
>> simple/obvious. I need to have the "sub()" not return quoted and
>> escaped characters to "just edit the language expression". In my
>> problem, there is a function that is supported from a different
>> package. So I always want to use the supported function as my base...
>> but a url in the supported function needs to be changed dynamically
>> for my application, which is easiest using "sub()".
>>
>> I am trying to do what you correctly indicate I would need to do:
>> "just edit the language expression that body(fsong) gives you, and
>> assign it back"
>> BUT, using sub, I get back a quoted string in my example if I just use
>> sed:
>>
>> > fsong
>> function(x){
>>   song=paste("my name is fuka,",x)
>>   return(song)
>> }
>> # Using "sub()" becomes:
>> > nsong
>> function (x)
>> {
>>  "song = paste(\"my name is muka,\", x)"
>>  return(song)
>> }
>
>
> You didn't do it right :-).   With fsong as above, the string to edit is
> body(fsong)[[c(2,3,2)]].  (Why c(2,3,2)?  Because that's where the string is
> in the parse tree.  Try looking at variations on body(fsong)[[c(2,3,2)]] to
> figure it out, e.g.
> body(fsong)[[c(2,3)]], or body(fsong)[[c(2,3,3)]], etc.)
>
> So this code would work:
>
> orig <- body(fsong)[[c(2,3,2)]]
> new <- sub("fuka", "muka", orig)
>
> # Now put it back in nsong:
> nsong <- fsong
> body(nsong)[[c(2,3,2)]] <- new
>
> But as Bill said, this is a really bad idea.  If you just *think* about
> changing that fsong function, it will break.
>
> Duncan Murdoch
>
>>
>> Thanks again for the quick reply and help you are giving me!
>> dan
>>
>> On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
>>  wrote:
>> > On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>> >>
>> >> Howdy,
>> >>
>> >> I have searched the lists and can not seem to find a solution to my
>> >> problem. I need to be able to dynamically modify a string inside a
>> >> function to build a new function. "sub" replaces with a quoted
>> >> string... and "parse" of "sub" returns expression... How can I get an
>> >> unquoted string from a regex to stick into a "body" of a function?
>> >
>> >
>> > It's possible to do what you want, though you don't want to be using
>> > parse(), you can just edit the language expression that body(fsong)
>> > gives
>> > you, and assign it back.  But that's a messy way to solve your problem.
>> >
>> > Why not create a new function containing the new string?  e.g.
>> >
>> > makefsong <- function(name = "fuka") {
>> >   line1 <- paste("my name is", name)
>> >   function(x) {
>> > song <- paste(line1, x)
>> > return(song)
>> >   }
>> > }
>> >
>> > f1 <- makefsong()
>> > f1("I live on the second floor")
>> > f2 <- makefsong("muka")
>> > f2("I live on the second floor")
>> >
>> > Duncan Murdoch
>> >
>> >>
>> >> Thanks for your help!
>> >> dan
>> >>
>> >> # Original Function
>> >> fsong=function(x){
>> >>   song=paste("my name is fuka,",x)
>> >>   return(song)
>> >> }
>> >> fsong("I live on the second floor")
>> >> #
>> >> # Copy and modify using "sub" returns quoted string with escaped quotes
>> >> #   internally... as expected.. which can not be evaluated.
>> >> nsong=fsong
>> >> body(nsong)[[grep("fuka",body(nsong))]]=
>> >> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>> >>
>> >> nsong("I live on the second floor") # broken
>> >>
>> >> #
>> >> # Copy and modify with "parse" of  "sub",  returns expression.. but
>> >> without quotes,
>> >> # o getting closer.
>> >> #
>> >> nsong=fsong
>> >> body(nsong)[[grep("fuka",body(nsong))]]=
>> >>
>> >>
>> >> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>> >>
>> >> __
>> >> R-help@r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide
>> >> http://www.R-project.org/posting-guide.html
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >
>> >
>
>

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


[R] robCompositions: Using impCoda

2014-09-22 Thread Rich Shepard

  I need to learn how to apply the methods in robCompositions and have read
the package docs. Two of my six data sets of proportions contain missing
values (not collected or not present); one set has a single missing value,
the other has 3 missing values. So my first task is to learn how to properly
apply the impCoda() method to my data to impute values for those that are
missing. After reading ?impData and emulating the syntax on that help page,
without understanding how to select appropriate options for the various
components, I end up with errors and have no clue how to correctly format
the command.

The data frame:
burns.co
   Filterer Gatherer Grazer Predator Shredder
date2000-07-18   0.0550   0.5596 0.0734   0.2294   0.0826
date2003-07-08   0.0734   0.6147 0.0183   0.2294   0.0642
date2005-07-13   0.1161   0.5714 0.0357   0.1696   0.1071
date2006-06-28   0.1000   0.4667 0.1500   0.1333   0.1500
date2010-09-14   0.0778   0.6111 0.0444   0.1889   0.0778
date2011-07-13   0.0879   0.5714 0.0659   0.2747   NA
date2012-07-11   0.1042   0.5313 0.0625   0.2396   0.0625
date2013-07-11   0.0723   0.5542 0.0602   0.2651   0.0482

has this structure:

str(burns.co)
'data.frame':   8 obs. of  5 variables:
 $ Filterer: num  0.055 0.0734 0.1161 0.1 0.0778 ...
 $ Gatherer: num  0.56 0.615 0.571 0.467 0.611 ...
 $ Grazer  : num  0.0734 0.0183 0.0357 0.15 0.0444 0.0659 0.0625 0.0602
 $ Predator: num  0.229 0.229 0.17 0.133 0.189 ...
 $ Shredder: num  0.0826 0.0642 0.1071 0.15 0.0778 ...

  Emulating the syntax in ?impCoda produces this result:

burnsImp <- impCoda(burns.co, maxit = 10, eps = 0.5, method = 'ltsReg',
closed = TRUE, init = 'KNN', k = 5, noise = 0.1, bruteforce = FALSE)
Error in ltsReg.default(x, y, intercept = (xint > 0), ...) :
  Need more than twice as many observations as variables.
In addition: Warning message:
In impCoda(burns.co, maxit = 10, eps = 0.5, method = "ltsReg", closed =
TRUE,  :
  k might be too large

  Please provide pointers so I can read and learn how to correctly specify
impCoda parameters for my data sets.

TIA,

Rich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 in quantile.default(resids) : missing values and NaN's not allowed if 'na.rm' is FALSE

2014-09-22 Thread Ben Bolker
Chad Danyluck  gmail.com> writes:

> 
> About a year ago I ran some analyses using lmer. The general syntax was:
> 
> mlm <- lmer(var1 ~ (1|dyad) + 
> var2 + var3*var4*var5, na.action=na.exclude);
> summary(mlm)
> 
> The model ran fine and I saved the output. I've recently turned back to
> those analyses, however, the model no longer runs. I get the following
> error:
> 
> Error in quantile.default(resids) :
>   missing values and NaN's not allowed if 'na.rm' is FALSE
> 
> I've searched the online forums and found that this topic has not been
> touched upon since 2006, and at that time someone
>  had indicated that it was
> a bug that had been resolved. I am using the most current version of lme4,
> so if the bug is fixed I am unsure why I am experiencing this problem.

   You missed

https://mailman.stat.ethz.ch/pipermail/r-sig-mixed-models/2014q3/022616.html

and the subsequent thread, which describes a recent issue.

This was fixed two weeks ago, at

https://github.com/lme4/lme4/commit/e68b7475d1d254bfbdae6cd3efb2d9c8dbe0b899

but hasn't made it into a released version of lme4, although at least
a Windows binary should be available @ http://lme4.r-forge.r-project.org/repos
(and you can install from Github via devtools::install_github() if you
have compilation tools available on your machine).

> I have since run the model using lmer's default for handling missing data
> (na.omit), but found the results do not match what I had saved previously
> when using na.exclude.
> 
> If anyone has an insight here I'd be very appreciative.
> 
> Kind regards,
> 
> Chad


  Perhaps worth noting that this bug only affects the summary print
method, not anything in the actual model fitting process.

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


[R] Error in quantile.default(resids) : missing values and NaN's not allowed if 'na.rm' is FALSE

2014-09-22 Thread Chad Danyluck
About a year ago I ran some analyses using lmer. The general syntax was:

mlm <- lmer(var1 ~ (1|dyad) + var2 + var3*var4*var5, na.action=na.exclude);
summary(mlm)

The model ran fine and I saved the output. I've recently turned back to
those analyses, however, the model no longer runs. I get the following
error:

Error in quantile.default(resids) :
  missing values and NaN's not allowed if 'na.rm' is FALSE

I've searched the online forums and found that this topic has not been
touched upon since 2006, and at that time someone had indicated that it was
a bug that had been resolved. I am using the most current version of lme4,
so if the bug is fixed I am unsure why I am experiencing this problem.

I have since run the model using lmer's default for handling missing data
(na.omit), but found the results do not match what I had saved previously
when using na.exclude.

If anyone has an insight here I'd be very appreciative.

Kind regards,

Chad

-- 
Chad M. Danyluck
PhD Candidate, Psychology
University of Toronto
Lab: http://embodiedsocialcognition.com


“There is nothing either good or bad but thinking makes it so.” - William
Shakespeare

[[alternative HTML version deleted]]

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


[R] error in rownames

2014-09-22 Thread Chris Jackson-Jordan
Dear fellow R users,

I am trying to run the random forest and Yaimpute packages in R to
impute a grid to project in a gis. However, after running the
imputation I keep getting an error in the rownames. This sounds simple
enough, but I cannot figure out what these rownames are reffering to.
Any ideas? I am fairly new to R so im sure it is an easy fix. Any help
would be awesome.

Thanks,

Chris


> y <- subset(training, select = c(ResponseSu)) > x <- subset(training,
select = c(sinaspect, habitat, slope, elevation, cosaspect, disttoroad,
disttowat)) > type.rf <- yai(x=x, y=y, method="randomForest",
rfMode="regression", ntree= 2000) > outfile <- list(Type =
"D:/R_Desktop_Data/RF_RespSurf/RespSurf_Reg.asc") > xfile <-list(sinaspect
="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/sinaspect.asc",
habitat
="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/habitat.asc",
elevation
="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/elevation.asc",
disttowat
="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/disttowat.asc",
disttoroad
="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/disttoroad.asc",
slope
="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/slope.asc",
cosaspect
="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/cosaspect.asc")
> AsciiGridImpute(type.rf, xfile, outfile) Rows per dot: 19 Rows to do:
1900 ToDo:

Done: . Error in `rownames<-`(`*tmp*`, value = c("23x0049", "23x0050",
"23x0051", : attempt to set rownames on object with no dimensions

here is an example of my training data


 > dput(training[1:20, ])structure(list(CID = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), cosaspect = c(-0.402376,
-0.263312, -0.978401, 0.0364174, 0.975655, -0.954148, -0.982731,
0.949282, -0.827262, -0.300375, -0.211474, -0.63658, 0.892831,
-0.0395686, 0.649339, 0.0129927, -0.428111, -0.970759, 0.891974,
-0.901187), disttoroad = c(475.928, 245.003, 671.958, 10.3074,
384.839, 180.305, 620.157, 290.441, 587.61, 72.1515, 10.3074,
43.7304, 20.6147, 10.3074, 428.717, 72.884, 106.121, 175.225,
249.302, 30.9221), disttowat = c(535.685, 309.907, 291.536, 1039.97,
258.507, 202.508, 387.315, 1233.18, 666.481, 457.721, 1553.81,
679.505, 1115.53, 515.162, 692.974, 498.604, 204.075, 388.138,
885.474, 343.097), elevation = c(1901.69, 1992.82, 1911.9, 1985.14,
1979.67, 1870.83, 1909.5, 2111.45, 1913.09, 1922.76, 1996.68,
2092.64, 2066.89, 1872.85, 2047.7, 1923.03, 1981.28, 1875.6,
2074.82, 1866.82), habitat = c(2L, 5L, 2L, 10L, 1L, 2L, 2L, 3L,
2L, 16L, 3L, 3L, 1L, 4L, 1L, 5L, 6L, 2L, 3L, 10L), sinaspect = c(0.915474,
-0.964711, 0.206717, 0.999337, 0.21931, -0.299336, -0.185039,
-0.314428, -0.561817, -0.953821, -0.977384, -0.771211, -0.450392,
-0.999217, -0.760499, 0.16, 0.903726, -0.240057, -0.452087,
-0.433431), slope = c(0.768307, 11.4002, 1.34928, 3.42667, 19.6776,
0.341443, 3.14869, 7.14637, 1.1572, 24.4974, 11.0014, 19.4188,
16., 5.23936, 9.95699, 17.1475, 21.374, 0.475218, 7.23375,
0.29158), POINT_X = c(517098.970249, 517940.940865, 517526.253849,
516073.554503, 516019.068701, 515506.165434, 517353.141738, 520076.487742,
517973.141394, 516823.388106, 514784.035218, 518298.237046, 519796.43389,
515714.490202, 518829.909017, 519385.491579, 518659.851297, 516654.780318,
519063.701155, 516270.975247), POINT_Y = c(4818385.61487, 4816762.97919,
4819015.00611, 4816604.93198, 4814958.09214, 4813316.65912, 4818923.42436,
4819217.24161, 4820124.20539, 4814172.9439, 4815372.65581, 4816674.91138,
4819393.11718, 4812616.30708, 4818780.85554, 4816287.01774, 4814503.57051,
4813614.51134, 4818804.92703, 4812168.6041), ResponseSu = c(1.822784,
398.591262, 5.565648, 69.106734, 235.114325, 2.162961, 8.170528,
389.107013, 11.32454, 4880.467707, 192.215083, 160.17186, 91.843573,
63.863233, 113.728819, 100.03871, 1288.273717, 14.032336, 141.478417,
10.020201)), .Names = c("CID", "cosaspect", "disttoroad", "disttowat",
"elevation", "habitat", "sinaspect", "slope", "POINT_X", "POINT_Y",
"ResponseSu"), row.names = c(NA, 20L), class = "data.frame")>
library("randomForest", lib.loc="~/RStudio/R/library")

[[alternative HTML version deleted]]

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


[R] Plotting boundary lines from shapefiles overtop a map of Canada

2014-09-22 Thread Alain Dubreuil
Hi.  I have a requirement to plot a series of points on a map of Canada along 
with boundaries defining search and rescue (SAR) regions.  I have been 
successful in plotting the map of Canada (Lambert projection) and the points, 
but I have been unable thus far to plot the SAR regions on top of the map.  I'm 
at the point now where I need help to resolve the issue.

To plot the map of Canada, I have used the following line of code:

  map(database= "worldHires","Canada", ylim=c(39,90), xlim=c(-150,-25), 
col=alpha("grey90",0.5), fill=TRUE, projection="lambert", param=c(50,65))

Note that the ylim and xlim limits go wider that the actual coordinates of 
Canada, but that is necessary because the SAR regions go out to sea quite a 
distance.  Also, I need the map to go all the way to the North Pole.

To plot the points, I have used a "dummy" list of points which I will 
eventually replace with my real data.  I convert the points to the lambert 
projection on the fly using the following lines of code:

  lon <- c(-60, -60, -80, -80.1, -90, -105, -140)  #a test longitude vector
  lat <- c(42.5, 42.6, 54.6, 54.4, 75, 68.3, 60)  #a test latitude vector
  coord <- mapproject(lon, lat, proj="lambert", param=c(50,65))  #convert 
points to projected lat/long 
  points(coord, add=TRUE, pch=20, cex=1.2, col=alpha("red", 0.5))  #plot 
converted points

As stated, plotting the SAR regions has not worked thus far.  The best I have 
ever gotten is a square box around the map.  I have data files that list the 
coordinates of the SAR regions, which is a succession of up to 12100 lat & long 
points.  A colleague converted those data files into shapefiles defining 
polygons, with the coordinates already projected to Lambert.  I have tried 
various options to plot the regions, but none have worked.

Using readOGR:

  region <- readOGR(dsn="C:/myRfolder",layer="mySARshapefile")
  plot(region, add=TRUE, xlim=c(-150,-25),ylim=c(39,90), 
col=alpha("lightgreen", 0.6), border=TRUE)

Using read.shp and draw.shp:

  region <- read.shp("C:/myRfolder/mySARshapefile.shp")
  draw.shape(shape=region, type="poly", col="red")

Using readShapePoly:

  region <- readShapePoly("C:/ myRfolder/mySARshapefile.shp")
  plot(halRegion, add=TRUE, xlim=c(-150,-25),ylim=c(39,90), 
col=alpha("lightgreen", 0.6), border=TRUE)

Using readShapeLines after converting the region coordinates to a Lines 
shapefile instead of a Polygon shapefile:

  region <- readShapeLines("C:/myRfolder/mySARshapefile_lines.shp")
  lines(region, col=alpha("black", 0.6))

I have tried playing with spplot, but I haven't quite understood how this one 
works yet (gives me an error message: "Error in 
stack.SpatialPointsDataFrame(as(data, "SpatialPointsDataFrame"),  :   all 
factors should have identical levels")

I would appreciate any help or insight that you could provide to help me get 
those boundaries drawn on-top of the country map.

Thanks

Alain Dubreuil
Ottawa, Canada

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dynamic regex/sub changes to function

2014-09-22 Thread Duncan Murdoch

On 22/09/2014 11:34 AM, Daniel Fuka wrote:

Howdy Duncan,

Thanks for the quick reply!  I must be missing something
simple/obvious. I need to have the "sub()" not return quoted and
escaped characters to "just edit the language expression". In my
problem, there is a function that is supported from a different
package. So I always want to use the supported function as my base...
but a url in the supported function needs to be changed dynamically
for my application, which is easiest using "sub()".

I am trying to do what you correctly indicate I would need to do:
"just edit the language expression that body(fsong) gives you, and
assign it back"
BUT, using sub, I get back a quoted string in my example if I just use sed:

> fsong
function(x){
  song=paste("my name is fuka,",x)
  return(song)
}
# Using "sub()" becomes:
> nsong
function (x)
{
 "song = paste(\"my name is muka,\", x)"
 return(song)
}


You didn't do it right :-).   With fsong as above, the string to edit is 
body(fsong)[[c(2,3,2)]].  (Why c(2,3,2)?  Because that's where the 
string is in the parse tree.  Try looking at variations on 
body(fsong)[[c(2,3,2)]] to figure it out, e.g.

body(fsong)[[c(2,3)]], or body(fsong)[[c(2,3,3)]], etc.)

So this code would work:

orig <- body(fsong)[[c(2,3,2)]]
new <- sub("fuka", "muka", orig)

# Now put it back in nsong:
nsong <- fsong
body(nsong)[[c(2,3,2)]] <- new

But as Bill said, this is a really bad idea.  If you just *think* about 
changing that fsong function, it will break.


Duncan Murdoch



Thanks again for the quick reply and help you are giving me!
dan

On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
 wrote:
> On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>>
>> Howdy,
>>
>> I have searched the lists and can not seem to find a solution to my
>> problem. I need to be able to dynamically modify a string inside a
>> function to build a new function. "sub" replaces with a quoted
>> string... and "parse" of "sub" returns expression... How can I get an
>> unquoted string from a regex to stick into a "body" of a function?
>
>
> It's possible to do what you want, though you don't want to be using
> parse(), you can just edit the language expression that body(fsong) gives
> you, and assign it back.  But that's a messy way to solve your problem.
>
> Why not create a new function containing the new string?  e.g.
>
> makefsong <- function(name = "fuka") {
>   line1 <- paste("my name is", name)
>   function(x) {
> song <- paste(line1, x)
> return(song)
>   }
> }
>
> f1 <- makefsong()
> f1("I live on the second floor")
> f2 <- makefsong("muka")
> f2("I live on the second floor")
>
> Duncan Murdoch
>
>>
>> Thanks for your help!
>> dan
>>
>> # Original Function
>> fsong=function(x){
>>   song=paste("my name is fuka,",x)
>>   return(song)
>> }
>> fsong("I live on the second floor")
>> #
>> # Copy and modify using "sub" returns quoted string with escaped quotes
>> #   internally... as expected.. which can not be evaluated.
>> nsong=fsong
>> body(nsong)[[grep("fuka",body(nsong))]]=
>> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>>
>> nsong("I live on the second floor") # broken
>>
>> #
>> # Copy and modify with "parse" of  "sub",  returns expression.. but
>> without quotes,
>> # o getting closer.
>> #
>> nsong=fsong
>> body(nsong)[[grep("fuka",body(nsong))]]=
>>
>> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>


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


Re: [R] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Unfortunately in this specific case the owner/maintainer is a complete
idiot and a major jerk... he is.. well.. me in this case. But, this is
something I have also been wanting to figure out for some time as it
is often the case when a quick and simple regex based "patch" to a
function can be useful. I do not see why even when I "noquote()" the
assignment into a line of a "body()" it keeps adding the quotes and
associated escapes.



On Mon, Sep 22, 2014 at 12:01 PM, William Dunlap  wrote:
> If you really want to continue to use the function in the supported
> package, then you could try asking the maintainer of the package to
> make the problematic URL an argument to the function.  I thnk that
> changing the function on the fly, no matter how you do it, is likely
> to cause problems when the maintainer changes the function in a future
> release of the package.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Mon, Sep 22, 2014 at 8:34 AM, Daniel Fuka  wrote:
>> Howdy Duncan,
>>
>> Thanks for the quick reply!  I must be missing something
>> simple/obvious. I need to have the "sub()" not return quoted and
>> escaped characters to "just edit the language expression". In my
>> problem, there is a function that is supported from a different
>> package. So I always want to use the supported function as my base...
>> but a url in the supported function needs to be changed dynamically
>> for my application, which is easiest using "sub()".
>>
>> I am trying to do what you correctly indicate I would need to do:
>> "just edit the language expression that body(fsong) gives you, and
>> assign it back"
>> BUT, using sub, I get back a quoted string in my example if I just use sed:
>>
>>> fsong
>> function(x){
>>  song=paste("my name is fuka,",x)
>>  return(song)
>> }
>> # Using "sub()" becomes:
>>> nsong
>> function (x)
>> {
>> "song = paste(\"my name is muka,\", x)"
>> return(song)
>> }
>>
>> Thanks again for the quick reply and help you are giving me!
>> dan
>>
>> On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
>>  wrote:
>>> On 22/09/2014 9:16 AM, Daniel Fuka wrote:

 Howdy,

 I have searched the lists and can not seem to find a solution to my
 problem. I need to be able to dynamically modify a string inside a
 function to build a new function. "sub" replaces with a quoted
 string... and "parse" of "sub" returns expression... How can I get an
 unquoted string from a regex to stick into a "body" of a function?
>>>
>>>
>>> It's possible to do what you want, though you don't want to be using
>>> parse(), you can just edit the language expression that body(fsong) gives
>>> you, and assign it back.  But that's a messy way to solve your problem.
>>>
>>> Why not create a new function containing the new string?  e.g.
>>>
>>> makefsong <- function(name = "fuka") {
>>>   line1 <- paste("my name is", name)
>>>   function(x) {
>>> song <- paste(line1, x)
>>> return(song)
>>>   }
>>> }
>>>
>>> f1 <- makefsong()
>>> f1("I live on the second floor")
>>> f2 <- makefsong("muka")
>>> f2("I live on the second floor")
>>>
>>> Duncan Murdoch
>>>

 Thanks for your help!
 dan

 # Original Function
 fsong=function(x){
   song=paste("my name is fuka,",x)
   return(song)
 }
 fsong("I live on the second floor")
 #
 # Copy and modify using "sub" returns quoted string with escaped quotes
 #   internally... as expected.. which can not be evaluated.
 nsong=fsong
 body(nsong)[[grep("fuka",body(nsong))]]=
 sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))

 nsong("I live on the second floor") # broken

 #
 # Copy and modify with "parse" of  "sub",  returns expression.. but
 without quotes,
 # o getting closer.
 #
 nsong=fsong
 body(nsong)[[grep("fuka",body(nsong))]]=

 parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))

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

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


Re: [R] Dynamic regex/sub changes to function

2014-09-22 Thread William Dunlap
If you really want to continue to use the function in the supported
package, then you could try asking the maintainer of the package to
make the problematic URL an argument to the function.  I thnk that
changing the function on the fly, no matter how you do it, is likely
to cause problems when the maintainer changes the function in a future
release of the package.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Sep 22, 2014 at 8:34 AM, Daniel Fuka  wrote:
> Howdy Duncan,
>
> Thanks for the quick reply!  I must be missing something
> simple/obvious. I need to have the "sub()" not return quoted and
> escaped characters to "just edit the language expression". In my
> problem, there is a function that is supported from a different
> package. So I always want to use the supported function as my base...
> but a url in the supported function needs to be changed dynamically
> for my application, which is easiest using "sub()".
>
> I am trying to do what you correctly indicate I would need to do:
> "just edit the language expression that body(fsong) gives you, and
> assign it back"
> BUT, using sub, I get back a quoted string in my example if I just use sed:
>
>> fsong
> function(x){
>  song=paste("my name is fuka,",x)
>  return(song)
> }
> # Using "sub()" becomes:
>> nsong
> function (x)
> {
> "song = paste(\"my name is muka,\", x)"
> return(song)
> }
>
> Thanks again for the quick reply and help you are giving me!
> dan
>
> On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
>  wrote:
>> On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>>>
>>> Howdy,
>>>
>>> I have searched the lists and can not seem to find a solution to my
>>> problem. I need to be able to dynamically modify a string inside a
>>> function to build a new function. "sub" replaces with a quoted
>>> string... and "parse" of "sub" returns expression... How can I get an
>>> unquoted string from a regex to stick into a "body" of a function?
>>
>>
>> It's possible to do what you want, though you don't want to be using
>> parse(), you can just edit the language expression that body(fsong) gives
>> you, and assign it back.  But that's a messy way to solve your problem.
>>
>> Why not create a new function containing the new string?  e.g.
>>
>> makefsong <- function(name = "fuka") {
>>   line1 <- paste("my name is", name)
>>   function(x) {
>> song <- paste(line1, x)
>> return(song)
>>   }
>> }
>>
>> f1 <- makefsong()
>> f1("I live on the second floor")
>> f2 <- makefsong("muka")
>> f2("I live on the second floor")
>>
>> Duncan Murdoch
>>
>>>
>>> Thanks for your help!
>>> dan
>>>
>>> # Original Function
>>> fsong=function(x){
>>>   song=paste("my name is fuka,",x)
>>>   return(song)
>>> }
>>> fsong("I live on the second floor")
>>> #
>>> # Copy and modify using "sub" returns quoted string with escaped quotes
>>> #   internally... as expected.. which can not be evaluated.
>>> nsong=fsong
>>> body(nsong)[[grep("fuka",body(nsong))]]=
>>> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>>>
>>> nsong("I live on the second floor") # broken
>>>
>>> #
>>> # Copy and modify with "parse" of  "sub",  returns expression.. but
>>> without quotes,
>>> # o getting closer.
>>> #
>>> nsong=fsong
>>> body(nsong)[[grep("fuka",body(nsong))]]=
>>>
>>> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Using read.csv.sql() to read in specific columns

2014-09-22 Thread David Reiner
That seems right to me.

You might want to look into a persistent connection as in Example 10 at
  https://code.google.com/p/sqldf/#Example_10._Persistent_Connections

This will save reloading the DB for every query.

You might even want to create a permanent DB as in Example 9.

This is one of my favorite packages - kudos to Gabor again!
-- David

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Doran, Harold
Sent: Thursday, September 18, 2014 10:38 AM
To: r-help@r-project.org
Subject: [R] Using read.csv.sql() to read in specific columns

I am dealing with data frames that have thousands of columns and hundreds of 
thousands of rows and only need a few specific columns from the data. The data 
take various formats, but normally are tab-delimited.

I have written the following which is working as expected. However, because I�m 
so new at using sqldf(), just looking for some verification from users that 
this is in fact efficient and correct in the R-ish sense of the word and 
generalizable to larger data sets.

Harold

tmp <- data.frame(replicate(50, rnorm(10)))
names(tmp) <- paste('item', 1:50, sep='')
write.table(tmp, 'tmp.txt')
read.csv.sql("tmp.txt", sql = "select item1, item2, item50 from file", sep = ' 
')

[[alternative HTML version deleted]]



This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON’S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Howdy Duncan,

Thanks for the quick reply!  I must be missing something
simple/obvious. I need to have the "sub()" not return quoted and
escaped characters to "just edit the language expression". In my
problem, there is a function that is supported from a different
package. So I always want to use the supported function as my base...
but a url in the supported function needs to be changed dynamically
for my application, which is easiest using "sub()".

I am trying to do what you correctly indicate I would need to do:
"just edit the language expression that body(fsong) gives you, and
assign it back"
BUT, using sub, I get back a quoted string in my example if I just use sed:

> fsong
function(x){
 song=paste("my name is fuka,",x)
 return(song)
}
# Using "sub()" becomes:
> nsong
function (x)
{
"song = paste(\"my name is muka,\", x)"
return(song)
}

Thanks again for the quick reply and help you are giving me!
dan

On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
 wrote:
> On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>>
>> Howdy,
>>
>> I have searched the lists and can not seem to find a solution to my
>> problem. I need to be able to dynamically modify a string inside a
>> function to build a new function. "sub" replaces with a quoted
>> string... and "parse" of "sub" returns expression... How can I get an
>> unquoted string from a regex to stick into a "body" of a function?
>
>
> It's possible to do what you want, though you don't want to be using
> parse(), you can just edit the language expression that body(fsong) gives
> you, and assign it back.  But that's a messy way to solve your problem.
>
> Why not create a new function containing the new string?  e.g.
>
> makefsong <- function(name = "fuka") {
>   line1 <- paste("my name is", name)
>   function(x) {
> song <- paste(line1, x)
> return(song)
>   }
> }
>
> f1 <- makefsong()
> f1("I live on the second floor")
> f2 <- makefsong("muka")
> f2("I live on the second floor")
>
> Duncan Murdoch
>
>>
>> Thanks for your help!
>> dan
>>
>> # Original Function
>> fsong=function(x){
>>   song=paste("my name is fuka,",x)
>>   return(song)
>> }
>> fsong("I live on the second floor")
>> #
>> # Copy and modify using "sub" returns quoted string with escaped quotes
>> #   internally... as expected.. which can not be evaluated.
>> nsong=fsong
>> body(nsong)[[grep("fuka",body(nsong))]]=
>> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>>
>> nsong("I live on the second floor") # broken
>>
>> #
>> # Copy and modify with "parse" of  "sub",  returns expression.. but
>> without quotes,
>> # o getting closer.
>> #
>> nsong=fsong
>> body(nsong)[[grep("fuka",body(nsong))]]=
>>
>> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>

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


Re: [R] Dynamic regex/sub changes to function

2014-09-22 Thread Duncan Murdoch

On 22/09/2014 9:16 AM, Daniel Fuka wrote:

Howdy,

I have searched the lists and can not seem to find a solution to my
problem. I need to be able to dynamically modify a string inside a
function to build a new function. "sub" replaces with a quoted
string... and "parse" of "sub" returns expression... How can I get an
unquoted string from a regex to stick into a "body" of a function?


It's possible to do what you want, though you don't want to be using 
parse(), you can just edit the language expression that body(fsong) 
gives you, and assign it back.  But that's a messy way to solve your 
problem.


Why not create a new function containing the new string?  e.g.

makefsong <- function(name = "fuka") {
  line1 <- paste("my name is", name)
  function(x) {
song <- paste(line1, x)
return(song)
  }
}

f1 <- makefsong()
f1("I live on the second floor")
f2 <- makefsong("muka")
f2("I live on the second floor")

Duncan Murdoch



Thanks for your help!
dan

# Original Function
fsong=function(x){
  song=paste("my name is fuka,",x)
  return(song)
}
fsong("I live on the second floor")
#
# Copy and modify using "sub" returns quoted string with escaped quotes
#   internally... as expected.. which can not be evaluated.
nsong=fsong
body(nsong)[[grep("fuka",body(nsong))]]=
sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))

nsong("I live on the second floor") # broken

#
# Copy and modify with "parse" of  "sub",  returns expression.. but
without quotes,
# o getting closer.
#
nsong=fsong
body(nsong)[[grep("fuka",body(nsong))]]=
parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))

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


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


Re: [R] A new environment within the main function

2014-09-22 Thread billy am
Hi Everyone ,

Thanks for the input.



On Mon, Sep 22, 2014 at 6:48 AM, David Winsemius 
wrote:

>
> On Sep 21, 2014, at 6:06 AM, billy am wrote:
>
>  Hi Everyone ,
>>
>> I am having an issue with the following code and would need kind
>> assistant.
>>
>> For a specific reason , I would need to create a new environment for
>> variables within the function and use them and I am having issue with it
>> on
>> the project I am doing.
>>
>> The issue is that no matter what I do , I am getting the following error
>> on
>>
>> "Error in eval(expr, envir, enclos) : object 'x3' not found"
>>
>> and it is the x3 that is within the groupedData(y~-1 + x3 | g
>>
>> and not in the data.frame
>>
>> fun1 <- function()
>> {
>>  ee <- new.env()
>>  t <- 10
>>  x <- 5
>>  g<- 8
>>
>>  assign("x2",x,envir = as.environment(ee))
>>
>>  x3 <- get("x2" , envir = as.environment(ee))
>>
>>  if(t == 10)
>>  {
>>if(g == 8)
>>  {
>>
>> data.fr <- groupedData(y~-1 + x3 | g,
>>data=data.frame(y,x3,h, dummy))
>>}
>>
>>  }
>>
>> }
>>
>
> I don't get that error;  I get the perfectly understandable error:
>
> > fun1()
> Error in data.frame(y, x3, h, dummy) : object 'y' not found
>
> And if you create a `y` variable I would expect both h and dummy to be
> "not found" as well.
>
>
>
>> Thanks and Regards
>> Billy
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> Alameda, CA, USA
>
>

[[alternative HTML version deleted]]

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


Re: [R] splm package: Spatial weights matrix of the 103 Italian provinces

2014-09-22 Thread Millo Giovanni
Hello. The row numbers correspond to the standard Istat codes for Italian 
provinces, 103-version of course. I.e., 1=Torino, 2=Vercelli, ...
I am sending you a correspondence table by separate email.

Best,
Giovanni

> Hello,
>
> I'm using the spatial weights matrix of the 103 Italian provinces
> "itaww" of the package splm
> example:
>
> library(splm)
>
> data(itaww)
>
> itaww
>
> It is a matrix of 103 rows and 103 columns. Each row (and each column)
> corresponds to an italian province and I would like to know the row's
> names of the matrix (currently defined by numeric ID).
>
> Thank you for your help
>
> Alfonso

Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:12}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Howdy,

I have searched the lists and can not seem to find a solution to my
problem. I need to be able to dynamically modify a string inside a
function to build a new function. "sub" replaces with a quoted
string... and "parse" of "sub" returns expression... How can I get an
unquoted string from a regex to stick into a "body" of a function?

Thanks for your help!
dan

# Original Function
fsong=function(x){
 song=paste("my name is fuka,",x)
 return(song)
}
fsong("I live on the second floor")
#
# Copy and modify using "sub" returns quoted string with escaped quotes
#   internally... as expected.. which can not be evaluated.
nsong=fsong
body(nsong)[[grep("fuka",body(nsong))]]=
   sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))

nsong("I live on the second floor") # broken

#
# Copy and modify with "parse" of  "sub",  returns expression.. but
without quotes,
# o getting closer.
#
nsong=fsong
body(nsong)[[grep("fuka",body(nsong))]]=
   parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))

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


Re: [R] Data frame which includes a non-existent date

2014-09-22 Thread Frank S.
Thanks Richard!
  
[[alternative HTML version deleted]]

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


[R] Course Lisbon: Introduction to Linear mixed effects models, GLMM and MCMC with R

2014-09-22 Thread Highland Statistics Ltd

Apologies for cross-posting


We would like to announce the following statistics course:

Course:   Introduction to Linear mixed effects models,  GLMM and MCMC with R
Location: Lisbon, Portugal
Date:   9 - 13 February, 2015

Course website: http://www.highstat.com/statscourse.htm
Course flyer: http://www.highstat.com/Courses/Flyer2015_2Lisbon_GLMM.pdf


Kind regards,

Alain Zuur


--
Dr. Alain F. Zuur

First author of:
1. Beginner's Guide to GAMM with R (2014).
2. Beginner's Guide to GLM and GLMM with R (2013).
3. Beginner's Guide to GAM with R (2012).
4. Zero Inflated Models and GLMM with R (2012).
5. A Beginner's Guide to R (2009).
6. Mixed effects models and extensions in ecology with R (2009).
7. Analysing Ecological Data (2007).

Highland Statistics Ltd.
9 St Clair Wynd
UK - AB41 6DZ Newburgh
Tel:   0044 1358 788177
Email: highs...@highstat.com
URL:   www.highstat.com

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


Re: [R] splm package: Spatial weights matrix of the 103 Italian provinces

2014-09-22 Thread Rui Barradas

Hello,

I have no knoledge of that package, but you could try

rownames(itaww)
colnames(itaww)

or ask the package maintainer

maintainer("splm")

Hope this helps,

Rui Barradas

Em 22-09-2014 10:16, alfonso.carf...@uniparthenope.it escreveu:

Hello,

I'm using the spatial weights matrix of the 103 Italian provinces
"itaww" of the package splm
example:

library(splm)

data(itaww)

itaww

It is a matrix of 103 rows and 103 columns. Each row (and each column)
corresponds to an italian province and I would like to know the row's
names of the matrix (currently defined by numeric ID).

Thank you for your help

Alfonso





**

IL MERITO DEGLI STUDENTI VIENE RICONOSCIUTO

Il 5 per mille all'Universita' degli Studi di Napoli "Parthenope"
incrementa le borse di studio agli studenti - codice fiscale 80018240632
http://www.uniparthenope.it/index.php/5xmille
Questa informativa e' inserita in automatico dal sistema al fine
esclusivo della realizzazione dei fini istituzionali dell'ente.

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


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


Re: [R] apply block of if statements with menu function

2014-09-22 Thread PIKAL Petr
Hi

> -Original Message-
> From: r...@openmailbox.org [mailto:r...@openmailbox.org]
> Sent: Thursday, September 18, 2014 4:35 PM
> To: PIKAL Petr
> Cc: r-help@r-project.org
> Subject: RE: [R] apply block of if statements with menu function
>
> On 2014-09-16 12:35, PIKAL Petr wrote:
> >
> > So if result of menu is 0 (you did not choose anything) you can
> either
> > stay with 0, then switch does not return anything or add 1 and let
> > evaluate something meaningful specified in second and following
> > positions of switch command.
> >
>
> Thanks for your explanation, which completed my understanding! :) For
> the benefit of other novices, below is an example to demonstrate how
> 'switch' and 'menu' can be used:
>
> switch(menu(c(1,2),graphics=FALSE,title='select something'),
> {(seq(1:10))}, {(rnorm(20))})
>
> However, how to make the option '0 to exit' to appear in the command
> terminal?

Hm. Put it in a title.

switch(menu(c(1,2), title="select item from menu, 0 to exit"), {(seq(1:10))}, 
{(rnorm(20))})

Or modify source code of menu function to suite your needs. Nobody can restrain 
you to change it.

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-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] splm package: Spatial weights matrix of the 103 Italian provinces

2014-09-22 Thread alfonso . carfora

Hello,

I'm using the spatial weights matrix of the 103 Italian provinces  
"itaww" of the package splm

example:

library(splm)

data(itaww)

itaww

It is a matrix of 103 rows and 103 columns. Each row (and each column)  
corresponds to an italian province and I would like to know the row's  
names of the matrix (currently defined by numeric ID).


Thank you for your help

Alfonso





**  
IL MERITO DEGLI STUDENTI VIENE RICONOSCIUTO

Il 5 per mille all'Universita' degli Studi di Napoli "Parthenope" incrementa le 
borse di studio agli studenti - codice fiscale 80018240632
http://www.uniparthenope.it/index.php/5xmille 


Questa informativa e' inserita in automatico dal sistema al fine esclusivo 
della realizzazione dei fini istituzionali dell'ente.

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