Re: [R] example of geom_contour() with function argument

2017-10-09 Thread Big Floppy Dog
Thank you very much! So, it appears that a grid has to be created for the
function to be used in stat_contour(). Thanks again for this example! It is
very helpful (and could be a worthwhile addition to geom_contour's help
example).

Btw, I was also trying to make the contour plot have shaded regions
corresponding to how much mass there is in between wach contour and I seem
to be getting something very ugly (and useless). Any suggestions?

library(mvtnorm)
## you were misusing "require"... only use require if you plan to
library(ggplot2)
## test the return value and fail gracefully when the
package is missing
set.seed( 1234 )
xx <- data.frame( rmvt( 100, df = c( 13, 13 ) ) )
xx2 <- expand.grid( X1 = seq( -5, 5, 0.1 )
   ## all combinations... could  be used to fill a matrix
   , X2 = seq( -5, 5, 0.1 )
   )
## compute density as a function of the grid of points
xx2$d <- dmvt( as.matrix( xx2[,1:2] ) ) #! feels weird not specifying
measures of centrality or spread


ggplot( data = xx
   ,  aes( x = X1
 , y = X2
 )
   ) +
geom_tile(data = xx2, aes(fill = d, alpha = 0.01)) +
geom_contour(data = xx2, aes(x = X1
 , y = X2
 , z = d
   )
 ) +
geom_point() + theme_light() +
theme(legend.position="none")


Also, I had not completely appreciated the different between require() and
library(). I will look into the differences again! Thanks for pointing this
out.

TIAA.
BFD



On Mon, Oct 9, 2017 at 4:01 PM, jdnewmil  wrote:

> library(mvtnorm) # you were misusing "require"... only use require if you
> plan to
> library(ggplot2) # test the return value and fail gracefully when the
> package is missing
> set.seed( 1234 )
> xx <- data.frame( rmvt( 100, df = c( 13, 13 ) ) )
> xx2 <- expand.grid( X1 = seq( -5, 5, 0.1 ) # all combinations... could be
> used to fill a matrix
>   , X2 = seq( -5, 5, 0.1 )
>   )
> # compute density as a function of the grid of points
> xx2$d <- dmvt( as.matrix( xx2[,1:2] ) ) # feels weird not specifying
> measures of centrality or spread
> ggplot( data = xx
>   ,  aes( x = X1
> , y = X2
> )
>   ) +
> geom_point() + # might want this line after the geom_contour
> geom_contour( data = xx2 # may want to consider geom_tile as well
> , mapping = aes( x = X1
>, y = X2
>, z = d
>)
> )
> #' ![](https://i.imgur.com/8ExFYtI.png)
> ## generated/tested with the reprex package to double check that it is
> reproducible
>
>
> On 2017-10-09 09:52, Big Floppy Dog wrote:
>
>> Hi,
>>
>> This is not a HW problem, sadly: I was last in a classroom 30 years ago,
>> and can no longer run off to the instructor :-(
>>
>> I apologize but I cut and paste the wrong snippet earlier and made a typo
>> in doing so, but the result is the same with the more appropriate
>> snippet.
>>
>> require(mvtnorm)
>> require(ggplot2)
>> set.seed(1234)
>> xx <- data.frame(rmvt(100, df = c(13, 13)))
>>
>> v <- ggplot(data = xx, aes(x = X1, y = X2, z = dmvt, df = c(13,13)))
>> v + geom_contour()
>>
>> Don't know how to automatically pick scale for object of type function.
>> Defaulting to continuous.
>> Error: Aesthetics must be either length 1 or the same as the data (100):
>> x,
>> y, z, df
>>
>> I do not understand how to put in a function as an argument to
>> geom_contour() and the examples in the help fileor in the link that Ulrik
>> sent are not very helpful to me. Hence, I was asking for some examples
>> that
>> might be helpful.
>>
>> I guess the answer is to make a second dataset that is regular and make
>> the
>> function estimate that, but how do I combine this?
>>
>> TIA.
>> BFD
>>
>>
>> On Mon, Oct 9, 2017 at 11:32 AM, David Winsemius 
>> wrote:
>>
>>
>>> > On Oct 9, 2017, at 6:03 AM, Big Floppy Dog 
>>> wrote:
>>> >
>>> > Hello Ulrik,
>>> >
>>> > I apologize, but I can not see how to provide a pdf in place of the
>>> density
>>> > function which calculates a KDE (that is, something from the dataset in
>>> the
>>> > example). Can you please point to the specific example that might help?
>>> >
>>> > Here is what I get:
>>> >
>>> > require(mvtnorm)
>>> > require(ggplot2)
>>> > set.seed(1234)
>>> > xx <- data.frame(rmvt(100, df = c(13, 13)))
>>> >
>>> >
>>> > v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df =
>>> c(13,13)))
>>> > v + geom_contour()
>>> >
>>> > Don't know how to automatically pick scale for object of type function.
>>> > Defaulting to continuous.
>>> > Error: Aesthetics must be either length 1 or the same as the data
>>> (5625):
>>> > x, y, z, df
>>> >
>>>
>>> That's not what I get:
>>>
>>> > v <- ggplot(faithfuld, aes(waiting, eruptions, z = 

Re: [R] Regular expression help

2017-10-09 Thread Georges Monette
How about this (I'm showing it as a pipe because it's easier to read 
that way):


library(magrittr)
"f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587" %>%
  strsplit(' ') %>%
  unlist %>%
  sub('^[^/]*/*','',.) %>%
  sub('^[^/]*/*','',.) %>%
  paste(collapse = ' ')

Georges Monette

--
Georges Monette, PhD P.Stat.(SSC) | Associate Professor. Faculty of Science, 
Department of Mathematics & Statistics | North 626 Ross Building | York 
University | 4700 Keele Street, Toronto, ON M3J 1P3 | Telephone: 416-736-5250 | 
Fax: 416-736-5757 | E-Mail: geor...@yorku.ca


On 2017-10-09 11:02 AM, Duncan Murdoch wrote:

I have a file containing "words" like


a

a/b

a/b/c

where there may be multiple words on a line (separated by spaces).  
The a, b, and c strings can contain non-space, non-slash characters. 
I'd like to use gsub() to extract the c strings (which should be empty 
if there are none).


A real example is

"f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"

which I'd like to transform to

" 587 587 587 587"

Another real example is

"f 1067 28680 24462"

which should transform to "   ".

I've tried a few different regexprs, but am unable to find a way to 
say "transform words by deleting everything up to and including the 
2nd slash" when there might be zero, one or two slashes.  Any 
suggestions?


Duncan Murdoch

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

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



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

Re: [ESS] (Aquamacs) Why is text at R prompt read-only, cannot delete? 2

2017-10-09 Thread Ista Zahn
Hi Christian,

1. The subject line appears to be unrelated to the body of your message.
2. Aquamacs configures ESS for you, so why are you trying to load it yourself?
3. Your message itself is very hard to understand. Consider spending
some time with a guide such as
http://www.catb.org/esr/faqs/smart-questions.html. This will help you
ask questions in a way that is more likely to elicit helpful
responses.

Best,
Ista

On Mon, Oct 9, 2017 at 4:53 PM, Christian  wrote:
> Hi,
> Starting Aquamacs 3.3 on MacbookPro MacOS 10.12.6, I get an error
> 
> Warning (initialization): An error occurred while loading
> ‘/Users/hoffmannc/.emacs’:
>
> File error: Cannot open load file, No such file or directory,
> ~/elisp/vendor/ess/lisp/ess-site.el
> ---
>
> My /Users/hoffmannc/.emacs looks like this
> _
> ;; ESS: Emacs Speaks Statistics
> (load "~/elisp/vendor/ess/lisp/ess-site.el")
>
> ---> SORRY: it is currently:
> (load
> "/Applications/Aquamacs3.3.app/Contents/Resources/lisp/aquamacs/edit-modes/ess-mode/lisp/ess/ess-site.elc")
>
> ;; Use shift-enter to split window & launch R (if not running), execute
> highlighted
>
> ... clip
>(local-set-key [C-down] 'comint-next-input)))
>   (require 'ess-site)
> _
> ..and the last line seems to cause the error, as can be seen by C-x C-e.
> How can I correct this error?
>
> Thanks for any hints.
> Christian
> --
> Christian Hoffmann
> Rigiblickstrasse 15b
> CH-8915 Hausen am Albis
> Switzerland
> Telefon +41-(0)44-7640853
>
> __
> ESS-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help

Re: [R] example of geom_contour() with function argument

2017-10-09 Thread jdnewmil
library(mvtnorm) # you were misusing "require"... only use require if 
you plan to
library(ggplot2) # test the return value and fail gracefully when the 
package is missing

set.seed( 1234 )
xx <- data.frame( rmvt( 100, df = c( 13, 13 ) ) )
xx2 <- expand.grid( X1 = seq( -5, 5, 0.1 ) # all combinations... could 
be used to fill a matrix

  , X2 = seq( -5, 5, 0.1 )
  )
# compute density as a function of the grid of points
xx2$d <- dmvt( as.matrix( xx2[,1:2] ) ) # feels weird not specifying 
measures of centrality or spread

ggplot( data = xx
  ,  aes( x = X1
, y = X2
)
  ) +
geom_point() + # might want this line after the geom_contour
geom_contour( data = xx2 # may want to consider geom_tile as well
, mapping = aes( x = X1
   , y = X2
   , z = d
   )
)
#' ![](https://i.imgur.com/8ExFYtI.png)
## generated/tested with the reprex package to double check that it is 
reproducible


On 2017-10-09 09:52, Big Floppy Dog wrote:

Hi,

This is not a HW problem, sadly: I was last in a classroom 30 years 
ago,

and can no longer run off to the instructor :-(

I apologize but I cut and paste the wrong snippet earlier and made a 
typo
in doing so, but the result is the same with the more appropriate  
snippet.


require(mvtnorm)
require(ggplot2)
set.seed(1234)
xx <- data.frame(rmvt(100, df = c(13, 13)))

v <- ggplot(data = xx, aes(x = X1, y = X2, z = dmvt, df = c(13,13)))
v + geom_contour()

Don't know how to automatically pick scale for object of type function.
Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data 
(100): x,

y, z, df

I do not understand how to put in a function as an argument to
geom_contour() and the examples in the help fileor in the link that 
Ulrik
sent are not very helpful to me. Hence, I was asking for some examples 
that

might be helpful.

I guess the answer is to make a second dataset that is regular and make 
the

function estimate that, but how do I combine this?

TIA.
BFD


On Mon, Oct 9, 2017 at 11:32 AM, David Winsemius 


wrote:



> On Oct 9, 2017, at 6:03 AM, Big Floppy Dog 
wrote:
>
> Hello Ulrik,
>
> I apologize, but I can not see how to provide a pdf in place of the
density
> function which calculates a KDE (that is, something from the dataset in
the
> example). Can you please point to the specific example that might help?
>
> Here is what I get:
>
> require(mvtnorm)
> require(ggplot2)
> set.seed(1234)
> xx <- data.frame(rmvt(100, df = c(13, 13)))
>
>
> v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df = c(13,13)))
> v + geom_contour()
>
> Don't know how to automatically pick scale for object of type function.
> Defaulting to continuous.
> Error: Aesthetics must be either length 1 or the same as the data (5625):
> x, y, z, df
>

That's not what I get:

> v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df = c(13,13)))
> v + geom_contour()
Error in FUN(X[[i]], ...) : object 'drmvt' not found
>
> ? faithfuld
> str(faithfuld)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   5625 obs. of  3 
variables:

 $ eruptions: num  1.6 1.65 1.69 1.74 1.79 ...
 $ waiting  : num  43 43 43 43 43 43 43 43 43 43 ...
 $ density  : num  0.00322 0.00384 0.00444 0.00498 0.00542 ...

