Re: [R] Book Recommendation

2023-08-28 Thread William Michels via R-help
I'm a big fan of the sqldf package by Gabor Grothendieck:

"sqldf: Manipulate R Data Frames Using SQL"
https://CRAN.R-project.org/package=sqldf

The sqldf "README.html" converts to a 42 page PDF:
https://cran.r-project.org/web/packages/sqldf/readme/README.html

You can also find favorable blog posts for the sqldf package on the
web, notably a post (circa 2013) from Patrick Burns:
https://www.burns-stat.com/translating-r-sql-basics/

HTH,

Bill.

W. Michels, Ph.D.



On Mon, Aug 28, 2023 at 8:47 AM Stephen H. Dawson, DSL via R-help
 wrote:
>
> Good Morning,
>
>
> I am doing some research to develop a new course where I teach. I am
> looking for a book to use in the course content to teach accomplishing
> SQL in R.
>
> Does anyone know of a book on this topic to recommend for consideration?
>
>
> Thank You,
> --
> *Stephen Dawson, DSL*
> /Executive Strategy Consultant/
> Business & Technology
> +1 (865) 804-3454
> http://www.shdawson.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.

__
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] Connect R with Ensemble Rest API to fetch variations

2022-01-03 Thread William Michels via R-help
Hello Anas,

You can find courses and/or training materials on the Ensembl/EBI
websites, including R code:

https://www.ebi.ac.uk/training/online/courses/ensembl-rest-api/
http://training.ensembl.org/

You can also click on individual 'Ensembl REST API Endpoints', and
find sample R code there:

http://rest.ensembl.org/

Good luck,

Bill.

W. Michels, Ph.D.





On Mon, Jan 3, 2022 at 5:08 PM Anas Jamshed  wrote:
>
> I have a list of 422 genes in excel file .I want to know if its possible to
> get snps details of these gene by using Ensemble Rest API or biomart?
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] how to install npsm package

2021-09-01 Thread William Michels via R-help
Hi,

I found package "npsm" at the links below:

https://mran.microsoft.com/snapshot/2017-02-04/web/packages/npsm/index.html
https://cran.r-project.org/src/contrib/Archive/npsm/

HTH, Bill.

W. Michels, Ph.D.


On Wed, Sep 1, 2021 at 8:27 AM  wrote:
>
> I need to install the package "npsm" to follow Kloke & McKean book. However,
> npsm is no longer on CRAN. So, please let me know in detail how to proceed
> to install it.
>
>
>
> Thanks.
>
>
>
> Carlos Gonzalez
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] How to solve this?

2021-08-31 Thread William Michels via R-help
Hello,

You may have more luck posting your question to the R-SIG-Geo mailing-list:

https://stat.ethz.ch/mailman/listinfo/R-SIG-Geo/

Be sure to use an appropriate "Subject" line, for example, the
particular package/function that seems problematic.

HTH, Bill.

W. Michels, Ph.D.



On Mon, Aug 30, 2021 at 1:36 AM SITI AISYAH ZAKARIA
 wrote:
>
> Dear all,
>
> Can anyone help me? I'm using this coding to get the spatial gev model and
> plotting the quantile plot to justify the model is fit but the plot look
> like not fit.. How can I solve this? It is I need to change in the any
> value at the coding.For example I want to change form.shape <-shape ~1 to
> form.shape <- shape ~average shape but is not available for average coding.
>
> below is my coding
>
> #--
> # fitspatgev
> #--
> # response surface model
> Ozone<-data.matrix(Ozone_S)
> Ozone
> LotLatAlt<-data.matrix(OzoneLotLatAlt_S)
> LotLatAlt
> form.loc <- loc ~ Lon + Lat + Alt
> form.scale <- scale ~ 1
> form.shape <- shape ~ 1
> dim(Ozone_S)
> dim(OzoneLotLatAlt_S)
> fit1 <- fitspatgev(Ozone, scale(LotLatAlt,scale=FALSE), form.loc,
> form.scale, form.shape);fit1
> TIC(fit1)
> fit1$param
> #data(rain
> #symbolplot(rain, coord, plot.border = swiss)
> #check the fit of the model: compute QQplots for each station
> par(mfrow=c(1,3))
> par(mar=c(3,2.5,1.5,0.5),mgp=c(1.5,0.5,0),font.main=1,cex=0.66,cex.main=1)
> #calculation of confidance intervals
> nc <- 1
> M1 <- matrix(rfrechet(nc*nobs),nrow=nobs,ncol=nc)
> M <- t(apply(M1,2,sort))
> E <- boot::envelope(mat=M) #compute 95% confidance bands
> for (k in c(1:3,4,5,6)){ #choose some stations
>   park <- predict(fit1)[k,]
>   fk <- gev2frech(Ozone[,k],loc=park[4],scale=park[5],shape=park[6])
>   qqplot(y=fk,x=qfrechet((1:nobs)/(nobs+1)),log='xy',main=k,ylab='Sample
> Quantiles',xlab='Theoretical Quantiles',cex=0.7);
>   abline(0,1)
>   lines(y=E$overall[1,],x=qfrechet((1:nobs)/(nobs +1)),lty='dotted')
>   lines(y=E$overall[2,],x=qfrechet((1:nobs)/(nobs +1)),lty='dotted')
> }
>
> the quantile plot is in attachment file.
> please, can anyone help me?
>
> thank you
>
> --
>
>
>
>
>
> "..Millions of trees are used to make papers, only to be thrown away
> after a couple of minutes reading from them. Our planet is at stake. Please
> be considerate. THINK TWICE BEFORE PRINTING THIS.."
>
> DISCLAIMER: This email
> and any files transmitted with it are confidential and intended solely for
> the use of the individual orentity to whom they are addressed. If you have
> received this email in error please notify the UniMAP's Email
> Administrator. Please note that any views or opinions presented in this
> email are solely those of the author and do not necessarily represent those
> of the university. Finally, the recipient should check this email and any
> attachments for the presence of viruses.The university accepts no liability
> for any damage caused by any virus transmitted by this email.
>
> Universiti
> Malaysia Perlis (UniMAP) | Digital Management & Development Centre (DMDC),
> Universiti Malaysia Perlis (UniMAP), Pauh Putra Campus, 02600 Arau, Perlis,
> MALAYSIA | www.unimap.edu.my 
> __
> 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] How to spot/stop making the same mistake

2021-06-23 Thread William Michels via R-help
Hi Phillips,

Maybe these examples will be useful:

> vec <- c("a","b","c","d","e")
> vec[c(1,1,1,0,0)]
[1] "a" "a" "a"
> vec[c(1,1,1,2,2)]
[1] "a" "a" "a" "b" "b"
> vec[c(5,5,5,5,5)]
[1] "e" "e" "e" "e" "e"
> vec[c(NA,NA,NA,0,0,0,0)]
[1] NA NA NA
> vec[c(NA,NA,NA,1,1,1,1)]
[1] NA  NA  NA  "a" "a" "a" "a"
> vec[c(7:9)]
[1] NA NA NA
>
> R.version.string
[1] "R version 3.6.3 (2020-02-29)"

HTH, Bill.

W. Michels, Ph.D.








On Wed, Jun 23, 2021 at 10:39 AM Phillips Rogfield
 wrote:
>
> Dear all,
>
> thank for for your suggestion.
>
> Yes I come from languages where 1 means TRUE and 0 means FALSE. In
> particular from C/C++ and Python.
>
> Evidently this is not the case for R.
>
> In my mind I kind took for granted that that was the case (1=TRUE, 0=FALSE).
>
> Knowing this is not the case for R makes things simpler.
>
> Mine was just an example, sometimes I load datasets taken from outside
> and variables are coded with 1/0 (for example, a treatment variable may
> be coded that way).
>
> I also did not know the !!() syntax!
>
> Thank you for your help and best regards.
>
> On 23/06/2021 17:55, Bert Gunter wrote:
> > Just as a way to save a bit of typing, instead of
> >
> > > as.logical(0:4)
> > [1] FALSE  TRUE  TRUE  TRUE  TRUE
> >
> > > !!(0:4)
> > [1] FALSE  TRUE  TRUE  TRUE  TRUE
> >
> > DO NOTE that the parentheses in the second expression should never be
> > omitted, a possible reason to prefer the as.logical() construction.
> > Also note that !!  "acts [only] on raw, logical and number-like
> > vectors," whereas as.logical() is more general. e.g. (from ?logical):
> >
> > > charvec <- c("FALSE", "F", "False", "false","fAlse", "0",
> > +  "TRUE",  "T", "True",  "true", "tRue",  "1")
> > > as.logical(charvec)
> >  [1] FALSE FALSE FALSE FALSENANA  TRUE  TRUE  TRUE  TRUENA
> >NA
> > > !!charvec
> > Error in !charvec : invalid argument type
> >
> >
> > Cheers,
> > Bert
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming along
> > and sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Wed, Jun 23, 2021 at 8:31 AM Eric Berger  > > wrote:
> >
> > In my code, instead of 't', I name a vector of indices with a
> > meaningful
> > name, such as idxV, to make it obvious.
> >
> > Alternatively, a minor change in your style would be to replace your
> > definition of t by
> >
> > t <- as.logical(c(1,1,1,0,0))
> >
> > HTH,
> > Eric
> >
> >
> > On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield
> > mailto:thebudge...@gmail.com>>
> > wrote:
> >
> > > I make the same mistake all over again.
> > >
> > > In particular, suppose we have:
> > >
> > > a = c(1,2,3,4,5)
> > >
> > > and a variable that equals 1 for the elements I want to select:
> > >
> > > t = c(1,1,1,0,0)
> > >
> > > To select the first 3 elements.
> > >
> > > The problem is that
> > >
> > > a[t]
> > >
> > > would repeat the first element 3 times .
> > >
> > > I have to either convert `t` to boolean:
> > >
> > > a[t==1]
> > >
> > > Or use `which`
> > >
> > > a[which(t==1)]
> > >
> > > How can I "spot" this error?
> > >
> > > It often happens in long scripts.
> > >
> > > Do I have to check the type each time?
> > >
> > > Do you have any suggestions?
> > >
> > > __
> > > 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] Need to compare two columns in two data.frames and return all rows from df where rows values are missing

2021-06-13 Thread William Michels via R-help
Maybe something like this?

> df_A <- data.frame(names=LETTERS[1:10], values_A=1:10)
> df_B <- data.frame(names=LETTERS[6:15], values_B=11:20)
> df_AB <- merge(df_A, df_B, by="names")
> df_AAB <- merge(df_A, df_AB, all.x=TRUE)
> df_BAB <- merge(df_B, df_AB, all.x=TRUE)
> df_C <- df_AAB[is.na(df_AAB$values_B), ]
> df_D <- df_BAB[is.na(df_BAB$values_A), ]
> df_AB
  names values_A values_B
1 F6   11
2 G7   12
3 H8   13
4 I9   14
5 J   10   15
> df_C
  names values_A values_B
1 A1   NA
2 B2   NA
3 C3   NA
4 D4   NA
5 E5   NA
> df_D
   names values_B values_A
6  K   16   NA
7  L   17   NA
8  M   18   NA
9  N   19   NA
10 O   20   NA
>

HTH, Bill.

W. Michels, Ph.D.











On Sun, Jun 13, 2021 at 2:38 PM Gregg Powell via R-help
 wrote:
>
> This is even complicated to write into a question
>
> Have two data.frames (A and B)
>
> data.frame A and B each have a name column. Want to compare A and B 
> data.frame to each other based on the values in the 'names' columns - for 
> every name that appears in dataframe A  but not B, I want to copy the 
> corresponding rows to a third dataframe C, and for every name that appears in 
> B but not A, I want to copy the corresponding rows to a fourth dataframe D. I 
> can then row bind the dataframes C and D together and get a complete list of 
> all the rows that were missing in either A or B.
>
> try as I might - I can't get this to work. Can someone help P-L-E-A-S-E
>
>
>  Thanks,
>  Gregg Powell
>  AZ, USA__
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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] Beginner problem - using mod function to print odd numbers

2021-06-06 Thread William Michels via R-help
Dear Bert,

First off, I want to thank you for the many hundreds (if not
thousands) of excellent posts I've read from you on this mailing list
over the years. And you are absolutely correct that when using the
`%%` modulo operator, your code is the most compact and the most
idiomatic.

That being said, if someone coming from another programming language
is posting code on this mailing list using a `for()` loop,  they may
be most comfortable getting working code back from this mailing-list
that still uses a `for()` loop in R. Furthermore, people often start
by *filtering* their data, when a better approach might be to first
*recode* it, for which the `ifelse()` function provides a nice
solution. But of course, a more simple approach than I previously
posted would be below (although less idiomatic than your answer):

> object <- 1:100
> index <- ifelse(object %% 2 == 1, TRUE, FALSE)
> object[index]
 [1]  1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43
45 47 49 51 53 55 57
[30] 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
>

This brings us to the question of programming 'philosophy':  certain
languages advise "TMTOWTDI", while another advises "There should be
one--and preferably only one--obvious way to do it." Where does R fit
on this spectrum? I believe one of R's underappreciated strengths is
being more in-line with the "TMTOWTDI" principle. So people coming
from other languages can get good results right off the bat using
vectorized indexing/filtering, or for() loops, or the apply() family
of functions, or writing a custom function (all answers given in this
thread).

Finally, if a nascent R programmer ever ventures into filtering their
data using objects and indexes of different lengths, they should have
a grasp of the code examples below (recycling rule):

long_vec <- 1:16
print(long_vec)
short_vec <- rep(4,8)
print(short_vec)
print(long_vec[long_vec > short_vec])

span <- 1:length(short_vec)
print(long_vec[span][long_vec[span] > short_vec])
print(long_vec[span][long_vec > short_vec])

Best Regards, Bill.

W. Michels, Ph.D.



On Sat, Jun 5, 2021 at 12:26 PM Bert Gunter  wrote:
>
> I'm sorry, but  this is a good example of how one should *not* do this in R. 
> I also should apologize for any pedantry that follows, but I believe this 
> serves as a nice example of the ideas.
>
> Two of R's central features as a "data science" language are that many of its 
> core capabilities are "vectorized" -- can calculate on whole objects (at the 
> user-visible interpreter level) rather than requiring explicit loops; and 
> that it can use object indexing in several different modalities, here logical 
> indexing, for extraction and replacement in whole objects such as vectors and 
> matrices. Not only does this typically yield simpler, more readable code 
> (admittedly, a subjective judgment), but it is also typically much faster, 
> though I grant you that this can often be overrated.
>
> In this instance, the several lines of looping code you presented can be 
> condensed into a single line:
>
> > span <- 1:20
> > span[span %% 2 == 1]
>  [1]  1  3  5  7  9 11 13 15 17 19
>
> ### Trickier, but perhaps instructive, is: ###
> > span[TRUE & span %% 2]
>  [1]  1  3  5  7  9 11 13 15 17 19
>
> All languages trade off various strengths and weaknesses, but I think it's 
> fair to say that one should try to work within the paradigms that are the 
> language's strengths when possible, R's vectorization and indexing in this 
> example.
>
> Cheers,
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sat, Jun 5, 2021 at 11:05 AM William Michels via R-help 
>  wrote:
>>
>> > i <- 1L; span <- 1:100; result <- NA;
>> > for (i in span){
>> + ifelse(i %% 2 != 0, result[i] <- TRUE, result[i] <- FALSE)
>> + }
>> > span[result]
>>  [1]  1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43
>> 45 47 49 51 53 55 57
>> [30] 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
>> >
>>
>> HTH, Bill.
>>
>> W. Michels, Ph.D.
>>
>>
>> On Sat, Jun 5, 2021 at 12:55 AM Stefan Evert  
>> wrote:
>> >
>> > >
>> > > I don't understand. --
>> > >
>> > > 7%%2=1
>> > > 9%%2=1
>> > > 11%%2=1
>> > >
>> > > What aren't these numbers printing ?
>> > >
>> > > num<-0
>> > > for (i in 1:100){

Re: [R] Beginner problem - using mod function to print odd numbers

2021-06-05 Thread William Michels via R-help
> i <- 1L; span <- 1:100; result <- NA;
> for (i in span){
+ ifelse(i %% 2 != 0, result[i] <- TRUE, result[i] <- FALSE)
+ }
> span[result]
 [1]  1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43
45 47 49 51 53 55 57
[30] 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
>

HTH, Bill.

W. Michels, Ph.D.


On Sat, Jun 5, 2021 at 12:55 AM Stefan Evert  wrote:
>
> >
> > I don't understand. --
> >
> > 7%%2=1
> > 9%%2=1
> > 11%%2=1
> >
> > What aren't these numbers printing ?
> >
> > num<-0
> > for (i in 1:100){
> >  num<-num+i
> > if (num%%2 != 0)
> >  print(num)
> > }
>
> Your code tests the numbers
>
> 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, …
>
> and correctly prints the odd ones among them.
>
> But I suppose that's not what you wanted to do?
>
> __
> 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] series of densities

2021-05-17 Thread William Michels via R-help
Hi Troels,

Have you considered using Lattice graphics?
Adapting from examples on the help page:

> ?histogram()
> histogram( ~ BC | pH, data = ddd, type = "density",
   xlab  = "BC", layout = c(1, 3), aspect = 0.618,
   strip = strip.custom(strip.levels=c(TRUE,TRUE)),
   panel = function(x, ...) {
   panel.histogram(x, ...)
   panel.mathdensity(dmath = dnorm, col = 1,
   args = list(mean=mean(x), sd=sd(x)) )
   } )


HTH, Bill.

W. Michels, Ph.D.






On Mon, May 17, 2021 at 8:12 AM Troels Ring  wrote:
>
> Dear friends
> I'm trying to plot in silico derived values of 3 types of
> buffer-capacities  over pH values and want densities of the three types
> together at each pH with the pH values on the abscissa.
>
> I have generated some data
>
> set.seed(2345)
> pHs <- c(7.2,7.4,7.6)
> pH <- rep(pHs,each=30)
> BC <- rep(rep(c(20,10,10),each=10),3)+rnorm(90,0,5)
> type <- rep(rep(c("TOT","NC","CA"),each=10),3)
>
> ddd <- data.frame(pH,BC,type)
>
> GG <- ggplot()
> for (i in 1:3) {
>dd <- ddd[ddd$pH==pHs[i],]
>GG <- GG + geom_density(data=dd,aes(x=BC,fill=type),alpha=0.1)
> }
> GG
>
> but here I only get all pH values  plotted together whereas I want 3
> series in the vertical direction at the three pH values.
>
> I wonder how this could be done?
>
> All best wishes
>
> Troels Ring, MD
> Aalborg, Denmark
>
> PS: Windows 10,
>
> R version 4.0.5 (2021-03-31
>
> __
> 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] Stata/Rstudio evil attributes

2021-04-10 Thread William Michels via R-help
Hi Roger,

You could look at the attributes() function in base-R. See:

> ?attributes

>From the help-page:

> ## strip an object's attributes:
> attributes(x) <- NULL

HTH, Bill.

W. Michels, Ph.D.



On Sat, Apr 10, 2021 at 4:20 AM Koenker, Roger W  wrote:
>
> Wolfgang,
>
> Thanks, this is _extremely_ helpful.
>
> Roger
>
> > On Apr 10, 2021, at 11:59 AM, Viechtbauer, Wolfgang (SP) 
> >  wrote:
> >
> > Dear Roger,
> >
> > The problem is this. qss() looks like this:
> >
> > if (is.matrix(x)) {
> >   [...]
> > }
> > if (is.vector(x)) {
> >   [...]
> > }
> > qss
> >
> > Now let's check these if() statements:
> > is.vector(B$x) # TRUE
> > is.vector(D$x) # FALSE
> > is.matrix(B$x) # FALSE
> > is.matrix(D$x) # FALSE
> >
> > is.vector(D$x) being FALSE may be surprising, but see ?is.vector: 
> > "is.vector returns TRUE if x is a vector of the specified mode having no 
> > attributes other than names. It returns FALSE otherwise." And as D$x shows, 
> > this vector has additional attributes.
> >
> > So, with 'D', qss() returns the qss function (c.f., qss(B$x) and qss(D$x)) 
> > which makes no sense. So, the internal logic in qss() needs to be fixed.
> >
> >> In accordance with the usual R-help etiquette I first tried to contact the
> >> maintainer of the haven package, i.e. RStudio, which elicited the 
> >> response: "since
> >> the error is occurring outside RStudio we’re not responsible, so try Stack
> >> Overflow".  This is pretty much what I would have expected from the 
> >> capitalist
> >> running dogs they are.  Admittedly, the error is probably due to some 
> >> unforeseen
> >
> > This kind of bashing is really silly. Can you tell us again how much you 
> > paid for the use of the haven package?
> >
> > Best,
> > Wolfgang
> >
> >> -Original Message-
> >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Koenker, 
> >> Roger W
> >> Sent: Saturday, 10 April, 2021 11:26
> >> To: r-help
> >> Subject: [R] Stata/Rstudio evil attributes
> >>
> >> As shown in the reproducible example below, I used the RStudio function 
> >> haven() to
> >> read a Stata .dta file, and then tried to do some fitting with the 
> >> resulting
> >> data.frame.  This produced an error from my fitting function rqss() in the 
> >> package
> >> quantreg.  After a bit of frustrated cursing, I converted the data.frame, 
> >> D, to a
> >> matrix A, and thence back to a data.frame B, and tried again, which worked 
> >> as
> >> expected.  The conversion removed the attributes of D.  My question is:  
> >> why were
> >> the attributes inhibiting the fitting?
> >>
> >> In accordance with the usual R-help etiquette I first tried to contact the
> >> maintainer of the haven package, i.e. RStudio, which elicited the 
> >> response: "since
> >> the error is occurring outside RStudio we’re not responsible, so try Stack
> >> Overflow".  This is pretty much what I would have expected from the 
> >> capitalist
> >> running dogs they are.  Admittedly, the error is probably due to some 
> >> unforeseen
> >> infelicity in my rqss() coding, but it does seem odd that attributes could 
> >> have
> >> such a drastic  effect.  I would be most grateful for any insight the R 
> >> commune
> >> might offer.
> >>
> >> #require(haven) # for reading dta file
> >> #Ddta <- read_dta(“foo.dta")
> >> #D <- with(Ddta, data.frame(y = access_merg, x = meannets_allhh, z = 
> >> meanhh))
> >> #save(D, file = "D.Rda")
> >> con <- url("http://www.econ.uiuc.edu/~roger/research/data/D.Rda";)
> >> load(con)
> >>
> >> # If I purge the Stata attributes in D:
> >> A <- as.matrix(D)
> >> B <- as.data.frame(A)
> >>
> >> # This works:
> >> with(D,plot(x, y, cex = .5, col = "grey"))
> >> taus <- 1:4/5
> >> require(quantreg)
> >> for(i in 1:length(taus)){
> >>   f <- rqss(y ~ qss(x, constraint = "I", lambda = 1), tau = taus[i], data 
> >> = B)
> >>   plot(f, add = TRUE, col = i)
> >> }
> >> # However, the same code with data = D, does not.  Why?
>
> __
> 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] Calculating column differences

2021-03-24 Thread William Michels via R-help
More correctly, with an initial "NA" value in the "diff" column:

> df <- data.frame(ID=1:5,Score=4*2:6)
> df1 <- rbind(c(0,0), df)
> cbind(df1, "diff"=c(NA, diff(df1$Score)) )
  ID Score diff
1  0 0   NA
2  1 88
3  2124
4  3164
5  4204
6  5244
>

HTH, Bill.
On Wed, Mar 24, 2021 at 10:59 AM William Michels  wrote:
>
> Dear Jeff,
>
> Rather than diff-ing a linear vector you're trying to diff values from
> two different rows. Also you indicate that you want to place the
> diff-ed value in the 'lower' row of a new column. Try this (note
> insertion of an initial "zero" row):
>
> > df <- data.frame(ID=1:5,Score=4*2:6)
> > df1 <- rbind(c(0,0), df)
> > cbind(df1, "diff"=c(0, diff(df1$Score)) )
>   ID Score diff
> 1  0 00
> 2  1 88
> 3  2124
> 4  3164
> 5  4204
> 6  5244
> >
>
> HTH, Bill.
>
> W. Michels, Ph.D.
>
>
>
> On Wed, Mar 24, 2021 at 9:49 AM Jeff Reichman  wrote:
> >
> > r-help forum
> >
> >
> >
> > I'm trying to calculate the diff between two rows and them mutate the
> > difference into a new column. I'm using the diff function but not giving me
> > what I want.
> >
> >
> >
> > df <- data.frame(ID=1:5,Score=4*2:6)
> >
> >
> >
> > What a want  where
> >
> >   ID Score  diff
> >
> > 1  1 8  8
> >
> > 2  212 4
> >
> > 3  316 4
> >
> > 4  420 4
> >
> > 5  524 4
> >
> >
> >
> > What I am getting
> >
> >   ID Score  diff
> >
> > 1  1 8  NA
> >
> > 2  212 4
> >
> > 3  316 4
> >
> > 4  420 4
> >
> > 5  524 4
> >
> >
> >
> > Jeff
> >
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Calculating column differences

2021-03-24 Thread William Michels via R-help
Dear Jeff,

Rather than diff-ing a linear vector you're trying to diff values from
two different rows. Also you indicate that you want to place the
diff-ed value in the 'lower' row of a new column. Try this (note
insertion of an initial "zero" row):

> df <- data.frame(ID=1:5,Score=4*2:6)
> df1 <- rbind(c(0,0), df)
> cbind(df1, "diff"=c(0, diff(df1$Score)) )
  ID Score diff
1  0 00
2  1 88
3  2124
4  3164
5  4204
6  5244
>

HTH, Bill.

W. Michels, Ph.D.



On Wed, Mar 24, 2021 at 9:49 AM Jeff Reichman  wrote:
>
> r-help forum
>
>
>
> I'm trying to calculate the diff between two rows and them mutate the
> difference into a new column. I'm using the diff function but not giving me
> what I want.
>
>
>
> df <- data.frame(ID=1:5,Score=4*2:6)
>
>
>
> What a want  where
>
>   ID Score  diff
>
> 1  1 8  8
>
> 2  212 4
>
> 3  316 4
>
> 4  420 4
>
> 5  524 4
>
>
>
> What I am getting
>
>   ID Score  diff
>
> 1  1 8  NA
>
> 2  212 4
>
> 3  316 4
>
> 4  420 4
>
> 5  524 4
>
>
>
> Jeff
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Installing Perl For Use in R

2020-10-08 Thread William Michels via R-help
Hi Philip,

"Perl Download"
https://www.perl.org/get.html

The above link gives you the option to install from source or from
ActiveState. The first link below (source) proudly proclaims, "Perl
compiles on over 100 platforms..." and the second link below (binary)
similarly proclaims, "Perl supports over 100 platforms!":

"Perl Source"
https://www.cpan.org/src/README.html

"Perl Ports (Binary Distributions)"
https://www.cpan.org/ports/index.html

HTH, Bill.

W. Michels, Ph.D.



On Tue, Oct 6, 2020 at 8:32 AM Marc Schwartz via R-help
 wrote:
>
> Hi,
>
> What OS are you on?
>
> It has been years since I used ActiveState, but it looks like you now need to 
> create an account with them prior to downloading the installation files. They 
> seem to give you the option of creating an account with them, or using 
> Github. I would opt for the former, even though I have a Github account.
>
> If you are on Windows, an alternative Perl distribution is Strawberry Perl:
>
>   http://strawberryperl.com
>
> Regards,
>
> Marc Schwartz
>
> > On Oct 6, 2020, at 11:21 AM, Philip  wrote:
> >
> > I’m getting nowhere with this.  From the website below  I clicked on the 
> > ActivePerl 5.26 button which seems to lead me into creating projects on the 
> > Cloud rather than downloading the software to my hard drive.
> >
> >https://www.activestate.com/products/perl/downloads/
> >
> > Can someone give me some advise?  What the website is trying to do seems 
> > rather shady.
> >
> > Thanks,
> > Philip
>
> __
> 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] Lahman Baseball Data Using R DBI Package

2020-10-07 Thread William Michels via R-help
Hi Philip,

You've probably realized by now that R doesn't like column names that
start with a number. If you try to access an R-dataframe column named
2B or 3B with the familiar "$" notation, you'll get an error:

> library(DBI)
> library(RSQLite)
> con2 <- dbConnect(SQLite(), "~/R_Dir/lahmansbaseballdb.sqlite")
> Hack12Batting <- dbGetQuery(con2,"SELECT * FROM batting WHERE yearID = 2018 
> AND AB >600 ORDER BY AB DESC")
> Hack12Batting$AB
 [1] 664 661 639 632 632 632 626 623 620 618 617 613 606 605 602
> Hack12Batting$3B
Error: unexpected numeric constant in "Hack12Batting$3"

How to handle? You can rename columns on-the-fly by piping. See
reference [1] and use either library(magrittr) or library(dplyr) or a
combination thereof:

library(magrittr)
dbGetQuery(con2,"SELECT * FROM batting WHERE yearID = 2018 AND AB >600
ORDER BY AB DESC") %>% set_colnames(make.names(colnames(.)))

#OR one of the following:

library(dplyr)
dbGetQuery(con2,"SELECT * FROM batting WHERE yearID = 2018 AND AB >600
ORDER BY AB DESC") %>% rename(X2B = `2B`, X3B = `3B`)

library(dplyr)
dbGetQuery(con2,"SELECT * FROM batting WHERE yearID = 2018 AND AB >600
ORDER BY AB DESC") %>% `colnames<-`(make.names(colnames(.)))

library(dplyr)
dbGetQuery(con2,"SELECT * FROM batting WHERE yearID = 2018 AND AB >600
ORDER BY AB DESC") %>% magrittr::set_colnames(make.names(colnames(.)))

Best, Bill.

W. Michels, Ph.D.

[1] 
https://stackoverflow.com/questions/28100780/use-with-replacement-functions-like-colnames










On Fri, Oct 2, 2020 at 7:34 PM Bill Dunlap  wrote:
>
> The double quotes are required by SQL if a name is not of the form
> letter-followed-by-any-number-of-letters-or-numbers or if the name is a SQL
> keyword like 'where' or 'select'.  If you are doing this from a function,
> you may as well quote all the names.
>
> -Bill
>
> On Fri, Oct 2, 2020 at 6:18 PM Philip  wrote:
>
> > The \”2B\” worked.  Have no idea why.  Can you point me somewhere that can
> > explain this to me.
> >
> > Thanks,
> > Philip
> >
> > *From:* Bill Dunlap
> > *Sent:* Friday, October 2, 2020 3:54 PM
> > *To:* Philip
> > *Cc:* r-help
> > *Subject:* Re: [R] Lahman Baseball Data Using R DBI Package
> >
> > Have you tried putting double quotes around 2B and 3B:  "...2B, 3B, ..."
> > -> "...\"2B\",\"3B\",..."?
> >
> > -Bill
> >
> > On Fri, Oct 2, 2020 at 3:49 PM Philip  wrote:
> >
> >> I’m trying to pull data from one table (batting) in the Lahman Baseball
> >> database.  Notice X2B for doubles and X3B for triples – fourth and fifth
> >> from the right.
> >>
> >> The dbGetQuery function runs fine when I leave there two out but I get
> >> error messages (in red) when I include 2B/3B or X2B/X3B.
> >>
> >> Can anyone give me some direction?
> >>
> >> Thanks,
> >> Philip Heinrich
> >>
> >> ***
> >> tail(dbReadTable(Lahman,"batting"))
> >>
> >> ID   playerID  yearIDstint teamID team_ID
> >> lgID   GG_batting   AB R H   X2BX3B   HR   RBI   SB
> >> 107414 107414 yastrmi01  2019   1   SFN   2920
> >> NL 107NA  371   64  101  22   3 21
> >> 552
> >> 107416 107416 yelicch01  20191   MIL   2911
> >> NL 130NA  489 100  161  29   3 4497   
> >> 30
> >> 107419 107419 youngal01 2019   1   ARI2896
> >> NL   17NA25 1  10   0
> >> 0  0 0
> >> 107420 107420 zagunma01   20191  CHN   2901  NL
> >> 30NA 36 2  93   0  0
> >> 5 0
> >> 107422 107422 zavalse01  20191  CHA   2900
> >> AL5NA 12 1  10   0
> >> 0   0 0
> >> 107427 107427 zimmery01 20191  WAS  2925  NL
> >> 52NA   171   20449  0  6  27 0
> >> 107428 107428 zobribe01   20191  CHN  2901
> >> NL  47NA   150   24   39 5  0  1
> >> 17 0
> >> 107429 107429 zuninmi01   20191  TBA   2922
> >> AL  90NA   26630  44   10  1  9
> >> 32 0
> >>
> >>
> >> Hack11Batting <- dbGetQuery(Lahman,"SELECT
> >> playerID,yearID,AB,R,H,2B,3B,HR,
> >> RBI,SB,CS,BB,SO,IBB,HBP,SH,SF,GIDP FROM
> >> batting
> >> WHERE yearID = 2018 AND AB >99")
> >> Error: unrecognized token: "2B"
> >>
> >> Hack11Batting <- dbGetQuery(Lahman,"SELECT
> >> playerID,yearID,AB,R,H,X2B,X3B,HR,
> >> RBI,SB,CS,BB,SO,IBB,HBP,SH,SF,GIDP FROM
> >> batting
> >> WHERE yearID = 2018 AND AB >99")
> >> Error: no such column: X2B
> >>
> >> [[alternative HTML version deleted]]
>

Re: [R] Unnesting JSON using R

2020-09-17 Thread William Michels via R-help
Hi Fred, I believe the preferred package is jsonlite:

https://cran.r-project.org/package=jsonlite
https://jeroen.cran.dev/jsonlite/index.html

HTH, Bill.

W. Michels, Ph.D.

On Tue, Sep 15, 2020 at 1:48 PM Fred Kwebiha  wrote:
>
> Source=https://jsonformatter.org/e038ec
>
> The above is nested json.
>
> I want the output to be as below
> dataElements.name,dataElements.id,categoryOptionCombos.name,categoryOptionCombos.id
>
> Any help in r?
> *Best Regards,*
>
> *FRED KWEBIHA*
> *+256-782-746-154*
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Connection to Oracle DB failing from R

2020-08-31 Thread William Dunlap via R-help
Which version of java do you have installed?  Oracle's web site says
ojdbc5.jar is for Java 1.5 and ojdbc6.jar is for more recent versions.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Aug 31, 2020 at 3:56 AM Christofer Bogaso
 wrote:
>
> Hi,
>
> I am trying to establish a connection to a Oracle DB from R and used below
> code which is failing every time I try -
>
> > library(RJDBC)
> Loading required package: DBI
> > jdbcDriver =JDBC("oracle.jdbc.OracleDriver",classPath="ojdbc5.jar")
>
>  *** caught segfault ***
> address 0x854961, cause 'memory not mapped'
>
> Traceback:
>  1: .jinit(classPath)
>  2: JDBC("oracle.jdbc.OracleDriver", classPath = "ojdbc5.jar")
>
> Possible actions:
> 1: abort (with core dump, if enabled)
> 2: normal R exit
> 3: exit R without saving workspace
> 4: exit R saving workspace
> Selection:
>
>
> Below is my session info -
>
> > sessionInfo()
> R version 4.0.2 (2020-06-22)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Catalina 10.15.6
>
> Matrix products: default
> BLAS:
>  /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>
> locale:
> [1] C/UTF-8/C/C/C/C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] RJDBC_0.2-8  DBI_1.1.0rJava_0.9-13
>
> loaded via a namespace (and not attached):
> [1] compiler_4.0.2
>
> I downloaded the JAR file from
> https://www.oracle.com/database/technologies/jdbcdriver-ucp-downloads.html
>
> Can you please help me to understand why it is failing?
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] PROBLEM: quickly downloading 10,000 articles to sift through

2020-08-30 Thread William Michels via R-help
Hello John, Does this help?

https://cran.r-project.org/web/packages/bibliometrix/vignettes/bibliometrix-vignette.html
https://bibliometrix.org/

Best, Bill.

W. Michels, Ph.D.


On Fri, Aug 28, 2020 at 11:04 PM Fraedrich, John  wrote:
>
>
>
> To analyze 10,000+ articles within several journals to determine major 
> theories used, empirical research of models, constructs, and variables, 
> differences in standard definitions by discipline, etc. Is/does R have this 
> in a software package?
>
>
>
> Sent from Mail for Windows 10
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] serialize does not work as expected

2020-08-29 Thread William Dunlap via R-help
For some reason l[[2]] is serialized as a 'compact_realseq' and l[3]]
is not.  They both unserialize to the same thing.  On Windows I get:

> lapply(l, function(x)rawToChar(serialize(x, connection=NULL, ascii=TRUE)))
[[1]]
[1] 
"A\n3\n262146\n197888\n6\nCP1252\n238\n2\n1\n262153\n14\ncompact_intseq\n2\n1\n262153\n4\nbase\n2\n13\n1\n13\n254\n14\n3\n3\n1\n1\n254\n"

[[2]]
[1] 
"A\n3\n262146\n197888\n6\nCP1252\n238\n2\n1\n262153\n15\ncompact_realseq\n2\n1\n262153\n4\nbase\n2\n13\n1\n14\n254\n14\n3\n3\n1\n1\n254\n"

[[3]]
[1] "A\n3\n262146\n197888\n6\nCP1252\n14\n3\n1\n2\n3\n"

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Aug 29, 2020 at 8:37 AM Sigbert Klinke
 wrote:
>
> Hi,
>
> if I create a list with
>
> l <- list(1:3, as.numeric(1:3), c(1,2,3))
>
> and applying
>
> lapply(l, 'class')
> lapply(l, 'mode')
> lapply(l, 'storage.mode')
> lapply(l, 'typeof')
> identical(l[[2]], l[[3]])
>
> then I would believe that as,numeric(1:3) and c(1,2,3) are identical
> objects. However,
>
> lapply(l, serialize, connection=NULL)
>
> returns different results for each list element :(
>
> Any ideas, why it is like that?
>
> Best Sigbert
>
> --
> https://hu.berlin/sk
> https://hu.berlin/mmstat3
>
> __
> 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] Passing formula and weights error

2020-08-28 Thread William Dunlap via R-help
Note that neither call to glm in your myglm function really works -
the first one is using the 'weights' object from the global
environment, not the weights argument.  E.g., in the fresh R session,
where I avoid making unneeded assignments and use fixed x and y for
repeatability,

  > n <- 16
  > data <- data.frame(x = log2(1:n), y = 1:n)
  > myglm2 <- function(formula, data, weights)
  {
  glm(formula, data=data, family=gaussian(), weights=weights)
  }
  > myglm2(y~., data=data, weights=1/(1:n))
  Error in model.frame.default(formula = formula, data = data, weights
= weights,  :
invalid type (closure) for variable '(weights)'

The error arises because glm finds stats::weights, a function, not the
argument called weights.  glm(), lm() and their ilk evaluate their
weights and subset arguments in the environment of the formula.  In
this case environment(y~.) is .GlobalEnv, not the function's
environment.  The following function gives one way to deal with this,
by giving formula a new environment that inherits from its original
environment and contains the extra variables.

  > myglm3 <- function(formula, data, weights)
  {
  envir <- list2env(list(weights=weights), parent=environment(formula))
  environment(formula) <- envir
  glm(formula, data=data, family=gaussian(), weights=weights)
  }
  > myglm3(y~., data=data, weights=1/(1:n))

  Call:  glm(formula = formula, family = gaussian(), data = data,
weights = weights)

  Coefficients:
  (Intercept)x
 -0.09553  2.93352

  Degrees of Freedom: 15 Total (i.e. Null);  14 Residual
  Null Deviance:  60.28
  Residual Deviance: 7.72 AIC: 70.42

This is the same result you get with a direct call to
  glm(y~., data=data, weights=1/(1:n))

This is a common problem and I don't know if there is a FAQ on it or a
standard function to deal with it.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Aug 28, 2020 at 8:33 AM John Smith  wrote:
>
> Dear R-help:
>
> I am writing a function based on glm and would like some variations of
> weights. In the code below, I couldn't understand why the second glm
> function fails and don't know how to fix it:
>
> Error in eval(extras, data, env) : object 'newweights' not found
>  Calls: print ... eval ->  -> model.frame.default -> eval -> eval
>  Execution halted
>
> ### R code
> y <- rnorm(100)
>  x <- rnorm(100)
>  data <- data.frame(cbind(x, y))
>  weights <- rep(1, 100)
>  n <- 100
>  myglm <- function(formula, data, weights){
>  ## this works
>  print(glm(formula, data, family=gaussian(), weights))
>  ## this is not working
>  newweights <- rep(1, n)
>  glm(formula, data, family=gaussian(), weights=newweights)
>  }
>  myglm(y~., data, weights)
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] [External] rNOMADS package

2020-08-24 Thread William Dunlap via R-help
Add the arguments type="source" and repos=NULL to your call to
install.packages().  repos=NULL means that this is a local file, not
something to download from a repository.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Aug 24, 2020 at 8:31 AM Richard M. Heiberger  wrote:
>
> incorrect double slash c://
> use single slash c:/
>
> On Mon, Aug 24, 2020 at 11:21 Philip  wrote:
>
> > I am struggling to install a fix for the rNOMADS package which reads
> > National Weather Service data.  I copied the fix (rNOMADS_2.5.0.tar.gz)
> > from an email to a local drive and then tried to install it with the
> > command below.  I also tried installing it without the .tar.gz extension
> > and without the _2.5.0 extension but I get the same error message.  The
> > author, Daniel Bowman, emailed me that the fix should work for R version
> > 4.0 or better.
> >
> >
> >
> > Do I need to untar it?
> >
> >
> >
> >
> > install.packages("C://Documents/Ballooning/WeatherBriefing/rNOMADS_2.5.0.tar.gz")
> >
> >
> >
> > Installing package into ‘C:/Users/Owner/Documents/R/win-library/4.0’
> >
> > (as ‘lib’ is unspecified)
> >
> > Warning in install.packages :
> >
> >   package ‘C://Documents/Ballooning/WeatherBriefing/rNOMADS_2.5.0.tar.gz’
> > is not available (for R version 4.0.2)
> >
> > [[alternative HTML version deleted]]
> >
> >
> >
> > __
> >
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >
> > https://stat.ethz.ch/mailman/listinfo/r-help
> >
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> >
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-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] & and |

2020-08-19 Thread William Dunlap via R-help
Instead of intersect you could use grepl(pattern1,x) &
grepl(pattern2,x).  Use which() on the result if you must have
integers, but the logicals that grepl() produces are often easier to
use as subscripts.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Aug 19, 2020 at 8:54 AM Ivan Calandra  wrote:
>
> Indeed!
> I was just hoping that there would be a shorter way... intersect() is a
> nice alternative too. Maybe I can make it work with pipes so that I
> don't have to repeat "mydata" but that's another story.
>
> Thank you for the help!
> Ivan
>
> --
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
>
> On 19/08/2020 17:31, Bert Gunter wrote:
> > Well... wouldn't it be:
> >
> > rep("(ConfoMap.*GuineaPigs)|(GuineaPigs.*ConfoMap)", mydata, value=TRUE)
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming along
> > and sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Wed, Aug 19, 2020 at 8:23 AM Ivan Calandra  > > wrote:
> >
> > Thank you Bert for the pointer.
> >
> > So I guess the solution is:
> > grep("ConfoMap.+GuineaPigs", mydata, value=TRUE)
> >
> > This is not the case here, but what if "GuineaPigs" comes before
> > "ConfoMap"?
> > Of course I could do two "grep()" calls, but if there a better
> > solution?
> >
> > Ivan
> >
> > --
> > Dr. Ivan Calandra
> > TraCEr, laboratory for Traceology and Controlled Experiments
> > MONREPOS Archaeological Research Centre and
> > Museum for Human Behavioural Evolution
> > Schloss Monrepos
> > 56567 Neuwied, Germany
> > +49 (0) 2631 9772-243
> > https://www.researchgate.net/profile/Ivan_Calandra
> >
> > On 19/08/2020 17:07, Bert Gunter wrote:
> > > "&" is not a regex metacharacter.
> > > See ?regexp
> > >
> > > Bert Gunter
> > >
> > > "The trouble with having an open mind is that people keep coming
> > along
> > > and sticking things into it."
> > > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> > >
> > >
> > > On Wed, Aug 19, 2020 at 7:53 AM Ivan Calandra  > 
> > > >> wrote:
> > >
> > > Dear useRs,
> > >
> > > I feel really stupid, but I cannot understand why "&"
> > doesn't work
> > > as I
> > > expect, while "|" does.
> > >
> > > I have the following vector:
> > > mydata <- c("SSFA-ConfoMap_GuineaPigs_NMPfilled.csv",
> > > "SSFA-ConfoMap_Lithics_NMPfilled.csv",
> > > "SSFA-ConfoMap_Sheeps_NMPfilled.csv",
> > > "SSFA-Toothfrax_GuineaPigs.xlsx",
> > > "SSFA-Toothfrax_Lithics.xlsx", "SSFA-Toothfrax_Sheeps.xlsx")
> > > and I want to find the values that include both "ConfoMap" and
> > > "GuineaPigs".
> > >
> > > If I do:
> > > grep("ConfoMap&GuineaPigs", mydata, value=TRUE)
> > > it returns an empty vector, character(0).
> > >
> > > But if I do:
> > > grep("ConfoMap|GuineaPigs", mydata, value=TRUE)
> > > it returns all the elements that include either "ConfoMap" or
> > > "GuineaPigs", as I would expect.
> > >
> > > So what is wrong with my "&" construct? How can I return the
> > elements
> > > that include both parts?
> > >
> > > Thank you for your help!
> > > Ivan
> > >
> > > --
> > > Dr. Ivan Calandra
> > > TraCEr, laboratory for Traceology and Controlled Experiments
> > > MONREPOS Archaeological Research Centre and
> > > Museum for Human Behavioural Evolution
> > > Schloss Monrepos
> > > 56567 Neuwied, Germany
> > > +49 (0) 2631 9772-243
> > > https://www.researchgate.net/profile/Ivan_Calandra
> > >
> > > __
> > > 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
> > h

Re: [R] Dependent Variable in Logistic Regression

2020-08-01 Thread William Dunlap via R-help
I like using a logical response in cases like this, but put its
construction in the formula so it is unambiguous when I look at the
results later.
> d <- data.frame(Covid=c("Pos","Pos","Neg","Pos","Neg","Neg"), Age=41:46)
> glm(family=binomial, data=d, Covid=="Pos"~Age)

Call:  glm(formula = Covid == "Pos" ~ Age, family = binomial, data = d)

Coefficients:
(Intercept)  Age
 52.810   -1.214

Degrees of Freedom: 5 Total (i.e. Null);  4 Residual
Null Deviance:  8.318
Residual Deviance: 4.956AIC: 8.956


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Aug 1, 2020 at 12:21 PM John Fox  wrote:
>
> Dear Paul,
>
> I think that this thread has gotten unnecessarily complicated. The
> answer, as is easily demonstrated, is that a binary response for a
> binomial GLM in glm() may be a factor, a numeric variable, or a logical
> variable, with identical results; for example:
>
> --- snip -
>
>  > set.seed(123)
>
>  > head(x <- rnorm(100))
> [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
>
>  > head(y <- rbinom(100, 1, 1/(1 + exp(-x
> [1] 0 1 1 1 1 0
>
>  > head(yf <- as.factor(y))
> [1] 0 1 1 1 1 0
> Levels: 0 1
>
>  > head(yl <- y == 1)
> [1] FALSE  TRUE  TRUE  TRUE  TRUE FALSE
>
>  > glm(y ~ x, family=binomial)
>
> Call:  glm(formula = y ~ x, family = binomial)
>
> Coefficients:
> (Intercept)x
>   0.3995   1.1670
>
> Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
> Null Deviance:  134.6
> Residual Deviance: 114.9AIC: 118.9
>
>  > glm(yf ~ x, family=binomial)
>
> Call:  glm(formula = yf ~ x, family = binomial)
>
> Coefficients:
> (Intercept)x
>   0.3995   1.1670
>
> Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
> Null Deviance:  134.6
> Residual Deviance: 114.9AIC: 118.9
>
>  > glm(yl ~ x, family=binomial)
>
> Call:  glm(formula = yl ~ x, family = binomial)
>
> Coefficients:
> (Intercept)x
>   0.3995   1.1670
>
> Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
> Null Deviance:  134.6
> Residual Deviance: 114.9AIC: 118.9
>
> --- snip -
>
> The original poster claimed to have encountered an error with a 0/1
> numeric response, but didn't show any data or even a command. I suspect
> that the response was a character variable, but of course can't really
> know that.
>
> Best,
>   John
>
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> web: https://socialsciences.mcmaster.ca/jfox/
>
> On 2020-08-01 2:25 p.m., Paul Bernal wrote:
> > Dear friend,
> >
> > I am aware that I have a binomial dependent variable, which is covid status
> > (1 if covid positive, and 0 otherwise).
> >
> > My question was if R requires to turn a binomial response variable into a
> > factor or not, that's all.
> >
> > Cheers,
> >
> > Paul
> >
> > El sáb., 1 de agosto de 2020 1:22 p. m., Bert Gunter 
> > 
> > escribió:
> >
> >> ... yes, but so does lm() for a categorical **INdependent** variable with
> >> more than 2 numerically labeled levels. n levels  = (n-1) df for a
> >> categorical covariate, but 1 for a continuous one (unless more complex
> >> models are explicitly specified of course). As I said, the OP seems
> >> confused about whether he is referring to the response or covariates. Or
> >> maybe he just made the same typo I did.
> >>
> >> Bert Gunter
> >>
> >> "The trouble with having an open mind is that people keep coming along and
> >> sticking things into it."
> >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>
> >>
> >> On Sat, Aug 1, 2020 at 11:15 AM Patrick (Malone Quantitative) <
> >> mal...@malonequantitative.com> wrote:
> >>
> >>> No, R does not. glm() does in order to do logistic regression.
> >>>
> >>> On Sat, Aug 1, 2020 at 2:11 PM Paul Bernal 
> >>> wrote:
> >>>
>  Hi Bert,
> 
>  Thank you for the kind reply.
> 
>  But what if I don't turn the variable into a factor. Let's say that in
>  excel I just coded the variable as 1s and 0s and just imported the
>  dataset
>  into R and fitted the logistic regression without turning any categorical
>  variable or dummy variable into a factor?
> 
>  Does R requires every dummy variable to be treated as a factor?
> 
>  Best regards,
> 
>  Paul
> 
>  El sáb., 1 de agosto de 2020 12:59 p. m., Bert Gunter <
>  bgunter.4...@gmail.com> escribió:
> 
> > x <- factor(0:1)
> > x <- factor("yes","no")
> >
> > will produce identical results up to labeling.
> >
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming along
>  and
> > sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Sat, Aug 1, 2020 at 10:40 AM Paul Bernal 
> > wrote:
> >
> >> Dear friends,
> >>
> >> 

Re: [R] [External] Re: help with web scraping

2020-07-25 Thread William Michels via R-help
Dear Spencer Graves (and Rasmus Liland),

I've had some luck just using gsub() to alter the offending ""
characters, appending a "___" tag at each instance of "" (first I
checked the text to make sure it didn't contain any pre-existing
instances of "___"). See the output snippet below:

> library(RCurl)
> library(XML)
> sosURL <- 
> "https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975";
> sosChars <- getURL(sosURL)
> sosChars2 <- gsub("", "___", sosChars)
> MOcan <- readHTMLTable(sosChars2)
> MOcan[[2]]
  Name  Mailing Address Random
Number Date Filed
1   Raleigh Ritter  4476 FIVE MILE RD___SENECA MO 64865
   185  2/25/2020
2  Mike Parson 1458 E 464 RD___BOLIVAR MO 65613
   348  2/25/2020
3 James W. (Jim) NeelyPO BOX 343___CAMERON MO 64429
   477  2/25/2020
4 Saundra McDowell 3854 SOUTH AVENUE___SPRINGFIELD MO 65807
3/31/2020
>

It's true, there's one a 'section' of MOcan output that contains
odd-looking characters (see the "Total" line of MOcan[[1]]). But my
guess is you'll be deleting this 'line' anyway--and recalulating totals in R.

Now that you have a comprehensive list object, you should be able to
pull out districts/races of interest. You might want to take a look at
the "rlist" package, to see if it can make your work a little easier:

https://CRAN.R-project.org/package=rlist
https://renkun-ken.github.io/rlist-tutorial/index.html

HTH, Bill.

W. Michels, Ph.D.









On Sat, Jul 25, 2020 at 7:56 AM Spencer Graves
 wrote:
>
> Dear Rasmus et al.:
>
>
> On 2020-07-25 04:10, Rasmus Liland wrote:
> > On 2020-07-24 10:28 -0500, Spencer Graves wrote:
> >> Dear Rasmus:
> >>
> >>> Dear Spencer,
> >>>
> >>> I unified the party tables after the
> >>> first summary table like this:
> >>>
> >>> url <- 
> >>> "https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975";
> >>> M_sos <- RCurl::getURL(url)
> >>> saveRDS(object=M_sos, file="dcp.rds")
> >>> dat <- XML::readHTMLTable(M_sos)
> >>> idx <- 2:length(dat)
> >>> cn <- unique(unlist(lapply(dat[idx], colnames)))
> >> This is useful for this application.
> >>
> >>> dat <- do.call(rbind,
> >>>   sapply(idx, function(i, dat, cn) {
> >>> x <- dat[[i]]
> >>> x[,cn[!(cn %in% colnames(x))]] <- NA
> >>> x <- x[,cn]
> >>> x$Party <- names(dat)[i]
> >>> return(list(x))
> >>>   }, dat=dat, cn=cn))
> >>> dat[,"Date Filed"] <-
> >>>   as.Date(x=dat[,"Date Filed"],
> >>>   format="%m/%d/%Y")
> >> This misses something extremely
> >> important for this application:?  The
> >> political office.? That's buried in
> >> the HTML or whatever it is.? I'm using
> >> something like the following to find
> >> that:
> >>
> >> str(LtGov <- gregexpr('Lieutenant Governor', M_sos)[[1]])
> > Dear Spencer,
> >
> > I came up with a solution, but it is not
> > very elegant.  Instead of showing you
> > the solution, hoping you understand
> > everything in it, I istead want to give
> > you some emphatic hints to see if you
> > can come up with a solution on you own.
> >
> > - XML::htmlTreeParse(M_sos)
> >- *Gandalf voice*: climb the tree
> >  until you find the content you are
> >  looking for flat out at the level of
> >  «The Children of the Div», *uuuUUU*
> >- you only want to keep the table and
> >  header tags at this level
> > - Use XML::xmlValue to extract the
> >values of all the headers (the
> >political positions)
> > - Observe that all the tables on the
> >page you were able to extract
> >previously using XML::readHTMLTable,
> >are at this level, shuffled between
> >the political position header tags,
> >this means you extract the political
> >position and party affiliation by
> >using a for loop, if statements,
> >typeof, names, and [] and [[]] to grab
> >different things from the list
> >(content or the bag itself).
> >XML::readHTMLTable strips away the
> >line break tags from the Mailing
> >address, so if you find a better way
> >of extracting the tables, tell me,
> >e.g. you get
> >
> >   8805 HUNTER AVEKANSAS CITY MO 64138
> >
> >and not
> >
> >   8805 HUNTER AVEKANSAS CITY MO 64138
> >
> > When you've completed this «programming
> > quest», you're back at the level of the
> > previous email, i.e.  you have have the
> > same tables, but with political position
> > and party affiliation added to them.
>
>
>Please excuse:  Before my last post, I had written code to do all
> that.  In brief, the political offices are "h3" tags.  I used "strsplit"
> to split the string at "".  I then wrote a function to find "",
> extract the political office and pass the rest to "XML::readHTMLTable",
> adding columns for party and political office.
>
>
>However, this suppressed "" everywhere.  I thought there
> should be an

Re: [R] help with web scraping

2020-07-23 Thread William Michels via R-help
Hi Spencer,

I tried the code below on an older R-installation, and it works fine.
Not a full solution, but it's a start:

> library(RCurl)
Loading required package: bitops
> url <- 
> "https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975";
> M_sos <- getURL(url)
> print(M_sos)
[1] "\r\n\r\n\r\n\r\n\r\n\tSOS, Missouri - Elections:
Offices Filed in Candidate Filing\r\n wrote:
>
> Hello, All:
>
>
>I've failed with multiple attempts to scrape the table of
> candidates from the website of the Missouri Secretary of State:
>
>
> https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975
>
>
>I've tried base::url, base::readLines, xml2::read_html, and
> XML::readHTMLTable; see summary below.
>
>
>Suggestions?
>Thanks,
>Spencer Graves
>
>
> sosURL <-
> "https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975";
>
> str(baseURL <- base::url(sosURL))
> # this might give me something, but I don't know what
>
> sosRead <- base::readLines(sosURL) # 404 Not Found
> sosRb <- base::readLines(baseURL) # 404 Not Found
>
> sosXml2 <- xml2::read_html(sosURL) # HTTP error 404.
>
> sosXML <- XML::readHTMLTable(sosURL)
> # List of 0;  does not seem to be XML
>
> sessionInfo()
>
> R version 4.0.2 (2020-06-22)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Catalina 10.15.5
>
> Matrix products: default
> BLAS:
> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets
> [6] methods   base
>
> loaded via a namespace (and not attached):
> [1] compiler_4.0.2 tools_4.0.2curl_4.3
> [4] xml2_1.3.2 XML_3.99-0.3
>
> __
> 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] Looping thorugh dataframe

2020-07-22 Thread William Dunlap via R-help
> library(dplyr, warn.conflicts=FALSE)
> d <- data.frame(Company=c("MATH","IFUL","SSI","MATH","MATH","SSI"), 
> Turnover=c(2,3,5,7,9,11))
> d %>% group_by(Company) %>% summarize(Count=n(), MeanTurnover=mean(Turnover), 
> TotalTurnover=sum(Turnover))
`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 3 x 4
  Company Count MeanTurnover TotalTurnover
  
1 IFUL13 3
2 MATH3618
3 SSI 2816

[The 'override with .groups' comment arose in a recent version of
dplyr.  It is a bit annoying.]

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Jul 22, 2020 at 4:36 PM e-mail ma015k3113 via R-help
 wrote:
>
> Bert, thanks for responding to my email. I do realise that newbie's like my 
> can expect curt answers but not to worry. I am definitely learning 'R' and 
> what I posted are also statements from R. The statements run perfectly well 
> but don't do what I want them to do. My mistake I have posted sample data. 
> Here is the data:
>
> COMPANY_NUMBER  COMPANY_NAMEYEAR_END_DATE   Turnover
> 22705   AA  30/09/10420,000
> 22705   AA  30/09/09406,000
> 113560  BB  30/06/19474,000
> 192761  CC  31/01/19796,000
> 192761  CC  31/01/18909,000
> 192761  CC  31/01/17788,000
> 5625107 DD  30/06/193,254,002
> 5625107 DD  30/06/181,840,436
>
> All_companies$count <-0
> while All_companies$COMPANY_NAME == All_companies$COMPANY_NAME + 1
> + {All_companies$count=All_companies$count+1}
>
> I want to find out many times each company has appeared in the dataframe and 
> the average of the turnover for the years. Like company AA appears twice and 
> average turnover is 413,000.
>
> 'All_companies' is the name of the dataframe.
>
> In the end apologies for not being more clear the first time around and of 
> course many thanks for your help in advance.
>
> Kind regards
>
>
> Ahson
>
> On 21 July 2020 at 18:41 Bert Gunter  wrote:
>
> What language are you programming in? -- it certainly isn't R.
>
> I suggest that you stop what you're doing and go through an R tutorial or two 
> before proceeding. This list cannot serve as a substitute for doing such 
> homework (is this homework, btw? -- that's off topic here) nor can we provide 
> such tutorials.
>
> I'm pretty sure the answer is quite simple, though it's a bit unclear as you 
> did not provide a reprex (see the posting guide linked below for how to post 
> here). However, I see no purpose in my blurting it out when you do not seem 
> aware of even the most basic R constructs -- e.g. see ?while. Of course, 
> others may disagree and provide you what you seek.
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> __
> 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] Help with read.csv.sql()

2020-07-18 Thread William Michels via R-help
Do either of the postings/threads below help?

https://r.789695.n4.nabble.com/read-csv-sql-to-select-from-a-large-csv-file-td4650565.html#a4651534
https://r.789695.n4.nabble.com/using-sqldf-s-read-csv-sql-to-read-a-file-with-quot-NA-quot-for-missing-td4642327.html

Otherwise you can try reading through the FAQ on Github:

https://github.com/ggrothendieck/sqldf

HTH, Bill.

W. Michels, Ph.D.



On Sat, Jul 18, 2020 at 9:59 AM H  wrote:
>
> On 07/18/2020 11:54 AM, Rui Barradas wrote:
> > Hello,
> >
> > I don't believe that what you are asking for is possible but like Bert 
> > suggested, you can do it after reading in the data.
> > You could write a convenience function to read the data, then change what 
> > you need to change.
> > Then the function would return this final object.
> >
> > Rui Barradas
> >
> > Às 16:43 de 18/07/2020, H escreveu:
> >
> >> On 07/17/2020 09:49 PM, Bert Gunter wrote:
> >>> Is there some reason that you can't make the changes to the data frame 
> >>> (column names, as.date(), ...) *after* you have read all your data in?
> >>>
> >>> Do all your csv files use the same names and date formats?
> >>>
> >>>
> >>> Bert Gunter
> >>>
> >>> "The trouble with having an open mind is that people keep coming along 
> >>> and sticking things into it."
> >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>>
> >>>
> >>> On Fri, Jul 17, 2020 at 6:28 PM H  >>> > wrote:
> >>>
> >>>  I have created a dataframe with columns that are characters, 
> >>> integers and numeric and with column names assigned by me. I am using 
> >>> read.csv.sql() to read portions of a number of large csv files into this 
> >>> dataframe, each csv file having a header row with columb names.
> >>>
> >>>  The problem I am having is that the csv files have header rows with 
> >>> column names that are slightly different from the column names I have 
> >>> assigned in the dataframe and it seems that when I read the csv data into 
> >>> the dataframe, the column names from the csv file replace the column 
> >>> names I chose when creating the dataframe.
> >>>
> >>>  I have been unable to figure out if it is possible to assign column 
> >>> names of my choosing in the read.csv.sql() function? I have tried various 
> >>> variations but none seem to work. I tried colClasses = c() but that 
> >>> did not work, I tried field.types = c(...) but could not get that to work 
> >>> either.
> >>>
> >>>  It seems that the above should be feasible but I am missing 
> >>> something? Does anyone know?
> >>>
> >>>  A secondary issue is that the csv files have a column with a date in 
> >>> mm/dd/ format that I would like to make into a Date type column in my 
> >>> dataframe. Again, I have been unable to find a way - if at all possible - 
> >>> to force a conversion into a Date format when importing into the 
> >>> dataframe. The best I have so far is to import is a character column and 
> >>> then use as.Date() to later force the conversion of the dataframe column.
> >>>
> >>>  Is it possible to do this when importing using read.csv.sql()?
> >>>
> >>>  __
> >>>  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.
> >>>
> >> Yes, the files use the same column names and date format (at least as far 
> >> as I know now.) I agree I could do it as you suggest above but from a 
> >> purist perspective I would rather do it when importing the data using 
> >> read.csv.sql(), particularly if column names and/or date format might 
> >> change, or be different between different files. I am indeed selecting 
> >> rows from a large number of csv files so this is entirely plausible.
> >>
> >> Has anyone been able to name columns in the read.csv.sql() call and/or 
> >> force date format conversion in the call itself? The first refers to 
> >> naming columns differently from what a header in the csv file may have.
> >>
> >>
> >> [[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.
> >
> The documentation for read.csv.sql() suggests that colClasses() and/or 
> field.types() should work but I may well have misunderstood the 
> documentation, hence my question in this group.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-

Re: [R] Character (1a, 1b) to numeric

2020-07-11 Thread William Michels via R-help
Agreed, I meant to add this line (for unclassed factor levels 1-through-8):

> ((1:8 - 1)*(0.25))+1
[1] 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75

Depending on the circumstance, you can also consider using dummy
factors or even "NA" as a level; see the "factor" help page for
details.

Best, Bill.

W. Michels, Ph.D.



On Sat, Jul 11, 2020 at 12:16 AM Jean-Louis Abitbol  wrote:
>
> Hello Bill,
>
> Thanks.
>
> That has indeed the advantage of keeping the histology classification on the  
> plot instead of some arbitrary numeric scale.
>
> Best wishes, JL
>
> On Sat, Jul 11, 2020, at 8:25 AM, William Michels wrote:
> > Hello Jean-Louis,
> >
> > Noting the subject line of your post I thought the first answer would
> > have been encoding histology stages as factors, and "unclass-ing" them
> > to obtain integers that then can be mathematically manipulated. You
> > can get a lot of work done with all the commands listed on the
> > "factor" help page:
> >
> > ?factor
> > samples <- 1:36
> > values <- runif(length(samples), min=1, max=length(samples))
> > hist <- rep(c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c"), times=1:8)
> > data1 <- data.frame("samples" = samples, "values" = values, "hist" = hist )
> > (data1$hist <- factor(data1$hist, levels=c("1", "1a", "1b", "1c", "2",
> > "2a", "2b", "2c")) )
> > unclass(data1$hist)
> >
> > library(RColorBrewer); pal_1 <- brewer.pal(8, "Pastel2")
> > barplot(data1$value, beside=T, col=pal_1[data1$hist])
> > plot(data1$hist, data1$value, col=pal_1)
> > pal_2 <- brewer.pal(8, "Dark2")
> > plot(unclass(data1$hist)/4, data1$value, pch=19, col=pal_2[data1$hist] )
> > group <- c(rep(0,10),rep(1,26)); data1$group <- group
> > library(lattice); dotplot(hist ~ values | group, data=data1, xlim=c(0,36) )
> >
> > HTH, Bill.
> >
> > W. Michels, Ph.D.
> >
> >
> >
> >
> > On Fri, Jul 10, 2020 at 1:41 PM Jean-Louis Abitbol  wrote:
> > >
> > > Many thanks to all. This help-list is wonderful.
> > >
> > > I have used Rich Heiberger solution using match and found something to 
> > > learn in each answer.
> > >
> > > off topic, I also enjoyed very much his 2008 paper on the graphical 
> > > presentation of safety data
> > >
> > > Best wishes.
> > >
> > >
> > > On Fri, Jul 10, 2020, at 10:02 PM, Fox, John wrote:
> > > > Hi,
> > > >
> > > > We've had several solutions, and I was curious about their relative
> > > > efficiency. Here's a test with a moderately large data vector:
> > > >
> > > > > library("microbenchmark")
> > > > > set.seed(123) # for reproducibility
> > > > > x <- sample(xc, 1e4, replace=TRUE) # "data"
> > > > > microbenchmark(John = John <- xn[x],
> > > > +Rich = Rich <- xn[match(x, xc)],
> > > > +Jeff = Jeff <- {
> > > > + n <- as.integer( sub( "[a-i]$", "", x ) )
> > > > + d <- match( sub( "^\\d+", "", x ), letters[1:9] )
> > > > + d[ is.na( d ) ] <- 0
> > > > + n + d / 10
> > > > + },
> > > > +David = David <- as.numeric(gsub("a", ".3",
> > > > +  gsub("b", ".5",
> > > > +   gsub("c", ".7", x,
> > > > +times=1000L
> > > > +)
> > > > Unit: microseconds
> > > >   expr   minlq   mean median uq   max 
> > > > neval cld
> > > >   John   228.816   345.371   513.5614   503.5965   533.0635  10829.08  
> > > > 1000 a
> > > >   Rich   217.395   343.035   534.2074   489.0075   518.3260  15388.96  
> > > > 1000 a
> > > >   Jeff 10325.471 13070.737 15387.2545 15397.9790 17204.0115 153486.94  
> > > > 1000  b
> > > >  David 14256.673 18148.492 20185.7156 20170.3635 22067.6690  34998.95  
> > > > 1000   c
> > > > > all.equal(John, Rich)
> >

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread William Michels via R-help
Hello Jean-Louis,

Noting the subject line of your post I thought the first answer would
have been encoding histology stages as factors, and "unclass-ing" them
to obtain integers that then can be mathematically manipulated. You
can get a lot of work done with all the commands listed on the
"factor" help page:

?factor
samples <- 1:36
values <- runif(length(samples), min=1, max=length(samples))
hist <- rep(c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c"), times=1:8)
data1 <- data.frame("samples" = samples, "values" = values, "hist" = hist )
(data1$hist <- factor(data1$hist, levels=c("1", "1a", "1b", "1c", "2",
"2a", "2b", "2c")) )
unclass(data1$hist)

library(RColorBrewer); pal_1 <- brewer.pal(8, "Pastel2")
barplot(data1$value, beside=T, col=pal_1[data1$hist])
plot(data1$hist, data1$value, col=pal_1)
pal_2 <- brewer.pal(8, "Dark2")
plot(unclass(data1$hist)/4, data1$value, pch=19, col=pal_2[data1$hist] )
group <- c(rep(0,10),rep(1,26)); data1$group <- group
library(lattice); dotplot(hist ~ values | group, data=data1, xlim=c(0,36) )

HTH, Bill.

W. Michels, Ph.D.




On Fri, Jul 10, 2020 at 1:41 PM Jean-Louis Abitbol  wrote:
>
> Many thanks to all. This help-list is wonderful.
>
> I have used Rich Heiberger solution using match and found something to learn 
> in each answer.
>
> off topic, I also enjoyed very much his 2008 paper on the graphical 
> presentation of safety data
>
> Best wishes.
>
>
> On Fri, Jul 10, 2020, at 10:02 PM, Fox, John wrote:
> > Hi,
> >
> > We've had several solutions, and I was curious about their relative
> > efficiency. Here's a test with a moderately large data vector:
> >
> > > library("microbenchmark")
> > > set.seed(123) # for reproducibility
> > > x <- sample(xc, 1e4, replace=TRUE) # "data"
> > > microbenchmark(John = John <- xn[x],
> > +Rich = Rich <- xn[match(x, xc)],
> > +Jeff = Jeff <- {
> > + n <- as.integer( sub( "[a-i]$", "", x ) )
> > + d <- match( sub( "^\\d+", "", x ), letters[1:9] )
> > + d[ is.na( d ) ] <- 0
> > + n + d / 10
> > + },
> > +David = David <- as.numeric(gsub("a", ".3",
> > +  gsub("b", ".5",
> > +   gsub("c", ".7", x,
> > +times=1000L
> > +)
> > Unit: microseconds
> >   expr   minlq   mean median uq   max neval 
> > cld
> >   John   228.816   345.371   513.5614   503.5965   533.0635  10829.08  1000 
> > a
> >   Rich   217.395   343.035   534.2074   489.0075   518.3260  15388.96  1000 
> > a
> >   Jeff 10325.471 13070.737 15387.2545 15397.9790 17204.0115 153486.94  1000 
> >  b
> >  David 14256.673 18148.492 20185.7156 20170.3635 22067.6690  34998.95  1000 
> >   c
> > > all.equal(John, Rich)
> > [1] TRUE
> > > all.equal(John, David)
> > [1] "names for target but not for current"
> > > all.equal(John, Jeff)
> > [1] "names for target but not for current" "Mean relative difference:
> > 0.1498243"
> >
> > Of course, efficiency isn't the only consideration, and aesthetically
> > (and no doubt subjectively) I prefer Rich Heiberger's solution. OTOH,
> > Jeff's solution is more general in that it generates the correspondence
> > between letters and numbers. The argument for Jeff's solution would,
> > however, be stronger if it gave the desired answer.
> >
> > Best,
> >  John
> >
> > > On Jul 10, 2020, at 3:28 PM, David Carlson  wrote:
> > >
> > > Here is a different approach:
> > >
> > > xc <-  c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c")
> > > xn <- as.numeric(gsub("a", ".3", gsub("b", ".5", gsub("c", ".7", xc
> > > xn
> > > # [1] 1.0 1.3 1.5 1.7 2.0 2.3 2.5 2.7
> > >
> > > David L Carlson
> > > Professor Emeritus of Anthropology
> > > Texas A&M University
> > >
> > > On Fri, Jul 10, 2020 at 1:10 PM Fox, John  wrote:
> > > Dear Jean-Louis,
> > >
> > > There must be many ways to do this. Here's one simple way (with no claim 
> > > of optimality!):
> > >
> > > > xc <-  c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c")
> > > > xn <- c(1, 1.3, 1.5, 1.7, 2, 2.3, 2.5, 2.7)
> > > >
> > > > set.seed(123) # for reproducibility
> > > > x <- sample(xc, 20, replace=TRUE) # "data"
> > > >
> > > > names(xn) <- xc
> > > > z <- xn[x]
> > > >
> > > > data.frame(z, x)
> > >  z  x
> > > 1  2.5 2b
> > > 2  2.5 2b
> > > 3  1.5 1b
> > > 4  2.3 2a
> > > 5  1.5 1b
> > > 6  1.3 1a
> > > 7  1.3 1a
> > > 8  2.3 2a
> > > 9  1.5 1b
> > > 10 2.0  2
> > > 11 1.7 1c
> > > 12 2.3 2a
> > > 13 2.3 2a
> > > 14 1.0  1
> > > 15 1.3 1a
> > > 16 1.5 1b
> > > 17 2.7 2c
> > > 18 2.0  2
> > > 19 1.5 1b
> > > 20 1.5 1b
> > >
> > > I hope this helps,
> > >  John
> > >
> > >   -
> > >   John Fox, Professor Emeritus
> > >   McMaster University
> > >   Hamilton, Ontario, Canada
> > >   Web: http::/socserv.mcmaster.ca/jfox
> > >
> > > > On Jul 10, 2020, at 1:50 PM, Jean-Louis Abitbol  
> > > > wrote:

Re: [R] R Compied for Mac OS X

2020-06-25 Thread William Michels via R-help
Hi, you can try starting at the link below:

https://stat.ethz.ch/R-manual/R-patched/doc/html/packages.html

Or type any of following commands into your R-Console (for starters):

> library()
> library(help="base")
> library(help="stats")
> library(help="graphics")
> library(help="grDevices")
> library(help="utils")
> library(help="datasets")
> library(help="methods")
>

HTH, Bill.

W. Michels, Ph.D.

On Thu, Jun 25, 2020 at 4:09 PM Gregory Coats via R-help
 wrote:
>
> Today, I downloaded, and installed the June 6, 2020 version of R, from the 
> CRAN official site at Carnegie Mellon University. Unfortunately, while the 
> CMU compiled Mac OS X R application provides access to base R stat functions, 
> like mean, it does not provide me with access to any of R’s more advanced 
> functions like movavg, and ggplot.
> From where can I download a more complete R executable, compiled for Mac OS X?
> Greg Coats
>
> http://lib.stat.cmu.edu/R/CRAN/ 
> Download R for (Mac) OS X
> R-4.0.2.pkg (notarized and signed)
> > version
> platform   x86_64-apple-darwin17.0
> arch   x86_64
> os darwin17.0
> system x86_64, darwin17.0
> status
> major  4
> minor  0.1
> year   2020
> month  06
> day06
> svn rev78648
> language   R
> version.string R version 4.0.1 (2020-06-06)
> nickname   See Things Now
> > mean
> function (x, ...)
> UseMethod("mean")
> 
> 
> > movavg
> Error: object 'movavg' not found
> > ggplot
> Error: object 'ggplot' not found
> >
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] How to convert column from millisecond epoch time to yyyy-mm-dd GMT

2020-06-23 Thread William Dunlap via R-help
When you give an example it really helps to (a) show the data as the output
of dput() or dump() so one can copy and paste into R and (b) show the
result (the wrong value or error message) that you got.

You example is missing some quotes and has an unneeded call to lapply().

> dump("Data", file=stdout())
Data <-
structure(list(Id = c("INCBR0005072277", "INCBR0005073034",
"INCBR0005073131",
"INCBR0005074186", "INCBR0005074188"), Timestamp = c(157705920,
157705920, 157705920, 157705920, 157705920),
`Data Type` = c("itsm-ticket", "itsm-ticket", "itsm-ticket",
"itsm-ticket", "itsm-ticket"), Visibility = c("U&FOUO&USA",
"U&FOUO&USA", "U&FOUO&USA", "U&FOUO&USA", "U&FOUO&USA"),
TYPE_SERVER = c(0L, 1L, 0L, 0L, 0L)), row.names = c(NA, -5L
), class = "data.frame")
> str(as.POSIXct(Data$Timestamp/1000,
origin=as.POSIXct("1970-01-01",tz="UTC"), tz="UTC"))
 POSIXct[1:5], format: "2019-12-23" "2019-12-23" "2019-12-23" "2019-12-23"
"2019-12-23"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jun 23, 2020 at 11:24 AM Gregg via R-help 
wrote:

> Hello to all the smart people out there
>
> I have a data.frame labeled itsm_service_type_field. I need to convert the
> Timestamp field which is epoch time in milliseconds to a -mm-dd GMT
> Date.
>
> Data.frame format is below.
>
> I've attempted to use the lapply and as.POSIXct functions to convert the
> time field in the original data.frame to a new data.frame I've labeled
> "itsm_service_type_field_adjusted_time",
> but I've got the order and syntax wrong.
>
> Help would be so much appreciated.
>
> Thanks in advance.
> Gregg
> Arizona
>
> Details - See Below:
>
> itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv")
>
> >???itsm_service_type_field_adjusted_time <-
> lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp,
> origin="1970-01-01", tz="GMT"))
>
> head(itsm_service_type_field)
> Id  Timestamp Data Type
> Visibility  TYPE_SERVICE
> 1: INCBR0005072277 157705920 itsm-ticket U&FOUO&USA0
> 2: INCBR0005073034 157705920 itsm-ticket U&FOUO&USA1
> 3: INCBR0005073131 157705920 itsm-ticket U&FOUO&USA0
> 4: INCBR0005074186 157705920 itsm-ticket U&FOUO&USA0
> 5: INCBR0005074188 157705920 itsm-ticket U&FOUO&USA0
> 6: INCBR0005074546 157705920 itsm-ticket U&FOUO&USA
> 0__
> 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] Strange behavior when sampling rows of a data frame

2020-06-19 Thread William Dunlap via R-help
It is a bug that has been present in R since at least R-2.14.0 (the oldest
that I have installed on my laptop).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 19, 2020 at 10:37 AM Rui Barradas  wrote:

> Hello,
>
>
> Thanks, I hadn't thought of that.
>
> But, why? Is it evaluated once before assignment and a second time when
> the assignment occurs?
>
> To trace both sample and `[<-` gives 2 calls to sample.
>
>
> trace(sample)
> trace(`[<-`)
> df[sample(nrow(df), 3),]$treated <- TRUE
> trace: sample(nrow(df), 3)
> trace: `[<-`(`*tmp*`, sample(nrow(df), 3), , value = list(unit = c(7L,
> 6L, 8L), treated = c(TRUE, TRUE, TRUE)))
> trace: sample(nrow(df), 3)
>
>
> Regards,
>
> Rui Barradas
>
>
> Às 17:20 de 19/06/2020, William Dunlap escreveu:
> > The first subscript argument is getting evaluated twice.
> > > trace(sample)
> > > set.seed(2020); df[i<-sample(10,3), ]$Treated <- TRUE
> > trace: sample(10, 3)
> > trace: sample(10, 3)
> > > i
> > [1]  1 10  4
> > > set.seed(2020); sample(10,3)
> > trace: sample(10, 3)
> > [1] 7 6 8
> > > sample(10,3)
> > trace: sample(10, 3)
> > [1]  1 10  4
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com <http://tibco.com>
> >
> >
> > On Fri, Jun 19, 2020 at 8:46 AM Rui Barradas  > <mailto:ruipbarra...@sapo.pt>> wrote:
> >
> > Hello,
> >
> > I don't have an answer on the reason why this happens but it seems
> > like
> > a bug. Where?
> >
> > In which of  `[<-.data.frame` or `[<-.default`?
> >
> > A solution is to subset and assign the vector:
> >
> >
> > set.seed(2020)
> > df2 <- data.frame(unit = 1:10)
> > df2$treated <- FALSE
> >
> > df2$treated[sample(nrow(df2), 3)] <- TRUE
> > df2
> > #  unit treated
> > #1 1   FALSE
> > #2 2   FALSE
> > #3 3   FALSE
> > #4 4   FALSE
> > #5 5   FALSE
> > #6 6TRUE
> > #7 7TRUE
> > #8 8TRUE
> > #9 9   FALSE
> > #10   10   FALSE
> >
> >
> > Or
> >
> >
> > set.seed(2020)
> > df3 <- data.frame(unit = 1:10)
> > df3$treated <- FALSE
> >
> > df3[sample(nrow(df3), 3), "treated"] <- TRUE
> > df3
> > # result as expected
> >
> >
> > Hope this helps,
> >
> > Rui  Barradas
> >
> >
> >
> > Às 13:49 de 19/06/2020, Sébastien Lahaie escreveu:
> > > I ran into some strange behavior in R when trying to assign a
> > treatment to
> > > rows in a data frame. I'm wondering whether any R experts can
> > explain
> > > what's going on.
> > >
> > > First, let's assign a treatment to 3 out of 10 rows as follows.
> > >
> > >> df <- data.frame(unit = 1:10)
> > >> df$treated <- FALSE
> > >> s <- sample(nrow(df), 3)
> > >> df[s,]$treated <- TRUE
> > >> df
> > > unit treated
> > >
> > > 1 1   FALSE
> > >
> > > 2 2TRUE
> > >
> > > 3 3   FALSE
> > >
> > > 4 4   FALSE
> > >
> > > 5 5TRUE
> > >
> > > 6 6   FALSE
> > >
> > > 7 7TRUE
> > >
> > > 8 8   FALSE
> > >
> > > 9 9   FALSE
> > >
> > > 10   10   FALSE
> > >
> > > This is as expected. Now we'll just skip the intermediate step
> > of saving
> > > the sampled indices, and apply the treatment directly as follows.
> > >
> > >> df <- data.frame(unit = 1:10)
> > >> df$treated <- FALSE
> > >> df[sample(nrow(df), 3),]$treated <- TRUE
> > >> df
> > > unit treated
> > >
> > > 1 6TRUE
> > >
> > > 2 2   FALSE
> > >
> > > 3 3   FALSE
> > >
> > > 4 9TRUE
> > >
> > > 5 5   FALSE
> > >
> > > 6 6   FALSE
> > >
> > > 7 7   FALSE
> > >
> > >

Re: [R] Strange behavior when sampling rows of a data frame

2020-06-19 Thread William Dunlap via R-help
The first subscript argument is getting evaluated twice.
> trace(sample)
> set.seed(2020); df[i<-sample(10,3), ]$Treated <- TRUE
trace: sample(10, 3)
trace: sample(10, 3)
> i
[1]  1 10  4
> set.seed(2020); sample(10,3)
trace: sample(10, 3)
[1] 7 6 8
> sample(10,3)
trace: sample(10, 3)
[1]  1 10  4

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 19, 2020 at 8:46 AM Rui Barradas  wrote:

> Hello,
>
> I don't have an answer on the reason why this happens but it seems like
> a bug. Where?
>
> In which of  `[<-.data.frame` or `[<-.default`?
>
> A solution is to subset and assign the vector:
>
>
> set.seed(2020)
> df2 <- data.frame(unit = 1:10)
> df2$treated <- FALSE
>
> df2$treated[sample(nrow(df2), 3)] <- TRUE
> df2
> #  unit treated
> #1 1   FALSE
> #2 2   FALSE
> #3 3   FALSE
> #4 4   FALSE
> #5 5   FALSE
> #6 6TRUE
> #7 7TRUE
> #8 8TRUE
> #9 9   FALSE
> #10   10   FALSE
>
>
> Or
>
>
> set.seed(2020)
> df3 <- data.frame(unit = 1:10)
> df3$treated <- FALSE
>
> df3[sample(nrow(df3), 3), "treated"] <- TRUE
> df3
> # result as expected
>
>
> Hope this helps,
>
> Rui  Barradas
>
>
>
> Às 13:49 de 19/06/2020, Sébastien Lahaie escreveu:
> > I ran into some strange behavior in R when trying to assign a treatment
> to
> > rows in a data frame. I'm wondering whether any R experts can explain
> > what's going on.
> >
> > First, let's assign a treatment to 3 out of 10 rows as follows.
> >
> >> df <- data.frame(unit = 1:10)
> >> df$treated <- FALSE
> >> s <- sample(nrow(df), 3)
> >> df[s,]$treated <- TRUE
> >> df
> > unit treated
> >
> > 1 1   FALSE
> >
> > 2 2TRUE
> >
> > 3 3   FALSE
> >
> > 4 4   FALSE
> >
> > 5 5TRUE
> >
> > 6 6   FALSE
> >
> > 7 7TRUE
> >
> > 8 8   FALSE
> >
> > 9 9   FALSE
> >
> > 10   10   FALSE
> >
> > This is as expected. Now we'll just skip the intermediate step of saving
> > the sampled indices, and apply the treatment directly as follows.
> >
> >> df <- data.frame(unit = 1:10)
> >> df$treated <- FALSE
> >> df[sample(nrow(df), 3),]$treated <- TRUE
> >> df
> > unit treated
> >
> > 1 6TRUE
> >
> > 2 2   FALSE
> >
> > 3 3   FALSE
> >
> > 4 9TRUE
> >
> > 5 5   FALSE
> >
> > 6 6   FALSE
> >
> > 7 7   FALSE
> >
> > 8 5TRUE
> >
> > 9 9   FALSE
> >
> > 10   10   FALSE
> >
> > Now the data frame still has 10 rows with 3 assigned to the treatment.
> But
> > the units are garbled. Units 1 and 4 have disappeared, for instance, and
> > there are duplicates for 6 and 9, one assigned to treatment and the other
> > to control. Why would this happen?
> >
> > Thanks,
> > Sebastien
> >
> >   [[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.
>
> --
> Este e-mail foi verificado em termos de vírus pelo software antivírus
> Avast.
> https://www.avast.com/antivirus
>
> __
> 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] Error in gee.fit$working.correlation[1, 2] : subscript out of bounds

2020-06-05 Thread William Dunlap via R-help
The usual reason for the 'subscript out of bounds' error is that an array's
subscripts exceed the dimensions of the array.  In this case
gee.fit$working.correlation is a 1 by 1 matrix, so subscripting with [1,2]
will cause the error.

Here is a self-contained example that you can send the package's maintainer.

> maintainer("geesmv")
[1] "Zheng Li "

> dx <- cbind(id=1:18, y=sin(1:18), expand.grid(period=c(1.1,1.2,1.3),
Ijt=c("i","ii","iii"))[c(1:9,1:9),])
> options(error=recover)
> test <- GEE.var.fg(y ~ factor(period) +
factor(Ijt),id="id",family=gaussian, dx,corstr="exchangeable")
Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27
running glm to get initial regression estimate
  (Intercept) factor(period)1.2 factor(period)1.3 factor(Ijt)ii
   0.02712257   -0.06015777   -0.115557840.04243596
   factor(Ijt)iii
   0.04114518
Error in gee.fit$working.correlation[1, 2] : subscript out of bounds

Enter a frame number, or 0 to exit

1: GEE.var.fg(y ~ factor(period) + factor(Ijt), id = "id", family =
gaussian,

Selection: 1
Called from: top level
Browse[1]> str(gee.fit$working.correlation)
 num [1, 1] 1

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 5, 2020 at 12:28 AM Phat Chau 
wrote:

> Hello,
>
> I have a dataframe in R that looks like the following
>
>   cluster id period   u_3 timeID startTrt Ijterror  y
> 1:   1  1  0 -1.26  11   0   1.2015 17.809
> 2:   1  2  0 -1.26  11   0  -1.6577 14.950
> 3:   1  3  0 -1.26  11   0  -3.8639 12.744
> 4:   1  4  0 -1.26  11   0   1.4978 18.105
> 5:   1  5  0 -1.26  11   0  -5.3182 11.289
>
> When I try to run a gee model on it using the geesmv package which adjusts
> the variance covariance matrix for small sample sizes as follows
>
> test <- GEE.var.fg(y ~ factor(period) +
> factor(Ijt),id="id",family=gaussian, dx,corstr="exchangeable")
>
> I get this error message:
>
> Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27
> running glm to get initial regression estimate
> (Intercept) factor(period)1 factor(period)2 factor(period)3
> factor(period)4 factor(period)5factor(Ijt)1
>   17.25   -8.27   -6.47   -9.13
>  -8.17  -11.898.96
> Error in gee.fit$working.correlation[1, 2] : subscript out of bounds
>
> I think the usual culprit for this kind of error message is that the
> variable being referred to (id in this case I assume) is non-existent. That
> is clearly not the case here and I checked to make sure it is it not a typo.
>
> Does anyone know why this is? How would I troubleshoot this?
>
> Thank you,
> Edward
>
>
> [[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] na.omit not omitting rows

2020-06-04 Thread William Dunlap via R-help
Does droplevels() help?

> d <- data.frame(size = factor(c("S","M","M","L","L"),
levels=c("S","M","L")), id=c(101,NA,NA,104,105))
> str(d)
'data.frame':   5 obs. of  2 variables:
 $ size: Factor w/ 3 levels "S","M","L": 1 2 2 3 3
 $ id  : num  101 NA NA 104 105
> str(na.omit(d))
'data.frame':   3 obs. of  2 variables:
 $ size: Factor w/ 3 levels "S","M","L": 1 3 3
 $ id  : num  101 104 105
 - attr(*, "na.action")= 'omit' Named int [1:2] 2 3
  ..- attr(*, "names")= chr [1:2] "2" "3"
> str(droplevels(na.omit(d)))
'data.frame':   3 obs. of  2 variables:
 $ size: Factor w/ 2 levels "S","L": 1 2 2
 $ id  : num  101 104 105
 - attr(*, "na.action")= 'omit' Named int [1:2] 2 3
  ..- attr(*, "names")= chr [1:2] "2" "3"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jun 4, 2020 at 12:18 PM Ted Stankowich <
theodore.stankow...@csulb.edu> wrote:

> Hello! I'm trying to create a subset of a dataset and then remove all rows
> with NAs in them. Ultimately, I am running phylogenetic analyses with trees
> that require the tree tiplabels to match exactly with the rows in the
> dataframe. But when I use na.omit to delete the rows with NAs, there is
> still a trace of those omitted rows in the data.frame, which then causes an
> error in the phylogenetic analyses. Is there any way to completely scrub
> those omitted rows from the dataframe? The code is below. As you can see
> from the result of the final str(Protect1) line, there are attributes with
> the omitted features still in the dataframe (356 species names in the
> UphamComplBinomial factor, but only 319 observations). These traces are
> causing errors with the phylo analyses.
>
> > Protect1=as.data.frame(cbind(UphamComplBinomial, DarkEum, NoctCrep,
> Shade))  #Create the dataframe with variables of interest from an attached
> dataset
> > row.names(Protect1)=Protect1$UphamComplBinomial #assign species names as
> rownames
> > Protect1=as.data.frame(na.omit(Protect1)) #drop rows with missing data
> > str(Protect1)
> 'data.frame': 319 obs. of  4 variables:
>  $ UphamComplBinomial: Factor w/ 356 levels
> "Allenopithecus_nigroviridis_CERCOPITHECIDAE_PRIMATES",..: 1 2 3 4 5 8 9 10
> 11 12 ...
>  $ DarkEum   : Factor w/ 2 levels "0","1": 2 1 2 2 2 2 2 2 2 2 ...
>  $ NoctCrep  : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 1 1 1 ...
>  $ Shade : Factor w/ 59 levels "0.1","0.2","0.25",..: 10 58 53
> 17 49 52 52 39 39 41 ...
>  - attr(*, "na.action")= 'omit' Named int  6 7 23 36 37 40 42 50 51 60 ...
>   ..- attr(*, "names")= chr  "Alouatta_macconnelli_ATELIDAE_PRIMATES"
> "Alouatta_nigerrima_ATELIDAE_PRIMATES" "Ateles_fusciceps_ATELIDAE_PRIMATES"
> "Callicebus_baptista_PITHECIIDAE_PRIMATES" ...
>
> Dr. Ted Stankowich
> Associate Professor
> Department of Biological Sciences
> California State University Long Beach
> Long Beach, CA 90840
> theodore.stankow...@csulb.edu
> 562-985-4826
> http://www.csulb.edu/mammal-lab/
> @CSULBMammalLab
>
>
>
>
> [[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] how to filter variables which appear in any row but do not include

2020-06-03 Thread William Michels via R-help
#Below returns long list of TRUE/FALSE values,
#Note: "IDs" is a column name,
#Wrap with head() to shorten:
df$IDs %in% c("ident_1", "ident_2");

#Below returns index of IDs that are TRUE,
#Wrap with head() to shorten:
which(df$IDs %in% c("ident_1", "ident_2"));

#Below returns short TRUE/FALSE table:
table(df$IDs %in% c("ident_1", "ident_2"));

#Below check df to see unique IDs returned by "%in%" code above,
#(Good for identifying missing "desired" IDs):
unique(df[df$IDs %in% c("ident_1", "ident_2"), "IDs"]);

#Below returns dimensions of dataframe "filtered" (retained) by desired IDs,
#(Note rows below should equal number of TRUE in table above):
dim(df[df$IDs %in% c("ident_1", "ident_2"), ]);

#Create filtered dataframe object:
df_filtered  <-  df[df$IDs %in% c("ident_1", "ident_2"),  ];

#Below returns row counts per "IDs" ("ident_1", "ident_2", etc.) in df_filtered:
aggregate(df_filtered$IDs, by=list(df_filtered$IDs), FUN = "length");


HTH, Bill.

W. Michels, Ph.D.





On Wed, Jun 3, 2020 at 7:56 AM Ana Marija  wrote:
>
> Hello.
>
> I am trying to filter only rows that have ANY of these variables:
> E109, E119, E149
>
> so I did:
> controls=t %>% filter_all(any_vars(. %in% c("E109", "E119","E149")))
>
> than I checked what I got:
> > s0 <- sapply(controls, function(x) grep('^E10', x, value = TRUE))
> > d0=unlist(s0)
> > d10=unique(d0)
> > d10
>  [1] "E10"  "E103" "E104" "E109" "E101" "E108" "E105" "E100" "E106" "E102"
> [11] "E107"
> s1 <- sapply(controls, function(x) grep('^E11', x, value = TRUE))
> d1=unlist(s1)
> d11=unique(d1)
> > d11
>  [1] "E11"  "E119" "E113" "E115" "E111" "E114" "E110" "E118" "E116" "E112"
> [11] "E117"
>
> I need help with changing this command
> controls=t %>% filter_all(any_vars(. %in% c("E109", "E119","E149")))
>
> so that in the output I do not have any rows that include E102 or E112?
>
> Thanks
> Ana
>
> __
> 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] iterators : checkFunc with ireadLines

2020-05-27 Thread William Michels via R-help
ed it's a raku problem, you can check the 'raku-grep'
help page at https://docs.raku.org/routine/grep, or post a question to
the perl6-users mailing list at perl6-us...@perl.org .

HTH, Bill.

W. Michels, Ph.D.
On Wed, May 27, 2020 at 1:56 AM Laurent Rhelp  wrote:
>
> I installed raku on my PC to test your solution:
>
> The command raku -e '.put for lines.grep( / ^^N053 | ^^N163 /, :p );'
> Laurents.txt works fine when I write it in the bash command but when I
> use the pipe command in R as you say there is nothing in lines with
> lines <- read.table(i)
>
> There is the same problem with Ivan's solution the command grep -E
> '^(N053|N163)' test.txt works fine under the bash command but not i <-
> pipe("grep -E '^(N053|N163)' test.txt"); lines <- read.table(i)
>
> May be it is because I work with MS windows ?
>
> thx
> LP
>
>
>
>
> Le 24/05/2020 à 04:34, William Michels a écrit :
> > Hi Laurent,
> >
> > Seeking to give you an "R-only" solution, I thought the read.fwf()
> > function might be useful (to read-in your first column of data, only).
> > However Jeff is correct that this is a poor strategy, since read.fwf()
> > reads the entire file into R (documented in "Fixed-width-format
> > files", Section 2.2: R Data Import/Export Manual).
> >
> > Jeff has suggested a number of packages, as well as using a database.
> > Ivan Krylov has posted answers using grep, awk and perl (perl5--to
> > disambiguate). [In point of fact, the R Data Import/Export Manual
> > suggests using perl]. Similar to Ivan, I've posted code below using
> > the Raku programming language (the language formerly known as Perl6).
> > Regexes are claimed to be more readable, but are currently very slow
> > in Raku. However on the plus side, the language is designed to handle
> > Unicode gracefully:
> >
> >> # pipe() using raku-grep on Laurent's data (sep=mult whitespace):
> >> con_obj1 <- pipe(paste("raku -e '.put for lines.grep( / ^^N053 | ^^N163 /, 
> >> :p );' ", "Laurents.txt"), open="rt");
> >> p6_import_a <- scan(file=con_obj1, 
> >> what=list("","","","","","","","","",""), flush=TRUE, multi.line=FALSE, 
> >> quiet=TRUE);
> >> close(con_obj1);
> >> as.data.frame(sapply(p6_import_a, t), stringsAsFactors=FALSE);
> >V1   V2V3V4V5V6V7V8
> >V9   V10
> > 1  2 N053 -0.014083 -0.004741  0.001443 -0.010152 -0.012996 -0.005337
> > -0.008738 -0.015094
> > 2  4 N163 -0.054023 -0.049345 -0.037158  -0.04112 -0.044612 -0.036953
> > -0.036061 -0.044516
> >> # pipe() using raku-grep "starts-with" to find genbankID ( >3GB TSV file)
> >> # "lines[0..5]" restricts raku to reading first 6 lines!
> >> # change "lines[0..5]" to "lines" to run raku code on whole file:
> >> con_obj2 <- pipe(paste("raku -e '.put for lines[0..5].grep( 
> >> *.starts-with(q[A00145]), :p);' ", "genbankIDs_3GB.tsv"), "rt");
> >> p6_import_b <- read.table(con_obj2, sep="\t");
> >> close(con_obj2)
> >> p6_import_b
> >V1 V2   V3  V4 V5
> > 1  4 A00145 A00145.1 IFN-alpha A NA
> >> # unicode test using R's system() function:
> >> try(system("raku -ne '.grep( /  你好  |  こんにちは  |  مرحبا  |  Привет  /, :v 
> >> ).put;'  hello_7lang.txt", intern = TRUE, ignore.stderr = FALSE))
> > [1] """"""
> > "你好 Chinese"
> > [5] "こんにちは Japanese" "مرحبا Arabic""Привет Russian"
> > [special thanks to Brad Gilbert, Joseph Brenner and others on the
> > perl6-users mailing list. All errors above are my own.]
> >
> > HTH, Bill.
> >
> > W. Michels, Ph.D.
> >
> >
> >
> >
> > On Fri, May 22, 2020 at 4:48 AM Laurent Rhelp  wrote:
> >> Hi Ivan,
> >> Endeed, it is a good idea. I am under MSwindows but I can use the
> >> bash command I use with git. I will see how to do that with the unix
> >> command lines.
> >>
> >>
> >> Le 20/05/2020 à 09:46, Ivan Krylov a écrit :
> >>> Hi Laurent,
> >>>
> >>> I am not saying this will work every time and I do recognise that this
> >>> is very diff

Re: [R] Partial matching list elements in R 4.0

2020-05-27 Thread William Dunlap via R-help
all.equal()

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, May 27, 2020 at 1:13 PM John Harrold 
wrote:

> Thankyou Bert and Bill.
>
> I have one last question. Is there a tool that will recursively compare
> two lists to find differences in both their structure and contents?
>
> I'm afraid that in the process of converting code from $ to [[]] formats I
> may inadvertently introduce some errors. And I'd like to QC it in some way.
>
> Thanks
> John
>
> On Tue, May 26, 2020 at 11:33 AM William Dunlap  wrote:
>
>> Another symptom of this problem is:
>>
>> > {x <- list(Abc=list(Pqr="Old Abc$Pqr")); x$Ab$Pqr <- "New Ab$Pqr" ; x}
>> R version 3.6.2 (2019-12-12) | R version 4.0.0 (2020-04-24)
>> List of 2| List of 2
>>  $ Abc:List of 1 |  $ Abc:List of 1
>>   ..$ Pqr: chr "Old Abc$Pqr" |   ..$ Pqr: chr "New Ab$Pqr"
>>  $ Ab :List of 1 |  $ Ab :List of 1
>>   ..$ Pqr: chr "New Ab$Pqr"  |   ..$ Pqr: chr "New Ab$Pqr"
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>
>> On Tue, May 26, 2020 at 10:45 AM John Harrold 
>> wrote:
>>
>>> Hello,
>>>
>>>
>>> I'm testing some code in R 4.0, and I'm having an issue with the
>>> following"
>>>
>>> # -
>>> rm(list=ls())
>>> graphics.off()
>>> #load("/tmp/post.RData")
>>> var = list();
>>> # If I uncomment this it fixes things:
>>> # var$options = list(mi   = list(),
>>> #misc = list())
>>> #
>>> var$options$misc$abc = "123"
>>> var$options$mi$something= 13
>>> #
>>>
>>> This is a stripped down example but it exhibits the issue I"m having.
>>> Basically when I create the list element var$options$mi the contents of
>>> var$options$misc move over to var$options$mi. And what was in
>>> var$options$misc become NULL:
>>>
>>> So now var$options looks like:
>>>
>>> var$options
>>> $misc
>>> $misc$abc
>>> NULL
>>>
>>> $mi
>>> $mi$abc
>>> [1] "123"
>>> $mi$something
>>> [1] 13
>>>
>>> This worked (still works) in R 3.5.1. I understand partial matching, but
>>> is
>>> this normal lists moving over to elements like this? I can uncomment the
>>> text mentioned in the example and it seems to fix it, but I'm wondering
>>> if
>>> this is a bug or just my poor programming coming back to bite me.
>>>
>>> I've included my sessionInfo() at the bottom.
>>>
>>> Thanks
>>> John
>>> :wq
>>>
>>>
>>> sessionInfo()
>>>
>>> R version 4.0.0 (2020-04-24)
>>>
>>> Platform: x86_64-apple-darwin17.0 (64-bit)
>>>
>>> Running under: macOS Mojave 10.14.5
>>>
>>>
>>> Matrix products: default
>>>
>>> BLAS:
>>> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
>>>
>>> LAPACK:
>>>
>>> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>>>
>>>
>>> locale:
>>>
>>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>>
>>>
>>> attached base packages:
>>>
>>> [1] stats graphics  grDevices utils datasets  methods   base
>>>
>>>
>>> other attached packages:
>>>
>>> [1] gdata_2.18.0  ggplot2_3.3.0 deSolve_1.28
>>>
>>>
>>> loaded via a namespace (and not attached):
>>>
>>>  [1] Rcpp_1.0.4.6 gtools_3.8.2 withr_2.2.0  assertthat_0.2.1
>>>
>>>  [5] dplyr_0.8.5  digest_0.6.25crayon_1.3.4 grid_4.0.0
>>>
>>>  [9] R6_2.4.1 lifecycle_0.2.0  gtable_0.3.0 magrittr_1.5
>>>
>>> [13] scales_1.1.1 pillar_1.4.4 rlang_0.4.6  vctrs_0.3.0
>>>
>>> [17] ellipsis_0.3.1   glue_1.4.1   purrr_0.3.4  munsell_0.5.0
>>>
>>> [21] compiler_4.0.0   pkgconfig_2.0.3  colorspace_1.4-1 tidyselect_1.1.0
>>>
>>> [25] tibble_3.0.1
>>>
>>> [[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.
>>>
>>
>
> --
> John
> :wq
>

[[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] Partial matching list elements in R 4.0

2020-05-26 Thread William Dunlap via R-help
Another symptom of this problem is:

> {x <- list(Abc=list(Pqr="Old Abc$Pqr")); x$Ab$Pqr <- "New Ab$Pqr" ; x}
R version 3.6.2 (2019-12-12) | R version 4.0.0 (2020-04-24)
List of 2| List of 2
 $ Abc:List of 1 |  $ Abc:List of 1
  ..$ Pqr: chr "Old Abc$Pqr" |   ..$ Pqr: chr "New Ab$Pqr"
 $ Ab :List of 1 |  $ Ab :List of 1
  ..$ Pqr: chr "New Ab$Pqr"  |   ..$ Pqr: chr "New Ab$Pqr"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, May 26, 2020 at 10:45 AM John Harrold 
wrote:

> Hello,
>
>
> I'm testing some code in R 4.0, and I'm having an issue with the following"
>
> # -
> rm(list=ls())
> graphics.off()
> #load("/tmp/post.RData")
> var = list();
> # If I uncomment this it fixes things:
> # var$options = list(mi   = list(),
> #misc = list())
> #
> var$options$misc$abc = "123"
> var$options$mi$something= 13
> #
>
> This is a stripped down example but it exhibits the issue I"m having.
> Basically when I create the list element var$options$mi the contents of
> var$options$misc move over to var$options$mi. And what was in
> var$options$misc become NULL:
>
> So now var$options looks like:
>
> var$options
> $misc
> $misc$abc
> NULL
>
> $mi
> $mi$abc
> [1] "123"
> $mi$something
> [1] 13
>
> This worked (still works) in R 3.5.1. I understand partial matching, but is
> this normal lists moving over to elements like this? I can uncomment the
> text mentioned in the example and it seems to fix it, but I'm wondering if
> this is a bug or just my poor programming coming back to bite me.
>
> I've included my sessionInfo() at the bottom.
>
> Thanks
> John
> :wq
>
>
> sessionInfo()
>
> R version 4.0.0 (2020-04-24)
>
> Platform: x86_64-apple-darwin17.0 (64-bit)
>
> Running under: macOS Mojave 10.14.5
>
>
> Matrix products: default
>
> BLAS:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
>
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>
>
> locale:
>
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
>
> attached base packages:
>
> [1] stats graphics  grDevices utils datasets  methods   base
>
>
> other attached packages:
>
> [1] gdata_2.18.0  ggplot2_3.3.0 deSolve_1.28
>
>
> loaded via a namespace (and not attached):
>
>  [1] Rcpp_1.0.4.6 gtools_3.8.2 withr_2.2.0  assertthat_0.2.1
>
>  [5] dplyr_0.8.5  digest_0.6.25crayon_1.3.4 grid_4.0.0
>
>  [9] R6_2.4.1 lifecycle_0.2.0  gtable_0.3.0 magrittr_1.5
>
> [13] scales_1.1.1 pillar_1.4.4 rlang_0.4.6  vctrs_0.3.0
>
> [17] ellipsis_0.3.1   glue_1.4.1   purrr_0.3.4  munsell_0.5.0
>
> [21] compiler_4.0.0   pkgconfig_2.0.3  colorspace_1.4-1 tidyselect_1.1.0
>
> [25] tibble_3.0.1
>
> [[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] iterators : checkFunc with ireadLines

2020-05-24 Thread William Michels via R-help
Strike that one sentence in brackets: "[In point of fact, the R Data
Import/Export Manual suggests using perl]", to pre-process data before
loading into R. The manual's recommendation only pertains to large
fixed width formatted files [see #1], whereas Laurent's data is
whitespace-delimited:

> read.table( "Laurents.txt")
> read.delim( "Laurents.txt", sep="")

Best Regards, Bill.

W. Michels, Ph.D.

Citation:
[#1] 
https://cran.r-project.org/doc/manuals/r-release/R-data.html#Fixed_002dwidth_002dformat-files

__
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] iterators : checkFunc with ireadLines

2020-05-23 Thread William Michels via R-help
Hi Laurent,

Seeking to give you an "R-only" solution, I thought the read.fwf()
function might be useful (to read-in your first column of data, only).
However Jeff is correct that this is a poor strategy, since read.fwf()
reads the entire file into R (documented in "Fixed-width-format
files", Section 2.2: R Data Import/Export Manual).

Jeff has suggested a number of packages, as well as using a database.
Ivan Krylov has posted answers using grep, awk and perl (perl5--to
disambiguate). [In point of fact, the R Data Import/Export Manual
suggests using perl]. Similar to Ivan, I've posted code below using
the Raku programming language (the language formerly known as Perl6).
Regexes are claimed to be more readable, but are currently very slow
in Raku. However on the plus side, the language is designed to handle
Unicode gracefully:

> # pipe() using raku-grep on Laurent's data (sep=mult whitespace):
> con_obj1 <- pipe(paste("raku -e '.put for lines.grep( / ^^N053 | ^^N163 /, :p 
> );' ", "Laurents.txt"), open="rt");
> p6_import_a <- scan(file=con_obj1, what=list("","","","","","","","","",""), 
> flush=TRUE, multi.line=FALSE, quiet=TRUE);
> close(con_obj1);
> as.data.frame(sapply(p6_import_a, t), stringsAsFactors=FALSE);
  V1   V2V3V4V5V6V7V8
  V9   V10
1  2 N053 -0.014083 -0.004741  0.001443 -0.010152 -0.012996 -0.005337
-0.008738 -0.015094
2  4 N163 -0.054023 -0.049345 -0.037158  -0.04112 -0.044612 -0.036953
-0.036061 -0.044516
>
> # pipe() using raku-grep "starts-with" to find genbankID ( >3GB TSV file)
> # "lines[0..5]" restricts raku to reading first 6 lines!
> # change "lines[0..5]" to "lines" to run raku code on whole file:
> con_obj2 <- pipe(paste("raku -e '.put for lines[0..5].grep( 
> *.starts-with(q[A00145]), :p);' ", "genbankIDs_3GB.tsv"), "rt");
> p6_import_b <- read.table(con_obj2, sep="\t");
> close(con_obj2)
> p6_import_b
  V1 V2   V3  V4 V5
1  4 A00145 A00145.1 IFN-alpha A NA
>
> # unicode test using R's system() function:
> try(system("raku -ne '.grep( /  你好  |  こんにちは  |  مرحبا  |  Привет  /, :v 
> ).put;'  hello_7lang.txt", intern = TRUE, ignore.stderr = FALSE))
[1] """"""
"你好 Chinese"
[5] "こんにちは Japanese" "مرحبا Arabic""Привет Russian"
>

[special thanks to Brad Gilbert, Joseph Brenner and others on the
perl6-users mailing list. All errors above are my own.]

HTH, Bill.

W. Michels, Ph.D.




On Fri, May 22, 2020 at 4:48 AM Laurent Rhelp  wrote:
>
> Hi Ivan,
>Endeed, it is a good idea. I am under MSwindows but I can use the
> bash command I use with git. I will see how to do that with the unix
> command lines.
>
>
> Le 20/05/2020 à 09:46, Ivan Krylov a écrit :
> > Hi Laurent,
> >
> > I am not saying this will work every time and I do recognise that this
> > is very different from a more general solution that you had envisioned,
> > but if you are on an UNIX-like system or have the relevant utilities
> > installed and on the %PATH% on Windows, you can filter the input file
> > line-by-line using a pipe and an external program:
> >
> > On Sun, 17 May 2020 15:52:30 +0200
> > Laurent Rhelp  wrote:
> >
> >> # sensors to keep
> >> sensors <-  c("N053", "N163")
> > # filter on the beginning of the line
> > i <- pipe("grep -E '^(N053|N163)' test.txt")
> > # or:
> > # filter on the beginning of the given column
> > # (use $2 for the second column, etc.)
> > i <- pipe("awk '($1 ~ \"^(N053|N163)\")' test.txt")
> > # or:
> > # since your message is full of Unicode non-breaking spaces, I have to
> > # bring in heavier machinery to handle those correctly;
> > # only this solution manages to match full column values
> > # (here you can also use $F[1] for second column and so on)
> > i <- pipe("perl -CSD -F'\\s+' -lE \\
> >   'print join qq{\\t}, @F if $F[0] =~ /^(N053|N163)$/' \\
> >   test.txt
> > ")
> > lines <- read.table(i) # closes i when done
> >
> > The downside of this approach is having to shell-escape the command
> > lines, which can become complicated, and choosing between use of regular
> > expressions and more wordy programs (Unicode whitespace in the input
> > doesn't help, either).
> >
>
>
> --
> L'absence de virus dans ce courrier électronique a été vérifiée par le 
> logiciel antivirus Avast.
> https://www.avast.com/antivirus
>
> __
> 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] Help with ggplot error: #Error in FUN(X[[i]], ...) : object 'x' not found

2020-05-19 Thread Poling, William via R-help
Hello Chris, and thank you for your response.
I tried it both TRUE and FALSE given my confusion with the reference I found 
that idea in.

It did not help either way.

Glad you noticed though, thank you.

WHP

William H. Poling Ph.D., MPH  | Senior Data Scientist, Medicare Stars, CVS 
Health 
p 813-777-5030


Proprietary

-Original Message-
From: Chris Evans  
Sent: Tuesday, May 19, 2020 9:08 AM
To: Poling, William 
Cc: Ben Tupper ; r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with ggplot error: #Error in FUN(X[[i]], ...) 
: object 'x' not found

 External Email - Use Caution 



- Original Message -
> From: "Poling, William via R-help" 
> To: "Ben Tupper" 
> Cc: r-help@r-project.org
> Sent: Tuesday, 19 May, 2020 15:04:25
> Subject: Re: [R] Help with ggplot error: #Error in FUN(X[[i]], ...) : 
> object 'x' not found

> Hello Ben and thank you for your response.
> 
> I thought that was what I was doing when I ran this version:
> Test1
> p <- ggplot(c1members2, aes(x,y)) +
>  geom_point()
> 
> p +  geom_line(data = paths, aes(group = trip_id),inherit.aes = FALSE) 
> + #Error in FUN(X[[i]], ...) : object 'x' not found  
> ggtitle(paste0("Optimal route with cost: ", 
> round(objective_value(result), 2)))
> 
> Is this not what you mean?


I'm no expert but isn't "inherit.aes = FALSE" the culprit?  I think that means 
that that line only has a group for the aesthetic as you've turned off 
inheritance of the x and y mapping in the earlier aes().  That would seem to 
fit with the error message.

No time to try it all out but thought I'd throw this in.

Good luck (all!)

Chris

> 
> str(p)
> List of 9
> $ data   :'data.frame':   7 obs. of  3 variables:
>  ..$ id: int [1:7] 1 2 3 4 5 6 7
>  ..$ x : num [1:7] 95.5 90.2 46.8 40.9 43.3 ...
>  ..$ y : num [1:7] 4.65 47.57 8.07 38.43 28.59 ...
> $ layers :List of 1
>  ..$ :Classes 'LayerInstance', 'Layer', 'ggproto', 'gg'  object: Class  LayerInstance, Layer, gg>
>aes_params: list
>compute_aesthetics: function
>compute_geom_1: function
>compute_geom_2: function
>compute_position: function
>compute_statistic: function
>data: waiver
>draw_geom: function
>finish_statistics: function
>geom: 
>aesthetics: function
>default_aes: uneval
>draw_group: function
>draw_key: function
>draw_layer: function
>draw_panel: function
>extra_params: na.rm
>handle_na: function
>non_missing_aes: size shape colour
>optional_aes:
>parameters: function
>required_aes: x y
>setup_data: function
>setup_params: function
>use_defaults: function
>super:  
>geom_params: list
>inherit.aes: TRUE
>layer_data: function
>map_statistic: function
>mapping: NULL
>position: 
>compute_layer: function
>compute_panel: function
>required_aes:
>setup_data: function
>setup_params: function
>super:  
>print: function
>setup_layer: function
>show.legend: NA
>stat: 
>aesthetics: function
>compute_group: function
>compute_layer: function
>compute_panel: function
>default_aes: uneval
>extra_params: na.rm
>finish_layer: function
>non_missing_aes:
>parameters: function
>required_aes:
>retransform: TRUE
>setup_data: function
>setup_params: function
>super:  
>stat_params: list
>super:  
> $ scales :Classes 'ScalesList', 'ggproto', 'gg'  ScalesList, gg>
>add: function
>clone: function
>find: function
>get_scales: function
>has_scale: function
>input: function
>n: function
>non_position_scales: function
>scales: list
>super:  
> $ mapping:List of 2
>  ..$ x: language ~x
>  .. ..- attr(*, ".Environment")=  ..$ y: 
> language ~y  .. ..- attr(*, ".Environment")=
>  ..- attr(*, "class")= chr "uneval"
> $ theme  : list()
> $ coordinates:Classes 'CoordCartesian', 'Coord', 'ggproto', 'gg' 
>  object: Class CoordCartesian, Coord, gg>
>aspect: function
>backtransform_range: function
>clip: on
>default: TRUE
>distance: function
>expand: TRUE
>is_free: function
>is_linear: function
>labels: function
>limits: list
>modify_scales: fun

Re: [R] Help with ggplot error: #Error in FUN(X[[i]], ...) : object 'x' not found

2020-05-19 Thread Poling, William via R-help

Hello Ben and thank you for your response.

I thought that was what I was doing when I ran this version:
Test1
p <- ggplot(c1members2, aes(x,y)) + 
  geom_point() 

p +  geom_line(data = paths, aes(group = trip_id),inherit.aes = FALSE) + #Error 
in FUN(X[[i]], ...) : object 'x' not found
  ggtitle(paste0("Optimal route with cost: ", round(objective_value(result), 
2)))

Is this not what you mean?  

str(p)
List of 9
 $ data   :'data.frame':7 obs. of  3 variables:
  ..$ id: int [1:7] 1 2 3 4 5 6 7
  ..$ x : num [1:7] 95.5 90.2 46.8 40.9 43.3 ...
  ..$ y : num [1:7] 4.65 47.57 8.07 38.43 28.59 ...
 $ layers :List of 1
  ..$ :Classes 'LayerInstance', 'Layer', 'ggproto', 'gg' 
aes_params: list
compute_aesthetics: function
compute_geom_1: function
compute_geom_2: function
compute_position: function
compute_statistic: function
data: waiver
draw_geom: function
finish_statistics: function
geom: 
aesthetics: function
default_aes: uneval
draw_group: function
draw_key: function
draw_layer: function
draw_panel: function
extra_params: na.rm
handle_na: function
non_missing_aes: size shape colour
optional_aes: 
parameters: function
required_aes: x y
setup_data: function
setup_params: function
use_defaults: function
super:  
geom_params: list
inherit.aes: TRUE
layer_data: function
map_statistic: function
mapping: NULL
position: 
compute_layer: function
compute_panel: function
required_aes: 
setup_data: function
setup_params: function
super:  
print: function
setup_layer: function
show.legend: NA
stat: 
aesthetics: function
compute_group: function
compute_layer: function
compute_panel: function
default_aes: uneval
extra_params: na.rm
finish_layer: function
non_missing_aes: 
parameters: function
required_aes: 
retransform: TRUE
setup_data: function
setup_params: function
super:  
stat_params: list
super:   
 $ scales :Classes 'ScalesList', 'ggproto', 'gg' 
add: function
clone: function
find: function
get_scales: function
has_scale: function
input: function
n: function
non_position_scales: function
scales: list
super:   
 $ mapping:List of 2
  ..$ x: language ~x
  .. ..- attr(*, ".Environment")= 
  ..$ y: language ~y
  .. ..- attr(*, ".Environment")= 
  ..- attr(*, "class")= chr "uneval"
 $ theme  : list()
 $ coordinates:Classes 'CoordCartesian', 'Coord', 'ggproto', 'gg' 
aspect: function
backtransform_range: function
clip: on
default: TRUE
distance: function
expand: TRUE
is_free: function
is_linear: function
labels: function
limits: list
modify_scales: function
range: function
render_axis_h: function
render_axis_v: function
render_bg: function
render_fg: function
setup_data: function
setup_layout: function
setup_panel_guides: function
setup_panel_params: function
setup_params: function
train_panel_guides: function
transform: function
super:   
 $ facet  :Classes 'FacetNull', 'Facet', 'ggproto', 'gg' 
compute_layout: function
draw_back: function
draw_front: function
draw_labels: function
draw_panels: function
finish_data: function
init_scales: function
map_data: function
params: list
setup_data: function
setup_params: function
shrink: TRUE
train_scales: function
vars: function
super:   
 $ plot_env   : 
 $ labels :List of 2
  ..$ x: chr "x"
  ..$ y: chr "y"
 - attr(*, "class")= chr [1:2] "gg" "ggplot"














From: Ben Tupper  
Sent: Tuesday, May 19, 2020 7:46 AM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with ggplot error: #Error in FUN(X[[i]], ...) 
: object 'x' not found

 External Email - Use Caution 
Hi,

When you add a new layer to a plot and you provide new data, wouldn't it make 
sense to provide aes() with some indication of the names of the variables to 
use for coordinate plotting?  You have provided a grouping variable for the 
paths, but what of coordinates x and y?  How could geom_path() know that your 
lon/lat variables are to be used as x and y coordinates in the plot? 

Cheers,
Ben



On Tue, May 19, 2020 at 8:29 AM Poling, William via R-help 
<mailto:r-help@r-project.org> wrote:
#RStudio Version Version 1.2.1335 
sessionInfo() 
# R version 4.0.0 P

[R] Help with ggplot error: #Error in FUN(X[[i]], ...) : object 'x' not found

2020-05-19 Thread Poling, William via R-help
#RStudio Version Version 1.2.1335 
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

Good morning.

I am testing a small sample of my data using an example found here:
#https://www.r-orms.org/mixed-integer-linear-programming/practicals/problem-tsp/

If needed I can provide my complete script which is simply the same as the 
example only using a few rows from my data, let me know, as I think this is 
just a ggplot issue.

I am getting this error when I use ggplot
#Error in FUN(X[[i]], ...) : object 'x' not found

1. I have reviewed the following with no success.
#Sources referred to for help
#https://github.com/business-science/anomalize/issues/2
#https://stackoverflow.com/questions/38988028/error-in-funxi-object-x-not-found
#https://community.rstudio.com/t/error-in-fun-x-i-object-variable-not-found/62532/3
#https://www.neonscience.org/packages-in-r

2. I have rebooted and re-installed ggplot2 for updates

3. These are the only libraries running
library(knitr)
library(dplyr)
library(ggplot2)
library(ggmap)
library(ompr)
library(ompr.roi)
library(ROI.plugin.glpk)   

Here is the original plot attempt:
ggplot(c1members2, aes(x , y)) + 
  geom_point() + 
  geom_line(data = paths, aes(group = trip_id)) + #Error in FUN(X[[i]], ...) : 
object 'x' not found
  ggtitle(paste0("Optimal route with cost: ", round(objective_value(result), 
2)))

#I have gone through each of the steps one by one and error occurs at --> 
geom_line(data = paths, aes(group = trip_id))

I have also tried the following:
Test1
p <- ggplot(c1members2, aes(x,y)) + 
  geom_point() 

p +  geom_line(data = paths, aes(group = trip_id),inherit.aes = FALSE) + #Error 
in FUN(X[[i]], ...) : object 'x' not found
  ggtitle(paste0("Optimal route with cost: ", round(objective_value(result), 
2)))

Test2
ggplot(c1members2, aes(x,y)) + 
  geom_point() +
geom_line(data = paths, aes(group = trip_id),inherit.aes = TRUE) + #Error in 
FUN(X[[i]], ...) : object 'x' not found
  ggtitle(paste0("Optimal route with cost: ", round(objective_value(result), 
2)))

Here are the data involved.
str(c1members2)
'data.frame':   7 obs. of  3 variables:
 $ id: int  1 2 3 4 5 6 7
 $ x : num  95.5 90.2 46.8 40.9 43.3 ...
 $ y : num  4.65 47.57 8.07 38.43 28.59 ...

str(paths)
data.frame':14 obs. of  6 variables:
 $ trip_id  : int  1 2 3 4 5 6 7 1 2 3 ...
 $ property : chr  "from" "from" "from" "from" ...
 $ idx_val  : int  3 1 5 7 6 4 2 1 2 3 ...
 $ Longitude: num  -122 -122 -122 -122 -122 ...
 $ Latitude : num  47.3 47.2 47.3 47.6 47.6 ...
 $ city : Factor w/ 1337 levels "ABBOTTSTOWN",..: 1169 1169 1169 1069 1069 
1069 1069 1169 1069 1169 ...

Here are the dput()'s

I hope I have provided enough information to elicit a response.

Thank you.

WHP

dput(c1members2)
structure(list(id = 1:7, x = c(95.521828085515, 90.2272877161736, 
46.8465689660691, 40.8959155605829, 43.2591531526978, 23.7485886058345, 
64.0406297698986), y = c(4.64803485876031, 47.5678629996171, 
8.0689847051367, 38.4256264258875, 28.5930051512296, 43.5934562642672, 
42.415566619041)), class = "data.frame", row.names = c(NA, -7L

dput(paths) #Although I am only using city %in% c("SEATTLE","TACOMA")) from the 
original 2353 rows = 7 rows in c1members2
structure(list(trip_id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L), property = c("from", "from", "from", "from", 
"from", "from", "from", "to", "to", "to", "to", "to", "to", "to"
), idx_val = c(3L, 1L, 5L, 7L, 6L, 4L, 2L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L), Longitude = c(-122.490417, -122.429323, -122.358115, 
-122.37003, -122.41282, -122.299261, -122.390815, -122.429323, 
-122.390815, -122.490417, -122.299261, -122.358115, -122.41282, 
-122.37003), Latitude = c(47.274599, 47.176596, 47.276776, 47.565667, 
47.646222, 47.673056, 47.549377, 47.176596, 47.549377, 47.274599, 
47.673056, 47.276776, 47.646222, 47.565667), city = structure(c(1169L, 
1169L, 1169L, 1069L, 1069L, 1069L, 1069L, 1169L, 1069L, 1169L, 
1069L, 1169L, 1069L, 1069L), .Label = c("ABBOTTSTOWN", "ABILENE", 
"ACWORTH", "ADAMS", "ADDISON", "ADKINS", "ALBANY", "ALBIA", "ALBUQUERQUE", 
"ALEXANDRIA", "ALFRED", "ALIQUIPPA", "ALISO VIEJO", "ALLEN PARK", 
"ALLENTOWN", "ALPHA", "ALPHARETTA", "ALPINE", "ALTOONA", "AMARILLO", 
"AMBLER", "AMBRIDGE", "AMHERST", "AMITYVILLE", "ANAHIEM", "ANDERSON", 
"ANDOVER", "ANGIER", "ANGLETON", "ANKENY", "ANN ARBOR", "ANZA", 
"APEX", "APOLLO", "ARCADIA", "ARCHDALE", "ARDMORE", "ARGYLE", 
"ARKANSAS CITY", "ARLINGTON", "ARNOLD", "ARTHUR", "ASHEBORO", 
"ASHEVILLE", "ASHLAND", "ASHLAND CITY", "ASHTON", "ASTON", "ATHENS", 
"ATLANTA", "ATLANTIC BCH", "AUBORN", "AUGUSTA", "AURORA", "AUSTELL", 
"AUSTIN", "AVENTURA", "AVONDALE ESTATES", "BAKERSFIELD", "BALDWIN CITY", 
"BALDWIN PLACE", "BALLWIN", "BANGOR", "BARBOURSVILLE", "BARNEGAT", 
"BARTLETT", "BARTON", "BARTONVILLE", "BASSETT", "BATAVIA", "BATESBURG", 
"BATON ROUGE", "BAXTER SPRINGS", "BAY CITY", "BAYONNE", "BAYSIDE", 

Re: [R] iterators : checkFunc with ireadLines

2020-05-18 Thread William Michels via R-help


Dear Laurent,

I'm going through your code quickly, and the first question I have is
whether you loaded the "gmp" library?

> library(gmp)

Attaching package: ‘gmp’

The following objects are masked from ‘package:base’:

%*%, apply, crossprod, matrix, tcrossprod

> library(iterators)
> iter(1:100, checkFunc = function(n) isprime(n))
$state


$length
[1] 100

$checkFunc
function (n)
isprime(n)

$recycle
[1] FALSE

attr(,"class")
[1] "containeriter" "iter"
>

HTH, Bill.

W. Michels, Ph.D.



On Sun, May 17, 2020 at 5:43 PM Laurent Rhelp  wrote:
>
> Dear R-Help List,
>
> I would like to use an iterator to read a file filtering some
> selected lines according to the line name in order to use after a
> foreach loop. I wanted to use the checkFunc argument as the following
> example found on internet to select only prime numbers :
>
> |iprime <- ||iter||(1:100, checkFunc =
> ||function||(n) ||isprime||(n))|
>
> |(https://datawookie.netlify.app/blog/2013/11/iterators-in-r/)
> |
>
> but the checkFunc argument seems not to be available with the function
> ireadLines (package iterators). So, I did the code below to solve my
> problem but I am sure that I miss something to use iterators with files.
> Since I found nothing on the web about ireadLines and the checkFunc
> argument, could somebody help me to understand how we have to use
> iterator (and foreach loop) on files keeping only selected lines ?
>
> Thank you very much
> Laurent
>
> Presently here is my code:
>
> ##mock file to read: test.txt
> ##
> # Time00.0009990.0019990.0029980.003998 0.004997
> 0.0059970.0069960.007996
> # N023-0.031323-0.035026-0.029759-0.024886 -0.024464
> -0.026816-0.03369-0.041067-0.038747
> # N053-0.014083-0.0047410.001443-0.010152 -0.012996
> -0.005337-0.008738-0.015094-0.012104
> # N123-0.019008-0.013494-0.01318-0.029208 -0.032748
> -0.020243-0.015089-0.014439-0.011681
> # N163-0.054023-0.049345-0.037158-0.04112 -0.044612
> -0.036953-0.036061-0.044516-0.046436
> # N193-0.022171-0.022384-0.022338-0.023304 -0.022569
> -0.021827-0.021996-0.021755-0.021846
>
>
> # sensors to keep
>
> sensors <-  c("N053", "N163")
>
>
> library(iterators)
>
> library(rlist)
>
>
> file_name <- "test.txt"
>
> con_obj <- file( file_name , "r")
> ifile <- ireadLines( con_obj , n = 1 )
>
>
> ## I do not do a loop for the example
>
> res <- list()
>
> r <- get_Lines_iter( ifile , sensors)
> res <- list.append( res , r )
> res
> r <- get_Lines_iter( ifile , sensors)
> res <- list.append( res , r )
> res
> r <- get_Lines_iter( ifile , sensors)
> do.call("cbind",res)
>
> ## the function get_Lines_iter to select and process the line
>
> get_Lines_iter  <-  function( iter , sensors, sep = '\t', quiet = FALSE){
>## read the next record in the iterator
>r = try( nextElem(iter) )
>   while(  TRUE ){
>  if( class(r) == "try-error") {
>return( stop("The iterator is empty") )
> } else {
> ## split the read line according to the separator
>  r_txt <- textConnection(r)
>  fields <- scan(file = r_txt, what = "character", sep = sep, quiet =
> quiet)
>   ## test if we have to keep the line
>   if( fields[1] %in% sensors){
> ## data processing for the selected line (for the example
> transformation in dataframe)
> n <- length(fields)
> x <- data.frame( as.numeric(fields[2:n]) )
> names(x) <- fields[1]
> ## We return the values
> print(paste0("sensor ",fields[1]," ok"))
> return( x )
>   }else{
>print(paste0("Sensor ", fields[1] ," not selected"))
>r = try(nextElem(iter) )}
> }
> }# end while loop
> }
>
>
>
>
>
>
>
> --
> L'absence de virus dans ce courrier électronique a été vérifiée par le 
> logiciel antivirus Avast.
> https://www.avast.com/antivirus
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] iterators : checkFunc with ireadLines

2020-05-18 Thread William Michels via R-help


Apologies, Laurent, for this two-part answer. I misunderstood your
post where you stated you wanted to "filter(ing) some
selected lines according to the line name... ." I thought that meant
you had a separate index (like a series of primes) that you wanted to
use to only read-in selected line numbers from a file (test file below
with numbers 1:1000 each on a separate line):

> library(gmp)
> library(iterators)
> iprime <- iter(1:100, checkFunc = function(n) isprime(n))
> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
Read 1 item
[1] 2
> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
Read 1 item
[1] 3
> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
Read 1 item
[1] 5
> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
Read 1 item
[1] 7
>

However, what it really seems that you want to do is read each line of
a (possibly enormous) file, test each line "string-wise" to keep or
discard, and if you're keeping it, append the line to a list. I can
certainly see the advantage of this strategy for reading in very, very
large files, but it's not clear to me how the "ireadLines" function (
in the "iterators" package) will help you, since it doesn't seem to
generate anything but a sequential index.

Anyway, below is an absolutely standard read-in of your data using
read.table(). Hopefully some of the code I've posted has been useful
to you.

> sensors <-  c("N053", "N163")
> read.table("test2.txt")
V1V2V3V4V5V6V7
   V8V9   V10
1 Time  0.00  0.000999  0.001999  0.002998  0.003998  0.004997
0.005997  0.006996  0.007996
2 N023 -0.031323 -0.035026 -0.029759 -0.024886 -0.024464 -0.026816
-0.033690 -0.041067 -0.038747
3 N053 -0.014083 -0.004741  0.001443 -0.010152 -0.012996 -0.005337
-0.008738 -0.015094 -0.012104
4 N123 -0.019008 -0.013494 -0.013180 -0.029208 -0.032748 -0.020243
-0.015089 -0.014439 -0.011681
5 N163 -0.054023 -0.049345 -0.037158 -0.041120 -0.044612 -0.036953
-0.036061 -0.044516 -0.046436
6 N193 -0.022171 -0.022384 -0.022338 -0.023304 -0.022569 -0.021827
-0.021996 -0.021755 -0.021846
> Laurent_data <- read.table("test2.txt")
> Laurent_data[Laurent_data$V1 %in% sensors, ]
V1V2V3V4V5V6V7
   V8V9   V10
3 N053 -0.014083 -0.004741  0.001443 -0.010152 -0.012996 -0.005337
-0.008738 -0.015094 -0.012104
5 N163 -0.054023 -0.049345 -0.037158 -0.041120 -0.044612 -0.036953
-0.036061 -0.044516 -0.046436

Best, Bill.

W. Michels, Ph.D.


On Sun, May 17, 2020 at 5:43 PM Laurent Rhelp  wrote:
>
> Dear R-Help List,
>
> I would like to use an iterator to read a file filtering some
> selected lines according to the line name in order to use after a
> foreach loop. I wanted to use the checkFunc argument as the following
> example found on internet to select only prime numbers :
>
> |iprime <- ||iter||(1:100, checkFunc =
> ||function||(n) ||isprime||(n))|
>
> |(https://datawookie.netlify.app/blog/2013/11/iterators-in-r/)
> |
>
> but the checkFunc argument seems not to be available with the function
> ireadLines (package iterators). So, I did the code below to solve my
> problem but I am sure that I miss something to use iterators with files.
> Since I found nothing on the web about ireadLines and the checkFunc
> argument, could somebody help me to understand how we have to use
> iterator (and foreach loop) on files keeping only selected lines ?
>
> Thank you very much
> Laurent
>
> Presently here is my code:
>
> ##mock file to read: test.txt
> ##
> # Time00.0009990.0019990.0029980.003998 0.004997
> 0.0059970.0069960.007996
> # N023-0.031323-0.035026-0.029759-0.024886 -0.024464
> -0.026816-0.03369-0.041067-0.038747
> # N053-0.014083-0.0047410.001443-0.010152 -0.012996
> -0.005337-0.008738-0.015094-0.012104
> # N123-0.019008-0.013494-0.01318-0.029208 -0.032748
> -0.020243-0.015089-0.014439-0.011681
> # N163-0.054023-0.049345-0.037158-0.04112 -0.044612
> -0.036953-0.036061-0.044516-0.046436
> # N193-0.022171-0.022384-0.022338-0.023304 -0.022569
> -0.021827-0.021996-0.021755-0.021846
>
>
> # sensors to keep
>
> sensors <-  c("N053", "N163")
>
>
> library(iterators)
>
> library(rlist)
>
>
> file_name <- "test.txt"
>
> con_obj <- file( file_name , "r")
> ifile <- ireadLines( con_obj , n = 1 )
>
>
> ## I do not do a loop for the example
>
> res <- list()
>
> r <- get_Lines_iter( ifile , sensors)
> res <- list.append( res , r )
> res
> r <- get_Lines_iter( ifile , sensors)
> res <- list.append( res , r )
> res
> r <- get_Lines_iter( ifile , sensors)
> do.call("cbind",res)
>
> ## the function get_Lines_iter to select and process the line
>
> get_Lines_iter  <-  fun

Re: [R] iterators : checkFunc with ireadLines

2020-05-18 Thread William Michels via R-help


Hi Laurent,

Thank you for explaining your size limitations. Below is an example
using the read.fwf() function to grab the first column of your input
file (in 2000 row chunks). This column is converted to an index, and
the index is used to create an iterator useful for skipping lines when
reading input with scan(). (You could try processing your large file
in successive 2000 line chunks, or whatever number of lines fits into
memory). Maybe not as elegant as the approach you were going for, but
read.fwf() should be pretty efficient:

> sensors <-  c("N053", "N163")
> read.fwf("test2.txt", widths=c(4), as.is=TRUE, flush=TRUE, n=2000, skip=0)
V1
1 Time
2 N023
3 N053
4 N123
5 N163
6 N193
> first_col <- read.fwf("test2.txt", widths=c(4), as.is=TRUE, flush=TRUE, 
> n=2000, skip=0)
> which(first_col$V1 %in% sensors)
[1] 3 5
> index1 <- which(first_col$V1 %in% sensors)
> iter_index1 <- iter(1:2000, checkFunc= function(n) {n %in% index1})
> unlist(scan(file="test2.txt", what=list("","","","","","","","","",""), 
> flush=TRUE, multi.line=FALSE, skip=nextElem(iter_index1)-1, nlines=1, 
> quiet=TRUE))
 [1] "N053"  "-0.014083" "-0.004741" "0.001443"  "-0.010152"
"-0.012996" "-0.005337" "-0.008738" "-0.015094" "-0.012104"
> unlist(scan(file="test2.txt", what=list("","","","","","","","","",""), 
> flush=TRUE, multi.line=FALSE, skip=nextElem(iter_index1)-1, nlines=1, 
> quiet=TRUE))
 [1] "N163"  "-0.054023" "-0.049345" "-0.037158" "-0.04112"
"-0.044612" "-0.036953" "-0.036061" "-0.044516" "-0.046436"
>

(Note for this email and the previous one, I've deleted the first
"hash" character from each line of your test file for clarity).

HTH, Bill.

W. Michels, Ph.D.





On Mon, May 18, 2020 at 3:35 AM Laurent Rhelp  wrote:
>
> Dear William,
>   Thank you for your answer
> My file is very large so I cannot read it in my memory (I cannot use
> read.table). So I want to put in memory only the line I need to process.
> With readLines, as I did, it works but I would like to use an iterator
> and a foreach loop to understand this way to do because I thought that
> it was a better solution to write a nice code.
>
>
> Le 18/05/2020 à 04:54, William Michels a écrit :
> > Apologies, Laurent, for this two-part answer. I misunderstood your
> > post where you stated you wanted to "filter(ing) some
> > selected lines according to the line name... ." I thought that meant
> > you had a separate index (like a series of primes) that you wanted to
> > use to only read-in selected line numbers from a file (test file below
> > with numbers 1:1000 each on a separate line):
> >
> >> library(gmp)
> >> library(iterators)
> >> iprime <- iter(1:100, checkFunc = function(n) isprime(n))
> >> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
> > Read 1 item
> > [1] 2
> >> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
> > Read 1 item
> > [1] 3
> >> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
> > Read 1 item
> > [1] 5
> >> scan(file="one_thou_lines.txt", skip=nextElem(iprime)-1, nlines=1)
> > Read 1 item
> > [1] 7
> > However, what it really seems that you want to do is read each line of
> > a (possibly enormous) file, test each line "string-wise" to keep or
> > discard, and if you're keeping it, append the line to a list. I can
> > certainly see the advantage of this strategy for reading in very, very
> > large files, but it's not clear to me how the "ireadLines" function (
> > in the "iterators" package) will help you, since it doesn't seem to
> > generate anything but a sequential index.
> >
> > Anyway, below is an absolutely standard read-in of your data using
> > read.table(). Hopefully some of the code I've posted has been useful
> > to you.
> >
> >> sensors <-  c("N053", "N163")
> >> read.table("test2.txt")
> >  V1V2V3V4V5V6V7
> > V8V9   V10
> > 1 Time  0.00  0.000999  0.001999  0.002998  0.003998  0.004997
> > 0.005997  0.006996  0.007996
> > 2 

Re: [R] Help with spTransform() function and final plot colors

2020-05-18 Thread Poling, William via R-help
Thank you Ege, I appreciate your response.

I have move this to r-sig-geo.

WHP

Proprietary

-Original Message-
From: Ege Rubak  
Sent: Monday, May 18, 2020 6:41 AM
To: Poling, William ; r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with spTransform() function and final plot 
colors

 External Email - Use Caution 

You are more likely to get help with specific problems related to
spTransform() on the dedicated list r-sig-geo.

You should provide a minimal reproducible example. Your code refers to e.g. the 
object `tmp1b`, which we don't have. I think the spTransform() part will work 
with this correction:

xy <- SpatialPointsDataFrame(sample[,2:3], sample[,1,drop=FALSE],
 proj4string=CRS("+proj=longlat
+ellps=WGS84 +datum=WGS84"))

xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))

The spatial workflow in R has largely moved to the `sf` package and you are 
probably better off using that in the future if you are new in the game anyway.

Hope this helps,
Ege

On Sun, 2020-05-17 at 09:50 +, Poling, William via R-help wrote:
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 
> x64 (build 17763)
> 
> Hello. I am running my data through a routine I found that finds 
> clusters of data points based on distance rule.
> 
https://urldefense.proofpoint.com/v2/url?u=https-3A__gis.stackexchange.com_questions_64392_finding-2Dclusters-2Dof-2Dpoints-2Dbased-2Ddistance-2Drule-2Dusing-2Dr&d=DwIGaQ&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY&m=sFygsSovnYNWjYOpjSzuSLI1MUrJN8Lih39pDQN98xI&s=2FCT-JBdWSB66pNvGLTM7Ec5Q7IbXatXBLsQqYT0gng&e=
 
> 
> 1. I get this error when I get to this point in the routine, see 
> complete routine below?
> xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite 
> transformation detected:
> 
> I tried converting columns from numeric to Integer but did not help.
> 
> However, I continue to run the rest of the routine and the final 
> sequence, the plot itself, seems to work Can this error be corrected 
> somehow, despite the fact that it continues to work, just curious what 
> it is I guess"
> 
> 2. However in the plot at the end of the routine the color key appears 
> with the colors but the clusters in the plot are black, see plot call 
> at the end of the routine below?
> 
> Thank you for any advice.
> 
> WHP
> 
> ERROR:
> non finite transformation detected:
>   coords.x1 coords.x2
>  [1,] -119.7339  39.53939 Inf Inf
>  [2,] -119.7665  39.39630 Inf Inf
>  [3,] -119.7794  39.28768 Inf Inf
>  [4,] -121.0234  39.20503 Inf Inf
>  [5,] -122.0047  47.19262 Inf Inf
>  [6,] -122.0135  47.18883 Inf Inf
>  [7,] -122.0379  47.52190 Inf Inf
>  [8,] -122.0578  47.60975 Inf Inf
>  [9,] -122.1330  47.13669 Inf Inf
> [10,] -122.1509  47.55962 Inf Inf
> [11,] -122.1706  47.15546 Inf Inf
> [12,] -122.1846  47.23485 Inf Inf
> [13,] -122.1846  48.15307 Inf Inf
> [14,] -122.1851  47.44870 Inf Inf
> [15,] -122.1954  47.68485 Inf Inf
> [16,] -122.1990  47.51610 Inf Inf
> [17,] -122.2014  47.44772 Inf Inf
> [18,] -122.2025  47.69815 Inf Inf
> [19,] -122.2037  47.67190 Inf Inf
> [20,] -122.2090  47.40378 Inf Inf
> [21,] -122.2108  47.25336 Inf Inf
> [22,] -122.2291  47.63880 Inf Inf
> [23,] -122.2419  47.76870 Inf Inf
> [24,] -122.2722  48.04803 Inf Inf
> [25,] -122.2732  47.87700 Inf Inf
> [26,] -122.2804  47.77620 Inf Inf
> [27,] -122.2839  47.82103 Inf Inf
> [28,] -122.2890  47.86899 Inf Inf
> [29,] -122.2993  47.67306 Inf Inf
> [30,] -122.3180  47.38217 Inf Inf
> [31,] -122.3270  47.40378 Inf Inf
> [32,] -122.3474  47.43884 Inf Inf
> [33,] -122.3484  47.53083 Inf Inf
> [34,] -122.3581  47.27678 Inf Inf
> [35,] -122.3618  47.76735 Inf Inf
> [36,] -122.3700  47.56567 Inf Inf
> [37,] -122.3908  47.54938 Inf Inf
> [38,] -122.4128  47.64622 Inf Inf
> [39,] -122.4293  47.17660 Inf Inf
> [40,] -122.4621  47.44505 Inf Inf
> [41,] -122.4904  47.27460 Inf Inf
> [42,] -122.5515  46.93979 Inf Inf
> [43,] -122.7348  42.37320 Inf Inf
> [44,] -122.7827  47.31059 Inf Inf
> [45,] -122.7987  47.23475 Inf Inf
> [46,] -122.8385  42.35119 Inf Inf
> [47,] -122.8537  42.34495 Inf Inf
> [48,] -122.8904  42.39555 Inf Inf
> [49,] -122.8927  42.33022 Inf Inf
> [50,] -122.9451  47.37574 Inf Inf
> [51,] -122.9594  42.30376 Inf Inf
> [52,] -123.0641  47.16428 Inf Inf
> [53,] -123.3413  42.44117 Inf Inf
> Error in spTransform(xSP, CRSobj, ...) : 
>   failure in points
> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:
> 

Re: [R] Help with spTransform() function and final plot colors

2020-05-17 Thread Poling, William via R-help
Hello again.

I also found this discussion on non-finite transformation error, however, I am 
not sure what to look for in the output after I apply my data?

https://stackoverflow.com/questions/14880294/non-finite-transformation-detected-in-sptransform-in-rgdal-r-package


str(sample)
GPS.Points <- sample[,c(2,3)]

n_chunks <- 3 #number of pieces you will break you data into
n.points <- dim(GPS.Points)[1]
breaks <- seq(1,n.points, by=round(n.points/n_chunks))
breaks <- c(breaks, n.points) #make sure to include last points as well

i=1
for (i in 1:(length(breaks)-1)){
  cat('\n','converting points', breaks[i], "to", breaks[i+1])  
  temp.GPS.Points=GPS.Points[breaks[i]:breaks[i+1],]
  temp.GPS.Points.Spatial.Data <- SpatialPoints(temp.GPS.Points, 
proj4string=CRS("+proj=longlat 
+ellps=WGS84"))
  temp.GPS.Points.UTM.Spatial.Data <- spTransform(temp.GPS.Points.Spatial.Data,
  CRS("+proj=utm +south 
+zone=34 
+ellps=WGS84"))
}

Thank you for any advice.

WHP

Proprietary

-Original Message-
From: Poling, William  
Sent: Sunday, May 17, 2020 5:20 AM
To: r-help@r-project.org
Cc: Poling, William 
Subject: RE: Help with spTransform() function and final plot colors

Hello, I have found an additional problem.

I should be getting 3 columns back in the xy@data at some point.
$ ID   : int  1 2 3 4 5 6 7 8 9 10 ...
# $ Clust  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
# $ Clust.1   : int  1 1 1 1 1 1 1 1 1 1 ... This would be the 
cluster number, like 1-3, I am not getting this column back?


Yet the plot runs and indicates three different clusters?



WHP


Proprietary

-Original Message-
From: Poling, William  
Sent: Sunday, May 17, 2020 4:50 AM
To: r-help@r-project.org
Cc: Poling, William 
Subject: Help with spTransform() function and final plot colors

#RStudio Version Version 1.2.1335
sessionInfo()
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 
(build 17763)

Hello. I am running my data through a routine I found that finds clusters of 
data points based on distance rule.
https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

1. I get this error when I get to this point in the routine, see complete 
routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite 
transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the 
plot itself, seems to work Can this error be corrected somehow, despite the 
fact that it continues to work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the 
colors but the clusters in the plot are black, see plot call at the end of the 
routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
  coords.x1 coords.x2
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 In

Re: [R] Help with spTransform() function and final plot colors

2020-05-17 Thread Poling, William via R-help
Hello, I have found an additional problem.

I should be getting 3 columns back in the xy@data at some point.
$ ID   : int  1 2 3 4 5 6 7 8 9 10 ...
# $ Clust  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
# $ Clust.1   : int  1 1 1 1 1 1 1 1 1 1 ... This would be the 
cluster number, like 1-3, I am not getting this column back?


Yet the plot runs and indicates three different clusters?



WHP


Proprietary

-Original Message-
From: Poling, William  
Sent: Sunday, May 17, 2020 4:50 AM
To: r-help@r-project.org
Cc: Poling, William 
Subject: Help with spTransform() function and final plot colors

#RStudio Version Version 1.2.1335
sessionInfo()
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 
(build 17763)

Hello. I am running my data through a routine I found that finds clusters of 
data points based on distance rule.
https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

1. I get this error when I get to this point in the routine, see complete 
routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite 
transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the 
plot itself, seems to work Can this error be corrected somehow, despite the 
fact that it continues to work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the 
colors but the clusters in the plot are black, see plot call at the end of the 
routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
  coords.x1 coords.x2
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 Inf Inf
Error in spTransform(xSP, CRSobj, ...) : 
  failure in points 
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite

Here is the data:
dput(sample)
structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, -119.779416, 
-121.0234, -122.004736, -122.013456, -122.0379, -122.0578, -122.132971, 
-122.150901, -122.170608, -122.18462, -122.184639, -122.185079, -122.195398, 
-122.198994, -122.201356, -122.202507, -122.20371, -122.209047, -122.210797, 
-122.229095, -122.2419, -122.27216, -122.273164, -122.280355, -122.28389, 
-122.289043, -122.299261, -122.318009, -122.326987, -122.347382, -122.34844, 
-122.358115, -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, 
-122.462136, -122.490417, -122.551483, -122.734847, -122.782736, -122.798669, 
-122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407, 
-123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 
39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 
47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723, 
47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027, 
47

[R] Help with spTransform() function and final plot colors

2020-05-17 Thread Poling, William via R-help
#RStudio Version Version 1.2.1335 
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

Hello. I am running my data through a routine I found that finds clusters of 
data points based on distance rule.
https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

1. I get this error when I get to this point in the routine, see complete 
routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))
non finite transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the 
plot itself, seems to work
Can this error be corrected somehow, despite the fact that it continues to 
work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the 
colors but the clusters in the plot are black, see plot call at the end of the 
routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
  coords.x1 coords.x2
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 Inf Inf
Error in spTransform(xSP, CRSobj, ...) : 
  failure in points 
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite

Here is the data:
dput(sample)
structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, 
-119.779416, -121.0234, -122.004736, -122.013456, -122.0379, 
-122.0578, -122.132971, -122.150901, -122.170608, -122.18462, 
-122.184639, -122.185079, -122.195398, -122.198994, -122.201356, 
-122.202507, -122.20371, -122.209047, -122.210797, -122.229095, 
-122.2419, -122.27216, -122.273164, -122.280355, -122.28389, 
-122.289043, -122.299261, -122.318009, -122.326987, -122.347382, 
-122.34844, -122.358115, -122.361839, -122.37003, -122.390815, 
-122.41282, -122.429323, -122.462136, -122.490417, -122.551483, 
-122.734847, -122.782736, -122.798669, -122.838498, -122.853683, 
-122.8904, -122.89271, -122.94511, -122.959407, -123.064087, 
-123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 39.205028, 
47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 
47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 
47.447723, 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 
47.768701, 48.048027, 47.876997, 47.776205, 47.821029, 47.868987, 
47.673056, 47.382165, 47.403785, 47.438836, 47.530831, 47.276776, 
47.76735, 47.565667, 47.549377, 47.646222, 47.176596, 47.445053, 
47.274599, 46.939789, 42.373195, 47.310595, 47.234748, 42.351189, 
42.344953, 42.395547, 42.33022, 47.375736, 42.303755, 47.164278, 
42.441172)), class = "data.frame", row.names = c(NA, -53L))

Here is the routine:
require(sp)
require(rgdal)
#25*1609.34 = 40233.5  
dis <- 40233.5 #Distance threshold 25miles converted to meters

x <- tmp1b[,c(6)]
head(x)
y <- tmp1b[,c(5)]
head(y)
str(y)

xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2), 
data.frame(ID=seq(1:length(x))),
 pro

Re: [R] Help with map()

2020-05-14 Thread Poling, William via R-help
Hi Jim, thanks for the advice, those modifications are outside my capabilities 
at the moment but I will play around with it I guess.

Thank you.

WHP



Proprietary

-Original Message-
From: Jim Lemon  
Sent: Thursday, May 14, 2020 7:27 AM
To: Poling, William ; r-help mailing list 

Subject: [EXTERNAL] Re: Re: [R] Help with map()

 External Email - Use Caution 

Hi Bill,
I guess if you run makeDensityMatrix on subsets of the geographic locations and 
then overlay the different results with densityGrid using different colors, it 
should work as long as the regions don't overlap.

Jim

On Thu, May 14, 2020 at 10:20 PM Poling, William  wrote:
>
> Hello Jim, et.al, again.
>
> One last question please.
>
> Since this routine works best with larger volume of geo points, is there a 
> way to modify this routine to accommodate more than one cluster and 
> differentiated by different colors?
>
> #Single cluster routine
> clus3 <- individual_dets_sf_3X %>%
>
>   
> dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
>  %>% #Notice now that these are capitalized <--"L"
>
>   filter(clusters == 3)
>
> str(clus3)
>
> clus3 <- as.data.frame(clus3)
>
> geomat<-makeDensityMatrix(clus3[,c("Latitude","Longitude")],
>   
> xlim=range(clus3$Longitude),ylim=range(clus3$Latitude))
> # Range of density (>0) - 1.292155 3.89646
> latlim<-range(clus3$Latitude)
> lonlim<-range(clus3$Longitude)
>
> map("world",xlim=lonlim,ylim=latlim)
> axis(1)
> axis(2)
> densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
> red=c(0.5,1),green=0,blue=0,pch=15)
> title("Member Geo Density Plot For Cluster3")
>
> knitr::kable(individual_dets_sf_3X %>% group_by(clusters) %>% 
> tally(sort = TRUE))
>
> #   | clusters|   n|
> #   |:|---:|
> #   |3| 384|
> #   |5| 335|
> #   |9| 305|
> #   |7| 298|
> #   |   10| 286|
> #   |6| 279|
> #   |4| 168|
> #   |8| 131|
> #   |2| 113|
> #   |1|  53|
>
> 'data.frame':   384 obs. of  7 variables:
>  $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 908 2272 1613 
> 1357 1952 1437 795 1634 1160 902 ...
>  $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 10 23 23 10 33 10 
> 10 23 10 10 ...
>  $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 156 496 354 827 
> 670 1161 897 970 249 494 ...
>  $ clusters: num  3 3 3 3 3 3 3 3 3 3 ...
>  $ Latitude: num  31.2 35.3 36.5 33.4 34.2 ...
>  $ Longitude   : num  -81.5 -82.4 -81 -84.7 -80.7 ...
>  $ distances_Mi: num  770 586 471 769 573 ...
>
>
>
>
>
> Proprietary
>
> -Original Message-
> From: Poling, William
> Sent: Thursday, May 14, 2020 7:03 AM
> To: Jim Lemon 
> Cc: r-help@r-project.org; Mark Fowler 
> Subject: RE: [EXTERNAL] Re: [R] Help with map()
>
> Hi, it is working now using just the most necessary pkgs.
>
>  Evidently when there are so few rows (clus1=53) the map does not cooperate, 
> I get the plot but no map image?
>
> As I increase records the map begins to appear as it did for Radius1-8 
> routines
>
> Thank you for your time and trouble my friends.
>
> WHP
>
>
>
>
>
> Proprietary
>
> -Original Message-
> From: Poling, William
> Sent: Thursday, May 14, 2020 6:46 AM
> To: Jim Lemon 
> Cc: r-help@r-project.org; Mark Fowler 
> Subject: RE: [EXTERNAL] Re: [R] Help with map()
>
> Hi, I ran this which is partially successful. I got long & lat  (x&y) with 
> red plot values however, no map behind it?
>
> Not sure what I might be missing now in terms of pkgs I suppose?
> #Just use the basic pkgs
> library(magrittr)#for %>% function
> library(plotrix)
> library(maps)
> library(dplyr)#For filter()
> str(individual_dets_sf_3X)
> str(radius3)
> str(clus1)
>
>
> #rm(clus1)
>
> clus1 <- individual_dets_sf_3X %>%
>
>   
> dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
>  %>% #Notice now that these are capitalized <--"L"
>
>   filter(clusters == 1)
>
> str(clus1)
>
> clus1 <- as.data.frame(clus1)
>
> geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
>   
> xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))
> # Range of density (>0) - 1.292155 3.89646
> latlim<-range(clus1$Latitude)
> lonlim<-range(clus1$Longitude)
>
> map("world&qu

Re: [R] Help with map()

2020-05-14 Thread Poling, William via R-help
Hello Jim, et.al, again.

One last question please.

Since this routine works best with larger volume of geo points, is there a way 
to modify this routine to accommodate more than one cluster and differentiated 
by different colors?

#Single cluster routine
clus3 <- individual_dets_sf_3X %>% 
  
  
dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
 %>% #Notice now that these are capitalized <--"L"
  
  filter(clusters == 3)

str(clus3)

clus3 <- as.data.frame(clus3)

geomat<-makeDensityMatrix(clus3[,c("Latitude","Longitude")],
  
xlim=range(clus3$Longitude),ylim=range(clus3$Latitude))
# Range of density (>0) - 1.292155 3.89646 
latlim<-range(clus3$Latitude)
lonlim<-range(clus3$Longitude)

map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Cluster3")

knitr::kable(individual_dets_sf_3X %>% group_by(clusters) %>% tally(sort = 
TRUE))

#   | clusters|   n|
#   |:|---:|
#   |3| 384|
#   |5| 335|
#   |9| 305|
#   |7| 298|
#   |   10| 286|
#   |6| 279|
#   |4| 168|
#   |8| 131|
#   |2| 113|
#   |1|  53|

'data.frame':   384 obs. of  7 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 908 2272 1613 
1357 1952 1437 795 1634 1160 902 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 10 23 23 10 33 10 
10 23 10 10 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 156 496 354 827 
670 1161 897 970 249 494 ...
 $ clusters: num  3 3 3 3 3 3 3 3 3 3 ...
 $ Latitude: num  31.2 35.3 36.5 33.4 34.2 ...
 $ Longitude   : num  -81.5 -82.4 -81 -84.7 -80.7 ...
 $ distances_Mi: num  770 586 471 769 573 ...





Proprietary

-Original Message-
From: Poling, William 
Sent: Thursday, May 14, 2020 7:03 AM
To: Jim Lemon 
Cc: r-help@r-project.org; Mark Fowler 
Subject: RE: [EXTERNAL] Re: [R] Help with map()

Hi, it is working now using just the most necessary pkgs.

 Evidently when there are so few rows (clus1=53) the map does not cooperate, I 
get the plot but no map image?

As I increase records the map begins to appear as it did for Radius1-8 routines

Thank you for your time and trouble my friends.

WHP





Proprietary

-Original Message-
From: Poling, William 
Sent: Thursday, May 14, 2020 6:46 AM
To: Jim Lemon 
Cc: r-help@r-project.org; Mark Fowler 
Subject: RE: [EXTERNAL] Re: [R] Help with map()

Hi, I ran this which is partially successful. I got long & lat  (x&y) with red 
plot values however, no map behind it?

Not sure what I might be missing now in terms of pkgs I suppose?
#Just use the basic pkgs
library(magrittr)#for %>% function
library(plotrix)
library(maps)
library(dplyr)#For filter()
str(individual_dets_sf_3X)
str(radius3)
str(clus1)


#rm(clus1)

clus1 <- individual_dets_sf_3X %>% 
  
  
dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
 %>% #Notice now that these are capitalized <--"L"
  
  filter(clusters == 1)

str(clus1)

clus1 <- as.data.frame(clus1)

geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
  
xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))
# Range of density (>0) - 1.292155 3.89646 
latlim<-range(clus1$Latitude)
lonlim<-range(clus1$Longitude)

map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Cluster1")





Proprietary

-Original Message-
From: Poling, William 
Sent: Thursday, May 14, 2020 6:29 AM
To: Jim Lemon 
Cc: r-help@r-project.org; Mark Fowler 
Subject: RE: [EXTERNAL] Re: [R] Help with map()


Hi Jim, and Mark, thank you for your response.

1. I have restarted R
2. I have only initiated library(magrittr)#for %>% function & library(plotrix), 
no other libraries thinking that another may be overwriting something.
3. I have checked the str()

str(radius3)
'data.frame':   1990 obs. of  6 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 590 908 976 509 
1674 690 1336 726 1702 2331 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 32 10 25 11 9 32 13 
12 12 17 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 932 156 230 698 
965 1330 515 1127 1304 1316 ...
 $ Latitude: num  40.4 31.2 40.8 42.1 26.8 ...
 $ Longitude   : num  -79.9 -81.5 -74 -91.6 -82.1 ...
 $ distances_Mi: num  310.3 769.9 16.1 920.4 1057.6 ...

str(clus1)
tibble [53 x 7

Re: [R] Help with map()

2020-05-14 Thread Poling, William via R-help
Hi, it is working now using just the most necessary pkgs.

 Evidently when there are so few rows (clus1=53) the map does not cooperate, I 
get the plot but no map image?

As I increase records the map begins to appear as it did for Radius1-8 routines

Thank you for your time and trouble my friends.

WHP





Proprietary

-Original Message-
From: Poling, William 
Sent: Thursday, May 14, 2020 6:46 AM
To: Jim Lemon 
Cc: r-help@r-project.org; Mark Fowler 
Subject: RE: [EXTERNAL] Re: [R] Help with map()

Hi, I ran this which is partially successful. I got long & lat  (x&y) with red 
plot values however, no map behind it?

Not sure what I might be missing now in terms of pkgs I suppose?
#Just use the basic pkgs
library(magrittr)#for %>% function
library(plotrix)
library(maps)
library(dplyr)#For filter()
str(individual_dets_sf_3X)
str(radius3)
str(clus1)


#rm(clus1)

clus1 <- individual_dets_sf_3X %>% 
  
  
dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
 %>% #Notice now that these are capitalized <--"L"
  
  filter(clusters == 1)

str(clus1)

clus1 <- as.data.frame(clus1)

geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
  
xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))
# Range of density (>0) - 1.292155 3.89646 
latlim<-range(clus1$Latitude)
lonlim<-range(clus1$Longitude)

map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Cluster1")





Proprietary

-Original Message-
From: Poling, William 
Sent: Thursday, May 14, 2020 6:29 AM
To: Jim Lemon 
Cc: r-help@r-project.org; Mark Fowler 
Subject: RE: [EXTERNAL] Re: [R] Help with map()


Hi Jim, and Mark, thank you for your response.

1. I have restarted R
2. I have only initiated library(magrittr)#for %>% function & library(plotrix), 
no other libraries thinking that another may be overwriting something.
3. I have checked the str()

str(radius3)
'data.frame':   1990 obs. of  6 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 590 908 976 509 
1674 690 1336 726 1702 2331 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 32 10 25 11 9 32 13 
12 12 17 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 932 156 230 698 
965 1330 515 1127 1304 1316 ...
 $ Latitude: num  40.4 31.2 40.8 42.1 26.8 ...
 $ Longitude   : num  -79.9 -81.5 -74 -91.6 -82.1 ...
 $ distances_Mi: num  310.3 769.9 16.1 920.4 1057.6 ...

str(clus1)
tibble [53 x 7] (S3: tbl_df/tbl/data.frame)  $ MBR_SUBSCRIBERID: Factor w/ 2352 
levels "101040199600",..: 86 2111 995 899 953 924 769 92 790 1748 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 
31 39 39 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 
1203 604 1169 727 984 295 ...
 $ clusters: num [1:53] 1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude: num [1:53] 42.4 47.6 39.2 46.9 48 ...
 $ Longitude   : num [1:53] -123 -122 -121 -123 -122 ...
 $ distances_Mi: num [1:53] 2499 2406 2472 2430 2408 ...

4. I change clus1 to DF
'data.frame':   53 obs. of  7 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 86 2111 995 899 
953 924 769 92 790 1748 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 
31 39 39 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 
1203 604 1169 727 984 295 ...
 $ clusters: num  1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude: num  42.4 47.6 39.2 46.9 48 ...
 $ Longitude   : num  -123 -122 -121 -123 -122 ...
 $ distances_Mi: num  2499 2406 2472 2430 2408 ...

Then try again, no luck?

Weird?

Thanks

WHP

Proprietary

-Original Message-
From: Jim Lemon 
Sent: Thursday, May 14, 2020 5:44 AM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with map()

 External Email - Use Caution 

Hi Bill,
Have you compared str(radius3) to str(clus1)? It may be quite different.

Jim

On Thu, May 14, 2020 at 8:24 PM Poling, William via R-help 
 wrote:
>
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10
> x64 (build 17763)
>
> Good morning.
>
> I ran routines like this one yesterday with no errors.
>
> #Radius3
> str(radius3)
>
> radius3 <- individual_dets_sf_3X %>%
>
>   dplyr::select(MBR_SUBSCRIBERID,state,city,Latitude,Longitude,distances_Mi) 
> %>%
>   filter(dis

Re: [R] Help with map()

2020-05-14 Thread Poling, William via R-help
Hi, I ran this which is partially successful. I got long & lat  (x&y) with red 
plot values however, no map behind it?

Not sure what I might be missing now in terms of pkgs I suppose?
#Just use the basic pkgs
library(magrittr)#for %>% function
library(plotrix)
library(maps)
library(dplyr)#For filter()
str(individual_dets_sf_3X)
str(radius3)
str(clus1)


#rm(clus1)

clus1 <- individual_dets_sf_3X %>% 
  
  
dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
 %>% #Notice now that these are capitalized <--"L"
  
  filter(clusters == 1)

str(clus1)

clus1 <- as.data.frame(clus1)

geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
  
xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))
# Range of density (>0) - 1.292155 3.89646 
latlim<-range(clus1$Latitude)
lonlim<-range(clus1$Longitude)

map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Cluster1")





Proprietary

-Original Message-
From: Poling, William 
Sent: Thursday, May 14, 2020 6:29 AM
To: Jim Lemon 
Cc: r-help@r-project.org; Mark Fowler 
Subject: RE: [EXTERNAL] Re: [R] Help with map()


Hi Jim, and Mark, thank you for your response.

1. I have restarted R
2. I have only initiated library(magrittr)#for %>% function & library(plotrix), 
no other libraries thinking that another may be overwriting something.
3. I have checked the str()

str(radius3)
'data.frame':   1990 obs. of  6 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 590 908 976 509 
1674 690 1336 726 1702 2331 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 32 10 25 11 9 32 13 
12 12 17 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 932 156 230 698 
965 1330 515 1127 1304 1316 ...
 $ Latitude: num  40.4 31.2 40.8 42.1 26.8 ...
 $ Longitude   : num  -79.9 -81.5 -74 -91.6 -82.1 ...
 $ distances_Mi: num  310.3 769.9 16.1 920.4 1057.6 ...

str(clus1)
tibble [53 x 7] (S3: tbl_df/tbl/data.frame)  $ MBR_SUBSCRIBERID: Factor w/ 2352 
levels "101040199600",..: 86 2111 995 899 953 924 769 92 790 1748 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 
31 39 39 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 
1203 604 1169 727 984 295 ...
 $ clusters: num [1:53] 1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude: num [1:53] 42.4 47.6 39.2 46.9 48 ...
 $ Longitude   : num [1:53] -123 -122 -121 -123 -122 ...
 $ distances_Mi: num [1:53] 2499 2406 2472 2430 2408 ...

4. I change clus1 to DF
'data.frame':   53 obs. of  7 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 86 2111 995 899 
953 924 769 92 790 1748 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 
31 39 39 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 
1203 604 1169 727 984 295 ...
 $ clusters: num  1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude: num  42.4 47.6 39.2 46.9 48 ...
 $ Longitude   : num  -123 -122 -121 -123 -122 ...
 $ distances_Mi: num  2499 2406 2472 2430 2408 ...

Then try again, no luck?

Weird?

Thanks

WHP

Proprietary

-Original Message-
From: Jim Lemon 
Sent: Thursday, May 14, 2020 5:44 AM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with map()

 External Email - Use Caution 

Hi Bill,
Have you compared str(radius3) to str(clus1)? It may be quite different.

Jim

On Thu, May 14, 2020 at 8:24 PM Poling, William via R-help 
 wrote:
>
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10
> x64 (build 17763)
>
> Good morning.
>
> I ran routines like this one yesterday with no errors.
>
> #Radius3
> str(radius3)
>
> radius3 <- individual_dets_sf_3X %>%
>
>   dplyr::select(MBR_SUBSCRIBERID,state,city,Latitude,Longitude,distances_Mi) 
> %>%
>   filter(distances_Mi <= 1200)
>
> str(radius3)
>
>   geomat<-makeDensityMatrix(radius3[,c("Latitude","Longitude")],
> 
> xlim=range(radius3$Longitude),ylim=range(radius3$Latitude))
>
> latlim<-range(radius3$Latitude)
> lonlim<-range(radius3$Longitude)
>
> <- map("world",xlim=lonlim,ylim=latlim)
> axis(1)
> axis(2)
> densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
> red=c(0.5,1),gre

Re: [R] Help with map()

2020-05-14 Thread Poling, William via R-help


Hi Jim, and Mark, thank you for your response.

1. I have restarted R
2. I have only initiated library(magrittr)#for %>% function & library(plotrix), 
no other libraries thinking that another may be overwriting something.
3. I have checked the str()

str(radius3)
'data.frame':   1990 obs. of  6 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 590 908 976 509 
1674 690 1336 726 1702 2331 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 32 10 25 11 9 32 13 
12 12 17 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 932 156 230 698 
965 1330 515 1127 1304 1316 ...
 $ Latitude: num  40.4 31.2 40.8 42.1 26.8 ...
 $ Longitude   : num  -79.9 -81.5 -74 -91.6 -82.1 ...
 $ distances_Mi: num  310.3 769.9 16.1 920.4 1057.6 ...

str(clus1)
tibble [53 x 7] (S3: tbl_df/tbl/data.frame)
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 86 2111 995 899 
953 924 769 92 790 1748 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 
31 39 39 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 
1203 604 1169 727 984 295 ...
 $ clusters: num [1:53] 1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude: num [1:53] 42.4 47.6 39.2 46.9 48 ...
 $ Longitude   : num [1:53] -123 -122 -121 -123 -122 ...
 $ distances_Mi: num [1:53] 2499 2406 2472 2430 2408 ...

4. I change clus1 to DF
'data.frame':   53 obs. of  7 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 86 2111 995 899 
953 924 769 92 790 1748 ...
 $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 
31 39 39 ...
 $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 
1203 604 1169 727 984 295 ...
 $ clusters: num  1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude: num  42.4 47.6 39.2 46.9 48 ...
 $ Longitude   : num  -123 -122 -121 -123 -122 ...
 $ distances_Mi: num  2499 2406 2472 2430 2408 ...

Then try again, no luck?

Weird?

Thanks

WHP

Proprietary

-Original Message-
From: Jim Lemon  
Sent: Thursday, May 14, 2020 5:44 AM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with map()

 External Email - Use Caution 

Hi Bill,
Have you compared str(radius3) to str(clus1)? It may be quite different.

Jim

On Thu, May 14, 2020 at 8:24 PM Poling, William via R-help 
 wrote:
>
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 
> x64 (build 17763)
>
> Good morning.
>
> I ran routines like this one yesterday with no errors.
>
> #Radius3
> str(radius3)
>
> radius3 <- individual_dets_sf_3X %>%
>
>   dplyr::select(MBR_SUBSCRIBERID,state,city,Latitude,Longitude,distances_Mi) 
> %>%
>   filter(distances_Mi <= 1200)
>
> str(radius3)
>
>   geomat<-makeDensityMatrix(radius3[,c("Latitude","Longitude")],
> 
> xlim=range(radius3$Longitude),ylim=range(radius3$Latitude))
>
> latlim<-range(radius3$Latitude)
> lonlim<-range(radius3$Longitude)
>
> <- map("world",xlim=lonlim,ylim=latlim)
> axis(1)
> axis(2)
> densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
> red=c(0.5,1),green=0,blue=0,pch=15)
> title("Member Geo Density Plot For Radius3")
>
>
> This morning I am trying slightly new routine and receiving this error
>
> clus1 <- individual_dets_sf_3X %>%
>
>   
> dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
>  %>%
>   filter(clusters == 1)
>
> geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
>   
> xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))
>
> latlim<-range(clus1$Latitude)
> lonlim<-range(clus1$Longitude)
>
> map("world",xlim=lonlim,ylim=latlim)
> axis(1)
> axis(2)
> densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
> red=c(0.5,1),green=0,blue=0,pch=15)
> title("Member Geo Density Plot For Cluster1")
>
>
> geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
> +   
> + xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))
>
> > latlim<-range(clus1$Latitude)
> > lonlim<-range(clus1$Longitude)
> >
> > map("world",xlim=lonlim,ylim=latlim)
> Error in .C(C_map_type, as.character(mapbase), integer(1)) :
>   Incorrect number of arguments (2), expecting 0 for &#x

[R] Help with map()

2020-05-14 Thread Poling, William via R-help
#RStudio Version Version 1.2.1335 
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

Good morning. 

I ran routines like this one yesterday with no errors.

#Radius3
str(radius3)

radius3 <- individual_dets_sf_3X %>% 
  
  dplyr::select(MBR_SUBSCRIBERID,state,city,Latitude,Longitude,distances_Mi) 
%>% 
  filter(distances_Mi <= 1200)
  
str(radius3)

  geomat<-makeDensityMatrix(radius3[,c("Latitude","Longitude")],

xlim=range(radius3$Longitude),ylim=range(radius3$Latitude))

latlim<-range(radius3$Latitude)
lonlim<-range(radius3$Longitude)

<- map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Radius3")


This morning I am trying slightly new routine and receiving this error

clus1 <- individual_dets_sf_3X %>% 
  
  
dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi)
 %>%   
  filter(clusters == 1)

geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
  
xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))

latlim<-range(clus1$Latitude)
lonlim<-range(clus1$Longitude)

map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Cluster1")


geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
+   
xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))

> latlim<-range(clus1$Latitude)
> lonlim<-range(clus1$Longitude)
> 
> map("world",xlim=lonlim,ylim=latlim)
Error in .C(C_map_type, as.character(mapbase), integer(1)) : 
  Incorrect number of arguments (2), expecting 0 for ''
> axis(1)
Error in axis(1) : plot.new has not been called yet
> axis(2)
Error in axis(2) : plot.new has not been called yet
> densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
+ red=c(0.5,1),green=0,blue=0,pch=15)
Error in plot.xy(xy.coords(x, y), type = type, ...) : 
  plot.new has not been called yet
> title("Member Geo Density Plot For Cluster1")
Error in title("Member Geo Density Plot For Cluster1") : 
  plot.new has not been called yet


It seems to error at the point of map("world",xlim=lonlim,ylim=latlim)

I find a ref in stack overflow 
https://stackoverflow.com/questions/45066628/cannot-run-map-datastate
and tried solutions but they do not seem to work?

Here is a sample (MBR_SUBSCRIBERID(factor) is replaced with ID(integer) but of 
no consequence in my routine since not really used.

I hope someone recognizes the problem.

Thank you for any advice 

WHP

> dput(sample)
structure(list(state = structure(c(2L, 22L, 10L, 12L, 6L, 22L, 
11L, 22L, 22L, 32L, 19L, 29L, 9L, 9L, 10L, 30L, 33L, 35L, 41L, 
12L, 12L, 36L, 4L, 9L, 8L, 39L, 36L, 36L, 41L, 28L, 12L, 28L, 
28L, 12L, 11L, 2L, 12L, 22L, 32L, 22L, 12L, 10L, 10L, 22L, 10L
), .Label = c("AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", 
"FL", "GA", "IA", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", 
"MI", "MN", "MO", "NC", "NE", "NJ", "NM", "NV", "NY", "OH", "OK", 
"OR", "PA", "SC", "SD", "TN", "TX", "UT", "VA", "WA", "WI", "WV"
), class = "factor"), city = structure(c(838L, 1030L, 262L, 218L, 
166L, 973L, 339L, 451L, 660L, 358L, 281L, 1280L, 129L, 223L, 
989L, 721L, 550L, 731L, 1325L, 688L, 1184L, 281L, 759L, 1171L, 
1305L, 587L, 272L, 581L, 263L, 152L, 217L, 152L, 390L, 5L, 571L, 
1006L, 1162L, 939L, 170L, 1033L, 1002L, 586L, 586L, 192L, 586L
), .Label = c("ABBOTTSTOWN", "ABILENE", "ACWORTH", "ADAMS", "ADDISON", 
"ADKINS", "ALBANY", "ALBIA", "ALBUQUERQUE", "ALEXANDRIA", "ALFRED", 
"ALIQUIPPA", "ALISO VIEJO", "ALLEN PARK", "ALLENTOWN", "ALPHA", 
"ALPHARETTA", "ALPINE", "ALTOONA", "AMARILLO", "AMBLER", "AMBRIDGE", 
"AMHERST", "AMITYVILLE", "ANAHIEM", "ANDERSON", "ANDOVER", "ANGIER", 
"ANGLETON", "ANKENY", "ANN ARBOR", "ANZA", "APEX", "APOLLO", 
"ARCADIA", "ARCHDALE", "ARDMORE", "ARGYLE", "ARKANSAS CITY", 
"ARLINGTON", "ARNOLD", "ARTHUR", "ASHEBORO", "ASHEVILLE", "ASHLAND", 
"ASHLAND CITY", "ASHTON", "ASTON", "ATHENS", "ATLANTA", "ATLANTIC BCH", 
"AUBORN", "AUGUSTA", "AURORA", "AUSTELL", "AUSTIN", "AVENTURA", 
"AVONDALE ESTATES", "BAKERSFIELD", "BALDWIN CITY", "BALDWIN PLACE", 
"BALLWIN", "BANGOR", "BARBOURSVILLE", "BARNEGAT", "BARTLETT", 
"BARTON", "BARTONVILLE", "BASSETT", "BATAVIA", "BATESBURG", "BATON ROUGE", 
"BAXTER SPRINGS", "BAY CITY", "BAYONNE", "BAYSIDE", "BAYTOWN", 
"BEAR", "BEAUMONT", "BEECH CREEK", "BEECHER CITY", "BELFAIR", 
"BELLE VERNON", "BELLEAIR", "BELLEVUE", "BELLMAWR", "BELLMORE", 
"BELLWOOD", "BELMAR", "BELMONT", "BELVIDERE", "BENNET", "BENTON", 
"BENTONVILLE", "BERLIN", "BESSEMER CITY", "BETHANY", "BETHEL", 
"BETHEL PARK", "BETHESDA", "BETHLEHEM", "BETTENDORF", "BIGLERVILLE", 
"BINGHAMTON", "BIRDSBORO", "BIWABIK", "BLACK MOUNTAIN", "B

Re: [R] Help with Radius problem --update

2020-05-13 Thread Poling, William via R-help
Hello Abby and thank you for your response.

Your surly correct.

I have not worked a problem like this previously, however, I am learning fast.

I did not think I would need to apply mathematical formula-calculations for 
this task, math in general not my primary area of expertise, but always very 
curious.

However your point is provocative and now I am interested to learn more in that 
space as well.

By researching the literature on Radii, and disk partial coverage problem, and 
anything in stack overflow remotely relevant to my question I am slowly piecing 
a solution together.

What I described in the string is my best thinking in terms of delivering 
something, anything, at the moment that I can build on, refine, etc.

1. I have data set with 2352 geo locations in 41 states from Maine to California
2. I have determined, using density plot (thank to Jim L), that the most 
reasonable reference point in terms of realizing population density using 
distance among my 2353 is Brooklyn, NY.
3. Calculating distances from that point to the other 2351 based on a script 
referenced in stack over flow I simply plug in, manually-iteratively, distances 
(8 at the moment) and determine how many members are in that radius
4. Then determine the % decay from Max to Min of these 8 distances and settle 
on the one that has the highest concentration with the least decay
4. This piece (Item 3) I would like to make more efficient and was the point of 
my last submission to the R-Help list on this topic

For example: Radius2 = 1500 miles, Radius3 = 1200 miles, Radius4 = 1000 miles
The difference b/w Radius2 in terms of percent missing coverage and Radius3 is 
0.057 while the percent missing coverage b/w Radius2 and Radius4 is 0.204

So my logic is that despite being a larger radius ,Radius3 vs Radius4, the 
trade off is more inclusive of the membership and therefore optimal among the 8 
iterations. For the moment

I appreciate your response and any direction or advice would be most 
appreciated.

WHP

 



Proprietary

-Original Message-
From: Abby Spurdle  
Sent: Wednesday, May 13, 2020 3:17 PM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with Radius problem --update

 External Email - Use Caution 

> "determine the largest concentration of members in the smallest radius"

I haven't read the whole thread, and I'm not familiar with this topic.
However, looking at it from an intuitive perspective, isn't the smallest radius 
zero.
If the concentration means the number of "members" divided by the area...
...then would the largest concentration be undefined, merely because of 
division by zero.

Perhaps your question is a valid one.
But if you're wanting a large pool of people to consider helping, I'd recommend 
a more (mathematically) precise definition of the problem you're trying to 
solve.

NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think 
you have received this e-mail in error, please advise the sender by reply 
e-mail and then delete this e-mail immediately.  
This e-mail may also contain protected health information (PHI) with 
information about sensitive medical conditions, including, but not limited to, 
treatment for substance use disorders, behavioral health, HIV/AIDS, or 
pregnancy. This type of information may be protected by various federal and/or 
state laws which prohibit any further disclosure without the express written 
consent of the person to whom it pertains or as otherwise permitted by law. Any 
unauthorized further disclosure may be considered a violation of federal and/or 
state law. A general authorization for the release of medical or other 
information may NOT be sufficient consent for release of this type of 
information.
Thank you. Aetna
__
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 with R-Markdown please

2020-05-13 Thread Poling, William via R-help
I have R on personal laptop for consultative purposes from time to time, 
however, I cannot move data, confidentiality constraints, as you can imagine.

I have initiated another IT ticket with organization, I think I will get to the 
bottom of this at some point.

Thank you.

WHP


Proprietary

-Original Message-
From: Rasmus Liland  
Sent: Wednesday, May 13, 2020 2:50 PM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: Re: [R] Help with R-Markdown please

 External Email - Use Caution 

On 2020-05-13 19:27 +, Poling, William wrote:
> if this is something I can do without IT admin access.

Hi!  O.T. on laptops: Also, perhaps it is easier to find another laptop.  There 
seems to be some great ThinkPads readily available anywhere around the U.S., 
like an X61 or X220 or something, at least that is my impression from various 
Facebook groups ... I mean if it is easier for you to complete your work on 
another machine where you have admin access ... just for making a rmarkdown 
presentation or something, not for working with the sensitive insurance data 
... 

Best,
Rasmus

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

__
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 with R-Markdown please

2020-05-13 Thread Poling, William via R-help
Hi Rasmus, thank you I will see if this is something I can do without IT admin 
access.

In the mean time I have reloaded rmarkdown. To local

package ‘rmarkdown’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\A436798\AppData\Local\Temp\RtmpYjSy7G\downloaded_packages

library(rmarkdown)

But R is still looking for it in : " Could not fetch 
http://?/UNC/winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/h/default.html";


More recently I have installed other pkgs for the first time use and they have 
gone to local like above for rmarkdown and I have used functions from them so 
they are being searched for correctly I guess?

Very confusing.

Thank you for your response Sir!

WHP

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS 
Member-Geo-Location-Test-V1.utf8.md --to html4 --from 
markdown+autolink_bare_uris+tex_math_single_backslash+smart --output 
Member-Geo-Location-Test-V1.html --email-obfuscation none --self-contained 
--standalone --section-divs --template 
"\\winp-oaf-113\FldrRedir_1$\A436798\Data\R\R-4.0.0patched\library\rmarkdown\rmd\h\default.html"
 --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" 
--include-in-header 
"C:\Users\A436798\AppData\Local\Temp\RtmpglP9GJ\rmarkdown-str314c55414a00.html" 
--mathjax --variable 
"mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
 --lua-filter 
"\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/lua/pagebreak.lua"
 --lua-filter 
"\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/lua/latex-div.lua"
 
output file: Member-Geo-Location-Test-V1.knit.md

Could not fetch 
http://?/UNC/winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/h/default.html
HttpExceptionRequest Request {
  host = ""
  port = 80
  secure   = False
  requestHeaders   = []
  path = "/"
  queryString  = 
"?/UNC/winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/h/default.html"
  method   = "GET"
  proxy= Nothing
  rawBody  = False
  redirectCount= 10
  responseTimeout  = ResponseTimeoutDefault
  requestVersion   = HTTP/1.1
}
 (InvalidDestinationHost "")
Error: pandoc document conversion failed with error 61
Execution halted


WHP


Proprietary

-Original Message-
From: Rasmus Liland  
Sent: Wednesday, May 13, 2020 2:10 PM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with R-Markdown please

 External Email - Use Caution 

On 2020-05-13 18:46 +, Poling, William via R-help wrote:
> Hello all.
> 
> I am still struggling with this issue.
> 
> It appears that new installations are going to local drive.
> 
> # #Test 05/13/2020
> # install.packages("abjutils")
> # package ‘abjutils’ successfully unpacked and MD5 sums checked # # 
> The downloaded binary packages are in # 
> C:\Users\A436798\AppData\Local\Temp\RtmpCuXNJn\downloaded_packages
> 
> However, when I run .libPaths() it
> indicates our UNC path
> 
> [1] "winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library"
> 
> Is there a way for me to change this myself in my instance of R?

Dear William,

Perhaps you could try to set the variable R_LIBS_USER to some local folder.  I 
do not know how to do this on Windows, but there seems to be some guys in this 
rstudio discussion thread that came to some sort of a
conclusion: 
https://urldefense.proofpoint.com/v2/url?u=https-3A__community.rstudio.com_t_help-2Dregarding-2Dpackage-2Dinstallation-2Drenviron-2Drprofile-2Dr-2Dlibs-2Dr-2Dlibs-2Dsite-2Dand-2Dr-2Dlibs-2Duser-2Doh-2Dmy_13888_8&d=DwIDaQ&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY&m=q_5fam9luSaeNgs-KOUZS-w-YAVaPzQdZgIlejBCDFA&s=NWDnltFH8cjC-pj6K08lWXC1FjfFcyY1mueSZnor9Ng&e=
  

Since long ago, I have had this line in my ~/.zshrc.local  :)

[ -e /usr/bin/Rscript ] && R_LIBS_USER=`Rscript -e 
'cat(Sys.getenv("R_LIBS_USER"))'`

Best,
Rasmus

NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think 
you have received this e-mail in error, please advise the sender by reply 
e-mail and then delete this e-mail immediately.  
This e-mail may also contain protected health information (PHI) with 
information about sensitive medical conditions, including, but not limited to, 
treatment for substance use disorders, behavioral health, HIV/AIDS, or 
pregnancy. This type of information may be protected by various federal and/or 
state laws which prohi

Re: [R] Help with R-Markdown please

2020-05-13 Thread Poling, William via R-help
Hello all.

I am still struggling with this issue.

It appears that new installations are going to local drive.


# #Test 05/13/2020
# install.packages("abjutils")
# package ‘abjutils’ successfully unpacked and MD5 sums checked
# 
# The downloaded binary packages are in
# C:\Users\A436798\AppData\Local\Temp\RtmpCuXNJn\downloaded_packages

However, when I run .libPaths() it indicates our UNC path

[1] "winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library"


Is there a way for me to change this myself in my instance of R?

Thank you.

WHP 



Proprietary

-Original Message-
From: Ege Rubak  
Sent: Tuesday, May 12, 2020 7:43 AM
To: Poling, William ; r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with R-Markdown please

 External Email - Use Caution 

Looks like your files are on a Windows network drive (UNC path). I have 
experienced many problems with this on a Windows laptop from work. If at all 
possible you should avoid this. As an absolute minimum make sure your R library 
(collection of installed packages) is on the local file system and not a UNC 
path. If you are lucky this could be enough to make things work.

You can check your library location(s) with the command .libPaths() in an R 
session.

Good luck.

Ege

On Tue, 2020-05-12 at 10:15 +0000, Poling, William via R-help wrote:
> #UPDATED 05/05/2020
> #RStudio Version Version 1.2.1335 need this one--> 1.2.5019
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 
> x64 (build 17763)
> 
> Good morning.
> 
> This is the first time I have tried RMarkdown on new laptop with new 
> employer.
> I am not sure how to go about fixing this problem below?
> 
> Would someone please advise course of action.
> 
> Thank you.
> 
> WHP
> 
> 
> 
> processing file: Member-Geo-Location-Test-V1.Rmd
>  
> |..  
>   |  14%
>   ordinary text without R code
> 
>  
> |
>   |  29%
> label: unnamed-chunk-1 (with options) List of 1  $ echo: logi FALSE
> 
>  
> |..  
>   |  43%
>   ordinary text without R code
> 
>  
> |
>   |  57%
> label: setup (with options)
> List of 2
>  $ include: logi FALSE
>  $ warning: logi FALSE
> 
>  
> |..  
>   |  71%
>   ordinary text without R code
> 
>  
> |
>   |  86%
> label: Table1 (with options)
> List of 2
>  $ echo   : logi FALSE
>  $ results: chr "asis"
> 
>  
> |
> ..| 100%
>inline R code fragments
> 
> 
> output file: Member-Geo-Location-Test-V1.knit.md
> 
> "C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS Member- 
> Geo-Location-Test-V1.utf8.md --to html4 --from
> markdown+autolink_bare_uris+tex_math_single_backslash+smart --output
> Member-Geo-Location-Test-V1.html --email-obfuscation none --self- 
> contained --standalone --section-divs --template "\\winp-oaf-
> 113\FldrRedir_1$\A436798\Data\R\R-
> 4.0.0patched\library\rmarkdown\rmd\h\default.html" --no-highlight -- 
> variable highlightjs=1 --variable "theme:bootstrap" --include-in- 
> header "C:\Users\A436798\AppData\Local\Temp\RtmpSajZla\rmarkdown-
> str2ae846253313.html" --mathjax --variable "mathjax-url:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__mathjax.rstudio.c
> om_latest_MathJax.js-3Fconfig-3DTeX-2DAMS-2DMML-5FHTMLorMML&d=DwIGaQ&c
> =wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTC
> tKvneM2ExlYvnUWbsByY&m=uBce0mQRO8wdLXO8BDTtjk4R92KVzpjtkQ-NqYiAHCo&s=S
> MNU_B--j9FvBKh-0u1NG5RHd7AtLkvyVsi9ybyUwYU&e=
> " --lua-filter "\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-
> 4.0.0patched/library/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter
> "\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-
> 4.0.0patched/library/rmarkdown/rmd/lua/latex-div.lua" 
> Could not fetch http://?/UNC/winp-oaf-
> 113/FldrRedir_1$/A436798/Data/R/R-
> 4.0.0patched/library/rmarkdown/rmd/h/default.html
> HttpExceptionRequest Request {
>   host = ""
>   port = 80
>   secure   = False
>   requestHeaders   = []
>   path = "/"
>   queryString  = "?/UNC/winp-oaf-
> 113/FldrRedir_1$/A43

Re: [R] Help with Radius problem --update

2020-05-13 Thread Poling, William via R-help
ESPORT", "MCKINNEY", "MECHANICSBURG", 
"MECHANICSVILLE", "MEDFORD", "MEDIA", "MEDWAY", "MELVILLE", "MEMPHIS", 
"MERIDEN", "MERRIAM", "MERRICK", "MERRILL", "MERRILLVILLE", "MESA", 
"MESQUITE", "MIAMI", "MIAMI GARDENS", "MICHIGAN CITY", "MIDDLETOWN", 
"MIDLAND", "MIFFLINTOWN", "MILFORD", "MILL CREEK", "MILLBROOK", 
"MILLEDGEVILLE", "MILLINOCKET", "MILNER", "MILTON", "MILWAUKEE", 
"MINEOLA", "MINERAL SPGS", "MINERAL WELLS", "MINNEAPOLIS", "MISSION", 
"MISSION HILLS", "MISSION VIEJO", "MISSOURI CITY", "MISSOURI VALLEY", 
"MOLINE", "MONESSEN", "MONROE", "MONROE TOWNSHIP", "MONROEVILLE", 
"MONTCLAIR", "MONTEREY", "MONTICELLO", "MOORESVILLE", "MORGANTON", 
"MORGANTOWN", "MORRIS PLAINS", "MOUND", "MOUND CITY", "MOUNT HOPE", 
"MOUNT JOY", "MOUNT LAUREL", "MOUNT PLEASANT", "MOUNT POCONO", 
"MOUNT UNION", "MOUNT WOLF", "MOUNTVILLE", "MT HOLLY", "MT PLEASANT", 
"MULVANE", "MUNCIE", "MUNSTER", "MURFREESBORO", "MURRAY", "MURRELLS INLT", 
"MUSTANG", "MYERSTOWN", "MYSTIC", "N BRANFORD", "N FT MYERS", 
"NAPERVILLE", "NAPLES", "NAPOLEON", "NASHVILLE", "NATCHITOCHES", 
"NAUGATUCK", "NEOSHO", "NEPTUNE BEACH", "NESCONSET", "NETCONG", 
"NEW BLOOMFIELD", "NEW BRAUNFELS", "NEW BRITAIN", "NEW BRUNSWICK", 
"NEW CASTLE", "NEW CUMBERLAND", "NEW HAVEN", "NEW KENSINGTON", 
"NEW LONDON", "NEW ORLEANS", "NEW PRESTON", "NEW PROVIDENCE", 
"NEW ROCHELLE", "NEW TRIPOLI", "NEW ULM", "NEW WINDSOR", "NEW YORK", 
"NEWARK", "NEWBURGH HEIGHTS", "NEWINGTON", "NEWNAN", "NEWPORT", 
"NEWPORT BEACH", "NEWTON", "NEWTONVILLE", "NIAGARA FALLS", "NIXA", 
"NOANK", "NOKOMIS", "NORCROSS", "NORFOLK", "NORMAN", "NORMANDY PARK", 
"NORTH BABYLON", "NORTH HAVEN", "NORTH HUNTINGDON", "NORTH JACKSON", 
"NORTH LITTLE ROCK", "NORTH MIAMI", "NORTH PORT", "NORTH RICHLAND HILLS", 
"NORTH WALES", "NORTH WATERBORO", "NORTHFIELD", "NORTHRIDGE", 
"NORTON", "NORWALK", "NOTTINGHAM", "NUTLEY", "NYACK", "O FALLON", 
"OAK RIDGE", "OAKDALE", "OCALA", "OCEANSIDE", "OCILLA", "OLATHE", 
"OMAHA", "OMRO", "ONA", "ONALASKA", "OPA LOCKA", "ORADLL", "ORION", 
"ORONO", "ORRINGTON", "OSCEOLA", "OSKALOOSA", "OSSINING", "OSWEGO", 
"OTTAWA", "OVALO", "OVERLAND PARK", "OWASSO", "OWEGO", "OXFORD", 
"OYSTER BAY", "OZARK", "PALERMO", "PALM CITY", "PALM HARBOR", 
"PALMDALE", "PALMYRA", "PALOS HEIGHTS", "PANA", "PAOLA", "PARK RIDGE", 
"PARLIN", "PARMA", "PARRISH", "PARROTT", "PATASKALA", "PAULS VALLEY", 
"PAXTON", "PEA RIDGE", "PEARLAND", "PECULIAR", "PEEKSKILL", "PEKIN", 
"PELION", "PEMBROKE", "PEMBROKE PINES", "PENN YAN", "PENNELLVILLE", 
"PENNSBURG", "PENNSVILLE", "PEORIA", "PERRY", "PERRYOPOLIS", 
"PERRYSBURG", "PERRYVILLE", "PHARR", "PHILADELPHIA", "PHILIPPI", 
"PHOENIX", "PICKENS", "PICKERINGTON", "PIERSON", "PILOT MOUNTAIN", 
"PINE BLUFF", "PINE HILL", "PINEVILLE", "PINNELLAS PARK", "PISCATAWAY", 
"PITMAN", "PITTSBURGH", "PLACIDA", "PLAINFIELD", "PLANO", "PLANT CITY", 
"PLATTEKILL", "PLEASANT

Re: [R] Help with Radius problem

2020-05-13 Thread Poling, William via R-help
Good morning Jim.

This is awesome start, visualization is splendid, thank you very much.

I have signed on to r-sig-geo and submitted my question there. I have no idea 
of the volume of traffic on that list
However, hopefully, I will gain additional insight into how to determine max 
number of member locations in the most minimum radius area.

Have a great day!

WHP



Proprietary

-Original Message-
From: Jim Lemon  
Sent: Wednesday, May 13, 2020 1:39 AM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with Radius problem

 External Email - Use Caution 

Hi Bill,
A while ago I devised a couple of functions to accumulate millions of 
geographic locations of events and then display the resulting matrix of values 
on an existing plot. This may be of use to you, at least in the visualization 
of the density of the locations. As your example data only included a few 
points, the resulting plot looks pretty chunky as I had to use a large symbol 
to make the cells with non-zero counts obvious.

# read in your sample data
source("wp_data.R")
library(plotrix)
geomat<-makeDensityMatrix(geodat[,c("latitude","longitude")],
xlim=range(geodat$longitude),ylim=range(geodat$latitude))
# Range of density (>0) - 1.119816 3.922018
latlim<-range(geodat$latitude)
lonlim<-range(geodat$longitude)
library(maps)
map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
 red=c(0.5,1),green=0,blue=0,pch=15)

Jim

On Wed, May 13, 2020 at 10:57 AM Poling, William via R-help 
 wrote:
>
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 
> x64 (build 17763)
>
> Hello I am trying to figure out how to create concentration of ID's in 
> the following data, based on determining the highest concentration in 
> the smallest radius area based on Longitude and Latitude (geo 
> location)
>
> I have reviewed many websites looking for a function or tutorial, (if 
> you are aware of either please let me know)
>

NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think 
you have received this e-mail in error, please advise the sender by reply 
e-mail and then delete this e-mail immediately.  
This e-mail may also contain protected health information (PHI) with 
information about sensitive medical conditions, including, but not limited to, 
treatment for substance use disorders, behavioral health, HIV/AIDS, or 
pregnancy. This type of information may be protected by various federal and/or 
state laws which prohibit any further disclosure without the express written 
consent of the person to whom it pertains or as otherwise permitted by law. Any 
unauthorized further disclosure may be considered a violation of federal and/or 
state law. A general authorization for the release of medical or other 
information may NOT be sufficient consent for release of this type of 
information.
Thank you. Aetna
__
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 with Radius problem

2020-05-13 Thread Poling, William via R-help
Good morning Bert. I will sign up for r-sig-geo and review your suggested link 
as well, thank you very much for your response.

WHP




Proprietary

-Original Message-
From: Bert Gunter  
Sent: Tuesday, May 12, 2020 8:30 PM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with Radius problem

 External Email - Use Caution 

No insight But have you consulted:
https://urldefense.proofpoint.com/v2/url?u=https-3A__CRAN.R-2Dproject.org_view-3DSpatial&d=DwIBaQ&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY&m=gbt_psl_UbXJa0-nqZs2cDd5cTAtzTGE6OOluljG2U0&s=aT7qePkClGUoKBh0QatR5mvySgsYeUp9gU0WLReStTU&e=
 

Also, I believe this would be better posted on r-sig-geo, not here.

Bert Gunter

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

On Tue, May 12, 2020 at 5:57 PM Poling, William via R-help 
 wrote:
>
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 
> x64 (build 17763)
>
> Hello I am trying to figure out how to create concentration of ID's in 
> the following data, based on determining the highest concentration in 
> the smallest radius area based on Longitude and Latitude (geo 
> location)
>
> I have reviewed many websites looking for a function or tutorial, (if 
> you are aware of either please let me know)
>
> I have worked through the following to see if they are close to what I need, 
> but they are not.
>
> #Possible use 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
> _questions_21977720_r-2Dfinding-2Dclosest-2Dneighboring-2Dpoint-2Dand-
> 2Dnumber-2Dof-2Dneighbors-2Dwithin-2Da-2Dgiven-2Drad&d=DwIBaQ&c=wluqKI
> iwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2
> ExlYvnUWbsByY&m=gbt_psl_UbXJa0-nqZs2cDd5cTAtzTGE6OOluljG2U0&s=t6qPeVA_
> C9VbEMtn5earDo2F53CkazDyPAQrL81PifM&e=
>
> #Possible math ref 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__janmatuschek.de_La
> titudeLongitudeBoundingCoordinates&d=DwIBaQ&c=wluqKIiwffOpZ6k5sqMWMBOn
> 0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY&m=gb
> t_psl_UbXJa0-nqZs2cDd5cTAtzTGE6OOluljG2U0&s=o5R4BF22ow2gJd8RgJOS0pVRn6
> 6a4uCBcXXgK59Z1SM&e=
>
> #Possible use 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
> _questions_39008850_find-2Dnumber-2Dof-2Dpoints-2Dwithin-2Da-2Dradius-
> 2Din-2Dr-2Dusing-2Dlon-2Dand-2Dlat-2Dcoordinates&d=DwIBaQ&c=wluqKIiwff
> OpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlY
> vnUWbsByY&m=gbt_psl_UbXJa0-nqZs2cDd5cTAtzTGE6OOluljG2U0&s=cr5fY67h9cmL
> ZlNVPGcJ5gysN_qVQC-xZetElqwYVhk&e=
>
> # 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__gis.stackexchange
> .com_questions_229453_create-2Da-2Dcircle-2Dof-2Ddefined-2Dradius-2Dar
> ound-2Da-2Dpoint-2Dand-2Dthen-2Dfind-2Dthe-2Doverlapping-2Da&d=DwIBaQ&
> c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmT
> CtKvneM2ExlYvnUWbsByY&m=gbt_psl_UbXJa0-nqZs2cDd5cTAtzTGE6OOluljG2U0&s=
> xK2iPfFjKfUevj39Uk8ux2OZYYxE3N4kOQU3ecP0W4M&e=
>
> # 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
> _questions_23071026_drawing-2Da-2Dcircle-2Dwith-2Da-2Dradius-2Dof-2Da-
> 2Ddefined-2Ddistance-2Din-2Da-2Dmap_23072079-2323072079&d=DwIBaQ&c=wlu
> qKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvn
> eM2ExlYvnUWbsByY&m=gbt_psl_UbXJa0-nqZs2cDd5cTAtzTGE6OOluljG2U0&s=susH1
> Qr4Cz3oohO3OF6Bs6PWuAzo5hc7WMQccLvuX08&e=
>
> My actual data is 2353 records with 41 states and 1337 cities represented. 
> Here is a sample below.
>
> Some might call this a hotspot question I suppose: "What is the maximum 
> number of ID's I can gather in the smallest radius size given the data at 
> hand?
>
> For example it would be useful to have a function that I could use to test 
> different combinations of radius size and concentration of ID #'s by geo 
> location.
>
> Any insight would be very much appreciated.
>
> Thank you.
> WHP
>
> str(sample)
> 'data.frame':   35 obs. of  5 variables:
>  $ state: Factor w/ 41 levels "AL","AR","AZ",..: 19 29 9 9 10 30 33 35 41 
> 12 ...
>  $ city : Factor w/ 1337 levels "ABBOTTSTOWN",..: 281 1280 129 223 989 
> 721 550 731 1325 688 ...
>  $ latitude : num  43.5 40.1 26.5 27.9 31.9 ...
>  $ longitude: num  -7

[R] Help with Radius problem

2020-05-12 Thread Poling, William via R-help
#RStudio Version Version 1.2.1335 
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

Hello I am trying to figure out how to create concentration of ID's in the 
following data, based on determining the highest concentration in the smallest 
radius area based on Longitude and Latitude (geo location)

I have reviewed many websites looking for a function or tutorial, (if you are 
aware of either please let me know)

I have worked through the following to see if they are close to what I need, 
but they are not.

#Possible use 
https://stackoverflow.com/questions/21977720/r-finding-closest-neighboring-point-and-number-of-neighbors-within-a-given-rad

#Possible math ref http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates

#Possible use 
https://stackoverflow.com/questions/39008850/find-number-of-points-within-a-radius-in-r-using-lon-and-lat-coordinates

# 
https://gis.stackexchange.com/questions/229453/create-a-circle-of-defined-radius-around-a-point-and-then-find-the-overlapping-a

# 
https://stackoverflow.com/questions/23071026/drawing-a-circle-with-a-radius-of-a-defined-distance-in-a-map/23072079#23072079

My actual data is 2353 records with 41 states and 1337 cities represented. Here 
is a sample below.

Some might call this a hotspot question I suppose: "What is the maximum number 
of ID's I can gather in the smallest radius size given the data at hand?

For example it would be useful to have a function that I could use to test 
different combinations of radius size and concentration of ID #'s by geo 
location.

Any insight would be very much appreciated.

Thank you.
WHP

str(sample)
'data.frame':   35 obs. of  5 variables:
 $ state: Factor w/ 41 levels "AL","AR","AZ",..: 19 29 9 9 10 30 33 35 41 
12 ...
 $ city : Factor w/ 1337 levels "ABBOTTSTOWN",..: 281 1280 129 223 989 721 
550 731 1325 688 ...
 $ latitude : num  43.5 40.1 26.5 27.9 31.9 ...
 $ longitude: num  -70.6 -82.9 -80.1 -82.7 -81.4 ...
 $ ID   : int  2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 ...

dput(sample)
structure(list(state = structure(c(19L, 29L, 9L, 9L, 10L, 30L, 
33L, 35L, 41L, 12L, 12L, 36L, 4L, 9L, 8L, 39L, 36L, 36L, 41L, 
28L, 12L, 28L, 28L, 12L, 11L, 2L, 12L, 22L, 32L, 22L, 12L, 10L, 
10L, 22L, 10L), .Label = c("AL", "AR", "AZ", "CA", "CO", "CT", 
"DC", "DE", "FL", "GA", "IA", "IL", "IN", "KS", "KY", "LA", "MA", 
"MD", "ME", "MI", "MN", "MO", "NC", "NE", "NJ", "NM", "NV", "NY", 
"OH", "OK", "OR", "PA", "SC", "SD", "TN", "TX", "UT", "VA", "WA", 
"WI", "WV"), class = "factor"), city = structure(c(281L, 1280L, 
129L, 223L, 989L, 721L, 550L, 731L, 1325L, 688L, 1184L, 281L, 
759L, 1171L, 1305L, 587L, 272L, 581L, 263L, 152L, 217L, 152L, 
390L, 5L, 571L, 1006L, 1162L, 939L, 170L, 1033L, 1002L, 586L, 
586L, 192L, 586L), .Label = c("ABBOTTSTOWN", "ABILENE", "ACWORTH", 
"ADAMS", "ADDISON", "ADKINS", "ALBANY", "ALBIA", "ALBUQUERQUE", 
"ALEXANDRIA", "ALFRED", "ALIQUIPPA", "ALISO VIEJO", "ALLEN PARK", 
"ALLENTOWN", "ALPHA", "ALPHARETTA", "ALPINE", "ALTOONA", "AMARILLO", 
"AMBLER", "AMBRIDGE", "AMHERST", "AMITYVILLE", "ANAHIEM", "ANDERSON", 
"ANDOVER", "ANGIER", "ANGLETON", "ANKENY", "ANN ARBOR", "ANZA", 
"APEX", "APOLLO", "ARCADIA", "ARCHDALE", "ARDMORE", "ARGYLE", 
"ARKANSAS CITY", "ARLINGTON", "ARNOLD", "ARTHUR", "ASHEBORO", 
"ASHEVILLE", "ASHLAND", "ASHLAND CITY", "ASHTON", "ASTON", "ATHENS", 
"ATLANTA", "ATLANTIC BCH", "AUBORN", "AUGUSTA", "AURORA", "AUSTELL", 
"AUSTIN", "AVENTURA", "AVONDALE ESTATES", "BAKERSFIELD", "BALDWIN CITY", 
"BALDWIN PLACE", "BALLWIN", "BANGOR", "BARBOURSVILLE", "BARNEGAT", 
"BARTLETT", "BARTON", "BARTONVILLE", "BASSETT", "BATAVIA", "BATESBURG", 
"BATON ROUGE", "BAXTER SPRINGS", "BAY CITY", "BAYONNE", "BAYSIDE", 
"BAYTOWN", "BEAR", "BEAUMONT", "BEECH CREEK", "BEECHER CITY", 
"BELFAIR", "BELLE VERNON", "BELLEAIR", "BELLEVUE", "BELLMAWR", 
"BELLMORE", "BELLWOOD", "BELMAR", "BELMONT", "BELVIDERE", "BENNET", 
"BENTON", "BENTONVILLE", "BERLIN", "BESSEMER CITY", "BETHANY", 
"BETHEL", "BETHEL PARK", "BETHESDA", "BETHLEHEM", "BETTENDORF", 
"BIGLERVILLE", "BINGHAMTON", "BIRDSBORO", "BIWABIK", "BLACK MOUNTAIN", 
"BLACKSBURG", "BLAINE", "BLAIRSVILLE", "BLAKESLEE", "BLOOMFIELD", 
"BLUE BELL", "BLUE GRASS", "BLUE POINT", "BLUE SPRINGS", "BOCA RATON", 
"BODFISH", "BOILING SPRINGS", "BOLIVAR", "BON AQUA", "BONNER SPRINGS", 
"BONNEY LAKE", "BOONEVILLE", "BOSSIER CITY", "BOUNTIFUL", "BOWLING GREEN", 
"BOYERTOWN", "BOYNTON BEACH", "BRADENTON", "BRADENVILLE", "BRANDAMORE", 
"BRANDON", "BRANFORD", "BRANSON", "BRASELTON", "BREEZEWOOD", 
"BRENTON", "BRENTWOOD", "BREWSTER", "BRICK", "BRIDGEPORT", "BRIDGETON", 
"BRIGHAM CITY", "BROADDUS", "BROCKPORT", "BROGUE", "BROKEN ARROW", 
"BRONX", "BROOKFIELD", "BROOKHAVEN", "BROOKLYN", "BROWNS MILLS", 
"BROWNSBURG", "BROWNSVILLE", "BRUNSWICK", "BRYAN", "BUCKSPORT", 
"BUDD LAKE", "BUFFALO", "BULVERDE", "BUNKERVILLE", "BURBANK", 
"BURFORD", "BURIEN", "BURLINGTON", "BURR RIDG

Re: [R] Help with Kmeans output and using broom to tidy etc..

2020-05-12 Thread Poling, William via R-help
LD", "BALDWIN CITY", "BALDWIN PLACE",
"BALLWIN", "BANGOR", "BARBOURSVILLE", "BARNEGAT", "BARTLETT",
"BARTON", "BARTONVILLE", "BASSETT", "BATAVIA", "BATESBURG", "BATON ROUGE",
"BAXTER SPRINGS", "BAY CITY", "BAYONNE", "BAYSIDE", "BAYTOWN",
"BEAR", "BEAUMONT", "BEECH CREEK", "BEECHER CITY", "BELFAIR",
"BELLE VERNON", "BELLEAIR", "BELLEVUE", "BELLMAWR", "BELLMORE",
"BELLWOOD", "BELMAR", "BELMONT", "BELVIDERE", "BENNET", "BENTON",
"BENTONVILLE", "BERLIN", "BESSEMER CITY", "BETHANY", "BETHEL",
"BETHEL PARK", "BETHESDA", "BETHLEHEM", "BETTENDORF", "BIGLERVILLE",
"BINGHAMTON", "BIRDSBORO", "BIWABIK", "BLACK MOUNTAIN", "BLACKSBURG",
"BLAINE", "BLAIRSVILLE", "BLAKESLEE", "BLOOMFIELD", "BLUE BELL",
"BLUE GRASS", "BLUE POINT", "BLUE SPRINGS", "BOCA RATON", "BODFISH",
"BOILING SPRINGS", "BOLIVAR", "BON AQUA", "BONNER SPRINGS", "BONNEY LAKE",
"BOONEVILLE", "BOSSIER CITY", "BOUNTIFUL", "BOWLING GREEN", "BOYERTOWN",
"BOYNTON BEACH", "BRADENTON", "BRADENVILLE", "BRANDAMORE", "BRANDON",
"BRANFORD", "BRANSON", "BRASELTON", "BREEZEWOOD", "BRENTON",
"BRENTWOOD", "BREWSTER", "BRICK", "BRIDGEPORT", "BRIDGETON",
"BRIGHAM CITY", "BROADDUS", "BROCKPORT", "BROGUE", "BROKEN ARROW",
"BRONX", "BROOKFIELD", "BROOKHAVEN", "BROOKLYN", "BROWNS MILLS",
"BROWNSBURG", "BROWNSVILLE", "BRUNSWICK", "BRYAN", "BUCKSPORT",
"BUDD LAKE", "BUFFALO", "BULVERDE", "BUNKERVILLE", "BURBANK",
"BURFORD", "BURIEN", "BURLINGTON", "BURR RIDGE", "BURTON", "BUSKIRK",
"BUTLER", "BUXTON", "BYRON", "CALERA", "CAMBRIDGE", "CAMP HILL",
"CAMPBELL", "CANAAN", "CANAL WINCHESTER", "CANASTOTA", "CANTON",
"CARDIFF BY THE SEA", "CARL JUNCTION", "CARLISLE", "CARLTON",
"CAROL STREAM", "CARROLLTON", "CARSON CITY", "CARTERSVILLE",
"CARTHAGE", "CARY", "CASEYVILLE", "CASSVILLE", "CASWELL", "CATO",
"CEDAR RAPIDS", "CEDARBURG", "CEDARVILLE", "CENTER POINT", "CENTERTON",
"CENTRAL ISLIP", "CENTRAL POINT", "CHAGRIN FALLS", "CHALFONT",
"CHAPEL HILL", "CHAPIN", "CHARDON", "CHARITON", "CHARLESTON",
"CHARLOTTE", "CHEROKEE", "CHERRY HILL", "CHERRY VALLEY", "CHESHIRE",
"CHEST SPRINGS", "CHESTER", "CHESTERTON", "CHICAGO", "CHILLICOTHE",
"CHOCTAW", "CICERO", "CINCINNATI", "CLAY", "CLEARWATER", "CLEARWATER BEACH",
"CLEMMONS", "CLENDENIN", "CLEVELAND", "CLEVELAND HTS", "CLEVES",
"CLIFFSIDE PARK", "CLIFTON", "CLIFTON PARK", "CLIFTON SPGS",
"CLINTON", "COACHELLA", "COAL TOWNSHIP", "COATESVILLE", "COLLEGE STATION",
"COLLINSVILLE", "COLONIA", "COLUMBIA", "COLUMBUS", "COMMERCE",
"CONCORD", "CONCORD TOWNSHIP", "CONNELLSVILLE", "CONROE", "CONWAY",
"CONYERS", "COOKEVILLE", "COON RAPIDS", "CORAOPOLIS", "CORDOVA",
"CORNELIUS", "CORNWALL", "CORONADO", "CORPUS CHRISTI", "CORRY",
"COTTAGE HILLS", "COTTLEVILLE", "COTTONWOOD", "COVINGTON", "COWEN",
"CRANBERRY TOWNSHIP", "CROWN POINT", "CUBA", "CUMBERLAND CENTER",
"CUMBERLAND FORESIDE", "CUMMING", "CUYAHOGA FLS", "CYPRESS",
"DALLAS", "DALLASTOWN", "DANBU

Re: [R] Help with Kmeans output and using broom to tidy etc..

2020-05-12 Thread Poling, William via R-help
Hello Eric, thank you so much for your consideration.

Here are snippets of data that I hope will be helpful

WHP 

geo1a <- geo1[, c(2:5)] <-- eliminating ID which is not useful for my purposes 
anyway

#This is for R-Help use
geo1a <- geo1a %>% top_n(25)

state   city latitude longitude
1 ME  FAIRFIELD 44.64485 -69.65948
2 ME  JONESPORT 44.57935 -67.56743
3 MECASWELL 46.97529 -67.83023
4 ME  ELLSWORTH 44.52916 -68.38717
5 ME VASSALBORO 44.45095 -69.60629
6 ME  UNION 44.20059 -69.26123
7 MEPALERMO 44.45142 -69.41115
8 ME  ORONO 44.87426 -68.68327
9 MESANGERVILLE 45.10138 -69.33580
10ME  ISLESBORO 44.29015 -68.90812
11METOPSHAM 43.93600 -69.96565
12ME   FREEPORT 43.84089 -70.11160
13ME  SKOWHEGAN 44.76687 -69.71644
14MEMILLINOCKET 45.65501 -68.70261
15ME  ORRINGTON 44.72417 -68.74026
16ME ST. GEORGE 43.96726 -69.20827
17ME FORT FAIRFIELD 46.80911 -67.88079
18ME  MARS HILL 46.56580 -67.89006
19ME   FREEPORT 43.85302 -70.03726
20ME EASTON 46.64143 -67.91203
21ME WATERVILLE 44.53621 -69.65913
22ME  BRUNSWICK 43.87771 -69.96297
23ME  BRUNSWICK 43.91719 -69.89905
24ME  BUCKSPORT 44.60665 -68.81892
25MEFAYETTE 44.46380 -70.12047


trnd1_tbla <- trnd1_tbl %>% top_n(25)
print(trnd1_tbla)
head(trnd1_tbla,n=25)

A tibble: 25 x 5
   city  state Basecountsum Basecount2 prop_of_total
   
 1 ATLANTA   GA2352 12   0.00510
 2 BRADENTON FL2352  8   0.00340
 3 BROOKLYN  NY2352 30   0.0128 
 4 CHARLOTTE NC2352  8   0.00340
 5 CHICAGO   IL2352 17   0.00723
 6 COLUMBUS  OH2352 11   0.00468
 7 CUMMING   GA2352  8   0.00340
 8 DALLASTX2352  8   0.00340
 9 ERIE  PA2352 12   0.00510
10 HOUSTON   TX2352 12   0.00510
# ... with 15 more rows

WHP

From: Eric Berger  
Sent: Tuesday, May 12, 2020 8:39 AM
To: Poling, William 
Cc: r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with Kmeans output and using broom to tidy 
etc..

 External Email - Use Caution 
Can you create a reproducible example? 
Your question involves objects that are unknown to us. (geo1, trnd1_tbl)

On Tue, May 12, 2020 at 2:41 PM Poling, William via R-help 
<mailto:r-help@r-project.org> wrote:
#RStudio Version Version 1.2.1335 need this one--> 1.2.5019
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

Hello:

I have data that I am trying to manipulate for Kmeans clustering.

Original data looks like this

str(geo1) 
# 'data.frame': 2352 obs. of  5 variables:
# $ ID: Factor w/ 2352 levels "101040199600",..: 590 908 976 509 1674 690 1336 
86 726 1702 ...
# $ state           : Factor w/ 41 levels "AL","AR","AZ",..: 32 10 25 11 9 32 
13 31 12 12 ...
# $ city            : Factor w/ 1337 levels "ABBOTTSTOWN",..: 932 156 230 698 
965 1330 515 727 1127 1304 ...
# $ latitude        : num  40.4 31.2 40.8 42.1 26.8 ...
# $ longitude       : num  -79.9 -81.5 -74 -91.6 -82.1 ...

I created a subset adding column prop_of_total 
str(trnd1_tbl)
tibble [1,457 x 5] (S3: tbl_df/tbl/data.frame)
 $ city         : Factor w/ 1337 levels "ABBOTTSTOWN",..: 1 2 3 4 5 6 7 8 9 10 
...
 $ state        : Factor w/ 41 levels "AL","AR","AZ",..: 32 36 10 28 12 36 10 
11 26 38 ...
 $ Basecountsum : num [1:1457] 2352 2352 2352 2352 2352 ...
 $ Basecount2   : num [1:1457] 1 1 1 1 1 2 1 1 2 1 ...
 $ prop_of_total: num [1:1457] 0.000425 0.000425 0.000425 0.000425 0.000425 ...


Then I spread it

trnd2_tbl <- trnd1_tbl %>% 
    dplyr::select(city, state, prop_of_total) %>% 
    spread(key = city, value = prop_of_total, fill = 0) #remove the NA's with 
fill

str(trnd2_tbl)#tibble [41 x 1,338] (S3: tbl_df/tbl/data.frame)

Then I run a Kmeans

kmeans_obj1 <- trnd2_tbl  %>% 
  dplyr::select(- state) %>% 
  kmeans(centers = 20, nstart = 100)

str(kmeans_obj1)
List of 9
 $ cluster     : int [1:41] 11 11 9 11 11 4 11 11 16 2 ...
 $ centers     : num [1:20, 1:1337] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:20] "1" "2" "3" "4" ...
  .. ..$ : chr [1:1337] "ABBOTTSTOWN" "ABILENE" "ACWORTH" "ADAMS" ...
 $ totss       : num 0.00158
 $ withinss    : num [1:20] 0 0 0 0 0 0 0 0 0 0 ...
 $ tot.withinss: num 0.848
 $ betweenss   : num 0.0015
 $ size        : int [1:20] 1 1 1 1 1 1 1 1 1 1 ...
 $ iter        : int 3
 $ ifault    

Re: [R] Help with R-Markdown please

2020-05-12 Thread Poling, William via R-help
Wow, ok, yep 
"winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library"

Thank you Ege. I did not have this issue with previous employer, I will see 
what our IT group says.

Thank you 

WHP


William H. Poling Ph.D., MPH  | Senior Data Scientist, Medicare Stars, CVS 
Health 
p 813-777-5030


Proprietary

-Original Message-
From: Ege Rubak  
Sent: Tuesday, May 12, 2020 7:43 AM
To: Poling, William ; r-help@r-project.org
Subject: [EXTERNAL] Re: [R] Help with R-Markdown please

 External Email - Use Caution 

Looks like your files are on a Windows network drive (UNC path). I have 
experienced many problems with this on a Windows laptop from work. If at all 
possible you should avoid this. As an absolute minimum make sure your R library 
(collection of installed packages) is on the local file system and not a UNC 
path. If you are lucky this could be enough to make things work.

You can check your library location(s) with the command .libPaths() in an R 
session.

Good luck.

Ege

On Tue, 2020-05-12 at 10:15 +, Poling, William via R-help wrote:
> #UPDATED 05/05/2020
> #RStudio Version Version 1.2.1335 need this one--> 1.2.5019
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 
> x64 (build 17763)
> 
> Good morning.
> 
> This is the first time I have tried RMarkdown on new laptop with new 
> employer.
> I am not sure how to go about fixing this problem below?
> 
> Would someone please advise course of action.
> 
> Thank you.
> 
> WHP
> 
> 
> 
> processing file: Member-Geo-Location-Test-V1.Rmd
>  
> |..  
>   |  14%
>   ordinary text without R code
> 
>  
> |
>   |  29%
> label: unnamed-chunk-1 (with options) List of 1  $ echo: logi FALSE
> 
>  
> |..  
>   |  43%
>   ordinary text without R code
> 
>  
> |
>   |  57%
> label: setup (with options)
> List of 2
>  $ include: logi FALSE
>  $ warning: logi FALSE
> 
>  
> |..  
>   |  71%
>   ordinary text without R code
> 
>  
> |
>   |  86%
> label: Table1 (with options)
> List of 2
>  $ echo   : logi FALSE
>  $ results: chr "asis"
> 
>  
> |
> ..| 100%
>inline R code fragments
> 
> 
> output file: Member-Geo-Location-Test-V1.knit.md
> 
> "C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS Member- 
> Geo-Location-Test-V1.utf8.md --to html4 --from
> markdown+autolink_bare_uris+tex_math_single_backslash+smart --output
> Member-Geo-Location-Test-V1.html --email-obfuscation none --self- 
> contained --standalone --section-divs --template "\\winp-oaf-
> 113\FldrRedir_1$\A436798\Data\R\R-
> 4.0.0patched\library\rmarkdown\rmd\h\default.html" --no-highlight -- 
> variable highlightjs=1 --variable "theme:bootstrap" --include-in- 
> header "C:\Users\A436798\AppData\Local\Temp\RtmpSajZla\rmarkdown-
> str2ae846253313.html" --mathjax --variable "mathjax-url:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__mathjax.rstudio.c
> om_latest_MathJax.js-3Fconfig-3DTeX-2DAMS-2DMML-5FHTMLorMML&d=DwIGaQ&c
> =wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTC
> tKvneM2ExlYvnUWbsByY&m=uBce0mQRO8wdLXO8BDTtjk4R92KVzpjtkQ-NqYiAHCo&s=S
> MNU_B--j9FvBKh-0u1NG5RHd7AtLkvyVsi9ybyUwYU&e=
> " --lua-filter "\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-
> 4.0.0patched/library/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter
> "\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-
> 4.0.0patched/library/rmarkdown/rmd/lua/latex-div.lua" 
> Could not fetch http://?/UNC/winp-oaf-
> 113/FldrRedir_1$/A436798/Data/R/R-
> 4.0.0patched/library/rmarkdown/rmd/h/default.html
> HttpExceptionRequest Request {
>   host = ""
>   port = 80
>   secure   = False
>   requestHeaders   = []
>   path = "/"
>   queryString  = "?/UNC/winp-oaf-
> 113/FldrRedir_1$/A436798/Data/R/R-
> 4.0.0patched/library/rmarkdown/rmd/h/default.html"
>   method   = "GET"
>   proxy= Nothing
>   rawBody  = False
>   redirectCount= 10
>   responseTimeout  = ResponseTime

[R] Help with R-Markdown please

2020-05-12 Thread Poling, William via R-help
#UPDATED 05/05/2020
#RStudio Version Version 1.2.1335 need this one--> 1.2.5019
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

Good morning.

This is the first time I have tried RMarkdown on new laptop with new employer.
I am not sure how to go about fixing this problem below?

Would someone please advise course of action.

Thank you.

WHP 



processing file: Member-Geo-Location-Test-V1.Rmd
  |..|  14%
  ordinary text without R code

  |  |  29%
label: unnamed-chunk-1 (with options) 
List of 1
 $ echo: logi FALSE

  |..|  43%
  ordinary text without R code

  |  |  57%
label: setup (with options) 
List of 2
 $ include: logi FALSE
 $ warning: logi FALSE

  |..|  71%
  ordinary text without R code

  |  |  86%
label: Table1 (with options) 
List of 2
 $ echo   : logi FALSE
 $ results: chr "asis"

  |..| 100%
   inline R code fragments


output file: Member-Geo-Location-Test-V1.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS 
Member-Geo-Location-Test-V1.utf8.md --to html4 --from 
markdown+autolink_bare_uris+tex_math_single_backslash+smart --output 
Member-Geo-Location-Test-V1.html --email-obfuscation none --self-contained 
--standalone --section-divs --template 
"\\winp-oaf-113\FldrRedir_1$\A436798\Data\R\R-4.0.0patched\library\rmarkdown\rmd\h\default.html"
 --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" 
--include-in-header 
"C:\Users\A436798\AppData\Local\Temp\RtmpSajZla\rmarkdown-str2ae846253313.html" 
--mathjax --variable 
"mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
 --lua-filter 
"\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/lua/pagebreak.lua"
 --lua-filter 
"\\winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/lua/latex-div.lua"
 
Could not fetch 
http://?/UNC/winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/h/default.html
HttpExceptionRequest Request {
  host = ""
  port = 80
  secure   = False
  requestHeaders   = []
  path = "/"
  queryString  = 
"?/UNC/winp-oaf-113/FldrRedir_1$/A436798/Data/R/R-4.0.0patched/library/rmarkdown/rmd/h/default.html"
  method   = "GET"
  proxy= Nothing
  rawBody  = False
  redirectCount= 10
  responseTimeout  = ResponseTimeoutDefault
  requestVersion   = HTTP/1.1
}
 (InvalidDestinationHost "")
Error: pandoc document conversion failed with error 61
Execution halted

WHP


Proprietary

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

__
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 with Kmeans output and using broom to tidy etc..

2020-05-12 Thread Poling, William via R-help
#RStudio Version Version 1.2.1335 need this one--> 1.2.5019
sessionInfo() 
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 17763)

Hello:

I have data that I am trying to manipulate for Kmeans clustering.

Original data looks like this

str(geo1) 
# 'data.frame': 2352 obs. of  5 variables:
# $ ID: Factor w/ 2352 levels "101040199600",..: 590 908 976 509 1674 690 1336 
86 726 1702 ...
# $ state   : Factor w/ 41 levels "AL","AR","AZ",..: 32 10 25 11 9 32 
13 31 12 12 ...
# $ city: Factor w/ 1337 levels "ABBOTTSTOWN",..: 932 156 230 698 
965 1330 515 727 1127 1304 ...
# $ latitude: num  40.4 31.2 40.8 42.1 26.8 ...
# $ longitude   : num  -79.9 -81.5 -74 -91.6 -82.1 ...

I created a subset adding column prop_of_total 
str(trnd1_tbl)
tibble [1,457 x 5] (S3: tbl_df/tbl/data.frame)
 $ city : Factor w/ 1337 levels "ABBOTTSTOWN",..: 1 2 3 4 5 6 7 8 9 10 
...
 $ state: Factor w/ 41 levels "AL","AR","AZ",..: 32 36 10 28 12 36 10 
11 26 38 ...
 $ Basecountsum : num [1:1457] 2352 2352 2352 2352 2352 ...
 $ Basecount2   : num [1:1457] 1 1 1 1 1 2 1 1 2 1 ...
 $ prop_of_total: num [1:1457] 0.000425 0.000425 0.000425 0.000425 0.000425 ...


Then I spread it

trnd2_tbl <- trnd1_tbl %>% 
dplyr::select(city, state, prop_of_total) %>% 
spread(key = city, value = prop_of_total, fill = 0) #remove the NA's with 
fill

str(trnd2_tbl)#tibble [41 x 1,338] (S3: tbl_df/tbl/data.frame)

Then I run a Kmeans

kmeans_obj1 <- trnd2_tbl  %>% 
  dplyr::select(- state) %>% 
  kmeans(centers = 20, nstart = 100)

str(kmeans_obj1)
List of 9
 $ cluster : int [1:41] 11 11 9 11 11 4 11 11 16 2 ...
 $ centers : num [1:20, 1:1337] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:20] "1" "2" "3" "4" ...
  .. ..$ : chr [1:1337] "ABBOTTSTOWN" "ABILENE" "ACWORTH" "ADAMS" ...
 $ totss   : num 0.00158
 $ withinss: num [1:20] 0 0 0 0 0 0 0 0 0 0 ...
 $ tot.withinss: num 0.848
 $ betweenss   : num 0.0015
 $ size: int [1:20] 1 1 1 1 1 1 1 1 1 1 ...
 $ iter: int 3
 $ ifault  : int 0
 - attr(*, "class")= chr "kmeans"

Then I go and try to tidy:

#Tidy, glance, augment
#Just makes it easier to use or view the obj's in the obj list
  
  broom::tidy(kmeans_obj1) %>% glimpse()

broom::glance(kmeans_obj1)
##A tibble: 1 x 4
# totss tot.withinss betweenss  iter
#   
#   1 0.001580.848   0.00150 3

However, when I run this piece I get an error:

broom::augment(kmeans_obj1, trnd2_tbl) %>% 
  dplyr::select(city, .cluster) 

#Error: Must subset columns with a valid subscript vector.
# The subscript has the wrong type `data.frame<
 # u: double
#  x: double
>`.
i It must be numeric or character.

Here is the back trace:

rlang::last_error()

# Backtrace:
#   1. broom::augment(kmeans_obj1, trnd2_tbl)
# 9. dplyr::select(., city, .cluster)
# 11. tidyselect::vars_select(tbl_vars(.data), !!!enquos(...))
# 12. tidyselect:::eval_select_impl(...)
# 20. tidyselect:::vars_select_eval(...)
# 21. tidyselect:::walk_data_tree(expr, data_mask, context_mask)
# 22. tidyselect:::eval_c(expr, data_mask, context_mask)
# 23. tidyselect:::reduce_sels(node, data_mask, context_mask, init = init)
# 24. tidyselect:::walk_data_tree(new, data_mask, context_mask)
# 25. tidyselect:::as_indices_sel_impl(...)
# 26. tidyselect:::as_indices_impl(x, vars, strict = strict)
# 27. vctrs::vec_as_subscript(x, logical = "error")

I am not sure what I am supposed to fix?

Maybe someone has had similar error and can advise me please?

Thank you.

WHP







Proprietary

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

__
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] Subtracting Data Frame With a Different Number of Rows

2020-04-21 Thread William Michels via R-help
Hi Phillip,

You have two choices here: 1. Manually enter the missing rows into
your individual.df using rbind(), and cbind() the overall.df and
individual.df dataframes together (assuming the rows line up
properly), or 2. Use merge() to perform an SQL-like "Left Join", and
copy values from the "overall" columns to fill in missing values in
the "indiv" columns (imputation). Below is code starting from a .tsv
files showing the second (merge) method. Note: I've only included the
first 4 rows of data after the merge command (there are 24 rows
total):

> overall <- read.delim("overall.R", sep="\t")
> indiv <- read.delim("individual.R", sep="\t")
> merge(overall, indiv, all.x=TRUE, by.x=c("RunnerCode", "Outs"), 
> by.y=c("RunnerCode", "Outs"))

RunnerCode Outs X.x MeanRuns.x X.y MeanRuns.y
1   BasesEmpty0   1  0.5137615   1  0.4262295
2   BasesEmpty1   9  0.3963801   8  0.5238095
3   BasesEmpty2  17  0.4191011  15  0.3469388
4  BasesLoaded0   8  3.2173913  NA NA


HTH, Bill.

W. Michels, Ph.D.


On Tue, Apr 21, 2020 at 1:47 PM Phillip Heinrich  wrote:
>
> I have two small data frames of baseball data.  The first one is the mean
> number of runs that will score in each half inning for the 2018 Arizona
> Diamondbacks.  The second data frame is the same information but for only
> one player.  As you will see the individual player did not come up to bat
> any time during the season:
> with the bases loaded and no outs
> runners on first and third with one out
>
> Overall
>
> RunnerCodeOuts MeanRuns
> 1 Bases Empty 0   0.5137615
> 2 Runner:1st0   0.8967391
> 3 Runner:2nd   0   1.3018868
> 4 Runners:1st & 2nd0   1.6551724
> 5 Runner:3rd0   1.9545455
> 6 Runners:1st & 3rd 0   2.0571429
> 7 Runners:2nd & 3rd0   2.1578947
> 8 Bases Loaded0   3.2173913
> 9 Bases Empty  1   0.3963801
> 10 Runner:1st   1   0.6952596
> 11 Runner:2nd  1   0.9580838
> 12 Runners:1st & 2nd   1   1.4397163
> 13 Runner:3rd   1   1.5352113
> 14 Runners:1st & 3rd   11.5882353
> 15 Runners:2nd & 3rd  11.9215686
> 16 Bases Loaded  11.9193548
> 17 Bases Empty20.4191011
> 18 Runner:1st   20.5531915
> 19 Runner:2nd  20.8777293
> 20 Runners:1st & 2nd  2 0.9553073
> 21 Runner:3rd  2 1.2783505
> 22 Runners:1st & 3rd   2 1.5851064
> 23 Runners:2nd & 3rd  2 1.2794118
> 24 Bases Loaded 2  1.388235
>
> Individual Player
>
>   RunnerCode  Outs   MeanRuns
> 1 Bases Empty 0 0.4262295
> 2 Runner:1st0 1.320
> 3 Runner:2nd   0 1.2857143
> 4 Runners:1st & 2nd   0  0.5714286
> 5 Runner:3rd   0  2.000
> 6 Runners:1st & 3rd0  3.500
> 7 Runners:2nd & 3rd   0  1.000
> 8 Bases Empty 1  0.5238095
> 9 Runner:1st1  0.6578947
> 10 Runner:2nd 1  0.375
> 11 Runners:1st & 2nd 1   1.4285714
> 12 Runner:3rd 1   1.4285714
> 13 Runners:2nd & 3rd 1   0.667
> 14 Bases Loaded 1   3.000
> 15 Bases Empty   2   0.3469388
> 16 Runner:1st  2   0.1363636
> 17 Runner:2nd 2   0.7142857
> 18 Runners:1st & 2nd  2   1.667
> 19 Runner:3rd  2   1.250
> 20 Runners:1st & 3rd  22.1428571
> 21 Runners:2nd & 3rd 21.500
> 22 Bases Loaded 22.200
>
> RunnersCode is a factor
> Outs are integers
> MeanRuns is numerical data
>
> I would like to subtract the second from the first as a way to evaluate the
> players ability to produce runs. As part of this analysis I I would like to
> input the mean number of runs from the overall data frame into the two
> missing cells for the individual player:Bases Loaded no outs and 1st and 3rd
> one out.
>
> Can anyone give me some advise?
>
> __
> 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/listinf

Re: [R] NA command in a 'for' loop

2020-04-21 Thread William Dunlap via R-help
Read the files with read.csv(filename) or read.table(sep=",", filename) so
the commas don't become part of the R data.frame.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Apr 21, 2020 at 10:17 AM Helen Sawaya 
wrote:

> Thank you for your patience.
>
> This is the output of dput(head(d, 10))
>
> structure(list(V1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L), .Label = "9.9761E+11,", class = "factor"), V2 = structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "threat,", class =
> "factor"),
> V3 = structure(c(1L, 28L, 37L, 48L, 55L, 63L, 73L, 88L, 2L,
> 20L), .Label = c("1,", "10,", "100,", "101,", "102,", "104,",
> "107,", "108,", "109,", "110,", "111,", "112,", "113,", "114,",
> "115,", "116,", "117,", "118,", "119,", "12,", "13,", "14,",
> "15,", "16,", "17,", "18,", "19,", "2,", "20,", "21,", "22,",
> "23,", "24,", "27,", "28,", "29,", "3,", "30,", "31,", "32,",
> "33,", "34,", "35,", "36,", "37,", "38,", "39,", "4,", "42,",
> "44,", "46,", "47,", "48,", "49,", "5,", "50,", "52,", "53,",
> "54,", "55,", "57,", "59,", "6,", "60,", "61,", "62,", "63,",
> "64,", "65,", "66,", "68,", "69,", "7,", "71,", "74,", "75,",
> "76,", "78,", "81,", "82,", "83,", "84,", "85,", "86,", "87,",
> "88,", "89,", "9,", "90,", "91,", "92,", "94,", "95,", "96,",
> "97,", "98,"), class = "factor"), V4 = structure(c(1L, 2L,
> 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L), .Label = c("1,", "2,"), class =
> "factor"),
> V5 = structure(c(2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L), .Label =
> c("1,",
> "2,"), class = "factor"), V6 = structure(c(2L, 1L, 2L, 2L,
> 1L, 2L, 2L, 1L, 2L, 2L), .Label = c("1,", "2,"), class = "factor"),
> V7 = structure(c(2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L), .Label =
> c("1,",
> "2,"), class = "factor"), V8 = structure(c(41L, 92L, 63L,
> 36L, 2L, 81L, 12L, 14L, 23L, 33L), .Label = c("abduction,",
> "abortion,", "abuse,", "accident,", "addicted,", "agony,",
> "anger,", "angry,", "anguish,", "assault,", "bankrupt,",
> "bullet,", "burial,", "cancer,", "cemetery,", "coffin,",
> "corpse,", "crash,", "crisis,", "cruel,", "death,", "defeated,",
> "depressed,", "deserted,", "despair,", "destroy,", "disaster,",
> "disloyal,", "distress,", "dreadful,", "drown,", "dull,",
> "dump,", "emaciated,", "failure,", "fatigue,", "fault,",
> "feeble,", "fever,", "filth,", "forlorn,", "germs,", "gloomy,",
> "hardship,", "hell,", "helpless,", "horror,", "hostage,",
> "hostile,", "hurt,", "idiot,", "infest,", "injury,", "irritable,",
> "jail,", "killer,", "lonely,", "malaria,", "messy,", "misery,",
> "mistake,", "morbid,", "murder,", "mutilate,", "pain,", "panic,",
> "poison,", "prison,", "pus,", "rape,", "rat,", "rejected,",
> "sad,", "scum,", "shame,", "sick,", "slap,", "snake,", "spider,",
> "suicide,", "surgery,", "terrible,", "tormented,", "trash,",
> "trauma,", "ugly,", "ulcer,", "unease,", "unhappy,", "useless,",
> "victim,", "wasp,", "weep,", "worm,", "wound,"), class = "factor"),
> V9 = structure(c(24L, 90L, 73L, 10L, 92L, 33L, 84L, 96L,
> 70L, 57L), .Label = c("alley,", "ankle,", "appliance,", "audience,",
> "bandage,", "bathroom,", "bookcase,", "border,", "branch,",
> "cabinet,", "category,", "clean,", "cliff,", "cold,", "consider,",
> "consoled,", "context,", "country,", "crop,", "dentist,",
> "detail,", "dinner,", "doctor,", "dynamic,", "easygoing,",
> "elbow,", "energetic,", "farm,", "faucet,", "flat,", "flowing,",
> "fork,", "freezer,", "glass,", "grass,", "guess,", "humble,",
> "icebox,", "industry,", "invisible,", "jug,", "lighting,",
> "lion,", "listen,", "little,", "machine,", "metal,", "month,",
> "mushroom,", "napkin,", "news,", "noisy,", "north,", "nudge,",
> "number,", "numerous,", "obey,", "odd,", "oval,", "plant,",
> "possible,", "pot,", "public,", "puzzled,", "quarter,", "rational,",
> "ready,", "reflect,", "reliable,", "repentant,", "sand,",
> "school,", "secret,", "series,", "shark,", "shoe,", "shop,",
> "shortened,", "skyline,", "stable,", "storm,", "stove,",
> "table,", "theory,", "tower,", "truck,", "upgrade,", "upright,",
> "utensil,", "vest,", "vision,", "volcano,", "walk,", "watchful,",
> "window,", "winter,"), class = "factor"), V10 = structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "NA,", class =
> "factor"),
> V11 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label =
> "NA,", class = "factor"),
> V12 = structure(c(2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L), .Label =
> c("203,",
> "205,"), class = "factor"), V13 = structure(c(1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "1,", class = "factor"),
> V14 = c(4063L, 4914L, 1508L, 1819L, 1228L, 992L, 1898L, 1174L,
> 1294L, 1417L)), row.names = c(NA, 10L), class = "data.frame”)
>
> When I use the following:
>
> all.files <- list.files(".")
> txt.files <- gre

Re: [R] A stopifnot() nastiness, even if not a bug

2020-04-13 Thread William Dunlap via R-help
You can avoid the problem in Martin's example by only giving scalars to
stopifnot().  E.g., using stopifnot(all(x>0)) or stopifnot(length(x)==1,
x>0) instead of stopifnot(x>0).  I think having stopifnot call
all(predicate) if length(predicate)!=1 was probably a mistake.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Apr 13, 2020 at 9:28 AM Hervé Pagès  wrote:

>
>
> On 4/13/20 05:30, Martin Maechler wrote:
> >> peter dalgaard
> >>  on Mon, 13 Apr 2020 12:00:38 +0200 writes:
> >
> >  > Inline...
> >  >> On 13 Apr 2020, at 11:15 , Martin Maechler <
> maech...@stat.math.ethz.ch> wrote:
> >  >>
> >  >>> Bert Gunter
> >  >>> on Sun, 12 Apr 2020 16:30:09 -0700 writes:
> >  >>
> >  >>> Don't know if this has come up before, but ...
> >   x <- c(0,0)
> >   length(x)
> >  >>> [1] 2
> >  >>> ## but
> >   stopifnot(length(x))
> >  >>> Error: length(x) is not TRUE
> >  >>> Called from: top level
> >  >>> ## but
> >   stopifnot(length(x) > 0)  ## not an error;  nor is
> >   stopifnot(as.logical(length(x)))
> >  >>> ## Ouch!
> >  >>
> >  >>> Maybe the man page should say something about not assuming
> automatic
> >  >>> coercion to logical, which is the usual expectation. Or fix
> this.
> >  >>
> >  >>> Bert Gunter
> >  >>
> >  >> Well, what about the top most paragraph of the help page is not
> clear here ?
> >  >>
> >  >>> Description:
> >  >>
> >  >>> If any of the expressions (in '...' or 'exprs') are not 'all'
> >  >>> 'TRUE', 'stop' is called, producing an error message indicating
> >  >>> the _first_ expression which was not ('all') true.
> >  >>
> >
> >  > This, however, is somewhat less clear:
> >
> >  > ..., exprs: any number of (typically but not necessarily
> ‘logical’) R
> >  > expressions, which should each evaluate to (a logical vector
> >  > of all) ‘TRUE’.  Use _either_ ‘...’ _or_ ‘exprs’, the latter
> >
> >  > What does it mean, "typically but not necessarily ‘logical’"?
> >
> > That's a good question: The '()' must have been put there a while
> ago.
> > I agree that it's not at all helpful. Strictly, we are really
> > dealing with unevaluated expressions anyway ("promises"), but
> > definitely all of them must evaluate to logical (vector or
> > array..) of all TRUE values.  In the very beginning of
> > stopifnot(), I had thought that it should also work in other
> > cases, e.g.,  forMatrix(TRUE, 4,5)  {from the Matrix package} etc,
> > but several use cases had convinced us / me that stopifnot
> > should be stricter...
> >
> >  > The code actually tests explicitly with is.logical, as far as I
> can tell.
> >
> >  > This creates a discrepancy between if(!...)stop(...) and
> stopifnot(),
> >
> > yes indeed, on purpose now, for a very long time ...
> >
> > There's another discrepancy, more dangerous I think,
> > as shown in the following
> > {Note this discrepancy has been noted for a long time .. also on
> >   this R-devel list} :
> >
> >m <- matrix(1:12, 3,4)
> >i <- (1:4) %% 2 == 1  & (0:3) %% 5 == 0
> >
> >stopifnot(dim(m[,i]) == c(3,1))   # seems fine
> >
> >if(dim(m[,i]) != c(3,1)) stop("wrong dim") # gives an error (but not
> ..)
>
> mmh... that is not good. I was under the impression that we could at
> least expect 'stopifnot(x)' to be equivalent to 'if (!isTRUE(x))
> stop(...)'. I'll have to revisit my use of stopifnot() in many many
> places... again :-/ Or may be just stop using it and use 'if
> (!isTRUE(...))' instead.
>
> H.
>
> >
> >
> > Martin
> >
> >  >> as in
> >  >> f <- function (x) if (!x) stop(paste(deparse(substitute(x)), "is
> not TRUE"))
> >  >> f(0)
> >  > Error in f(0) : 0 is not TRUE
> >  >> f(1)
> >  >> stopifnot(0)
> >  > Error: 0 is not TRUE
> >  >> stopifnot(1)
> >  > Error: 1 is not TRUE
> >
> >  > -pd
> >
> >
> >  >> If useR's expectations alone would guide the behavior of a
> >  >> computer language, the language would have to behave
> >  >> "personalized" and give different results depending on the user,
> >  >> which may be desirable in medicine or psychotherapy but not with
> R.
> >  >>
> >  >> Martin
> >  >>
> >  >> __
> >  >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more,
> see
> >  >>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwIDaQ&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=2kAPk_-c9XEQGS0BB1rf03oPxqQtflyqhqi-0BT8bWE&s=W8I5sRKBBKZgSjXrQC_PQw6XXUApw5h2DI5EUoDdl9w&e=
> >  >> PLEASE do read the posting guide
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwIDaQ&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=2kAPk_-c9XEQGS0BB1rf03oPxqQtflyqhq

Re: [R] how to create a new column with conditions

2020-04-08 Thread William Dunlap via R-help
>I would like to create a new column called PHENO which would satisfy
>these
>conditions:
>
>if CURRELIG=1 and RTNPTHY=1 than PHENO=1
>if PLASER=2 than PHENO=2
>otherwise is -9

I assume that if CURRELIG==1 and RNPTHY==1 and PLASER==2 then PHENO should
be 1.  Or should that case flag a data error?.

In the former case try
a$PHENO <- with(a, {
tmp <- rep(-9, length(CURRELIG)),
tmp[CURRELIG==1 & RTNPTHY==1] <- 1
tmp[PLASER==2] <- 2
tmp})

In the latter case add some calls to stop() or warning() if any of the
"impossible" cases are seen.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Apr 8, 2020 at 1:32 PM Jeff Newmiller 
wrote:

> Now that you have been shown how to do this, post your (non-working) code
> next time. And configure your email program to send plain text so we will
> see what you saw.
>
> a$PHENO <- ifelse( a$CURRELIG==1
>  & a$RTNPTHY==1
>  , 1
>  ,  ifelse( a$PLASER==2
>   , 2
>   , -9 ) )
>
> or
>
> a$PHENO <- with( a
>, ifelse( CURRELIG==1
>& RTNPTHY==1
>, 1
>, ifelse( PLASER==2
>, 2
>, -9 ) ) )
>
>
> On April 8, 2020 1:17:38 PM PDT, Ana Marija 
> wrote:
> >Hi,
> >
> >I have a data frame like this:
> >
> >> head(a)
> >FID LASER2 CURRELIG PLASER RTNPTHY
> >1 fam1000_G1000  11  1   1
> >2 fam1001_G1001  11  1   1
> >3 fam1003_G1003  21  2   2
> >4 fam1005_G1005  11  1   2
> >5 fam1009_G1009  11  1   2
> >6 fam1052_G1052  11  1   2
> >...
> >
> >I would like to create a new column called PHENO which would satisfy
> >these
> >conditions:
> >
> >if CURRELIG=1 and RTNPTHY=1 than PHENO=1
> >if PLASER=2 than PHENO=2
> >otherwise is -9
> >
> >Thanks
> >Ana
> >
> >   [[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.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> 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] nls problem

2020-04-03 Thread William Dunlap via R-help
If you will be copying the printed coefficients into your function (instead
of just using fitted() or predict()), then use dput(coef(m)) to get them
printed to full precision.

Also, if you regress on pH-7 instead of pH you don't have to worry so much
about the roundoff or cancellation error.  This is akin to what
poly(pH,degree) does.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Apr 2, 2020 at 9:44 PM Troels Ring  wrote:

> Thank you – yes indeed, on suggestion from Rui I noticed that the problem
> was mainly that I took the parameters from “m” instead of coef(m) i.e
>
> abd
>
> -1630.71   457.68   -32.11
>
> Instead of
>
>   a   b   d
>
> -1630.70993   457.67555   -32.11469
>
>
>
> And that alone saves me.
>
> BW
> Troels
>
>
>
> *Fra:* William Dunlap 
> *Sendt:* 2. april 2020 18:50
> *Til:* Troels Ring 
> *Cc:* r-help mailing list 
> *Emne:* Re: [R] nls problem
>
>
>
> Roundoff/cancelation error: compare the following.  The first is
> equivalent to your function, the last to fitted().
>
>
>
> > with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=2)))
> [,1]  [,2]   [,3] [,4]   [,5]   [,6]
> [,7]   [,8]   [,9] [,10]
> [1,] -0.01635965 0.1076024 0.07477337 -0.007166685 -0.1337865 -0.2851877
> -0.4804638 -0.6865135 -0.9870137 -1.398027
> > with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=4)))
>[,1][,2]   [,3]   [,4]   [,5]   [,6]
> [,7]  [,8]  [,9] [,10]
> [1,] -0.2196286 -0.09864071 -0.1345213 -0.2180792 -0.3463237 -0.4991861
> -0.6959856 -0.903394 -1.205598 -1.618608
> > with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=16)))
>[,1][,2]   [,3]   [,4]   [,5]  [,6]
>  [,7]   [,8]  [,9] [,10]
> [1,] -0.2208705 -0.09989926 -0.1357969 -0.2193638 -0.3476174 -0.500488
> -0.697296 -0.9047119 -1.206926 -1.619947
>
>
>
> Note that your model is linear and could be fitted with
>
>lm(data=aedf, Flux ~ pH + I(pH^2))
>
>lm(data=aedf, Flux ~ poly(pH, 2))
> The latter uses a more stable parameterization.
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
>
>
>
> On Thu, Apr 2, 2020 at 4:15 AM Troels Ring  wrote:
>
> Dear friends - I'm on Win10 with R 6.3.1 and have a very simple problem
> with
> nls which apparently gives a decent fit to the parable below, even without
> starting values. But when I then think I know the meaning of the three
> parameters a, b, and d it goes very wrong. I guess I am again overlooking
> something easy but cannot spot it.
>
> BW
> Troels Ring,
>
> Aalborg, Denmark
>
>
>
>
>
> aedf <- structure(list(Flux = c(-0.141256, -0.154709, -0.215247,
> -0.302691,
>
> -0.32287, -0.511211, -0.605381, -0.813901, -1.11659, -1.76906
>
> ), pH = c(7.06273, 7.11182, 7.16182, 7.18818, 7.21455, 7.23818,
>
>   7.26273, 7.28455, 7.31182, 7.34364)), class = "data.frame",
> row.names = c(NA,
>
>
> -10L))
>
> m <- with(aedf,nls(Flux~a + b*pH + d*pH^2))
>
>
>
> with(aedf,plot(pH,Flux))
>
> with(aedf,lines(pH,fitted(m),lty=1,col="red",lwd=3))
>
>
>
> m
>
> # abd
>
> # -1630.70   457.67   -32.11
>
>
>
> fitted(m)
>
> # 1] -0.22087053 -0.09989926 -0.13579690 -0.21936385 -0.34761742
> -0.50048799
>
> # [7] -0.69729602 -0.90471194 -1.20692552 -1.61994657
>
>
>
> FPG <- function(pH) -1630.70 + 457.67*pH -32.11*pH^2
>
>
>
> FPG(aedf$pH)
>
> # [1] -0.016359649  0.107602395  0.074773375 -0.007166685 -0.133786467
>
> # [6] -0.285187665 -0.480463769 -0.686513537 -0.987013685 -1.398026917
>
>
>
> # So why aren't fitted(m) and FPG(aedf$pH) not closer ("equal")?
>
>
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <
> http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smt
> p&url=/>
>
> [[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.
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smtp&url=/>
>

[[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] nls problem

2020-04-02 Thread William Dunlap via R-help
Roundoff/cancelation error: compare the following.  The first is equivalent
to your function, the last to fitted().

> with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=2)))
[,1]  [,2]   [,3] [,4]   [,5]   [,6]
[,7]   [,8]   [,9] [,10]
[1,] -0.01635965 0.1076024 0.07477337 -0.007166685 -0.1337865 -0.2851877
-0.4804638 -0.6865135 -0.9870137 -1.398027
> with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=4)))
   [,1][,2]   [,3]   [,4]   [,5]   [,6]
  [,7]  [,8]  [,9] [,10]
[1,] -0.2196286 -0.09864071 -0.1345213 -0.2180792 -0.3463237 -0.4991861
-0.6959856 -0.903394 -1.205598 -1.618608
> with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=16)))
   [,1][,2]   [,3]   [,4]   [,5]  [,6]
 [,7]   [,8]  [,9] [,10]
[1,] -0.2208705 -0.09989926 -0.1357969 -0.2193638 -0.3476174 -0.500488
-0.697296 -0.9047119 -1.206926 -1.619947

Note that your model is linear and could be fitted with
   lm(data=aedf, Flux ~ pH + I(pH^2))
   lm(data=aedf, Flux ~ poly(pH, 2))
The latter uses a more stable parameterization.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Apr 2, 2020 at 4:15 AM Troels Ring  wrote:

> Dear friends - I'm on Win10 with R 6.3.1 and have a very simple problem
> with
> nls which apparently gives a decent fit to the parable below, even without
> starting values. But when I then think I know the meaning of the three
> parameters a, b, and d it goes very wrong. I guess I am again overlooking
> something easy but cannot spot it.
>
> BW
> Troels Ring,
>
> Aalborg, Denmark
>
>
>
>
>
> aedf <- structure(list(Flux = c(-0.141256, -0.154709, -0.215247,
> -0.302691,
>
> -0.32287, -0.511211, -0.605381, -0.813901, -1.11659, -1.76906
>
> ), pH = c(7.06273, 7.11182, 7.16182, 7.18818, 7.21455, 7.23818,
>
>   7.26273, 7.28455, 7.31182, 7.34364)), class = "data.frame",
> row.names = c(NA,
>
>
> -10L))
>
> m <- with(aedf,nls(Flux~a + b*pH + d*pH^2))
>
>
>
> with(aedf,plot(pH,Flux))
>
> with(aedf,lines(pH,fitted(m),lty=1,col="red",lwd=3))
>
>
>
> m
>
> # abd
>
> # -1630.70   457.67   -32.11
>
>
>
> fitted(m)
>
> # 1] -0.22087053 -0.09989926 -0.13579690 -0.21936385 -0.34761742
> -0.50048799
>
> # [7] -0.69729602 -0.90471194 -1.20692552 -1.61994657
>
>
>
> FPG <- function(pH) -1630.70 + 457.67*pH -32.11*pH^2
>
>
>
> FPG(aedf$pH)
>
> # [1] -0.016359649  0.107602395  0.074773375 -0.007166685 -0.133786467
>
> # [6] -0.285187665 -0.480463769 -0.686513537 -0.987013685 -1.398026917
>
>
>
> # So why aren't fitted(m) and FPG(aedf$pH) not closer ("equal")?
>
>
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <
> http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smt
> p&url=/
> >
>
>
> [[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] ncol() vs. length() on data.frames

2020-03-31 Thread William Michels via R-help
Hi Ivan,

Like Ivan Krylov, I'm not aware of circumstances for simple dataframes
where ncol(DF) does not equal length(DF).

As I understand it, using ncol() versus length() is important when
you're examining an object returned from a function like sapply(),
since sapply() will simplify one-column dataframes to vectors. Much
has been made of this sapply() feature, but it's simple enough in your
code to test whether or not an object returned by sapply() has NULL
columns:

> dim(testDF)
[1] 14  8
> length(testDF)
[1] 8
> length(testDF[1])
[1] 1
> length(testDF[, 1])
[1] 14
>
> ncol(testDF)
[1] 8
> ncol(testDF[1])
[1] 1
> ncol(testDF[, 1])
NULL
> is.null(ncol(testDF[, 1]))
[1] TRUE
>

HTH, Bill.

W. Michels, Ph.D.






On Tue, Mar 31, 2020 at 7:11 AM Ivan Calandra  wrote:
>
> Thanks Ivan for the answer.
>
> So it confirms my first thought that these two functions are equivalent
> when applied to a "simple" data.frame.
>
> The reason I was asking is because I have gotten used to use length() in
> my scripts. It works perfectly and I understand it easily. But to be
> honest, ncol() is more intuitive to most users (especially the novice)
> so I was thinking about switching to using this function instead (all my
> data.frames are created from read.csv() or similar functions so there
> should not be any issue). But before doing that, I want to be sure that
> it is not going to create unexpected results.
>
> Thank you,
> Ivan
>
> --
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
>
> On 31/03/2020 16:00, Ivan Krylov wrote:
> > On Tue, 31 Mar 2020 14:47:54 +0200
> > Ivan Calandra  wrote:
> >
> >> On a simple data.frame (i.e. each element is a vector), ncol() and
> >> length() will give the same result.
> >> Are they just equivalent on such objects, or are they differences in
> >> some cases?
> > I am not aware of any exceptions to ncol(dataframe)==length(dataframe)
> > (in fact, ncol(x) is dim(x)[2L] and ?dim says that dim(dataframe)
> > returns c(length(attr(dataframe, 'row.names')), length(dataframe))), but
> > watch out for AsIs columns which can have columns of their own:
> >
> > x <- data.frame(I(volcano))
> > dim(x)
> > # [1] 87  1
> > length(x)
> > # [1] 1
> > dim(x[,1])
> > # [1] 87 61
> >
> >
>
> __
> 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] Tidyverse Question

2020-03-27 Thread William Michels via R-help
Dear Ista (and Phillip),

Ista, that's the exact same advice I gave Phillip over a week ago:

https://stat.ethz.ch/pipermail/r-help/2020-March/465994.html

Phillip, it doesn't make sense to post the same question under
different subject headings. While I'm convinced you're making a
sincere effort to learn R on your own--i.e. this isn't
homework--anyone trying to help you (Ista, Jeff, Bert, John, Stefan,
Duncan, etc.) will need feedback on what advice you've taken from
people on this list, and what the outcome was. So please provide it.

I do have one last suggestion, that you contact the author of the book
you're using to see if there has been an error in his/her coding
instructions. You can file an "Issue" on Github, and/or find the
author's email there and email him/her directly:

https://github.com/maxtoki/baseball_R
https://github.com/maxtoki

HTH, Bill.

W. Michels, Ph.D.





On Mon, Mar 23, 2020 at 3:37 PM Ista Zahn  wrote:
>
> Hi Phillip,
>
> On Mon, Mar 23, 2020 at 6:33 PM Phillip Heinrich  wrote:
> >
> > Can someone out there run the following code from the book Analyzing 
> > Baseball Data with R – Chapter 7 page 164?
> >
> > library(tidyverse)
> > db <- src_sqlite(“data/pitchrx.sqlite”,create=TRUE)
> >
> > Over the past two weeks this code has run correctly twice but I have gotten 
> > the following error dozens of times:
> >
> > Error: Could not connect to database:
> > unable to open database file
>
> Probably you working directory has no sub-directory named 'data'.
>
> Best,
> Ista
> >
> > I’m trying to figure out if the problem is with my computer or if the 
> > tidyverse package has been revised since this book was written.  I got the 
> > same error when I loaded R onto my wife’s Mac.
> >
> > The file pitchrx.sqlite loaded into my directory C:/Users/Owner/Documents.  
> > The data file db contains four xml files used later in the analysis.
> >
> > Thanks.
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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] cannot coerce class '"expression"' to a data.frame

2020-03-21 Thread William Dunlap via R-help
Try using the I() function in the call to data.frame.  E.g.,

> d <- data.frame(X=1:3, Y=1:3, Substance=I(expression(H[2]*O, H[2] * O[2],
H*S*O[4])))
> with(d, {plot(X,Y,type="n",xlim=c(0,4)); text(X, Y, Substance)})

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Mar 21, 2020 at 1:45 AM Troels Ring  wrote:

> Dear friends - I have some old data of chemical results and want to
> annotate
> the points with chemical formula. If I just do
>
> ID <- c("HCl 7","HCl 5.25","HCl 3.5","HCL 7 no Na","HCl 3.5  No Na",
>
> "HSO4 7 no  Na",
>
> "HNO3 7 No Na")
>
> I can make a data.frame like
>
> DD <- data.frame(x=1:7,ID)
>
>
>
> and plotting works fine.
>
> But if I try to format sulfuric acid and nitric acid like
>
> ID <- c("HCl 7","HCl 5.25","HCl 3.5","HCL 7 no Na","HCl 3.5  No Na",
>
> expression(paste(HSO[4]," 7 no  Na")),
>
> expression(paste(HNO[3]," 7 No Na")))
>
>
>
> DD <- data.frame(x=1:7,ID)
>
> Elicits an error
>
> Error in as.data.frame.default(x[[i]], optional = TRUE) :
>
>   cannot coerce class '"expression"' to a data.frame
>
> and plotting is prohibited - so how is this bypassed?
>
>
>
> I'm on Windows 10,
>
> R version 3.6.1 (2019-07-05)
>
>
>
> All best wishes
>
> Troels Ring, MD
>
> Aalborg, Denmark
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <
> http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smt
> p&url=/
> >
>
>
> [[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] Analyzing Baseball Data With R

2020-03-16 Thread William Michels via R-help
Hi Phillip,

Generally these problems come down to knowing/setting your working
directory. The first question is whether you have a directory named
"data" inside your "C:/Users/Owner/Documents" directory? You may need
to create this directory first, outside of R and/or RStudio (using
your Windows OS).

Below is some example code (on a Mac). You might want to try 1)
creating the "data" directory in Windows as mentioned earlier, 2)
setting your working directory to "C:/Users/Owner/Documents/data",
then 3) re-running your src_sqlite() command giving "pitchrx.sqlite”
as the database file name.

> getwd()
[1] "/Users/homedir/R_Dir"
> setwd("/Users/homedir/R_Dir/data")
Error in setwd("/Users/homedir/R_Dir/data") :
  cannot change working directory
>

HTH, Bill.

W. Michels, Ph.D.


On Mon, Mar 16, 2020 at 3:35 PM Phillip Heinrich  wrote:
>
> Can’t get past first step of Chapter 7 page 164.
>
> Opened a new RStudio window.  Loaded tidyverse and keyed in 
> library(tidyverse) which of course includes dplyr.  The working directory is: 
> C:/Users/Owner/Documents.
>
> Then keyed in: db <- src_sqlite(“data/pitchrx.sqlite”,create=TRUE)
>
> And got the following error: Error: Could not connect to database:
> unable to open database file
>
> Googled everything I could think of to find the sqlite function and the 
> pitchrx.sqlite empty data base.  Can someone give me some direction?
>
> I wondering if I have configured RStudio incorrectly.  Why doesn’t my by 
> RStudio point to the correct data file?
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] fit for truncated normal distribution

2020-03-14 Thread William Dunlap via R-help
On Linux it says "Program received signal SIGFPE, Arithmetic exception".  I
think the only way to get a SIGFPE (floating point exception) any more (on
machines with IEEE floating point arithmetic) is taking an integer modulo
zero, which do_druncnorm does when length(x) is 0:
   const double cx = x[i % n_x];
Should R catch SIGFPE and turn it into an error condition?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Mar 14, 2020 at 12:19 PM peter dalgaard  wrote:

> I see it in three different Mac builds, including a quite recent local
> R-devel build.
>
> It boils down to this:
>
> > dtruncnorm(numeric(0), mean=6.7, sd=1.38, a=-Inf, b=9)
> Floating point exception: 8
>
> which looks like a bug in the truncnorm package, where dtruncnorm() is
> unprepared for a zero-length argument.
>
> (The indirect cause is fitdistrplus:::test1fun, which makes calls like the
> above.)
>
> -pd
>
> > On 14 Mar 2020, at 19:42 , Bert Gunter  wrote:
> >
> > Inline.
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming along
> and
> > sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Sat, Mar 14, 2020 at 10:36 AM |Juergen Hedderich <
> j.hedder...@t-online.de>
> > wrote:
> >
> >> Dear R-help list members,
> >>
> >> the R Session aborted without any 'comment'  for the following 'small
> >> example':
> >>
> >> /library(fitdistrplus)
> >> library(truncnorm)
> >>
> >> filter <- c(4.98, 8.60, 6.37, 4.37, 8.03, 7.43, 6.83, 5.64, 5.43, 6.88,
> >> 4.57, 7.50, 5.69, 7.88, 8.98, 6.79, 8.61, 6.70, 5.14, 7.29)
> >>
> >> fit  <- fitdist(filter, "truncnorm", fix.arg=list(a=-Inf, b=9),
> >> start=list(mean=mean(filter), sd=sd(filter)),
> >> optim.method="L-BFGS-B",
> >> lower=c(-0.1, -0.1), upper=c(Inf, Inf))/
> >>
> >> R worked fine in an 'older'  R-version (environment). Can anyone help
> me?
> >>
> >
> > I can't. But without including the specifics of the older and newer
> > software (including OS version, maybe), maybe no one can.
> > See ?sessionInfo
> >
> >
> >
> >>
> >> Many thanks in advance.
> >>
> >> Best regards
> >>
> >> J. Hedderich
> >>
> >>
> >>[[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.
>
> --
> 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.
>

[[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] file.access returning -1 for a file on remote Windows drive.

2020-02-28 Thread William Dunlap via R-help
If file.access() says the file is unreadable but file() says it can be
opened, why don't you
just open the file and read it?  You can use tryCatch to deal with problems
opening or
reading the file.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Feb 28, 2020 at 2:54 PM Sam Albers 
wrote:

> Thanks Jeff. I am probably not explaining myself very well but my
> question under what circumstances would
>
> summary(file(remote_file, "rb"))$`can read`
>
> be different from:
>
> file.access(remote_file, 4)
>
> If my permissions were different across remote and local should that
> not be reflected in both of these functions?
>
> On Fri, Feb 28, 2020 at 2:37 PM Jeff Newmiller 
> wrote:
> >
> > Dunno. They agree for me. Maybe look closer at all permissions via
> Windows File Manager?
> >
> > On February 28, 2020 2:06:34 PM PST, Sam Albers <
> tonightstheni...@gmail.com> wrote:
> > >Some additional follow-up:
> > >
> > >> summary(file(remote_file, "rb"))$`can read`
> > >[1] "yes"
> > >
> > >> summary(file(local_file, "rb"))$`can read`
> > >[1] "yes"
> > >
> > >compared to:
> > >
> > >> file.access(local_file, 4)
> > >local.R
> > > 0
> > >
> > >> file.access(remote_file, 4)
> > >remote.R
> > >-1
> > >
> > >Can anyone think why file.access and file would be contradicting each
> > >other?
> > >
> > >Sam
> > >
> > >On Fri, Feb 28, 2020 at 10:47 AM Sam Albers
> > > wrote:
> > >>
> > >> Hi there,
> > >>
> > >> Looking for some help in diagnosing or developing a work around to a
> > >> problem I am having on a Windows machine. I am running R 3.6.2.
> > >>
> > >> I have two identical files, one stored locally and the other stored
> > >on
> > >> a network drive.
> > >>
> > >> For access:
> > >>
> > >> > file.access(local_file, 4)
> > >> local.R
> > >>  0
> > >>
> > >> > file.access(remote_file, 4)
> > >> remote.R
> > >> -1
> > >>
> > >> Also for file.info
> > >>
> > >> > file.info(local_file)$mode:
> > >> [1] "666"
> > >>
> > >> > file.info(remote_file)$mode:
> > >> [1] "666"
> > >>
> > >> Ok so I am access issues. Maybe they are ephemeral and I can change
> > >> the permissions:
> > >>
> > >> > Sys.chmod('remote.R', mode = '666')
> > >> > file.access(remote_file, 4)
> > >> remote.R
> > >> -1
> > >>
> > >> Nope. I am thoroughly stumped and maybe can't make it any further
> > >> because of Windows.
> > >>
> > >> Downstream I am trying to use digest::digest to create a hash but
> > >> digest thinks we don't have permission because file.access is
> > >failing.
> > >> Any thoughts on how I can get file.access to return 0 for the
> > >remote.R
> > >> file? Any ideas?
> > >>
> > >> Thanks in advance,
> > >>
> > >> Sam
> > >
> > >__
> > >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.
> >
> > --
> > Sent from my phone. Please excuse my brevity.
>
> __
> 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] How to index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

2020-02-21 Thread William Dunlap via R-help
> all.equal(y, ave(d, cumsum(c(TRUE,is_true(diff(a)!=0))),
FUN=function(di)1L+cumsum(is_true(di>15
[1] TRUE

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 19, 2020 at 7:20 PM Lijun Zhao 
wrote:

> Dear William,
>
> Thank you so much.
>
>
>
> I am quiet new in R. I would like to do this based on another repeated
> variables.
>
>
>
> For example:
>
> a<-c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)
>
> d<-c(NA, 0, 0, 0, 8, 0, 577, 69, 0, NA, 0, 0, 0, 8, 0, 577, 69, 0)
>
> the outcome I want is :
>
> y<-c(1, 1, 1, 1, 1, 1, 2, 3, 3, 1, 1, 1 ,1, 1 ,1, 2, 3, 3)
>
>
>
> Therefore, I would like to create y based on the variable a. once variable
> a has changed, the index will start from 1 again. I wrote a for loop, but
> it did not give me what I want. Could you please help me again?
>
>
>
> Thanks in advance,
>
>
>
> Lijun
>
>
>
>
>
>
>
> *From:* William Dunlap 
> *Sent:* Thursday, 20 February 2020 1:53 AM
> *To:* Lijun Zhao 
> *Cc:* r-help@r-project.org
> *Subject:* Re: [R] How to index the occasions in a vector repeatedly
> under condition 1? if not, it will give a new index.
>
>
>
> Use cumsum(logicalVector) to increment a counter at the TRUE positions in
> logicalVector. .  E.g.,
>
>
>
> > d <- c(NA, 0, 0, 0, 8, 0, 577, 69, 0)
>
> > is_true <- function(x) !is.na(x) & x
> > 1 + cumsum( is_true(d >= 15) )
> [1] 1 1 1 1 1 1 2 3 3
>
>
>
> Some packages have the equivalent of that is_true function, which maps
> FALSE and NA to FALSE and TRUE to TRUE.  I don't think core R contains such
> a function.
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
>
>
>
> On Wed, Feb 19, 2020 at 7:08 AM Lijun Zhao 
> wrote:
>
> Dear all,
> Could you please help me how to get the output as I described in the
> following example?
>
> x<-c(543,  543,  543,  543,  551 , 551 ,1128 ,1197, 1197)
> diff<-x-lag(x)
> diff
> [1]  NA   0   0   0   8   0 577  69   0
>
> How to index the occasions in x repeatedly if the diff<15? if diff>=15, it
> will give a new index.
> I want the output be like y.
>
> y<-c(1,1,1,1,1,1,2,3,3)
>
> Thank you so much,
>
> Lijun Zhao (PhD Candidate)
> Nutrition and Metabolism
> Level 7 SAHMRI
> North Terrace
> Adelaide 5005
> Ph: +61 8 8128 4898
> e-mail: lijun.z...@adelaide.edu.au<mailto:lijun.z...@adelaide.edu.au> or
> lijun.z...@sahmri.com<mailto:lijun.z...@sahmri.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.
>
>

[[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] How to index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

2020-02-19 Thread William Dunlap via R-help
Use cumsum(logicalVector) to increment a counter at the TRUE positions in
logicalVector. .  E.g.,

> d <- c(NA, 0, 0, 0, 8, 0, 577, 69, 0)
> is_true <- function(x) !is.na(x) & x
> 1 + cumsum( is_true(d >= 15) )
[1] 1 1 1 1 1 1 2 3 3

Some packages have the equivalent of that is_true function, which maps
FALSE and NA to FALSE and TRUE to TRUE.  I don't think core R contains such
a function.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 19, 2020 at 7:08 AM Lijun Zhao 
wrote:

> Dear all,
> Could you please help me how to get the output as I described in the
> following example?
>
> x<-c(543,  543,  543,  543,  551 , 551 ,1128 ,1197, 1197)
> diff<-x-lag(x)
> diff
> [1]  NA   0   0   0   8   0 577  69   0
>
> How to index the occasions in x repeatedly if the diff<15? if diff>=15, it
> will give a new index.
> I want the output be like y.
>
> y<-c(1,1,1,1,1,1,2,3,3)
>
> Thank you so much,
>
> Lijun Zhao (PhD Candidate)
> Nutrition and Metabolism
> Level 7 SAHMRI
> North Terrace
> Adelaide 5005
> Ph: +61 8 8128 4898
> e-mail: lijun.z...@adelaide.edu.au or
> lijun.z...@sahmri.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.
>

[[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] Aggregate individual level data to age categories

2020-02-12 Thread William Dunlap via R-help
You didn't say how you wanted to use it as a data.frame, but here is one way

d <- data.frame(
check.names = FALSE,
age = c(45L, 45L, 46L, 47L, 47L),
x = c(1L, 2L, 1L, 3L, 3L))
with(d, as.data.frame(table(age,x)))

which gives:
  age x Freq
1  45 11
2  46 11
3  47 10
4  45 21
5  46 20
6  47 20
7  45 30
8  46 30
9  47 32

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 12, 2020 at 1:12 PM stefan.d...@gmail.com 
wrote:

> well, if I think about, its actually a simple frequency table grouped
> by age. but it should be usable a matrix or data frame.
>
> On Wed, Feb 12, 2020 at 9:48 PM  wrote:
> >
> > So a pivot table?
> >
> > On 12 Feb 2020 20:39, stefan.d...@gmail.com wrote:
> >
> > Dear All,
> >
> > I have a seemingly standard problem to which I somehow I do  not find
> > a simple solution. I have individual level data where x is a
> > categorical variable with 3 categories which I would like to aggregate
> > by age.
> >
> > age x
> > 45   1
> > 45   2
> > 46   1
> > 47   3
> > 47   3
> > and so on.
> >
> > It should after transformation look like that
> >
> > age x_1 x_2 x_3
> > 451 0   1
> > 461 0   0
> > 47 00   2
> >
> > Basically to calculate prevalences by age categories.
> >
> > Thanks for any pointers!
> >
> > Cheers!
> >
> > __
> > 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.
>

[[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] N Sizes between Pairs of Columns using cor(, , , use = 'pairwise')

2020-01-21 Thread William Dunlap via R-help
crossprod(!is.na(tmp))

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jan 21, 2020 at 11:56 AM Doran, Harold  wrote:

> I'm trying to find an efficient way to find the N size on correlations
> produced when using the pairwise option in cor().
>
> Here is a sample to illustrate:
>
> ### Create a sample data frame
> tmp <- data.frame(v1 = rnorm(10), v2 = rnorm(10), v3 = rnorm(10), v4 =
> rnorm(10))
>
> ### Create some random missingness
> for(i in 1:4) tmp[sample(1:10, 2, replace = FALSE), i] <- NA
>
> ### Correlate
> cor(tmp, use = 'pairwise')
>
> Now, a REALLY bad idea would be this (but conceptually it illustrates what
> I want)
>
> ### Identify all column pairs
> pairs <- combn(4,2)
>
> ### Now, write code to loop over each pair of columns and identify where
> both rows are TRUE
> !is.na(tmp[, pairs[,1]])
>
> Of course doing this when the number of pairwise combinations is silly.
> So, hmmm, I don't see as a by-product of the cor() function N sizes, and
> certainly looping over pairs of columns would be doable, but not efficient,
> but any suggestions on this?
>
> Thanks,
> Harold
>
> __
> 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] File names for mac newby

2020-01-21 Thread William Michels via R-help
Hi David,

Often on a Mac you can "right click" (or on a laptop--press down with
two fingers), and a pop-up will give you the option to "Copy File
Path". (You can also find this option in a Finder window under the
"Finder -> Services" menu bar) .This is the path you should use to
import your file into R.

There's also a R-Help mailing list for Mac users (R-SIG-Mac):
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

HTH, Bill.

W. Michels, Ph.D.

On Tue, Jan 21, 2020 at 9:38 AM David  wrote:
>
> I moved to a mac a few months ago after years in windows, and I'm still
> learning basics.  I'm wanting to create a data frame based on a text
> file called HouseTemps.txt.  That's a file within one called house which
> is within one called ah.  That may further be in one called  Documents.
> I tried various lines like:
>
> temps <-
> read.table("c:\\Users\\DFP\\Documents\\ah\\house\\HouseTemps.txt",header=T,row.names=1)
>
> based on my windows DOS experience, but nothing I try works.  So my
> question is, what do complete file names look like in a mac?
>
> I tried Apple support, but they couldn't help me with R.
>
> __
> 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] Data Carpentry - Creating a New SQLite Database

2020-01-10 Thread William Michels via R-help
Hi Phillip,

Skipping to the last few lines of your email, did you download a
program to look at Sqlite databases (independent of R) as listed
below? Maybe that program ("DB Browser for SQLite") and/or the
instructions below can help you locate your database directory:

https://datacarpentry.org/semester-biology/computer-setup/
https://datacarpentry.org/semester-biology/materials/sql-for-dplyr-users/

If you do have that program, and you're still seeing an error, you
might consider looking for similar issues at the appropriate
'datacarpentry' repository on Github (or posting a new issue
yourself):

https://github.com/datacarpentry/R-ecology-lesson/issues

Finally, I really feel you'll benefit from reading over the documents
pertaining to "R Data Import/Export" on the www.r-project.org website.
No disrespect to the people at 'datacarpentry', but you'll find
similar (and possibly, easier) R code to follow at section 4.3.1
'Packages using DBI' :

https://cran.r-project.org/doc/manuals/r-release/R-data.html

HTH, Bill.

W. Michels, Ph.D.




On Fri, Jan 10, 2020 at 10:32 AM Phillip Heinrich  wrote:
>
> Working my way through a tutorial named Data Carpentry 
> (https://datacarpentry.org/R-ecology-lesson/).  for the most part it is 
> excellent but I’m stuck on the very last section 
> (https://datacarpentry.org/R-ecology-lesson/05-r-and-databases.html).
>
> First, below are the packages I have loaded:
> [1] "forcats"   "stringr"   "purrr" "readr" "tidyr" "tibble"
> "ggplot2"   "tidyverse" "dbplyr""RMySQL""DBI"
> [12] "dplyr" "RSQLite"   "stats" "graphics"  "grDevices" "utils" 
> "datasets"  "methods"   "base"
>
>
> >
>
>
> Second,
> Second, is the text of the last section of the last chapter titled “Creating 
> a New SQLite Database”.
> Second, below is the text from the tutorial.  The black type is from the 
> tutorial.  The green and blue is the suggested R code.  My comments are in 
> red.
> Creating a new SQLite database
> So far, we have used a previously prepared SQLite database. But we can also 
> use R to create a new database, e.g. from existing csv files. Let’s recreate 
> the mammals database that we’ve been working with, in R. First let’s download 
> and read in the csv files. We’ll import tidyverse to gain access to the 
> read_csv() function.
>
> download.file("https://ndownloader.figshare.com/files/3299483";,
>   "data_raw/species.csv")
> download.file("https://ndownloader.figshare.com/files/10717177";,
>   "data_raw/surveys.csv")
> download.file("https://ndownloader.figshare.com/files/3299474";,
>   "data_raw/plots.csv")
> library(tidyverse)
> species <- read_csv("data_raw/species.csv")No problem here.  I’m pulling 
> three databases from the Web and saving them to a folder on my hard drive. 
> (...data_raw/species.csv) etc.surveys <- read_csv("data_raw/surveys.csv") 
> plots <- read_csv("data_raw/plots.csv")Again no problem.  I’m just creating 
> an R data files.  But here is where I loose it.  I’m creating something named 
> my_db_file from another file named portal-database-output with an sqlite 
> extension and then creating my_db from the My_db_file.  Not sure where the 
> sqlite extension file came from. Creating a new SQLite database with dplyr is 
> easy. You can re-use the same command we used above to open an existing 
> .sqlite file. The create = TRUE argument instructs R to create a new, empty 
> database instead.
>
> Caution: When create = TRUE is added, any existing database at the same 
> location is overwritten without warning.
>
> my_db_file <- "data/portal-database-output.sqlite"
> my_db <- src_sqlite(my_db_file, create = TRUE)Currently, our new database is 
> empty, it doesn’t contain any tables:
>
> my_db#> src:  sqlite 3.29.0 [data/portal-database-output.sqlite]
> #> tbls:To add tables, we copy the existing data.frames into the database one 
> by one:
>
> copy_to(my_db, surveys)
> copy_to(my_db, plots)
> my_dbI can follow the directions to fill in my_db but I have no idea how to 
> access the tables.  The text from the tutorial below says to check the 
> location of our database.  Huh!  Can someone give me some direction.  Thanks.
>
>
>
>
>
> If you check the location of our database you’ll see that data is 
> automatically being written to disk. R and dplyr not only provide easy ways 
> to query existing databases, they also allows you to easily create your own 
> databases from flat files!
>
>
>
> Here is where I loose it.
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, s

Re: [R] rnoaa library

2019-12-30 Thread William Michels via R-help
Hi Jeff,

You might have better luck posting your question on the R-SIG-Geo
mailing list, or perusing their archive. I've found a thread
pertaining to the rnoaa package from August 2016, along with a
particularly informative reply (reply link below):

https://stat.ethz.ch/mailman/listinfo/R-SIG-Geo
https://stat.ethz.ch/pipermail/r-sig-geo/
https://stat.ethz.ch/pipermail/r-sig-geo/2016-August/024768.html

If the above links don't help, you might consider checking for open
(or even closed) issues on Github:

https://github.com/ropensci/rnoaa/issues

HTH, Bill.

W. Michels, Ph.D.



On Sun, Dec 29, 2019 at 11:51 AM Jeff Reichman  wrote:
>
> r-help Forum
>
> Anyone familiar with the "rnoaa" library?  I'm trying to pull NOAA  temp
> data. I have a key but when I run the code highlighted in yellow  ..
>
> Warning message:
> Sorry, no data found
>
> No matter what station_id I use.
>
> # library
> library(rnoaa)
> library(lubridate)
>
> # set key
> options(noaakey = "")
>
> start_date = "2018-01-15"
> end_date = "2018-01-31"
> station_id = "USW00013994"
>
> weather_data <- ncdc(datasetid='NORMAL_HLY', stationid=paste0('GHCND:',
> station_id),
>  datatypeid = "HLY-TEMP-NORMAL",
>  startdate = start_date, enddate = end_date, limit=500)
> data <- weather_data$data
>
> data$year <- year(data$date)
> data$month <- month(data$date)
> data$day <- day(data$date)
> # summarize to average daily temps
> aggregate(value ~ year + month + day, mean, data = data)
>
> Sincerely
>
> Jeff Reichman
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread William Michels via R-help
Hi Paul,

Since you start from strings, it's not clear to me where ASCII enters
the picture. If you really need ASCII, you can use the charToInt()
function in the "R.oo" package. Also there's the AsciiToInt() function
in the  "sfsmisc" package. If you just want to use R's native
as.numeric() conversion, there's the digitsBase() function in the
"sfsmisc" package:

> library(sfsmisc)
> digitsBase(as.numeric("63"), base = 2)
Class 'basedInt'(base = 2) [1:1]
 [,1]
[1,]1
[2,]1
[3,]1
[4,]1
[5,]1
[6,]1
>

HTH, Bill.

W. Michels, Ph.D.


On Fri, Dec 27, 2019 at 8:11 AM Marc Schwartz via R-help
 wrote:
>
>
> > On Dec 27, 2019, at 10:42 AM, Paul Bernal  wrote:
> >
> > Dear friends,
> >
> > Hope you are all doing well. I need to find a way to convert ascii numbers
> > to six digit binary numbers:
> >
> > I am working with this example, I converted the string to ascii, and
> > finally to decimal, but I am having trouble converting the decimal numbers
> > into their six digit binary representation. The code below is exactly what
> > I have so far:
> >
> > ascii_datformat <- utf8ToInt("133m@ogP00PD;88MD5MTDww@2D7k")
> > ascii_datformat
> >
> > Base <- ascii_datformat - 48
> >
> > ifelse(Base > 40, Base-8, Base)
> >
> > x <- rev(intToBits(Base))
> > dec2bin <- function(x) paste(as.integer(rev(intToBits(x))), collapse = "")
> > dec2bin
> >
> > any guidance will be greatly appreciated,
> >
> > Best regards,
> >
> > Paul
>
>
> You might look at the intToBin() function in Henrik's R.utils package on CRAN:
>
> https://cran.r-project.org/web/packages/R.utils/index.html
>
> Regards,
>
> Marc Schwartz
>
> __
> 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] How does one pass arguments to a function, such as coxph, that itself is inside a function?

2019-12-16 Thread William Dunlap via R-help
You can use substitute() to fiddle with the formula.  The following shows
how to do it using lm() instead of coxph(), but the manipulations are the
same.  It also has an 'envir' argument in case the formula depends on
anything in the callers enviroment.  The 'substitute(data)' is make the
printouts prettier.

f <- function (response, data, envir = parent.frame())
{
formula <- eval(substitute(response ~ X), envir = envir)
eval(as.call(list(quote(lm), formula, data = substitute(data))),
envir = envir)
}

> d <- data.frame(check.names=FALSE, "Y-one"=1:10, "Y-two"=sqrt(1:10),
X=log(1:10))
> lm(`Y-one` ~ X, data=d)

Call:
lm(formula = `Y-one` ~ X, data = d)

Coefficients:
(Intercept)X
-0.4371   3.9307

> f(`Y-one`, data=d)

Call:
lm(formula = `Y-one` ~ X, data = d)

Coefficients:
(Intercept)X
-0.4371   3.9307
> g <- function() {
+ Y3 <- 1/(1:10)
+ f(Y3, data=d)
+ }
> g()

Call:
lm(formula = Y3 ~ X, data = d)

Coefficients:
(Intercept)X
 0.8338  -0.3581



E.g.,
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Dec 16, 2019 at 10:12 AM Sorkin, John 
wrote:

> Question summary: How does one pass arguments to a function, such as
> coxph, that itself is inside a function.
>
> I am trying to write a function that will allow me to call coxph using
> different outcome and time variables. The coxph works when the coxph is NOT
> contained in a larger function (which passes the outcome and time variable
> to  use), but does not work when coxph is contained in a  larger funciton.
>
> My code:
>
> fit0 <-
> coxph(Surv(FUtime,Death)~Age_in_years_at_A1_max+factor(Diabetes)+factor(CKD_stage)+
>
>  factor(Phase1_first),data=mydata)
> summary(fit0)
>
> this works:
>
> Call:
> coxph(formula = Surv(FUtime, Death) ~ Age_in_years_at_A1_max +
> factor(Diabetes) + factor(CKD_stage) +
> factor(Phase1_first),
> data = mydata)
>
>   n= 350, number of events= 56
>
>coef exp(coef) se(coef)  z Pr(>|z|)
> Age_in_years_at_A1_max  0.04618   1.04727  0.01384  3.338 0.000845 ***
> factor(Diabetes)1   0.12247   1.13029  0.28282  0.433 0.664991
> factor(CKD_stage)3 -0.28418   0.75263  0.38744 -0.733 0.463261
> factor(CKD_stage)4  0.33938   1.40407  0.36583  0.928 0.353572
> factor(CKD_stage)5  0.97121   2.64115  0.40171  2.418 0.015618 *
> factor(Phase1_first)1   0.02204   1.02229  0.29713  0.074 0.940868
>
> other output deleted.
>
> But this code does not work:
>
> doit <- function(time,outcome,data){
>   fit0 <-
>
> coxph(Surv(time,outcome)~Age_in_years_at_A1_max+factor(Diabetes)+factor(CKD_stage)+factor(Phase1_first),data=data)
>   print(summary(fit0))
> }
> doit(FUtime,Death,mydata)
>
>  Error in Surv(time, outcome) : object 'FUtime' not found
>
> I am certain I have a scoping problem, but I don't know how to solve it.
>
> John David Sorkin M.D., Ph.D.
>
> Professor of Medicine
>
> Chief, Biostatistics and Informatics
>
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
>
> Baltimore VA Medical Center
>
> 10 North Greene Street
>
> GRECC (BT/18/GR)
>
> Baltimore, MD 21201-1524
>
> (Phone) 410-605-7119
>
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
>
> __
> 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] table and unique seems to behave differently

2019-12-10 Thread William Dunlap via R-help
You can use save(ascii=TRUE,...) to make an ascii-only RData file that you
can include in the mail message.  E.g.,

> x <- c(3.4, 3.4 + 1e-15)
> save(x, ascii=TRUE, file=stdout())
RDA3
A
3
198145
197888
5
UTF-8
1026
1
262153
1
x
14
2
3.4
3.401
254

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Dec 10, 2019 at 8:37 AM Alain Guillet 
wrote:

> Another finding for me today: dput doesn't write exactly the vector that
> creates the problem. I could use an RData file but I think it is forbidden
> in this mailing list...
>
>
> Alain
> 
> De : Chris Evans 
> Envoyé : mardi 10 décembre 2019 15:41
> À : Alain Guillet 
> Cc : r-help@r-project.org 
> Objet : Re: [R] table and unique seems to behave differently
>
> This doesn't answer your question but I get exactly the same vector of
> length 210 with unique(toto) and names(table(toto)) using the same version
> of R that you are and I can't see any obvious reason why you wouldn't but
> when I hit things like that it tends to be that one version is string with
> initial or trailing spaces or a character set issue.  I can't see that
> those apply here but it's all I could imagine without racking my poor old
> brains much more.
>
> Good luck finding the answer!
>
> Chris
>
> - Original Message -
> > From: "Alain Guillet" 
> > To: r-help@r-project.org
> > Sent: Tuesday, 10 December, 2019 09:53:29
> > Subject: [R] table and unique seems to behave differently
>
> > Hi,
> >
> > I have a vector (see below the dput) and I use unique on it to get unique
> > values. If I then sort the result of the vector obtained by unique, I
> see some
> > elements that look like identical. I suspect it could be a matter of
> rounded
> > values but table gives a different result: unlike unique output which
> contains
> > "3.4  3.4", table has only one cell for 3.4.
> >
> > Can anybody know why I get results that look like incoherent between the
> two
> > functions?
> >
> >
> > Best regards,
> > Alain Guillet
> >
> > --
> > platform   x86_64-pc-linux-gnu
> > arch   x86_64
> > os linux-gnu
> > system x86_64, linux-gnu
> > status
> > major  3
> > minor  6.1
> > year   2019
> > month  07
> > day05
> > svn rev76782
> > language   R
> > version.string R version 3.6.1 (2019-07-05)
> > nickname   Action of the Toes
> > --
> >> dput(toto)
> > c(2.5, 2.6, 2.6, 2.6, 2.6, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.8,
> > 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.9, 2.9, 2.9, 2.9, 2.9,
> > 2.9, 2.9, 2.9, 3, 3, 3, 3, 3, 3, 3, 3, 3.1, 3.1, 3.1, 3.1, 3.1,
> > 3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2,
> > 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3,
> > 3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4,
> > 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.5, 3.5, 3.5, 3.5, 3.5,
> > 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.6, 3.6, 3.6,
> > 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6,
> > 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7,
> > 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7,
> > 3.7, 3.7, 3.7, 3.7, 3.7, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8,
> > 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8,
> > 3.8, 3.8, 3.8, 3.8, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9,
> > 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9,
> > 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1,
> > 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1,
> > 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1,
> > 4.1, 4.1, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2,
> > 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2,
> > 4.2, 4.2, 4.2, 4.2, 4.2, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3,
> > 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3,
> > 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.4, 4.4, 4.4, 4.4,
> > 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4,
> > 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4,
> > 4.4, 4.4, 4.4, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5,
> > 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5,
> > 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5,
> > 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.6,
> > 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6,
> > 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6,
> > 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6,
> > 4.6, 4.6, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7,
> > 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7,
> >

Re: [R] package MCMCpack

2019-12-04 Thread Prophet, William
That was it!! 😉😉😉
Thank you very much. 

Bill P.




-Original Message-
From: William Michels  
Sent: Wednesday, December 4, 2019 4:15 PM
To: Prophet, William 
Cc: Duncan Murdoch ; r-help@r-project.org
Subject: Re: [R] package MCMCpack

Sent by an external sender

--
You can try installing the mcmc package first:

https://cran.r-project.org/web/packages/mcmc/index.html
https://cran.r-project.org/src/contrib/Archive/mcmc/

I've used mcmc_0.9-5 with MCMCpack_1.4-3 under R version 3.3.3.

HTH, Bill.

W. Michels, Ph.D.


On Wed, Dec 4, 2019 at 2:52 PM Prophet, William  
wrote:
>
> Thank you for your reply. I have tried various versions and I get an error in 
> each case. In the case of MCMCpack_1.4-3 although the error may be related to 
> something specific in my configuration. In any case, I get the following 
> error when I try to install that version:
>
> > packageurl <- 
> > "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.4-3.tar.gz";
> > install.packages(packageurl, repos=NULL, type="source")
> trying URL 
> 'https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.4-3.tar.gz'
> Content type 'application/x-gzip' length 688047 bytes (671 KB) 
> downloaded 671 KB
>
> ERROR: dependency 'mcmc' is not available for package 'MCMCpack'
> * removing 'C:/R/R-3.5.3/library/MCMCpack'
> In R CMD INSTALL
> Warning in install.packages :
>   installation of package 
> 'C:/Users/prophetw/AppData/Local/Temp/RtmpykZoRh/downloaded_packages/M
> CMCpack_1.4-3.tar.gz' had non-zero exit status
>
>
>
>
>
> -Original Message-
> From: William Michels 
> Sent: Wednesday, December 4, 2019 3:45 PM
> To: Prophet, William 
> Cc: Duncan Murdoch ; r-help@r-project.org
> Subject: Re: [R] package MCMCpack
>
> Sent by an external sender
>
> --
> Hi William,
>
> It's not clear to me why you need this particular older version of MCMCpack. 
> From the archive I find MCMCpack_1.2-4 dates back to 2012-06-14, and 
> MCMCpack_1.2-4.1 dates back to 2013-04-07:
>
> MCMCpack_1.2-4.1.tar.gz 2013-04-07 00:05 481K MCMCpack_1.2-4.tar.gz 
> 2012-06-14 12:36 482K
>
> Have you tried newer versions of MCMCpack? While the newest version of 
> MCMCpack (1.4-5) may require R (≥ 3.6), I have sessionInfo() logs 
> suggesting that MCMCpack_1.4-3 (2018-05-15 09:54 672K) ran just fine 
> under R version 3.3.3 (2017-03-06) -- "Another Canoe". In fact, an 
> archived version of the MCMCpack_1.4-3 DESCRIPTION_file indicates that
> MCMCpack_1.4-3 only requires  R (>= 2.10.0).
>
> Hope this helps,
>
> Bill.
>
> W. Michels, Ph.D.
>
>
>
>
>
> On Wed, Dec 4, 2019 at 7:34 AM Prophet, William  
> wrote:
> >
> > Yes, I should have mentioned that I tried this same line of code and I 
> > still got an error.
> >
> >
> > -Original Message-
> > From: Duncan Murdoch 
> > Sent: Wednesday, December 4, 2019 8:32 AM
> > To: Prophet, William ; 
> > r-help@r-project.org
> > Subject: Re: [R] package MCMCpack
> >
> > Sent by an external sender
> >
> > 
> > -- On 04/12/2019 8:47 a.m., Prophet, William wrote:
> > > I am running R on my work computer with the following parameters:
> > >> sessionInfo()
> > > R version 3.5.3 (2019-03-11)
> > > Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 
> > > >=
> > > 8
> > > x64 (build 9200)
> > >
> > >
> > > I am trying to install the "MCMCpack" library. In the process however, I 
> > > receive the message:
> > >
> > >> install.packages("MCMCpack")
> > >
> > > Warning in install.packages :
> > >
> > >package 'MCMCpack' is not available (for R version 3.5.3)
> > >
> > >
> > > I have tried to install earlier versions of the "MCMCpack" library which 
> > > I obtained from the following website:
> > > https://cran.r-project.org/src/contrib/Archive/MCMCpack/
> > >
> > > using the following code:
> > > packageurl <- 
> > > "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
> > > install.packages(packageurl, type="source")
> >
> > That's not the way to install a tarball.  You should use
> >
> > install.packages(package

Re: [R] package MCMCpack

2019-12-04 Thread William Michels via R-help
You can try installing the mcmc package first:

https://cran.r-project.org/web/packages/mcmc/index.html
https://cran.r-project.org/src/contrib/Archive/mcmc/

I've used mcmc_0.9-5 with MCMCpack_1.4-3 under R version 3.3.3.

HTH, Bill.

W. Michels, Ph.D.


On Wed, Dec 4, 2019 at 2:52 PM Prophet, William
 wrote:
>
> Thank you for your reply. I have tried various versions and I get an error in 
> each case. In the case of MCMCpack_1.4-3 although the error may be related to 
> something specific in my configuration. In any case, I get the following 
> error when I try to install that version:
>
> > packageurl <- 
> > "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.4-3.tar.gz";
> > install.packages(packageurl, repos=NULL, type="source")
> trying URL 
> 'https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.4-3.tar.gz'
> Content type 'application/x-gzip' length 688047 bytes (671 KB)
> downloaded 671 KB
>
> ERROR: dependency 'mcmc' is not available for package 'MCMCpack'
> * removing 'C:/R/R-3.5.3/library/MCMCpack'
> In R CMD INSTALL
> Warning in install.packages :
>   installation of package 
> 'C:/Users/prophetw/AppData/Local/Temp/RtmpykZoRh/downloaded_packages/MCMCpack_1.4-3.tar.gz'
>  had non-zero exit status
>
>
>
>
>
> -Original Message-
> From: William Michels 
> Sent: Wednesday, December 4, 2019 3:45 PM
> To: Prophet, William 
> Cc: Duncan Murdoch ; r-help@r-project.org
> Subject: Re: [R] package MCMCpack
>
> Sent by an external sender
>
> --
> Hi William,
>
> It's not clear to me why you need this particular older version of MCMCpack. 
> From the archive I find MCMCpack_1.2-4 dates back to 2012-06-14, and 
> MCMCpack_1.2-4.1 dates back to 2013-04-07:
>
> MCMCpack_1.2-4.1.tar.gz 2013-04-07 00:05 481K MCMCpack_1.2-4.tar.gz 
> 2012-06-14 12:36 482K
>
> Have you tried newer versions of MCMCpack? While the newest version of 
> MCMCpack (1.4-5) may require R (≥ 3.6), I have sessionInfo() logs suggesting 
> that MCMCpack_1.4-3 (2018-05-15 09:54 672K) ran just fine under R version 
> 3.3.3 (2017-03-06) -- "Another Canoe". In fact, an archived version of the 
> MCMCpack_1.4-3 DESCRIPTION_file indicates that
> MCMCpack_1.4-3 only requires  R (>= 2.10.0).
>
> Hope this helps,
>
> Bill.
>
> W. Michels, Ph.D.
>
>
>
>
>
> On Wed, Dec 4, 2019 at 7:34 AM Prophet, William  
> wrote:
> >
> > Yes, I should have mentioned that I tried this same line of code and I 
> > still got an error.
> >
> >
> > -Original Message-
> > From: Duncan Murdoch 
> > Sent: Wednesday, December 4, 2019 8:32 AM
> > To: Prophet, William ;
> > r-help@r-project.org
> > Subject: Re: [R] package MCMCpack
> >
> > Sent by an external sender
> >
> > --
> > On 04/12/2019 8:47 a.m., Prophet, William wrote:
> > > I am running R on my work computer with the following parameters:
> > >> sessionInfo()
> > > R version 3.5.3 (2019-03-11)
> > > Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >=
> > > 8
> > > x64 (build 9200)
> > >
> > >
> > > I am trying to install the "MCMCpack" library. In the process however, I 
> > > receive the message:
> > >
> > >> install.packages("MCMCpack")
> > >
> > > Warning in install.packages :
> > >
> > >package 'MCMCpack' is not available (for R version 3.5.3)
> > >
> > >
> > > I have tried to install earlier versions of the "MCMCpack" library which 
> > > I obtained from the following website:
> > > https://cran.r-project.org/src/contrib/Archive/MCMCpack/
> > >
> > > using the following code:
> > > packageurl <- 
> > > "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
> > > install.packages(packageurl, type="source")
> >
> > That's not the way to install a tarball.  You should use
> >
> > install.packages(packageurl, type="source", repos=NULL)
> >
> > However, you may still have problems:  when I tried that, the install 
> > failed because of C++ errors.  I don't know if configure options (e.g.
> > specifying a particular version of C++) would have fixed the problems.
> >
> > Duncan Murdoch
> >
> > >
> >

Re: [R] package MCMCpack

2019-12-04 Thread Prophet, William
Thank you for your reply. I have tried various versions and I get an error in 
each case. In the case of MCMCpack_1.4-3 although the error may be related to 
something specific in my configuration. In any case, I get the following error 
when I try to install that version:

> packageurl <- 
> "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.4-3.tar.gz";
> install.packages(packageurl, repos=NULL, type="source")
trying URL 
'https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.4-3.tar.gz'
Content type 'application/x-gzip' length 688047 bytes (671 KB)
downloaded 671 KB

ERROR: dependency 'mcmc' is not available for package 'MCMCpack'
* removing 'C:/R/R-3.5.3/library/MCMCpack'
In R CMD INSTALL
Warning in install.packages :
  installation of package 
'C:/Users/prophetw/AppData/Local/Temp/RtmpykZoRh/downloaded_packages/MCMCpack_1.4-3.tar.gz'
 had non-zero exit status





-Original Message-
From: William Michels  
Sent: Wednesday, December 4, 2019 3:45 PM
To: Prophet, William 
Cc: Duncan Murdoch ; r-help@r-project.org
Subject: Re: [R] package MCMCpack

Sent by an external sender

--
Hi William,

It's not clear to me why you need this particular older version of MCMCpack. 
From the archive I find MCMCpack_1.2-4 dates back to 2012-06-14, and 
MCMCpack_1.2-4.1 dates back to 2013-04-07:

MCMCpack_1.2-4.1.tar.gz 2013-04-07 00:05 481K MCMCpack_1.2-4.tar.gz 2012-06-14 
12:36 482K

Have you tried newer versions of MCMCpack? While the newest version of MCMCpack 
(1.4-5) may require R (≥ 3.6), I have sessionInfo() logs suggesting that 
MCMCpack_1.4-3 (2018-05-15 09:54 672K) ran just fine under R version 3.3.3 
(2017-03-06) -- "Another Canoe". In fact, an archived version of the 
MCMCpack_1.4-3 DESCRIPTION_file indicates that
MCMCpack_1.4-3 only requires  R (>= 2.10.0).

Hope this helps,

Bill.

W. Michels, Ph.D.





On Wed, Dec 4, 2019 at 7:34 AM Prophet, William  
wrote:
>
> Yes, I should have mentioned that I tried this same line of code and I still 
> got an error.
>
>
> -Original Message-
> From: Duncan Murdoch 
> Sent: Wednesday, December 4, 2019 8:32 AM
> To: Prophet, William ; 
> r-help@r-project.org
> Subject: Re: [R] package MCMCpack
>
> Sent by an external sender
>
> --
> On 04/12/2019 8:47 a.m., Prophet, William wrote:
> > I am running R on my work computer with the following parameters:
> >> sessionInfo()
> > R version 3.5.3 (2019-03-11)
> > Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 
> > 8
> > x64 (build 9200)
> >
> >
> > I am trying to install the "MCMCpack" library. In the process however, I 
> > receive the message:
> >
> >> install.packages("MCMCpack")
> >
> > Warning in install.packages :
> >
> >package 'MCMCpack' is not available (for R version 3.5.3)
> >
> >
> > I have tried to install earlier versions of the "MCMCpack" library which I 
> > obtained from the following website:
> > https://cran.r-project.org/src/contrib/Archive/MCMCpack/
> >
> > using the following code:
> > packageurl <- 
> > "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
> > install.packages(packageurl, type="source")
>
> That's not the way to install a tarball.  You should use
>
> install.packages(packageurl, type="source", repos=NULL)
>
> However, you may still have problems:  when I tried that, the install failed 
> because of C++ errors.  I don't know if configure options (e.g.
> specifying a particular version of C++) would have fixed the problems.
>
> Duncan Murdoch
>
> >
> > but I get an identical error message:
> >
> >> packageurl <- 
> >> "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
> >
> >> install.packages(packageurl, type="source")
> >
> > Warning in install.packages :
> >
> >package
> > 'https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.
> > 2- 4.tar.gz' is not available (for R version 3.5.3)
> >
> >
> >
> > I realize that updating my R version to 3.6.1 could possibly solve the 
> > problem, but this would be impractical for me because my version needs to 
> > be consistent with others on my team. In any case, the fact that I am 
> > getting errors (detailed above) with *every* version of "MCMCpack" seems 
> &g

Re: [R] package MCMCpack

2019-12-04 Thread William Michels via R-help
Hi William,

It's not clear to me why you need this particular older version of
MCMCpack. From the archive I find MCMCpack_1.2-4 dates back to
2012-06-14, and MCMCpack_1.2-4.1 dates back to 2013-04-07:

MCMCpack_1.2-4.1.tar.gz 2013-04-07 00:05 481K
MCMCpack_1.2-4.tar.gz 2012-06-14 12:36 482K

Have you tried newer versions of MCMCpack? While the newest version of
MCMCpack (1.4-5) may require R (≥ 3.6), I have sessionInfo() logs
suggesting that MCMCpack_1.4-3 (2018-05-15 09:54 672K) ran just fine
under R version 3.3.3 (2017-03-06) -- "Another Canoe". In fact, an
archived version of the MCMCpack_1.4-3 DESCRIPTION_file indicates that
MCMCpack_1.4-3 only requires  R (>= 2.10.0).

Hope this helps,

Bill.

W. Michels, Ph.D.





On Wed, Dec 4, 2019 at 7:34 AM Prophet, William
 wrote:
>
> Yes, I should have mentioned that I tried this same line of code and I still 
> got an error.
>
>
> -Original Message-
> From: Duncan Murdoch 
> Sent: Wednesday, December 4, 2019 8:32 AM
> To: Prophet, William ; r-help@r-project.org
> Subject: Re: [R] package MCMCpack
>
> Sent by an external sender
>
> ------
> On 04/12/2019 8:47 a.m., Prophet, William wrote:
> > I am running R on my work computer with the following parameters:
> >> sessionInfo()
> > R version 3.5.3 (2019-03-11)
> > Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8
> > x64 (build 9200)
> >
> >
> > I am trying to install the "MCMCpack" library. In the process however, I 
> > receive the message:
> >
> >> install.packages("MCMCpack")
> >
> > Warning in install.packages :
> >
> >package 'MCMCpack' is not available (for R version 3.5.3)
> >
> >
> > I have tried to install earlier versions of the "MCMCpack" library which I 
> > obtained from the following website:
> > https://cran.r-project.org/src/contrib/Archive/MCMCpack/
> >
> > using the following code:
> > packageurl <- 
> > "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
> > install.packages(packageurl, type="source")
>
> That's not the way to install a tarball.  You should use
>
> install.packages(packageurl, type="source", repos=NULL)
>
> However, you may still have problems:  when I tried that, the install failed 
> because of C++ errors.  I don't know if configure options (e.g.
> specifying a particular version of C++) would have fixed the problems.
>
> Duncan Murdoch
>
> >
> > but I get an identical error message:
> >
> >> packageurl <- 
> >> "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
> >
> >> install.packages(packageurl, type="source")
> >
> > Warning in install.packages :
> >
> >package
> > 'https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-
> > 4.tar.gz' is not available (for R version 3.5.3)
> >
> >
> >
> > I realize that updating my R version to 3.6.1 could possibly solve the 
> > problem, but this would be impractical for me because my version needs to 
> > be consistent with others on my team. In any case, the fact that I am 
> > getting errors (detailed above) with *every* version of "MCMCpack" seems 
> > odd.
> >
> > Do you have any suggestions for how I can install a working version of 
> > "MCMCpack" for my version of R?
> >
> > Thank you,
> > Bill
> >
> >
> >
> >
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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] How to use preProcess in Caret?

2019-12-04 Thread William Michels via R-help
Hello,

Have you tried alternative methods of pre-processing your data, such
as simply calling scale()? What is the effect on convergence, for both
the caret package and and the neuralnet package? There's an example
using scale() with the neuralnet package at the link below:

https://datascienceplus.com/fitting-neural-network-in-r/

HTH, Bill.

W. Michels, Ph.D.



On Sun, Dec 1, 2019 at 10:04 AM Burak Kaymakci  wrote:
>
> Hello there,
>
> I am using caret and neuralnet to train a neural network to predict times
> table. I am using 'backprop' algorithm for neuralnet to experiment and
> learn.
>
> Before using caret, I've trained a neuralnet without using caret, I've
> normalized my input & outputs using preProcess with 'range' method. Then I
> predicted my test set, did the multiplication and addition on predictions
> to get the real values. It gave me good results.
>
> What I want to ask is, when I try to train my network using caret, I get an
> error saying algorithm did not converge. I am thinking that I might be
> doing something wrong with my pre-processing,
>
> How would I go about using preProcess in train?
> Do I pass my not-normalized data set to the train function and train
> function handles normalization internally?
>
> You can find my R gist here
> 
>
> Thank you,
> Burak
> __
> 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] Error in FUN(X[[i]], ...) : subscript out of bounds

2019-12-04 Thread William Dunlap via R-help
In your fit_bayes function, you have
   getTrainPerf(mod)[, "TrainRMSE"]
What are the column name of the output of getTrainPerf(mod)?
   print(colnames(getTrainPerf(mod)))
You can home in on the problem faster if you call
   traceback()
immediately after the error.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Dec 4, 2019 at 3:38 AM Neha gupta  wrote:

> Hi , I know nobody will respond to my query as I asked few in the past and
> no answer received for any of my questions. However, I am asking here with
> the hope it will get responded.
>
> I am using bayesian optimization to tune the parameter of mtry for random
> forest but it gives me the error: Error in FUN(X[[i]], ...) : subscript out
> of bounds
>
> I am using the following code:
>
> fit_bayes <- function(mtry) {
>   ## Use the same model code but for a single (C, sigma) pair.
>   mod <- train(Effort ~ ., data = tr,
>method = "rf",
>preProc = c("center", "scale", "zv"),
>metric = "RMSE",
>trControl = ctrl,
>tuneGrid = data.frame(C = 10^(mtry)))
>
>   list(Score = -getTrainPerf(mod)[, "TrainRMSE"], Pred = 0)
> }
>
>
> library(rBayesianOptimization)
>
> bounds <- list(mtry = c(-2,  5)
>
>
> set.seed(8606)
> bo_search <- BayesianOptimization(fit_bayes,
>   bounds = bounds,
>   init_points = 10,
>   n_iter = 100,
>   acq = "ucb",
>   kappa = 1,
>   eps = 0.0)
> bo_search
>
> [[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] package MCMCpack

2019-12-04 Thread Prophet, William
Yes, I should have mentioned that I tried this same line of code and I still 
got an error. 


-Original Message-
From: Duncan Murdoch  
Sent: Wednesday, December 4, 2019 8:32 AM
To: Prophet, William ; r-help@r-project.org
Subject: Re: [R] package MCMCpack

Sent by an external sender

--
On 04/12/2019 8:47 a.m., Prophet, William wrote:
> I am running R on my work computer with the following parameters:
>> sessionInfo()
> R version 3.5.3 (2019-03-11)
> Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 
> x64 (build 9200)
>
>
> I am trying to install the "MCMCpack" library. In the process however, I 
> receive the message:
>
>> install.packages("MCMCpack")
>
> Warning in install.packages :
>
>package 'MCMCpack' is not available (for R version 3.5.3)
>
>
> I have tried to install earlier versions of the "MCMCpack" library which I 
> obtained from the following website:
> https://cran.r-project.org/src/contrib/Archive/MCMCpack/
>
> using the following code:
> packageurl <- 
> "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
> install.packages(packageurl, type="source")

That's not the way to install a tarball.  You should use

install.packages(packageurl, type="source", repos=NULL)

However, you may still have problems:  when I tried that, the install failed 
because of C++ errors.  I don't know if configure options (e.g.
specifying a particular version of C++) would have fixed the problems.

Duncan Murdoch

>
> but I get an identical error message:
>
>> packageurl <- 
>> "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
>
>> install.packages(packageurl, type="source")
>
> Warning in install.packages :
>
>package 
> 'https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-
> 4.tar.gz' is not available (for R version 3.5.3)
>
>
>
> I realize that updating my R version to 3.6.1 could possibly solve the 
> problem, but this would be impractical for me because my version needs to be 
> consistent with others on my team. In any case, the fact that I am getting 
> errors (detailed above) with *every* version of "MCMCpack" seems odd.
>
> Do you have any suggestions for how I can install a working version of 
> "MCMCpack" for my version of R?
>
> Thank you,
> Bill
>
>
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


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


[R] package MCMCpack

2019-12-04 Thread Prophet, William
I am running R on my work computer with the following parameters:
> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)


I am trying to install the "MCMCpack" library. In the process however, I 
receive the message:

> install.packages("MCMCpack")

Warning in install.packages :

  package 'MCMCpack' is not available (for R version 3.5.3)


I have tried to install earlier versions of the "MCMCpack" library which I 
obtained from the following website:
https://cran.r-project.org/src/contrib/Archive/MCMCpack/

using the following code:
packageurl <- 
"https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";
install.packages(packageurl, type="source")

but I get an identical error message:

> packageurl <- 
> "https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz";

> install.packages(packageurl, type="source")

Warning in install.packages :

  package 
'https://cran.r-project.org/src/contrib/Archive/MCMCpack/MCMCpack_1.2-4.tar.gz' 
is not available (for R version 3.5.3)



I realize that updating my R version to 3.6.1 could possibly solve the problem, 
but this would be impractical for me because my version needs to be consistent 
with others on my team. In any case, the fact that I am getting errors 
(detailed above) with *every* version of "MCMCpack" seems odd.

Do you have any suggestions for how I can install a working version of 
"MCMCpack" for my version of R?

Thank you,
Bill





[[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] Conditions

2019-11-26 Thread William Michels via R-help
Hi Val,

Here's an answer using a series of ifelse() statements. Because the d4
column is created initially using NA as a placeholder, you can check
your conditional logic at the end using table(!is.na(dat2$d4)):

> dat2 <-read.table(text="ID  d1 d2 d3
+ A 0 25 35
+ B 12 22  0
+ C 0  0  31
+ E 10 20 30
+ F 0  0   0", header=TRUE, stringsAsFactors=F)
>
> dat2$d4 <- NA
> dat2$d4 <- with(dat2, ifelse(d1!=0, yes=d1, no=d4))
> dat2$d4 <- with(dat2, ifelse((d1==0 & d2!=0), yes=d2, no=d4))
> dat2$d4 <- with(dat2, ifelse((d1==0 & d2==0 & d3!=0), yes=d3, no=d4))
> dat2$d4 <- with(dat2, ifelse((d1==0 & d2==0 & d3==0), yes=0, no=d4))
>
> dat2
  ID d1 d2 d3 d4
1  A  0 25 35 25
2  B 12 22  0 12
3  C  0  0 31 31
4  E 10 20 30 10
5  F  0  0  0  0
>
> table(!is.na(dat2$d4))

TRUE
   5
>

Your particular conditionals don't appear sensitive to order, but
someone else using the same strategy may have to take care to run the
ifelse() statements in the correct (desired) order.

HTH, Bill.

W. Michels, Ph.D.



On Tue, Nov 26, 2019 at 3:15 PM Val  wrote:
>
> HI All, I am having a little issue in my ifelse statement,
> The data frame looks like as follow.
>
> dat2 <-read.table(text="ID  d1 d2 d3
> A 0 25 35
> B 12 22  0
> C 0  0  31
> E 10 20 30
> F 0  0   0",header=TRUE,stringsAsFactors=F)
> I want to create d4 and set the value based on the following conditions.
> If d1  !=0  then d4=d1
> if d1 = 0  and d2 !=0  then d4=d2
> if (d1  and d2 = 0) and d3  !=0 then d4=d3
> if all d1, d2 and d3 =0 then d4=0
>
> Here is the desired output and my attempt
>  ID d1 d2 d3 d4
>   A  0 25 35  25
>   B 12 22  0  12
>   C  0  0 31   31
>   E 10 20 30  10
>   F  0  0  0  0  0
>
> My attempt
> dat2$d4 <-  0
> dat2$d4  <- ifelse((dat2$d1 =="0"), dat2$d2, ifelse(dat2$d2 == "0"), dat2$d3, 
> 0)
> but not working.
>
> Thank you.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


  1   2   3   4   5   6   7   8   9   10   >