So you are apparently trying to throw together code and data that you
don't understand. The data you are using is already a density estimate
designed to simply be plotted. It is not the original data. 
Furthermore you

are passing drmvt that is apparently not in either the mvtnorm nor the
ggplot2 packages.

You should determine where that function is and then determine how to 
do a

2d estimate on the original data. I'm guessing this is homework so not
inclined to offer a complete solution.

--
David.


>
> Can you please tell me how to use this here? Or is some other example
more
> appropriate?
>
> TIA,
> BFD
>
>
>
> On Mon, Oct 9, 2017 at 2:22 AM, Ulrik Stervbo 
> wrote:
>
>> Hi BFD,
>>
>> ?geom_contour() *does* have helpful examples. Your Google-foo is weak:
>> Searching for geom_contour brought me: http://ggplot2.tidyverse.
>> org/reference/geom_contour.html as the first result.
>>
>> HTH
>> Ulrik
>>
>> On Mon, 9 Oct 2017 at 08:04 Big Floppy Dog 
wrote:
>>
>>> Can someone please point me to an example with geom_contour() that
uses a
>>> function? The help does not have an example of a function, and also  I
did
>>> not find anything from online searches.
>>>
>>> TIA,
>>> BFD
>>>
>>>
>>> 
>>> ---
>>>
>>> How about geom_contour()?
>>>
>>> Am So., 8. Okt. 2017, 20:52 schrieb Ranjan Maitra :
>>>
 Hi,

 I am no expert on ggplot2 and I do not know the answer to your
>>> 

Re: [R] Help RFM analysis in R (i want a code where i can define my own breaks instead of system defined breaks used in auto_RFM package)

2017-10-09 Thread Jim Lemon
I seriously doubt that you are running the code I sent. What you have
probably done is to run your data, which has a different date format,
without changing the breaks or the date format arguments. As you
haven't provided any example that shows what you are doing, I can't
guess what the problem is.

Jim


On Mon, Oct 9, 2017 at 9:40 PM, Hemant Sain  wrote:
> I'm getting all the rows as NA in  Cscore and almost most of the observation
> in R and F and M are also NA.
> what can be the reason for this. also suggest me the appropriate solution.
>
> On 9 October 2017 at 15:51, Jim Lemon  wrote:
>>
>> Hi Hemant,
>> Here is an example that might answer your questions. Please don't run
>> previous code as it might not work.
>>
>> I define the break values as arguments to the function
>> (rbreaks,fbreaks,mbreaks) If you want the breaks to work, make sure that
>> they cover the range of the input values, otherwise you get NAs.
>>
>> # expects a three (or more) column data frame where
>> # column 1 is customer ID, column 2 is amount of purchase
>> # and column 3 is date of purchase
>> qdrfm<-function(x,rbreaks=3,fbreaks=3,mbreaks=3,date.format="%Y-%m-%d",
>>  weights=c(1,1,1),finish=NA) {
>>
>>  # if no finish date is specified, use current date
>>  if(is.na(finish)) finish<-as.Date(date(), "%a %b %d %H:%M:%S %Y")
>>  x$rscore<-as.numeric(finish-as.Date(x[,3],date.format))
>>  x$rscore<-as.numeric(cut(x$rscore,breaks=rbreaks,labels=FALSE))
>>  custIDs<-unique(x[,1])
>>  ncust<-length(custIDs)
>>  rfmout<-data.frame(custID=custIDs,rscore=rep(0,ncust),
>>   fscore=rep(0,ncust),mscore=rep(0,ncust))
>>  rfmout$rscore<-cut(by(x$rscore,x[,1],min),breaks=rbreaks,labels=FALSE)
>>  rfmout$fscore<-cut(table(x[,1]),breaks=fbreaks,labels=FALSE)
>>  rfmout$mscore<-cut(by(x[,2],x[,1],sum),breaks=mbreaks,labels=FALSE)
>>  rfmout$cscore<-(weights[1]*rfmout$rscore+
>>   weights[2]*rfmout$fscore+
>>   weights[3]*rfmout$mscore)/sum(weights)
>>  return(rfmout[order(rfmout$cscore),])
>> }
>>
>> set.seed(12345)
>> x2<-data.frame(ID=sample(1:50,250,TRUE),
>>  purchase=round(runif(250,5,100),2),
>>  date=paste(rep(2016,250),sample(1:12,250,TRUE),
>>   sample(1:28,250,TRUE),sep="-"))
>>
>> # example 1
>> qdrfm(x2)
>>
>> # example 2
>> qdrfm(x2,rbreaks=c(0,200,400),fbreaks=c(0,5,10),mbreaks=c(0,350,700),
>>  finish=as.Date("2017-01-01"))
>>
>> Jim
>>
>
>
>
> --
> hemantsain.com

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


[ESS] (Aquamacs) Why is text at R prompt read-only, cannot delete? 2

2017-10-09 Thread Christian

Hi,
Starting Aquamacs 3.3 on MacbookPro MacOS 10.12.6, I get an error

Warning (initialization): An error occurred while loading 
‘/Users/hoffmannc/.emacs’:


File error: Cannot open load file, No such file or directory, 
~/elisp/vendor/ess/lisp/ess-site.el

---

My /Users/hoffmannc/.emacs looks like this
_
;; ESS: Emacs Speaks Statistics
(load "~/elisp/vendor/ess/lisp/ess-site.el")

---> SORRY: it is currently:
(load 
"/Applications/Aquamacs3.3.app/Contents/Resources/lisp/aquamacs/edit-modes/ess-mode/lisp/ess/ess-site.elc")


;; Use shift-enter to split window & launch R (if not running), execute 
highlighted


... clip
   (local-set-key [C-down] 'comint-next-input)))
  (require 'ess-site)
_
..and the last line seems to cause the error, as can be seen by C-x C-e.
How can I correct this error?

Thanks for any hints.
Christian
--
Christian Hoffmann
Rigiblickstrasse 15b
CH-8915 Hausen am Albis
Switzerland
Telefon +41-(0)44-7640853

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help

Re: [R] Adjusted survival curves

2017-10-09 Thread RStudio

Adjusted survival curves. (Sample code here:  
https://rpubs.com/daspringate/survival )
Deep gratitude to Moderator/Admin!
At David Winsemius prompt, more elegant working code:Thanks, Ted :)
library(survival)
library(survminer)
df<-read.csv("F:/R/data/edgr-orig.csv", header = TRUE, sep = ";")

df2 <- df
df2[,c('treatment', 'age', 'sex', 'stage')] <- lapply(df2[,c('treatment', 
'age', 'sex', 'stage')], factor)

model <- coxph (Surv(time = start, 
   time2 = stop, 
   event = censor)~ treatment + age + sex + 
stage, data = df2)
treat <- with(df2,
  data.frame(
  treatment = levels(treatment),
  age = rep(levels(age)[1], 2),
  sex = rep(levels(sex)[1], 2),
  stage = rep(levels(stage)[1], 2)))

plot(survfit(model, newdata = treat), 
 las=1,
 xscale = 1.00,
 conf.int = TRUE,
 xlab = "Months after diagnosis",
 ylab = "Proportion survived",
 col = c("red", "green"))
[[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] example of geom_contour() with function argument

2017-10-09 Thread Big Floppy Dog
Hi,

This is not a HW problem, sadly: I was last in a classroom 30 years ago,
and can no longer run off to the instructor :-(

I apologize but I cut and paste the wrong snippet earlier and made a typo
in doing so, but the result is the same with the more appropriate  snippet.

require(mvtnorm)
require(ggplot2)
set.seed(1234)
xx <- data.frame(rmvt(100, df = c(13, 13)))

v <- ggplot(data = xx, aes(x = X1, y = X2, z = dmvt, df = c(13,13)))
v + geom_contour()

Don't know how to automatically pick scale for object of type function.
Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (100): x,
y, z, df

I do not understand how to put in a function as an argument to
geom_contour() and the examples in the help fileor in the link that Ulrik
sent are not very helpful to me. Hence, I was asking for some examples that
might be helpful.

I guess the answer is to make a second dataset that is regular and make the
function estimate that, but how do I combine this?

TIA.
BFD


On Mon, Oct 9, 2017 at 11:32 AM, David Winsemius 
wrote:

>
> > On Oct 9, 2017, at 6:03 AM, Big Floppy Dog 
> wrote:
> >
> > Hello Ulrik,
> >
> > I apologize, but I can not see how to provide a pdf in place of the
> density
> > function which calculates a KDE (that is, something from the dataset in
> the
> > example). Can you please point to the specific example that might help?
> >
> > Here is what I get:
> >
> > require(mvtnorm)
> > require(ggplot2)
> > set.seed(1234)
> > xx <- data.frame(rmvt(100, df = c(13, 13)))
> >
> >
> > v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df = c(13,13)))
> > v + geom_contour()
> >
> > Don't know how to automatically pick scale for object of type function.
> > Defaulting to continuous.
> > Error: Aesthetics must be either length 1 or the same as the data (5625):
> > x, y, z, df
> >
>
> That's not what I get:
>
> > v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df = c(13,13)))
> > v + geom_contour()
> Error in FUN(X[[i]], ...) : object 'drmvt' not found
> >
> > ? faithfuld
> > str(faithfuld)
> Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   5625 obs. of  3 variables:
>  $ eruptions: num  1.6 1.65 1.69 1.74 1.79 ...
>  $ waiting  : num  43 43 43 43 43 43 43 43 43 43 ...
>  $ density  : num  0.00322 0.00384 0.00444 0.00498 0.00542 ...
>
> So you are apparently trying to throw together code and data that you
> don't understand. The data you are using is already a density estimate
> designed to simply be plotted. It is not the original data. Furthermore you
> are passing drmvt that is apparently not in either the mvtnorm nor the
> ggplot2 packages.
>
> You should determine where that function is and then determine how to do a
> 2d estimate on the original data. I'm guessing this is homework so not
> inclined to offer a complete solution.
>
> --
> David.
>
>
> >
> > Can you please tell me how to use this here? Or is some other example
> more
> > appropriate?
> >
> > TIA,
> > BFD
> >
> >
> >
> > On Mon, Oct 9, 2017 at 2:22 AM, Ulrik Stervbo 
> > wrote:
> >
> >> Hi BFD,
> >>
> >> ?geom_contour() *does* have helpful examples. Your Google-foo is weak:
> >> Searching for geom_contour brought me: http://ggplot2.tidyverse.
> >> org/reference/geom_contour.html as the first result.
> >>
> >> HTH
> >> Ulrik
> >>
> >> On Mon, 9 Oct 2017 at 08:04 Big Floppy Dog 
> wrote:
> >>
> >>> Can someone please point me to an example with geom_contour() that
> uses a
> >>> function? The help does not have an example of a function, and also  I
> did
> >>> not find anything from online searches.
> >>>
> >>> TIA,
> >>> BFD
> >>>
> >>>
> >>> 
> >>> ---
> >>>
> >>> How about geom_contour()?
> >>>
> >>> Am So., 8. Okt. 2017, 20:52 schrieb Ranjan Maitra :
> >>>
>  Hi,
> 
>  I am no expert on ggplot2 and I do not know the answer to your
> >>> question. I
>  looked around a bit but could not find an answer right away. But one
>  possibility could be, if a direct approach is not possible, to draw
>  ellipses corresponding to the confidence regions of the multivariate t
>  density and use geom_polygon to draw this successively?
> 
>  I will wait for a couple of days to see if there is a better answer
> >>> posted
>  and then write some code, unless you get to it first.
> 
>  Thanks,
>  Ranjan
> 
> 
>  On Sun, 8 Oct 2017 09:30:30 -0500 Big Floppy Dog <
> >>> bigfloppy...@gmail.com>
>  wrote:
> 
> > Note: I have posted this on SO also but while the question has been
> > upvoted, there has been no answer yet.
> >
> >
> 
> >>> https://stackoverflow.com/questions/46622243/ggplot-
> >>> plot-2d-probability-density-function-on-top-of-points-on-ggplot
> >
> > Apologies for those who have seen it 

Re: [R] load() failed to load .Rdata file in AWS-Ububtu

2017-10-09 Thread Eric Berger
Hi Christofer,
A few comments.
1. Your experiment seems to show (I hope) that the issue may not be a shiny
issue.
 If that is the case you can try to do things in a simpler setting,
such as a (non-shiny) R session,
 say from the shell. i.e. start an interactive R session and enter the
load command within that session.
2. Perhaps your RData file contains objects that need some libraries to be
loaded? (Not sure why that would cause a problem but on your local system
you can look at the variables resulting from the load command and see if
any of them require some libraries to be loaded.)
3. I found this reference which gives some useful information about RData
files that might also be helpful:
https://www.r-bloggers.com/safe-loading-of-rdata-files-2/

Good luck,
Eric


On Mon, Oct 9, 2017 at 8:24 PM, Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:

> Hi Eric, thanks for your further pointer.
>
> I have put a line with load() function just as an illustration of a
> bigger project of mine, which appears failing due to load() function
> issue.
>
> If I comment out that line my shiny app is working correctly locally
> and globally.
>
> otherwise, locally my shiny app is working but not with AWS.
>
> On Mon, Oct 9, 2017 at 12:37 PM, Eric Berger 
> wrote:
> > Hi Christofer,
> > The shiny code you have written does not depend on loading the Dat.RData
> > file.
> > I commented out that line and ran your shiny app on my machine and it
> works
> > fine.
> > What happens if you comment out  (or remove) the line
> >  load("/home/ubuntu/Dat.RData)
> > Does your shiny app still fail? If so, then your problem is quite basic
> with
> > your  AWS setup.
> > Try to work through a simple tutorial/documentation example that shows
> how
> > to get shiny running on AWS and see if following the steps helps you
> > discover the problem.
> >
> > Good luck,
> > Eric
> >
> >
> >
> >
> > On Sun, Oct 8, 2017 at 8:05 PM, Christofer Bogaso
> >  wrote:
> >>
> >> Thanks Eric for your pointer. However I just altered the argument of
> >> load() function a little bit to get that loaded. Below is the line
> >> what I tried.
> >>
> >> ubuntu@ip-172-31-23-148:~$ R
> >>
> >>
> >> R version 3.4.2 (2017-09-28) -- "Short Summer"
> >>
> >> Copyright (C) 2017 The R Foundation for Statistical Computing
> >>
> >> Platform: x86_64-pc-linux-gnu (64-bit)
> >>
> >>
> >> R is free software and comes with ABSOLUTELY NO WARRANTY.
> >>
> >> You are welcome to redistribute it under certain conditions.
> >>
> >> Type 'license()' or 'licence()' for distribution details.
> >>
> >>
> >>   Natural language support but running in an English locale
> >>
> >>
> >> R is a collaborative project with many contributors.
> >>
> >> Type 'contributors()' for more information and
> >>
> >> 'citation()' on how to cite R or R packages in publications.
> >>
> >>
> >> Type 'demo()' for some demos, 'help()' for on-line help, or
> >>
> >> 'help.start()' for an HTML browser interface to help.
> >>
> >> Type 'q()' to quit R.
> >>
> >>
> >> During startup - Warning message:
> >>
> >> Setting LC_CTYPE failed, using "C"
> >>
> >> > load("/home/ubuntu/Dat.RData")
> >>
> >> >
> >>
> >> However it still failing when I try that within my shiny app in AWS.
> >>
> >> Below are my ui.R and server.R files respectively.
> >>
> >> library(shiny)
> >>
> >> # Define UI for miles per gallon application
> >> fluidPage(
> >>   fluidRow(
> >> column(12,
> >>   tableOutput('table')
> >> )
> >>   )
> >> )
> >>
> >> server.R :
> >>
> >> library(shiny)
> >>
> >> load("/home/ubuntu/Dat.RData")
> >>
> >> shinyServer(function(input, output) {
> >> output$table = renderTable(head(data.frame(1:20, 1:20), 20))
> >> })
> >>
> >> with above setup when I deploy my shiny app I get below error :
> >>
> >> 18.221.184.94:3838 says
> >> The application unexpectedly exited
> >> Diagnostic information has been dumped to the JavaScript error console.
> >>
> >> appreciate any help to get rid of this error.
> >>
> >> Thanks for your time.
> >>
> >> On Sun, Oct 8, 2017 at 12:39 AM, Eric Berger 
> >> wrote:
> >> > Hi Christofer,
> >> > The directory /srv/shiny-server would normally be owned by the root
> >> > user.
> >> > Your options would seem to be to either (1) bring up the R session as
> >> > root
> >> > (dangerous)
> >> > or (2) try copying the file to your local directory and read it from
> >> > there
> >> > (if allowed).
> >> > e.g. from the Unix shell:
> >> >> cd ~   (i.e. cd to your home directory)
> >> >> cp /srv/shiny-server/Dat.Rdata .   (Note the '.' at the end. This may
> >> >> not
> >> >> work - if not then you can try the following
> >> >> sudo cp /srv/shiny-server/Dat.Rdata . (if you have sudo privileges -
> >> >> only
> >> >> do this if the former command did not work)
> >> >> chmod 777 Dat.Rdata  (a bit of overkill - again preface by sudo if it
> >> >> does
> >> >> not work without 

Re: [R] load() failed to load .Rdata file in AWS-Ububtu

2017-10-09 Thread Christofer Bogaso
Hi Eric, thanks for your further pointer.

I have put a line with load() function just as an illustration of a
bigger project of mine, which appears failing due to load() function
issue.

If I comment out that line my shiny app is working correctly locally
and globally.

otherwise, locally my shiny app is working but not with AWS.

On Mon, Oct 9, 2017 at 12:37 PM, Eric Berger  wrote:
> Hi Christofer,
> The shiny code you have written does not depend on loading the Dat.RData
> file.
> I commented out that line and ran your shiny app on my machine and it works
> fine.
> What happens if you comment out  (or remove) the line
>  load("/home/ubuntu/Dat.RData)
> Does your shiny app still fail? If so, then your problem is quite basic with
> your  AWS setup.
> Try to work through a simple tutorial/documentation example that shows how
> to get shiny running on AWS and see if following the steps helps you
> discover the problem.
>
> Good luck,
> Eric
>
>
>
>
> On Sun, Oct 8, 2017 at 8:05 PM, Christofer Bogaso
>  wrote:
>>
>> Thanks Eric for your pointer. However I just altered the argument of
>> load() function a little bit to get that loaded. Below is the line
>> what I tried.
>>
>> ubuntu@ip-172-31-23-148:~$ R
>>
>>
>> R version 3.4.2 (2017-09-28) -- "Short Summer"
>>
>> Copyright (C) 2017 The R Foundation for Statistical Computing
>>
>> Platform: x86_64-pc-linux-gnu (64-bit)
>>
>>
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>>
>> You are welcome to redistribute it under certain conditions.
>>
>> Type 'license()' or 'licence()' for distribution details.
>>
>>
>>   Natural language support but running in an English locale
>>
>>
>> R is a collaborative project with many contributors.
>>
>> Type 'contributors()' for more information and
>>
>> 'citation()' on how to cite R or R packages in publications.
>>
>>
>> Type 'demo()' for some demos, 'help()' for on-line help, or
>>
>> 'help.start()' for an HTML browser interface to help.
>>
>> Type 'q()' to quit R.
>>
>>
>> During startup - Warning message:
>>
>> Setting LC_CTYPE failed, using "C"
>>
>> > load("/home/ubuntu/Dat.RData")
>>
>> >
>>
>> However it still failing when I try that within my shiny app in AWS.
>>
>> Below are my ui.R and server.R files respectively.
>>
>> library(shiny)
>>
>> # Define UI for miles per gallon application
>> fluidPage(
>>   fluidRow(
>> column(12,
>>   tableOutput('table')
>> )
>>   )
>> )
>>
>> server.R :
>>
>> library(shiny)
>>
>> load("/home/ubuntu/Dat.RData")
>>
>> shinyServer(function(input, output) {
>> output$table = renderTable(head(data.frame(1:20, 1:20), 20))
>> })
>>
>> with above setup when I deploy my shiny app I get below error :
>>
>> 18.221.184.94:3838 says
>> The application unexpectedly exited
>> Diagnostic information has been dumped to the JavaScript error console.
>>
>> appreciate any help to get rid of this error.
>>
>> Thanks for your time.
>>
>> On Sun, Oct 8, 2017 at 12:39 AM, Eric Berger 
>> wrote:
>> > Hi Christofer,
>> > The directory /srv/shiny-server would normally be owned by the root
>> > user.
>> > Your options would seem to be to either (1) bring up the R session as
>> > root
>> > (dangerous)
>> > or (2) try copying the file to your local directory and read it from
>> > there
>> > (if allowed).
>> > e.g. from the Unix shell:
>> >> cd ~   (i.e. cd to your home directory)
>> >> cp /srv/shiny-server/Dat.Rdata .   (Note the '.' at the end. This may
>> >> not
>> >> work - if not then you can try the following
>> >> sudo cp /srv/shiny-server/Dat.Rdata . (if you have sudo privileges -
>> >> only
>> >> do this if the former command did not work)
>> >> chmod 777 Dat.Rdata  (a bit of overkill - again preface by sudo if it
>> >> does
>> >> not work without it)
>> >
>> > Then in your R session you can do the load from the file in this
>> > location.
>> > R>  load("~/Dat.Rdata")
>> >
>> > HTH,
>> > Eric
>> >
>> >
>> > On Sat, Oct 7, 2017 at 8:54 PM, Christofer Bogaso
>> >  wrote:
>> >>
>> >> Hi again,
>> >>
>> >> I hope this is the right place to post my question on running R within
>> >> Ubuntu, however if not, any pointer on right distribution list will be
>> >> helpful.
>> >>
>> >> I am currently using R in Ubuntu which is hosted in Amazon - AWS.
>> >>
>> >> I have a .Rdata file in AWS which I am trying to load in R. Used
>> >> following code, however, fails to load showing some permission issue.
>> >> However that same .Rdata file is getting loaded perfectly when I try
>> >> in my regular iOS.
>> >>
>> >> Below is my code and corresponding result :
>> >>
>> >> ubuntu@ip-172-31-23-148:~$ R
>> >>
>> >>
>> >> R version 3.4.2 (2017-09-28) -- "Short Summer"
>> >>
>> >> Copyright (C) 2017 The R Foundation for Statistical Computing
>> >>
>> >> Platform: x86_64-pc-linux-gnu (64-bit)
>> >>
>> >>
>> >> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> >>

Re: [ESS] (Aquamacs) Why is text at R prompt read-only, cannot delete?

2017-10-09 Thread Vitalie Spinu


>> On Mon, Oct 09 2017 17:57, Christian wrote:

> No such file or directory,
> ~/elisp/vendor/ess/lisp/ess-site.el

Isn't the above clear enough? Fixing your path should do it.

  Vitalie

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] example of geom_contour() with function argument

2017-10-09 Thread David Winsemius

> On Oct 9, 2017, at 6:03 AM, Big Floppy Dog  wrote:
> 
> Hello Ulrik,
> 
> I apologize, but I can not see how to provide a pdf in place of the density
> function which calculates a KDE (that is, something from the dataset in the
> example). Can you please point to the specific example that might help?
> 
> Here is what I get:
> 
> require(mvtnorm)
> require(ggplot2)
> set.seed(1234)
> xx <- data.frame(rmvt(100, df = c(13, 13)))
> 
> 
> v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df = c(13,13)))
> v + geom_contour()
> 
> Don't know how to automatically pick scale for object of type function.
> Defaulting to continuous.
> Error: Aesthetics must be either length 1 or the same as the data (5625):
> x, y, z, df
> 

That's not what I get:

> v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df = c(13,13)))
> v + geom_contour()
Error in FUN(X[[i]], ...) : object 'drmvt' not found
> 
> ? faithfuld
> str(faithfuld)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   5625 obs. of  3 variables:
 $ eruptions: num  1.6 1.65 1.69 1.74 1.79 ...
 $ waiting  : num  43 43 43 43 43 43 43 43 43 43 ...
 $ density  : num  0.00322 0.00384 0.00444 0.00498 0.00542 ...

So you are apparently trying to throw together code and data that you don't 
understand. The data you are using is already a density estimate designed to 
simply be plotted. It is not the original data. Furthermore you are passing 
drmvt that is apparently not in either the mvtnorm nor the ggplot2 packages.

You should determine where that function is and then determine how to do a 2d 
estimate on the original data. I'm guessing this is homework so not inclined to 
offer a complete solution.

-- 
David.


> 
> Can you please tell me how to use this here? Or is some other example more
> appropriate?
> 
> TIA,
> BFD
> 
> 
> 
> On Mon, Oct 9, 2017 at 2:22 AM, Ulrik Stervbo 
> wrote:
> 
>> Hi BFD,
>> 
>> ?geom_contour() *does* have helpful examples. Your Google-foo is weak:
>> Searching for geom_contour brought me: http://ggplot2.tidyverse.
>> org/reference/geom_contour.html as the first result.
>> 
>> HTH
>> Ulrik
>> 
>> On Mon, 9 Oct 2017 at 08:04 Big Floppy Dog  wrote:
>> 
>>> Can someone please point me to an example with geom_contour() that uses a
>>> function? The help does not have an example of a function, and also  I did
>>> not find anything from online searches.
>>> 
>>> TIA,
>>> BFD
>>> 
>>> 
>>> 
>>> ---
>>> 
>>> How about geom_contour()?
>>> 
>>> Am So., 8. Okt. 2017, 20:52 schrieb Ranjan Maitra :
>>> 
 Hi,
 
 I am no expert on ggplot2 and I do not know the answer to your
>>> question. I
 looked around a bit but could not find an answer right away. But one
 possibility could be, if a direct approach is not possible, to draw
 ellipses corresponding to the confidence regions of the multivariate t
 density and use geom_polygon to draw this successively?
 
 I will wait for a couple of days to see if there is a better answer
>>> posted
 and then write some code, unless you get to it first.
 
 Thanks,
 Ranjan
 
 
 On Sun, 8 Oct 2017 09:30:30 -0500 Big Floppy Dog <
>>> bigfloppy...@gmail.com>
 wrote:
 
> Note: I have posted this on SO also but while the question has been
> upvoted, there has been no answer yet.
> 
> 
 
>>> https://stackoverflow.com/questions/46622243/ggplot-
>>> plot-2d-probability-density-function-on-top-of-points-on-ggplot
> 
> Apologies for those who have seen it there also but I thought that
>>> this
> list of experts may have someone who knows the answer.
> 
> I have the following example code:
> 
> 
> 
> require(mvtnorm)
> require(ggplot2)
> set.seed(1234)
> xx <- data.frame(rmvt(100, df = c(13, 13)))
> ggplot(data = xx,  aes(x = X1, y= X2)) + geom_point() +
>>> geom_density2d()
> 
> 
> 
> It yields a scatterplot of X2 against X1 and a KDE contour plot of the
> density (as it should).
> 
> My question is: is it possible to change the contour plot to display
> the contours
> 
> of a two-dimensional density function (say dmvt), using ggplot2?
> 
> The remaining figures in my document are in ggplot2 and therefore I
> am looking for a ggplot2 solution.
> 
> Thanks in advance!
> 
> BFD
> 
>  [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
 
 
>>> 
>>>[[alternative HTML version 

Re: [R] Regular expression help

2017-10-09 Thread Duncan Murdoch

On 09/10/2017 12:06 PM, William Dunlap wrote:
"(^| +)([^/ ]*/?){0,2}", with the first "*" replaced by "+" would be a 
bit better.


Thanks!  I think I actually need the *, because theoretically the b part 
of the word could be empty, i.e. "a//c" would be legal and should become 
"c".


Duncan Murdoch



Bill Dunlap
TIBCO Software
wdunlap tibco.com 

On Mon, Oct 9, 2017 at 8:50 AM, William Dunlap > wrote:


 > x <- "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
 > gsub("(^| *)([^/ ]*/?){0,2}", "\\1", x)
[1] " 587 587 587 587"
 > y <- "aa aa/ aa/bb aa/bb/ aa/bb/cc aa/bb/cc/ aa/bb/cc/dd
aa/bb/cc/dd/"
 > gsub("(^| *)([^/ ]*/?){0,2}", "\\1", y)
[1] "    cc cc/ cc/dd cc/dd/"


Bill Dunlap
TIBCO Software
wdunlap tibco.com 

On Mon, Oct 9, 2017 at 8:02 AM, Duncan Murdoch
> wrote:

I have a file containing "words" like


a

a/b

a/b/c

where there may be multiple words on a line (separated by
spaces).  The a, b, and c strings can contain non-space,
non-slash characters. I'd like to use gsub() to extract the c
strings (which should be empty if there are none).

A real example is

"f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"

which I'd like to transform to

" 587 587 587 587"

Another real example is

"f 1067 28680 24462"

which should transform to "   ".

I've tried a few different regexprs, but am unable to find a way
to say "transform words by deleting everything up to and
including the 2nd slash" when there might be zero, one or two
slashes.  Any suggestions?

Duncan Murdoch

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

PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html

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





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

Re: [R-es] Incluir símbolo matemático en data frame

2017-10-09 Thread Manuel Spínola
Siguiendo la recomendación de Jesús encontré la solución:

columna1 <- c("a", "b", "c")
columna2 <- c("\u2265 0.3", 0.5, 0.8)
columna3 <- c("\u2265 0.3", 0.6, 0.9)

cuadro <- data.frame(columna1, columna2, columna3)

kable(cuadro)

El 9 de octubre de 2017, 9:26, Jesús Para Fernández <
j.para.fernan...@hotmail.com> escribió:

> Prueba con un paste0, que es para "pegar" strings.
>
> paste0("cadena1","cadena2",variable)
>
>
> --
> *De:* Manuel Spínola 
> *Enviado:* lunes, 9 de octubre de 2017 17:22
> *Para:* Jesús Para Fernández
> *Cc:* Carlos Ortega; R
>
> *Asunto:* Re: [R-es] Incluir símbolo matemático en data frame
>
> Muchas gracias Jesús,
>
> Por lo que veo hay que hacer una columna diferente para los símbolos, tal
> como sugiere Carlos.  No hay forma de ubicarlos en el mismo string,
> acompañando al número?
>
> Manuel
>
> El 9 de octubre de 2017, 8:52, Jesús Para Fernández <
> j.para.fernan...@hotmail.com> escribió:
>
>> Con
>>
>> print("\u2265")
>>
>>
>> lo consigues.
>>
>> Aqui tienes toda la lista:
>> https://www.w3schools.com/charsets/ref_utf_math.asp
>> HTML Unicode UTF-8 - W3Schools
>> 
>> Well organized and easy to understand Web building tutorials with lots of
>> examples of how to use HTML, CSS, JavaScript, SQL, PHP, and XML.
>> www.w3schools.com
>>
>>
>>
>> --
>> *De:* R-help-es  en nombre de Manuel
>> Spínola 
>> *Enviado:* lunes, 9 de octubre de 2017 14:59
>> *Para:* Carlos Ortega
>> *Cc:* R
>> *Asunto:* Re: [R-es] Incluir símbolo matemático en data frame
>>
>> Muchas gracias Carlos.
>>
>> Pero eso haría que el signo se muestre tal como se deba mostrar , es
>> decir:
>> ≤
>>
>> Manuel
>>
>> El 9 de octubre de 2017, 1:46, Carlos Ortega 
>> escribió:
>>
>> > Puedes incluir estos signos en una columna nueva antes de cada una de
>> las
>> > columnas numéricas.
>> > Que el data.frame tuviera esta pinta...
>> >
>> > Signo_1, Col_1, Signo_2, Col_2, Signo_3, Col_3
>> > "<=", 0.3, ">=", 0.5, "==", 0.8
>> > ">=", 0.8, "<", 0.9, ">", 1
>> > 
>> >
>> > Gracias,
>> > Carlos.
>> >
>> > El 9 de octubre de 2017, 4:02, Manuel Spínola 
>> > escribió:
>> >
>> >> Estimados miembros de la lista,
>> >>
>> >> Cómo se puede incluir. por ejemplo, el símbolo de menor o igual en un
>> >> data.frame para luego hacer un cuadro (table con kable in rmarkadown)?
>> >>
>> >> columna1 <- c("a", "b", "c")
>> >> columna2 <- c(<= 0.3, 0.5, 0.8)
>> >> columna3 <- c(>=0.5, 0.6, 0.9)
>> >>
>> >> cuadro <- data.frame(columna1, columna2, columna3)
>> >>
>> >> kable(cuadro)
>> >>
>> >> Manuel
>> >>
>> >> --
>> >> *Manuel Spínola, Ph.D.*
>> >> Instituto Internacional en Conservación y Manejo de Vida Silvestre
>> >> Universidad Nacional
>> >> Apartado 1350-3000
>> >> Heredia
>> >> COSTA RICA
>> >> mspin...@una.cr 
>> >> mspinol...@gmail.com
>> >> Teléfono: (506) 8706 - 4662
>> >> Personal website: Lobito de río > >> /lobitoderio/>
>> >> Institutional website: ICOMVIS 
>> >>
>> >> [[alternative HTML version deleted]]
>> >>
>> >> ___
>> >> R-help-es mailing list
>> >> R-help-es@r-project.org
>> >> https://stat.ethz.ch/mailman/listinfo/r-help-es
>> >>
>> >
>> >
>> >
>> > --
>> > Saludos,
>> > Carlos Ortega
>> > www.qualityexcellence.es
>> >
>>
>>
>>
>> --
>> *Manuel Spínola, Ph.D.*
>> Instituto Internacional en Conservación y Manejo de Vida Silvestre
>> Universidad Nacional
>> Apartado 1350-3000
>> Heredia
>> COSTA RICA
>> mspin...@una.cr 
>> mspinol...@gmail.com
>> Teléfono: (506) 8706 - 4662
>> Personal website: Lobito de río > /lobitoderio/>
>> Institutional website: ICOMVIS 
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
>
> --
> *Manuel Spínola, Ph.D.*
> Instituto Internacional en Conservación y Manejo de Vida Silvestre
> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> mspin...@una.cr 
> mspinol...@gmail.com
> Teléfono: (506) 8706 - 4662
> Personal website: Lobito de río
> 
> Institutional website: ICOMVIS 
>



-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative 

Re: [R] Regular expression help

2017-10-09 Thread Duncan Murdoch

On 09/10/2017 11:23 AM, Ulrik Stervbo wrote:

Hi Duncan,

why not split on / and take the correct elements? It is not as elegant 
as regex but could do the trick.


Thanks for the suggestion.  There are likely many thousands of lines of 
data like the two real examples (which had about 5000 and 6 lines 
respectively), so I was thinking that would be too slow, as it would 
involve nested strsplit() calls.  But in fact, it's not so bad, so I 
might go with it.  Here's a stab at it:


lines <- http://sci.esa.int/science-e/www/object/doc.cfm?fobjectid=54726>


l2 <- strsplit(lines, " ")
l3 <- lapply(l2, function(x) {
y <- strsplit(x, "/")
sapply(y, function(z) if (length(z) == 3) z[3] else "")
  })

Duncan



Best,
Ulrik

On Mon, 9 Oct 2017 at 17:03 Duncan Murdoch > wrote:


I have a file containing "words" like


a

a/b

a/b/c

where there may be multiple words on a line (separated by spaces).  The
a, b, and c strings can contain non-space, non-slash characters. I'd
like to use gsub() to extract the c strings (which should be empty if
there are none).

A real example is

"f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"

which I'd like to transform to

" 587 587 587 587"

Another real example is

"f 1067 28680 24462"

which should transform to "   ".

I've tried a few different regexprs, but am unable to find a way to say
"transform words by deleting everything up to and including the 2nd
slash" when there might be zero, one or two slashes.  Any suggestions?

Duncan Murdoch

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



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

Re: [R] Regular expression help

2017-10-09 Thread William Dunlap via R-help
"(^| +)([^/ ]*/?){0,2}", with the first "*" replaced by "+" would be a bit
better.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Oct 9, 2017 at 8:50 AM, William Dunlap  wrote:

> > x <- "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
> > gsub("(^| *)([^/ ]*/?){0,2}", "\\1", x)
> [1] " 587 587 587 587"
> > y <- "aa aa/ aa/bb aa/bb/ aa/bb/cc aa/bb/cc/ aa/bb/cc/dd aa/bb/cc/dd/"
> > gsub("(^| *)([^/ ]*/?){0,2}", "\\1", y)
> [1] "cc cc/ cc/dd cc/dd/"
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Mon, Oct 9, 2017 at 8:02 AM, Duncan Murdoch 
> wrote:
>
>> I have a file containing "words" like
>>
>>
>> a
>>
>> a/b
>>
>> a/b/c
>>
>> where there may be multiple words on a line (separated by spaces).  The
>> a, b, and c strings can contain non-space, non-slash characters. I'd like
>> to use gsub() to extract the c strings (which should be empty if there are
>> none).
>>
>> A real example is
>>
>> "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
>>
>> which I'd like to transform to
>>
>> " 587 587 587 587"
>>
>> Another real example is
>>
>> "f 1067 28680 24462"
>>
>> which should transform to "   ".
>>
>> I've tried a few different regexprs, but am unable to find a way to say
>> "transform words by deleting everything up to and including the 2nd slash"
>> when there might be zero, one or two slashes.  Any suggestions?
>>
>> Duncan Murdoch
>>
>> __
>> 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/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>

[[alternative HTML version deleted]]

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


[ESS] (Aquamacs) Why is text at R prompt read-only, cannot delete?

2017-10-09 Thread Christian

Hi,
Starting Aquamacs 3.3 on MacbookPro MacOS 10.12.6, I get an error

Warning (initialization): An error occurred while loading 
‘/Users/hoffmannc/.emacs’:


File error: Cannot open load file, No such file or directory, 
~/elisp/vendor/ess/lisp/ess-site.el

---

My /Users/hoffmannc/.emacs looks like this
_
;; ESS: Emacs Speaks Statistics
(load "~/elisp/vendor/ess/lisp/ess-site.el")

;; Use shift-enter to split window & launch R (if not running), execute 
highlighted

;; region (if R running & area highlighted), or execute current line
;; (and move to next line, skipping comments). Nice.
;; See http://www.emacswiki.org/emacs/EmacsSpeaksStatistics,
;; FelipeCsaszar. Adapted to split vertically instead of
;; horizontally.

(setq ess-ask-for-ess-directory nil)
  (setq ess-local-process-name "R")
  (setq ansi-color-for-comint-mode 'filter)
  (setq comint-prompt-read-only t)
  (setq comint-scroll-to-bottom-on-input t)
  (setq comint-scroll-to-bottom-on-output t)
  (setq comint-move-point-for-output t)
  (defun my-ess-start-R ()
(interactive)
(if (not (member "*R*" (mapcar (function buffer-name) (buffer-list
  (progn
(delete-other-windows)
(setq w1 (selected-window))
(setq w1name (buffer-name))
(setq w2 (split-window w1 nil t))
(R)
(set-window-buffer w2 "*R*")
(set-window-buffer w1 w1name
  (defun my-ess-eval ()
(interactive)
(my-ess-start-R)
(if (and transient-mark-mode mark-active)
(call-interactively 'ess-eval-region)
  (call-interactively 'ess-eval-line-and-step)))
  (add-hook 'ess-mode-hook
'(lambda()
   (local-set-key [(shift return)] 'my-ess-eval)))
  (add-hook 'inferior-ess-mode-hook
'(lambda()
   (local-set-key [C-up] 
'comint-previous-matching-input-from-input)

   (local-set-key [C-down] 'comint-next-input)))
  (require 'ess-site)
_
..and the last line seems to cause the error, as can be seen by C-x C-e.
How can I correct this error?

Thanks for any hints.
Christian
--
Christian Hoffmann
Rigiblickstrasse 15b
CH-8915 Hausen am Albis
Switzerland
Telefon +41-(0)44-7640853

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help

Re: [R] Regular expression help

2017-10-09 Thread William Dunlap via R-help
> x <- "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
> gsub("(^| *)([^/ ]*/?){0,2}", "\\1", x)
[1] " 587 587 587 587"
> y <- "aa aa/ aa/bb aa/bb/ aa/bb/cc aa/bb/cc/ aa/bb/cc/dd aa/bb/cc/dd/"
> gsub("(^| *)([^/ ]*/?){0,2}", "\\1", y)
[1] "cc cc/ cc/dd cc/dd/"


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Oct 9, 2017 at 8:02 AM, Duncan Murdoch 
wrote:

> I have a file containing "words" like
>
>
> a
>
> a/b
>
> a/b/c
>
> where there may be multiple words on a line (separated by spaces).  The a,
> b, and c strings can contain non-space, non-slash characters. I'd like to
> use gsub() to extract the c strings (which should be empty if there are
> none).
>
> A real example is
>
> "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
>
> which I'd like to transform to
>
> " 587 587 587 587"
>
> Another real example is
>
> "f 1067 28680 24462"
>
> which should transform to "   ".
>
> I've tried a few different regexprs, but am unable to find a way to say
> "transform words by deleting everything up to and including the 2nd slash"
> when there might be zero, one or two slashes.  Any suggestions?
>
> Duncan Murdoch
>
> __
> 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/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


[R] [R-pkgs] nofrills: Low-Cost Anonymous Functions

2017-10-09 Thread Eugene Ha
Dear R Users,

nofrills (0.2.0) has been published on CRAN:
https://cran.r-project.org/package=nofrills

This lightweight package provides `fn()`, a compact variation of the
usual syntax of function declaration, in order to support
tidyverse-style quasiquotation of a function’s arguments and body.

Aside from enabling a shorter but fully general syntax for function
declarations, the main benefit of `fn()` is its ability to create
_pure_ functions via quasiquotation, which is tricky to guarantee in
base R, due to the mutability of bindings in a function’s lexical scope.

To learn more, see the landing page of the source repository:
https://github.com/egnha/nofrills

Bug reports and other feedback are welcome at the issues page on GitHub:
https://github.com/egnha/nofrills/issues

Eugene Ha
___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
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] example of geom_contour() with function argument

2017-10-09 Thread Big Floppy Dog
Hello Ulrik,

I apologize, but I can not see how to provide a pdf in place of the density
function which calculates a KDE (that is, something from the dataset in the
example). Can you please point to the specific example that might help?

Here is what I get:

require(mvtnorm)
require(ggplot2)
set.seed(1234)
xx <- data.frame(rmvt(100, df = c(13, 13)))


v <- ggplot(faithfuld, aes(waiting, eruptions, z = drmvt, df = c(13,13)))
v + geom_contour()

Don't know how to automatically pick scale for object of type function.
Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (5625):
x, y, z, df


Can you please tell me how to use this here? Or is some other example more
appropriate?

TIA,
BFD



On Mon, Oct 9, 2017 at 2:22 AM, Ulrik Stervbo 
wrote:

> Hi BFD,
>
> ?geom_contour() *does* have helpful examples. Your Google-foo is weak:
> Searching for geom_contour brought me: http://ggplot2.tidyverse.
> org/reference/geom_contour.html as the first result.
>
> HTH
> Ulrik
>
> On Mon, 9 Oct 2017 at 08:04 Big Floppy Dog  wrote:
>
>> Can someone please point me to an example with geom_contour() that uses a
>> function? The help does not have an example of a function, and also  I did
>> not find anything from online searches.
>>
>> TIA,
>> BFD
>>
>>
>> 
>> ---
>>
>> How about geom_contour()?
>>
>> Am So., 8. Okt. 2017, 20:52 schrieb Ranjan Maitra :
>>
>> > Hi,
>> >
>> > I am no expert on ggplot2 and I do not know the answer to your
>> question. I
>> > looked around a bit but could not find an answer right away. But one
>> > possibility could be, if a direct approach is not possible, to draw
>> > ellipses corresponding to the confidence regions of the multivariate t
>> > density and use geom_polygon to draw this successively?
>> >
>> > I will wait for a couple of days to see if there is a better answer
>> posted
>> > and then write some code, unless you get to it first.
>> >
>> > Thanks,
>> > Ranjan
>> >
>> >
>> > On Sun, 8 Oct 2017 09:30:30 -0500 Big Floppy Dog <
>> bigfloppy...@gmail.com>
>> > wrote:
>> >
>> > > Note: I have posted this on SO also but while the question has been
>> > > upvoted, there has been no answer yet.
>> > >
>> > >
>> >
>> https://stackoverflow.com/questions/46622243/ggplot-
>> plot-2d-probability-density-function-on-top-of-points-on-ggplot
>> > >
>> > > Apologies for those who have seen it there also but I thought that
>> this
>> > > list of experts may have someone who knows the answer.
>> > >
>> > > I have the following example code:
>> > >
>> > >
>> > >
>> > > require(mvtnorm)
>> > > require(ggplot2)
>> > > set.seed(1234)
>> > > xx <- data.frame(rmvt(100, df = c(13, 13)))
>> > > ggplot(data = xx,  aes(x = X1, y= X2)) + geom_point() +
>> geom_density2d()
>> > >
>> > >
>> > >
>> > > It yields a scatterplot of X2 against X1 and a KDE contour plot of the
>> > > density (as it should).
>> > >
>> > > My question is: is it possible to change the contour plot to display
>> > > the contours
>> > >
>> > > of a two-dimensional density function (say dmvt), using ggplot2?
>> > >
>> > > The remaining figures in my document are in ggplot2 and therefore I
>> > > am looking for a ggplot2 solution.
>> > >
>> > > Thanks in advance!
>> > >
>> > > BFD
>> > >
>> > >   [[alternative HTML version deleted]]
>> > >
>> > > __
>> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > > and provide commented, minimal, self-contained, reproducible code.
>> > >
>> >
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[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] Help RFM analysis in R (i want a code where i can define my own breaks instead of system defined breaks used in auto_RFM package)

2017-10-09 Thread Hemant Sain
I'm getting all the rows as NA in  Cscore and almost most of the
observation in R and F and M are also NA.
what can be the reason for this. also suggest me the appropriate solution.

On 9 October 2017 at 15:51, Jim Lemon  wrote:

> Hi Hemant,
> Here is an example that might answer your questions. Please don't run
> previous code as it might not work.
>
> I define the break values as arguments to the function
> (rbreaks,fbreaks,mbreaks) If you want the breaks to work, make sure that
> they cover the range of the input values, otherwise you get NAs.
>
> # expects a three (or more) column data frame where
> # column 1 is customer ID, column 2 is amount of purchase
> # and column 3 is date of purchase
> qdrfm<-function(x,rbreaks=3,fbreaks=3,mbreaks=3,date.format="%Y-%m-%d",
>  weights=c(1,1,1),finish=NA) {
>
>  # if no finish date is specified, use current date
>  if(is.na(finish)) finish<-as.Date(date(), "%a %b %d %H:%M:%S %Y")
>  x$rscore<-as.numeric(finish-as.Date(x[,3],date.format))
>  x$rscore<-as.numeric(cut(x$rscore,breaks=rbreaks,labels=FALSE))
>  custIDs<-unique(x[,1])
>  ncust<-length(custIDs)
>  rfmout<-data.frame(custID=custIDs,rscore=rep(0,ncust),
>   fscore=rep(0,ncust),mscore=rep(0,ncust))
>  rfmout$rscore<-cut(by(x$rscore,x[,1],min),breaks=rbreaks,labels=FALSE)
>  rfmout$fscore<-cut(table(x[,1]),breaks=fbreaks,labels=FALSE)
>  rfmout$mscore<-cut(by(x[,2],x[,1],sum),breaks=mbreaks,labels=FALSE)
>  rfmout$cscore<-(weights[1]*rfmout$rscore+
>   weights[2]*rfmout$fscore+
>   weights[3]*rfmout$mscore)/sum(weights)
>  return(rfmout[order(rfmout$cscore),])
> }
>
> set.seed(12345)
> x2<-data.frame(ID=sample(1:50,250,TRUE),
>  purchase=round(runif(250,5,100),2),
>  date=paste(rep(2016,250),sample(1:12,250,TRUE),
>   sample(1:28,250,TRUE),sep="-"))
>
> # example 1
> qdrfm(x2)
>
> # example 2
> qdrfm(x2,rbreaks=c(0,200,400),fbreaks=c(0,5,10),mbreaks=c(0,350,700),
>  finish=as.Date("2017-01-01"))
>
> Jim
>
>


-- 
hemantsain.com

[[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] Regular expression help

2017-10-09 Thread peter dalgaard

> On 9 Oct 2017, at 17:02 , Duncan Murdoch  wrote:
> 
> I have a file containing "words" like
> 
> 
> a
> 
> a/b
> 
> a/b/c
> 
> where there may be multiple words on a line (separated by spaces).  The a, b, 
> and c strings can contain non-space, non-slash characters. I'd like to use 
> gsub() to extract the c strings (which should be empty if there are none).
> 
> A real example is
> 
> "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
> 
> which I'd like to transform to
> 
> " 587 587 587 587"
> 
> Another real example is
> 
> "f 1067 28680 24462"
> 
> which should transform to "   ".
> 
> I've tried a few different regexprs, but am unable to find a way to say 
> "transform words by deleting everything up to and including the 2nd slash" 
> when there might be zero, one or two slashes.  Any suggestions?
> 

I think you might need something like this:

s <- "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
l <- strsplit(s, " ")[[1]]
pat <- "[[:alnum:]]*/[[:alnum:]]*/([[:alnum:]]*)"
paste(ifelse(grepl(pat,l),gsub(pat, "\\1", l), ""), collapse=" ")

-pd

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

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

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


Re: [R] Regular expression help

2017-10-09 Thread Eric Berger
Hi Duncan,
You can try this:

library(readr)
f <- function(s) {
  t <- unlist(readr::tokenize(paste0(gsub(" ",",",s),"\n",collapse="")))
  i <- grep("[a-zA-Z0-9]*/[a-zA-Z0-9]*/",t)
  u <- sub("[a-zA-Z0-9]*/[a-zA-Z0-9]*/","",t[i])
  paste0(u,collapse=" ")
}

f("f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587")
# "587 587 587 587"

f("f 1067 28680 24462")
# ""

HTH,
Eric


On Mon, Oct 9, 2017 at 6:23 PM, Ulrik Stervbo 
wrote:

> Hi Duncan,
>
> why not split on / and take the correct elements? It is not as elegant as
> regex but could do the trick.
>
> Best,
> Ulrik
>
> On Mon, 9 Oct 2017 at 17:03 Duncan Murdoch 
> wrote:
>
> > I have a file containing "words" like
> >
> >
> > a
> >
> > a/b
> >
> > a/b/c
> >
> > where there may be multiple words on a line (separated by spaces).  The
> > a, b, and c strings can contain non-space, non-slash characters. I'd
> > like to use gsub() to extract the c strings (which should be empty if
> > there are none).
> >
> > A real example is
> >
> > "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
> >
> > which I'd like to transform to
> >
> > " 587 587 587 587"
> >
> > Another real example is
> >
> > "f 1067 28680 24462"
> >
> > which should transform to "   ".
> >
> > I've tried a few different regexprs, but am unable to find a way to say
> > "transform words by deleting everything up to and including the 2nd
> > slash" when there might be zero, one or two slashes.  Any suggestions?
> >
> > Duncan Murdoch
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Regular expression help

2017-10-09 Thread Ulrik Stervbo
Hi Duncan,

why not split on / and take the correct elements? It is not as elegant as
regex but could do the trick.

Best,
Ulrik

On Mon, 9 Oct 2017 at 17:03 Duncan Murdoch  wrote:

> I have a file containing "words" like
>
>
> a
>
> a/b
>
> a/b/c
>
> where there may be multiple words on a line (separated by spaces).  The
> a, b, and c strings can contain non-space, non-slash characters. I'd
> like to use gsub() to extract the c strings (which should be empty if
> there are none).
>
> A real example is
>
> "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"
>
> which I'd like to transform to
>
> " 587 587 587 587"
>
> Another real example is
>
> "f 1067 28680 24462"
>
> which should transform to "   ".
>
> I've tried a few different regexprs, but am unable to find a way to say
> "transform words by deleting everything up to and including the 2nd
> slash" when there might be zero, one or two slashes.  Any suggestions?
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


[R] Regular expression help

2017-10-09 Thread Duncan Murdoch

I have a file containing "words" like


a

a/b

a/b/c

where there may be multiple words on a line (separated by spaces).  The 
a, b, and c strings can contain non-space, non-slash characters. I'd 
like to use gsub() to extract the c strings (which should be empty if 
there are none).


A real example is

"f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587"

which I'd like to transform to

" 587 587 587 587"

Another real example is

"f 1067 28680 24462"

which should transform to "   ".

I've tried a few different regexprs, but am unable to find a way to say 
"transform words by deleting everything up to and including the 2nd 
slash" when there might be zero, one or two slashes.  Any suggestions?


Duncan Murdoch

__
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 wanted - R contributed documentation

2017-10-09 Thread Martyn Plummer
The R Foundation is looking for a volunteer to organize the collection
of contributed documentation for the R project.  The collection is
currently hosted on CRAN at https://cran.r-project.org/other-docs.html
We want to move it off the CRAN web site.

We think that this task would be suitable for someone whose primary
interest is in library and information science. Ideally the collection
would be reorganized as an R-project.org epub archive, based on re-
using available open source software which features the following: 

* export to .bib
* support for multiple revisions
* support for supplementary material (such as code and data).

If you are interested then please reply privately to me. The R
Foundation board will discuss this at the next meeting.  You can, of
course, put together a team of people but we really want a single
person to act as point of reference.

Martyn Plummer
Co-president, The R Foundation






___
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-es] Incluir símbolo matemático en data frame

2017-10-09 Thread Manuel Spínola
Muchas gracias Carlos.

Pero eso haría que el signo se muestre tal como se deba mostrar , es decir:
≤

Manuel

El 9 de octubre de 2017, 1:46, Carlos Ortega 
escribió:

> Puedes incluir estos signos en una columna nueva antes de cada una de las
> columnas numéricas.
> Que el data.frame tuviera esta pinta...
>
> Signo_1, Col_1, Signo_2, Col_2, Signo_3, Col_3
> "<=", 0.3, ">=", 0.5, "==", 0.8
> ">=", 0.8, "<", 0.9, ">", 1
> 
>
> Gracias,
> Carlos.
>
> El 9 de octubre de 2017, 4:02, Manuel Spínola 
> escribió:
>
>> Estimados miembros de la lista,
>>
>> Cómo se puede incluir. por ejemplo, el símbolo de menor o igual en un
>> data.frame para luego hacer un cuadro (table con kable in rmarkadown)?
>>
>> columna1 <- c("a", "b", "c")
>> columna2 <- c(<= 0.3, 0.5, 0.8)
>> columna3 <- c(>=0.5, 0.6, 0.9)
>>
>> cuadro <- data.frame(columna1, columna2, columna3)
>>
>> kable(cuadro)
>>
>> Manuel
>>
>> --
>> *Manuel Spínola, Ph.D.*
>> Instituto Internacional en Conservación y Manejo de Vida Silvestre
>> Universidad Nacional
>> Apartado 1350-3000
>> Heredia
>> COSTA RICA
>> mspin...@una.cr 
>> mspinol...@gmail.com
>> Teléfono: (506) 8706 - 4662
>> Personal website: Lobito de río > /lobitoderio/>
>> Institutional website: ICOMVIS 
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>



-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Merge me agrega siempre las columnas

2017-10-09 Thread Jesús Para Fernández
Gracias,

Entiendo el resultado, pero claro, si el numero de columnas a agregar 
coincidentes son muchas, agregarlas obviandolas no es trivial.

Creare por lo tanto una fórmula que elimine todas las columans coincidentes 
tras ser unidas.

Gracias de todos modos
Jesús

De: jose luis 
Enviado: lunes, 9 de octubre de 2017 13:48
Para: Jesús Para Fernández; r-help-es@r-project.org
Asunto: Re: [R-es] Merge me agrega siempre las columnas

Hola

Entiendo que donde pusiste
k<-c(1,3,8,7) querías poner
x<-c(1,3,8,7)

Si es correcto, creo que el problema es que al ser "y" una variable presente en 
las dos tablas, o la incluyes como argumento para el cruce o te saldrá 
"duplicada" (le añade un punto para diferenciarla).
¿es esto lo que quieres?



merge(df1,df2,by=c("id", "y"),all.x=TRUE)

  id y z  x
1: a1 1 3 NA
2: a2 2 5 NA
3: a3 3 6 NA
4: a4 4 7  7


El Lunes 9 de octubre de 2017 12:45, Jesús Para Fernández 
 escribió:


Buenas,

Tengo dos data.frames de la siguiente manera

library(data.table)
id<-c("a1","a2","a3","a4")
id2<-c("a2","a3","a1","a4")
y<-c(1,2,3,4)
z<-c(3,5,6,7)
k<-c(1,3,8,7)

df1<-data.table(id,y,z)

id<-c("a2","a3","a1","a4")
df2<-data.table(id,x,y)

Quiero que el resultado sea solo el LEFT JOIN, es decir, que me devuelva:

resultado--> id,x,y,z

Para ello pruebo, tal y como dicen en:
https://rstudio-pubs-static.s3.amazonaws.com/52230_5ae0d25125b544caab32f75f0360e775.html

merge(df1,df2,by="id",all.x=TRUE)

Pero me devuelve:

  id y.x z x y.y
1: a1  1 3 3  3
2: a2  2 5 0  1
3: a3  3 6 2  2
4: a4  4 7 1  4


Es decir, me est� duplicando la columna y.

He probado con data.frame y usando all=FALSE, all.x=T,... pero no lo consigo.

�Alguna idea de como puedo hacerlo?

Gracais

[[alternative HTML version deleted]]
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Merge me agrega siempre las columnas

2017-10-09 Thread jose luis via R-help-es
Hola
Entiendo que donde pusiste k<-c(1,3,8,7)                             querías 
poner
x<-c(1,3,8,7)

Si es correcto, creo que el problema es que al ser "y" una variable presente en 
las dos tablas, o la incluyes como argumento para el cruce o te saldrá 
"duplicada" (le añade un punto para diferenciarla).¿es esto lo que quieres?

merge(df1,df2,by=c("id", "y"),all.x=TRUE)

  id y z  x
1: a1 1 3 NA
2: a2 2 5 NA
3: a3 3 6 NA
4: a4 4 7  7 

El Lunes 9 de octubre de 2017 12:45, Jesús Para Fernández 
 escribió:
 

 Buenas,

Tengo dos data.frames de la siguiente manera

library(data.table)
id<-c("a1","a2","a3","a4")
id2<-c("a2","a3","a1","a4")
y<-c(1,2,3,4)
z<-c(3,5,6,7)
k<-c(1,3,8,7)

df1<-data.table(id,y,z)

id<-c("a2","a3","a1","a4")
df2<-data.table(id,x,y)

Quiero que el resultado sea solo el LEFT JOIN, es decir, que me devuelva:

resultado--> id,x,y,z

Para ello pruebo, tal y como dicen en:
https://rstudio-pubs-static.s3.amazonaws.com/52230_5ae0d25125b544caab32f75f0360e775.html

merge(df1,df2,by="id",all.x=TRUE)

Pero me devuelve:

  id y.x z x y.y
1: a1  1 3 3  3
2: a2  2 5 0  1
3: a3  3 6 2  2
4: a4  4 7 1  4


Es decir, me est� duplicando la columna y.

He probado con data.frame y usando all=FALSE, all.x=T,... pero no lo consigo.

�Alguna idea de como puedo hacerlo?

Gracais

    [[alternative HTML version deleted]]
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

   
[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Merge me agrega siempre las columnas

2017-10-09 Thread Carlos Ortega
Es normal que te esté dando ese resultado.
Las columnas "y" de df1 y de df2 no son iguales...

Si pruebas con "dplyr" el resultado es este:

> library(dplyr)
> left_join(df1, df2)
Joining, by = c("id", "y")
  id y z  x
1 a1 1 3 NA
2 a2 2 5 NA
3 a3 3 6 NA
4 a4 4 7  7

Que a lo mejor es lo que quieres...

Saludos,
Carlos Ortega
www.qualityexcellence.es


El 9 de octubre de 2017, 12:45, Jesús Para Fernández <
j.para.fernan...@hotmail.com> escribió:

> Buenas,
>
> Tengo dos data.frames de la siguiente manera
>
> library(data.table)
> id<-c("a1","a2","a3","a4")
> id2<-c("a2","a3","a1","a4")
> y<-c(1,2,3,4)
> z<-c(3,5,6,7)
> k<-c(1,3,8,7)
>
> df1<-data.table(id,y,z)
>
> id<-c("a2","a3","a1","a4")
> df2<-data.table(id,x,y)
>
> Quiero que el resultado sea solo el LEFT JOIN, es decir, que me devuelva:
>
> resultado--> id,x,y,z
>
> Para ello pruebo, tal y como dicen en:
> https://rstudio-pubs-static.s3.amazonaws.com/52230_
> 5ae0d25125b544caab32f75f0360e775.html
>
> merge(df1,df2,by="id",all.x=TRUE)
>
> Pero me devuelve:
>
>id y.x z x y.y
> 1: a1   1 3 3   3
> 2: a2   2 5 0   1
> 3: a3   3 6 2   2
> 4: a4   4 7 1   4
>
>
> Es decir, me está duplicando la columna y.
>
> He probado con data.frame y usando all=FALSE, all.x=T,... pero no lo
> consigo.
>
> ¿Alguna idea de como puedo hacerlo?
>
> Gracais
>
> [[alternative HTML version deleted]]
>
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Help RFM analysis in R (i want a code where i can define my own breaks instead of system defined breaks used in auto_RFM package)

2017-10-09 Thread Jim Lemon
Hi Hemant,
Here is an example that might answer your questions. Please don't run
previous code as it might not work.

I define the break values as arguments to the function
(rbreaks,fbreaks,mbreaks) If you want the breaks to work, make sure that
they cover the range of the input values, otherwise you get NAs.

# expects a three (or more) column data frame where
# column 1 is customer ID, column 2 is amount of purchase
# and column 3 is date of purchase
qdrfm<-function(x,rbreaks=3,fbreaks=3,mbreaks=3,date.format="%Y-%m-%d",
 weights=c(1,1,1),finish=NA) {

 # if no finish date is specified, use current date
 if(is.na(finish)) finish<-as.Date(date(), "%a %b %d %H:%M:%S %Y")
 x$rscore<-as.numeric(finish-as.Date(x[,3],date.format))
 x$rscore<-as.numeric(cut(x$rscore,breaks=rbreaks,labels=FALSE))
 custIDs<-unique(x[,1])
 ncust<-length(custIDs)
 rfmout<-data.frame(custID=custIDs,rscore=rep(0,ncust),
  fscore=rep(0,ncust),mscore=rep(0,ncust))
 rfmout$rscore<-cut(by(x$rscore,x[,1],min),breaks=rbreaks,labels=FALSE)
 rfmout$fscore<-cut(table(x[,1]),breaks=fbreaks,labels=FALSE)
 rfmout$mscore<-cut(by(x[,2],x[,1],sum),breaks=mbreaks,labels=FALSE)
 rfmout$cscore<-(weights[1]*rfmout$rscore+
  weights[2]*rfmout$fscore+
  weights[3]*rfmout$mscore)/sum(weights)
 return(rfmout[order(rfmout$cscore),])
}

set.seed(12345)
x2<-data.frame(ID=sample(1:50,250,TRUE),
 purchase=round(runif(250,5,100),2),
 date=paste(rep(2016,250),sample(1:12,250,TRUE),
  sample(1:28,250,TRUE),sep="-"))

# example 1
qdrfm(x2)

# example 2
qdrfm(x2,rbreaks=c(0,200,400),fbreaks=c(0,5,10),mbreaks=c(0,350,700),
 finish=as.Date("2017-01-01"))

Jim

[[alternative HTML version deleted]]

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


[R] Adjusted survival curves

2017-10-09 Thread RStudio

Adjusted survival curves (Thanks to sample code:  
https://rpubs.com/daspringate/survival )
Thanks to Moderator/Admin's Great Work! For a successful solution I used advice 
that could be understood:
1. Peter Dalgaard: The code does not work, because the covariates are not 
factors.
2. Jeff Newmiller: "Change the columns into factors before you give them to the 
coxph function, e.g. df$treatment <- as.factor(df$treatment)"
And I study David Winsemius's instructions.THANKS!!! 
Code works:

library(survival)
library(survminer)
df<-read.csv("F:/R/data/edgr-orig.csv", header = TRUE, sep = ";")

head(df)
# "age" means the age groups
ID start stop censor sex age stage treatment
1   0660 2   1   3 1
2   0180 1   2   4 2
3   0431 2   3   3 1
4   0471 2   3   NA2
5   0260 1   4   3NA

# Change continuous var. as factors
df$sex<-as.factor(df$sex)
df$age<-as.factor(df$age)
df$stage<-as.factor(df$stage)
df$treatment<-as.factor(df$treatment)

S <- Surv(
  time = df$start, 
  time2 = df$stop, 
  event = df$censor)

model <- coxph( S ~ treatment + age + sex + stage, data = df)

plot(survfit(model), 
 las=1,
 xscale = 1.00,
 xlab = "Months after diagnosis",
 ylab = "Proportion survived",
 main = "Baseline Hazard Curve")

treat <- with(df,
  data.frame(
  treatment = levels(treatment),
  age = rep(levels(age)[1], 2),
  sex = rep(levels(sex)[1], 2),
  stage = rep(levels(stage)[1], 2)))

plot(survfit(model, newdata = treat), 
 las=1,
 xscale = 1.00,
 conf.int = TRUE,
 xlab = "Months after diagnosis",
 ylab = "Proportion survived",
 col = c("red", "green"))

legend(8, 0.9, 
   legend = c("Beta blockers", 
  "No beta blockers"), 
   lty = 1, 
   col = c("green", "red"))
[[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] Manipulations with CO2 dataset on R

2017-10-09 Thread PIKAL Petr
Hi

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ludovico
> Piccolo
> Sent: Sunday, October 8, 2017 4:40 PM
> To: r-help@r-project.org
> Subject: [R] Manipulations with CO2 dataset on R
>
> Hi,
> I just started a new course this semester on R, I never used it in my life 
> and i'm
> stuck on these questions from 3 days, it would be really nice if someone could
> explain me the answers with the relative commands.
>
> thanks a lot in advance
>
> The following 7 questions are based on the CO2 dataset of R.
>
> 1) How many of the plants in CO2 are Mc2 for Plant?

?table

>
> 2) How many are either Mc2 or Mn2?

?table or ?aggregate

>
> 3) How many are Quebec for Type and nonchilled for Treatment?

?aggregate

>
> 4) How many have a concentration (conc) of 350 or bigger?

?table and ?">"

>
> 5) How many have a concentration between 350 and 435 (inclusive)?

?table and ?">"

>
> 6) How many have a concentration between 300 and 450 (inclusive) and are
> nonchilled?

?table or ?aggregate and ?">"

>
> 7)How many have an uptake that is less than 1/10 of the concentration (in the
> units reported)?
>

?table or ?aggregate and ?">"

R comes with quite extensive help pages and with R-intro which you should 
consult first.

Cheers
Petr

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


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 -- 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-es] Incluir símbolo matemático en data frame

2017-10-09 Thread Carlos Ortega
Puedes incluir estos signos en una columna nueva antes de cada una de las
columnas numéricas.
Que el data.frame tuviera esta pinta...

Signo_1, Col_1, Signo_2, Col_2, Signo_3, Col_3
"<=", 0.3, ">=", 0.5, "==", 0.8
">=", 0.8, "<", 0.9, ">", 1


Gracias,
Carlos.

El 9 de octubre de 2017, 4:02, Manuel Spínola 
escribió:

> Estimados miembros de la lista,
>
> Cómo se puede incluir. por ejemplo, el símbolo de menor o igual en un
> data.frame para luego hacer un cuadro (table con kable in rmarkadown)?
>
> columna1 <- c("a", "b", "c")
> columna2 <- c(<= 0.3, 0.5, 0.8)
> columna3 <- c(>=0.5, 0.6, 0.9)
>
> cuadro <- data.frame(columna1, columna2, columna3)
>
> kable(cuadro)
>
> Manuel
>
> --
> *Manuel Spínola, Ph.D.*
> Instituto Internacional en Conservación y Manejo de Vida Silvestre
> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> mspin...@una.cr 
> mspinol...@gmail.com
> Teléfono: (506) 8706 - 4662
> Personal website: Lobito de río  site/lobitoderio/>
> Institutional website: ICOMVIS 
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] example of geom_contour() with function argument

2017-10-09 Thread Ulrik Stervbo
Hi BFD,

?geom_contour() *does* have helpful examples. Your Google-foo is weak:
Searching for geom_contour brought me:
http://ggplot2.tidyverse.org/reference/geom_contour.html as the first
result.

HTH
Ulrik

On Mon, 9 Oct 2017 at 08:04 Big Floppy Dog  wrote:

> Can someone please point me to an example with geom_contour() that uses a
> function? The help does not have an example of a function, and also  I did
> not find anything from online searches.
>
> TIA,
> BFD
>
>
>
> ---
>
> How about geom_contour()?
>
> Am So., 8. Okt. 2017, 20:52 schrieb Ranjan Maitra :
>
> > Hi,
> >
> > I am no expert on ggplot2 and I do not know the answer to your question.
> I
> > looked around a bit but could not find an answer right away. But one
> > possibility could be, if a direct approach is not possible, to draw
> > ellipses corresponding to the confidence regions of the multivariate t
> > density and use geom_polygon to draw this successively?
> >
> > I will wait for a couple of days to see if there is a better answer
> posted
> > and then write some code, unless you get to it first.
> >
> > Thanks,
> > Ranjan
> >
> >
> > On Sun, 8 Oct 2017 09:30:30 -0500 Big Floppy Dog  >
> > wrote:
> >
> > > Note: I have posted this on SO also but while the question has been
> > > upvoted, there has been no answer yet.
> > >
> > >
> >
>
> https://stackoverflow.com/questions/46622243/ggplot-plot-2d-probability-density-function-on-top-of-points-on-ggplot
> > >
> > > Apologies for those who have seen it there also but I thought that this
> > > list of experts may have someone who knows the answer.
> > >
> > > I have the following example code:
> > >
> > >
> > >
> > > require(mvtnorm)
> > > require(ggplot2)
> > > set.seed(1234)
> > > xx <- data.frame(rmvt(100, df = c(13, 13)))
> > > ggplot(data = xx,  aes(x = X1, y= X2)) + geom_point() +
> geom_density2d()
> > >
> > >
> > >
> > > It yields a scatterplot of X2 against X1 and a KDE contour plot of the
> > > density (as it should).
> > >
> > > My question is: is it possible to change the contour plot to display
> > > the contours
> > >
> > > of a two-dimensional density function (say dmvt), using ggplot2?
> > >
> > > The remaining figures in my document are in ggplot2 and therefore I
> > > am looking for a ggplot2 solution.
> > >
> > > Thanks in advance!
> > >
> > > BFD
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] load() failed to load .Rdata file in AWS-Ububtu

2017-10-09 Thread Eric Berger
Hi Christofer,
The shiny code you have written does not depend on loading the Dat.RData
file.
I commented out that line and ran your shiny app on my machine and it works
fine.
What happens if you comment out  (or remove) the line
 load("/home/ubuntu/Dat.RData)
Does your shiny app still fail? If so, then your problem is quite basic
with your  AWS setup.
Try to work through a simple tutorial/documentation example that shows how
to get shiny running on AWS and see if following the steps helps you
discover the problem.

Good luck,
Eric




On Sun, Oct 8, 2017 at 8:05 PM, Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:

> Thanks Eric for your pointer. However I just altered the argument of
> load() function a little bit to get that loaded. Below is the line
> what I tried.
>
> ubuntu@ip-172-31-23-148:~$ R
>
>
> R version 3.4.2 (2017-09-28) -- "Short Summer"
>
> Copyright (C) 2017 The R Foundation for Statistical Computing
>
> Platform: x86_64-pc-linux-gnu (64-bit)
>
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
>
> You are welcome to redistribute it under certain conditions.
>
> Type 'license()' or 'licence()' for distribution details.
>
>
>   Natural language support but running in an English locale
>
>
> R is a collaborative project with many contributors.
>
> Type 'contributors()' for more information and
>
> 'citation()' on how to cite R or R packages in publications.
>
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
>
> 'help.start()' for an HTML browser interface to help.
>
> Type 'q()' to quit R.
>
>
> During startup - Warning message:
>
> Setting LC_CTYPE failed, using "C"
>
> > load("/home/ubuntu/Dat.RData")
>
> >
>
> However it still failing when I try that within my shiny app in AWS.
>
> Below are my ui.R and server.R files respectively.
>
> library(shiny)
>
> # Define UI for miles per gallon application
> fluidPage(
>   fluidRow(
> column(12,
>   tableOutput('table')
> )
>   )
> )
>
> server.R :
>
> library(shiny)
>
> load("/home/ubuntu/Dat.RData")
>
> shinyServer(function(input, output) {
> output$table = renderTable(head(data.frame(1:20, 1:20), 20))
> })
>
> with above setup when I deploy my shiny app I get below error :
>
> 18.221.184.94:3838 says
> The application unexpectedly exited
> Diagnostic information has been dumped to the JavaScript error console.
>
> appreciate any help to get rid of this error.
>
> Thanks for your time.
>
> On Sun, Oct 8, 2017 at 12:39 AM, Eric Berger 
> wrote:
> > Hi Christofer,
> > The directory /srv/shiny-server would normally be owned by the root user.
> > Your options would seem to be to either (1) bring up the R session as
> root
> > (dangerous)
> > or (2) try copying the file to your local directory and read it from
> there
> > (if allowed).
> > e.g. from the Unix shell:
> >> cd ~   (i.e. cd to your home directory)
> >> cp /srv/shiny-server/Dat.Rdata .   (Note the '.' at the end. This may
> not
> >> work - if not then you can try the following
> >> sudo cp /srv/shiny-server/Dat.Rdata . (if you have sudo privileges -
> only
> >> do this if the former command did not work)
> >> chmod 777 Dat.Rdata  (a bit of overkill - again preface by sudo if it
> does
> >> not work without it)
> >
> > Then in your R session you can do the load from the file in this
> location.
> > R>  load("~/Dat.Rdata")
> >
> > HTH,
> > Eric
> >
> >
> > On Sat, Oct 7, 2017 at 8:54 PM, Christofer Bogaso
> >  wrote:
> >>
> >> Hi again,
> >>
> >> I hope this is the right place to post my question on running R within
> >> Ubuntu, however if not, any pointer on right distribution list will be
> >> helpful.
> >>
> >> I am currently using R in Ubuntu which is hosted in Amazon - AWS.
> >>
> >> I have a .Rdata file in AWS which I am trying to load in R. Used
> >> following code, however, fails to load showing some permission issue.
> >> However that same .Rdata file is getting loaded perfectly when I try
> >> in my regular iOS.
> >>
> >> Below is my code and corresponding result :
> >>
> >> ubuntu@ip-172-31-23-148:~$ R
> >>
> >>
> >> R version 3.4.2 (2017-09-28) -- "Short Summer"
> >>
> >> Copyright (C) 2017 The R Foundation for Statistical Computing
> >>
> >> Platform: x86_64-pc-linux-gnu (64-bit)
> >>
> >>
> >> R is free software and comes with ABSOLUTELY NO WARRANTY.
> >>
> >> You are welcome to redistribute it under certain conditions.
> >>
> >> Type 'license()' or 'licence()' for distribution details.
> >>
> >>
> >>   Natural language support but running in an English locale
> >>
> >>
> >> R is a collaborative project with many contributors.
> >>
> >> Type 'contributors()' for more information and
> >>
> >> 'citation()' on how to cite R or R packages in publications.
> >>
> >>
> >> Type 'demo()' for some demos, 'help()' for on-line help, or
> >>
> >> 'help.start()' for an HTML browser interface to help.
> >>
> >> Type 'q()' to quit R.
> >>
> >>
> >> During startup - 

[R] example of geom_contour() with function argument

2017-10-09 Thread Big Floppy Dog
Can someone please point me to an example with geom_contour() that uses a
function? The help does not have an example of a function, and also  I did
not find anything from online searches.

TIA,
BFD


---

How about geom_contour()?

Am So., 8. Okt. 2017, 20:52 schrieb Ranjan Maitra :

> Hi,
>
> I am no expert on ggplot2 and I do not know the answer to your question. I
> looked around a bit but could not find an answer right away. But one
> possibility could be, if a direct approach is not possible, to draw
> ellipses corresponding to the confidence regions of the multivariate t
> density and use geom_polygon to draw this successively?
>
> I will wait for a couple of days to see if there is a better answer posted
> and then write some code, unless you get to it first.
>
> Thanks,
> Ranjan
>
>
> On Sun, 8 Oct 2017 09:30:30 -0500 Big Floppy Dog 
> wrote:
>
> > Note: I have posted this on SO also but while the question has been
> > upvoted, there has been no answer yet.
> >
> >
>
https://stackoverflow.com/questions/46622243/ggplot-plot-2d-probability-density-function-on-top-of-points-on-ggplot
> >
> > Apologies for those who have seen it there also but I thought that this
> > list of experts may have someone who knows the answer.
> >
> > I have the following example code:
> >
> >
> >
> > require(mvtnorm)
> > require(ggplot2)
> > set.seed(1234)
> > xx <- data.frame(rmvt(100, df = c(13, 13)))
> > ggplot(data = xx,  aes(x = X1, y= X2)) + geom_point() + geom_density2d()
> >
> >
> >
> > It yields a scatterplot of X2 against X1 and a KDE contour plot of the
> > density (as it should).
> >
> > My question is: is it possible to change the contour plot to display
> > the contours
> >
> > of a two-dimensional density function (say dmvt), using ggplot2?
> >
> > The remaining figures in my document are in ggplot2 and therefore I
> > am looking for a ggplot2 solution.
> >
> > Thanks in advance!
> >
> > BFD
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>

[[alternative HTML version deleted]]

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