Re: [R] Is this *always* the intended R^2 value for no intercept in lm?

2022-11-06 Thread David Winsemius
To Thierry; When you omit an intercept you require that the line in 
multivariate space that represents the ‘predictions’ go through the (0,0,0,…) 
I.e. the origin. It’s a fairly restrictive requirement. There IS an intercept, 
even though it’s not explicitly seen in the model. If it’s not required by 
theory in your domain of investigation, you are advised to avoid such a 
practice.

— 
David. 

Sent from my iPhone

> On Nov 5, 2022, at 12:41 PM, Bert Gunter  wrote:
> 
> FAQ 7.41
> and
> https://stackoverflow.com/questions/57415793/r-squared-in-lm-for-ero-intercept-model
> 
> (among numerous others that could no doubt be found with a bit of
> searching).
> 
> In short, the "null models" against which you are comparing the fitted
> model are different with and without an intercept.
> 
> --Bert
> 
> 
> 
>> On Sat, Nov 5, 2022 at 11:52 AM Thierry Zell  wrote:
>> 
>> I am puzzled by the computation of R^2 with intercept omitted that is
>> already illustrated by the following example taken from help("lm")
>> 
>> ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
>> ## Page 9: Plant Weight Data.
>> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
>> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
>> group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
>> weight <- c(ctl, trt)
>> lm.D9 <- lm(weight ~ group)
>> lm.D90 <- lm(weight ~ group - 1) # omitting intercept
>> 
>> The calculations for the R^2 for both models  are consistent with the
>> help("summary.lm") description:
>> "y* is the mean of y[i] if there is an intercept and zero otherwise."
>> Which causes a dramatic difference in the resulting R^2 values.
>> 
>> r2.D9 <- summary(lm.D9)$r.squared
>> r2.D90 <- summary(lm.D90)$r.squared
>> 
>> all.equal(r2.D9, 0.0730775989903856) #TRUE
>> all.equal(r2.D90, 0.981783272435264) #TRUE
>> 
>> This is counter-intuitive to say the least since the two models have
>> identical predictions and both models could be described more
>> accurately as two intercepts rather than zero. I see three
>> possibilities:
>> 
>> 1. This is the intended result, in which case no fix is required, but
>> I’d be curious to understand the argument better.
>> 2. This is an unfortunate outcome but not worth fixing as the user can
>> easily compute the correct R^2. In this case, I'd suggest that this
>> unintuitive behavior should be explicitly called out in the
>> documentation.
>> 3. This is a bug worth fixing.
>> 
>> I look forward to hearing the community’s opinion on this.
>> Thanks in advance!
>> 
>> __
>> 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.


[R] (no subject)

2022-11-06 Thread Nick Wray
Hello - I am using the MICE package to impute missing values - the input
data are up to six vectors of parallel hourly temperature measurements for
Scottish weather stations across a calendar year. None of the vectors have
more than 5% NAs as I have filtered ones with more out.  Most of the sets
work fine with MICE but with a few I get an error message:

This data set, which generated the error message has five columns

iter imp variable
  1   1  986Error in terms.formula(tmp, simplify = TRUE) :
  invalid term in model formula


986 is the station number which is the column name here for the first
column.  The third to fifth columns don't have any NAs and the first and
second have fewer than 1% - but they do have the NAs concentrated as
strings of 20 or so near the beginning of the data set.

I am puzzled as to why certain datasets, which don't seem very different
from the others provoke the error message - the only thing which I am
wondering is whether MICE has a problem with a too large concentration of
the NAs in particular regions but I can't find any reference to this in the
literature.  Has anyone else come across this as a problem, and if so, what
did they do about it?  Thanks Nick Wray

[[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] Associate a .R file with the RGui

2022-11-06 Thread Amarjit Chandhial via R-help




Hi Uwe,



I can do 1.


   1. Add the line
if ( length(z <- commandArgs(TRUE)) ) utils::file.edit(z[1])
to the Rprofile.site file; and

My Rprofile.site file is: "C:/PROGRA~1/R/R-42~1.2/etc/Rprofile.site"

How do I do 2, step-by-step?

2. Edit the registry to associate the .R extension with the command
C:\Program Files\R\R-4.2.2\bin\x64\Rgui.exe --args "%1"



Amarjit



-- Original Message --
From: "Uwe Ligges" 
To: "Amarjit Chandhial" ; "David Winsemius" 
; "Jeff Newmiller" 
Cc: "Amarjit Chandhial via R-help" 
Sent: Sunday, 6 Nov, 2022 At 17:19
Subject: Re: [R] Associate a .R file with the RGui

On 06.11.2022 17:21, Amarjit Chandhial via R-help wrote:

Hi Uwe,

RGui does have advantages vs. RStudio, and vice-versa.
RStudio is much faster than it used to be.
I currently have .R files associated with RStudio, i.e. in File Explorer
if I double-click on a .R file it opens in the editor in RStudio as an R
script.
In File Explorer if I right-click on a .R file, Open with, I get the
options: R for Windows GUI Front-end or RStudio or Search the Microsoft
Store or choose another app.
If I choose R for Windows GUI Front-end, RGui (64-bit) opens, but no .R
file, in the editor.
If I choose RStudio the .R file opens in the editor in RStudio as an R
script.
   From the adaptation, if I choose R for Windows GUI Front-end, will 
the
.R file open in RGui (64-bit) within the editor?
Yes.


I have a new Windows PC and maybe, at least for the time being, it's
best for me to have them associated with RStudio.
Although, yes, I agree, it should be naturally implemented in R, having
installed RStudio.
I meant to implement that one can choose the internal editor to open .R 
files. File associations can be set by RStudio, too, but that is not an 
R(-core) matter.
Best,
Uwe Ligges


thanks,
Amarjit


-- Original Message --
From: "Uwe Ligges" 
To: "David Winsemius" ; "Amarjit Chandhial"
; "Jeff Newmiller"

Cc: "Amarjit Chandhial via R-help" 
Sent: Sunday, 6 Nov, 2022 At 15:15
Subject: Re: [R] Associate a .R file with the RGui

On 06.11.2022 01:40, David Winsemius wrote:
On 11/5/22 09:58, Amarjit Chandhial via R-help wrote:
Hi Jeff,

Please see my original question.
You were told that RGui is not an editor.
Are you implying that your initial message contained an implicit
request for instructions on how to get R code in an .R file to be opened
automagically when double-clicked or to have "open in "
appear when right-clicked? (I didn't see that clearly expressed.)
If you want something else to happen with a file that has a .R
extension when double-clicked or right-clicked in a GUI file manager,
then you need to configure your OS to do whatever else it is that you
expect. This is not really an R question. It's an OS question. There are
many editors that can also bring up R consoles when the right  key combo
is pressed. They do require some study for their specific actions, but
this is not really the place to get guidance on the fine details.

Friends, RGui contains an editor. It allows to send lines / code
blocks to the R concole. We know users who need braille displays use the
RGui internal editor as that apparently cooperates better with braille
displays + R as many other editors.
And as it does not hide half of R by its own functions, I'd pefer 
that
over some very popular other editors if I had no other choice.

To answer the OP's question, R does not have a built in way to get
this task directly done, but searching the web suggests a rather simple
way (well,m a hack as starting R with other command args may fail now,
but you can extend this and look for a specific naming scheme):

 > >
let is adapt this for the recent version of R:

1. Add the line
if ( length(z <- commandArgs(TRUE)) ) utils::file.edit(z[1])
to the Rprofile.site file; and
2. Edit the registry to associate the .R extension with the command
C:\Program Files\R\R-4.2.2\bin\x64\Rgui.exe --args "%1"

I think we should implement this in R anyway.
Best,
Uwe Ligges



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

Re: [R] Associate a .R file with the RGui

2022-11-06 Thread Uwe Ligges




On 06.11.2022 17:21, Amarjit Chandhial via R-help wrote:




Hi Uwe,


RGui does have advantages vs. RStudio, and vice-versa.

RStudio is much faster than it used to be.

I currently have .R files associated with RStudio, i.e. in File Explorer
if I double-click on a .R file it opens in the editor in RStudio as an R
script.

In File Explorer if I right-click on a .R file, Open with, I get the
options: R for Windows GUI Front-end or RStudio or Search the Microsoft
Store or choose another app.
If I choose R for Windows GUI Front-end, RGui (64-bit) opens, but no .R
file, in the editor.
If I choose RStudio the .R file opens in the editor in RStudio as an R
script.

  From the adaptation, if I choose R for Windows GUI Front-end, will the
.R file open in RGui (64-bit) within the editor?


Yes.





I have a new Windows PC and maybe, at least for the time being, it's
best for me to have them associated with RStudio.

Although, yes, I agree, it should be naturally implemented in R, having
installed RStudio.


I meant to implement that one can choose the internal editor to open .R 
files. File associations can be set by RStudio, too, but that is not an 
R(-core) matter.


Best,
Uwe Ligges





thanks,
Amarjit




-- Original Message --
From: "Uwe Ligges" 
To: "David Winsemius" ; "Amarjit Chandhial"
; "Jeff Newmiller"

Cc: "Amarjit Chandhial via R-help" 
Sent: Sunday, 6 Nov, 2022 At 15:15
Subject: Re: [R] Associate a .R file with the RGui


   On 06.11.2022 01:40, David Winsemius wrote:

   On 11/5/22 09:58, Amarjit Chandhial via R-help wrote:
   Hi Jeff,


   Please see my original question.

   You were told that RGui is not an editor.

   Are you implying that your initial message contained an implicit
request for instructions on how to get R code in an .R file to be opened
automagically when double-clicked or to have "open in "
appear when right-clicked? (I didn't see that clearly expressed.)

   If you want something else to happen with a file that has a .R
extension when double-clicked or right-clicked in a GUI file manager,
then you need to configure your OS to do whatever else it is that you
expect. This is not really an R question. It's an OS question. There are
many editors that can also bring up R consoles when the right  key combo
is pressed. They do require some study for their specific actions, but
this is not really the place to get guidance on the fine details.


   Friends, RGui contains an editor. It allows to send lines / code
blocks to the R concole. We know users who need braille displays use the
RGui internal editor as that apparently cooperates better with braille
displays + R as many other editors.
   And as it does not hide half of R by its own functions, I'd pefer that
over some very popular other editors if I had no other choice.


   To answer the OP's question, R does not have a built in way to get
this task directly done, but searching the web suggests a rather simple
way (well,m a hack as starting R with other command args may fail now,
but you can extend this and look for a specific naming scheme):

    >

   let is adapt this for the recent version of R:


   1. Add the line

   if ( length(z <- commandArgs(TRUE)) ) utils::file.edit(z[1])

   to the Rprofile.site file; and

   2. Edit the registry to associate the .R extension with the command

   C:\Program Files\R\R-4.2.2\bin\x64\Rgui.exe --args "%1"


   I think we should implement this in R anyway.

   Best,
   Uwe Ligges







[[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] Associate a .R file with the RGui

2022-11-06 Thread Amarjit Chandhial via R-help




Hi Uwe,


RGui does have advantages vs. RStudio, and vice-versa.

RStudio is much faster than it used to be.

I currently have .R files associated with RStudio, i.e. in File Explorer 
if I double-click on a .R file it opens in the editor in RStudio as an R 
script.

In File Explorer if I right-click on a .R file, Open with, I get the 
options: R for Windows GUI Front-end or RStudio or Search the Microsoft 
Store or choose another app.
If I choose R for Windows GUI Front-end, RGui (64-bit) opens, but no .R 
file, in the editor.
If I choose RStudio the .R file opens in the editor in RStudio as an R 
script.

 From the adaptation, if I choose R for Windows GUI Front-end, will the 
.R file open in RGui (64-bit) within the editor?


I have a new Windows PC and maybe, at least for the time being, it's 
best for me to have them associated with RStudio.

Although, yes, I agree, it should be naturally implemented in R, having 
installed RStudio.


thanks,
Amarjit




-- Original Message --
From: "Uwe Ligges" 
To: "David Winsemius" ; "Amarjit Chandhial" 
; "Jeff Newmiller" 

Cc: "Amarjit Chandhial via R-help" 
Sent: Sunday, 6 Nov, 2022 At 15:15
Subject: Re: [R] Associate a .R file with the RGui


  On 06.11.2022 01:40, David Winsemius wrote:

  On 11/5/22 09:58, Amarjit Chandhial via R-help wrote:
  Hi Jeff,


  Please see my original question.

  You were told that RGui is not an editor.

  Are you implying that your initial message contained an implicit 
request for instructions on how to get R code in an .R file to be opened 
automagically when double-clicked or to have "open in " 
appear when right-clicked? (I didn't see that clearly expressed.)

  If you want something else to happen with a file that has a .R 
extension when double-clicked or right-clicked in a GUI file manager, 
then you need to configure your OS to do whatever else it is that you 
expect. This is not really an R question. It's an OS question. There are 
many editors that can also bring up R consoles when the right  key combo 
is pressed. They do require some study for their specific actions, but 
this is not really the place to get guidance on the fine details.


  Friends, RGui contains an editor. It allows to send lines / code 
blocks to the R concole. We know users who need braille displays use the 
RGui internal editor as that apparently cooperates better with braille 
displays + R as many other editors.
  And as it does not hide half of R by its own functions, I'd pefer that 
over some very popular other editors if I had no other choice.


  To answer the OP's question, R does not have a built in way to get 
this task directly done, but searching the web suggests a rather simple 
way (well,m a hack as starting R with other command args may fail now, 
but you can extend this and look for a specific naming scheme):

   >

  let is adapt this for the recent version of R:


  1. Add the line

  if ( length(z <- commandArgs(TRUE)) ) utils::file.edit(z[1])

  to the Rprofile.site file; and

  2. Edit the registry to associate the .R extension with the command

  C:\Program Files\R\R-4.2.2\bin\x64\Rgui.exe --args "%1"


  I think we should implement this in R anyway.

  Best,
  Uwe Ligges







[[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] Selecting a minimum value of an attribute associated with point values neighboring a given point and assigning it as a new attribute

2022-11-06 Thread Eric Berger
Whoops ... left out a line in Part 2. Resending with the correction

## PART 2: You can use this code on the real data with f() defined appropriately
A <- matrix(0,N,N)
v <- 1:N
## get the indices (j,k) where j < k (as columns in a data.frame)
idx <- expand.grid(v,v) |> rename(j=Var1,k=Var2) |> filter(j < k)
u <- sapply(1:nrow(idx),
   \(i){ j <- idx$j[i]; k <- idx$k[i]; A[j,k] <<- f(j,k,myData) })
B <- A + t(A) + diag(N)
C <- diag(myData$Conc)
D <- B %*% C
D[D==0] <- NA
myData$Conc_min <- apply(D,MAR=1,\(v){min(v,na.rm=TRUE)})
print(head(myData))

On Sun, Nov 6, 2022 at 5:19 PM Eric Berger  wrote:
>
> Hi Tiffany,
> Here is some code that might help with your problem. I solve a "toy"
> problem that is conceptually the same.
> Part 1 sets up my toy problem. You would have to replace Part 1 with
> your real case. The main point is to define
> a function f(i, j, data) which returns 0 or 1 depending on whether the
> observations in rows i and j in your dataset 'data'
> are within your cutoff distance (i.e. 50m).
>
> You can then use Part 2 almost without changes (except for changing
> 'myData' to the correct name of your data).
>
> I hope this helps,
> Eric
>
> library(dplyr)
>
> ## PART 1: create fake data for minimal example
> set.seed(123) ## for reproducibility
> N <- 5   ## replace by number of locations (approx 9000 in your case)
> MAX_DISTANCE <- 2  ## 50 in your case
> myData <- data.frame(x=rnorm(N),y=rnorm(N),Conc=sample(1:N,N))
>
> ## The function which you must re-define for your actual case.
> f <- function(i,j,a) {
>  dist <- sqrt(sum((a[i,1:2] - a[j,1:2])^2)) ## Euclidean distance
>  as.integer(dist < MAX_DISTANCE)
> }
>
> ## PART 2: You can use this code on the real data with f() defined 
> appropriately
> A <- matrix(0,N,N)
> ## get the indices (j,k) where j < k (as columns in a data.frame)
> idx <- expand.grid(v,v) |> rename(j=Var1,k=Var2) |> filter(j < k)
> u <- sapply(1:nrow(idx),\(i){ j <- idx$j[i]; k <- idx$k[i]; A[j,k] <<-
> f(j,k,myData) })
> B <- A + t(A) + diag(N)
> C <- diag(myData$Conc)
> D <- B %*% C
> D[D==0] <- NA
> myData$Conc_min <- apply(D,MAR=1,\(v){min(v,na.rm=TRUE)})
> print(head(myData))
>
>
> On Sat, Nov 5, 2022 at 5:14 PM Bert Gunter  wrote:
> >
> > Probably better posted on R-sig-geo.
> >
> > -- Bert
> >
> > On Sat, Nov 5, 2022 at 12:36 AM Duhl, Tiffany R. 
> > wrote:
> >
> > > Hello,
> > >
> > > I have sets of spatial points with LAT, LON coords (unprojected, WGS84
> > > datum) and several value attributes associated with each point, from
> > > numerous csv files (with an average of 6,000-9,000 points in each file) as
> > > shown in the following example:
> > >
> > > data<- read.csv("R_find_pts_testdata.csv")
> > >
> > > > data
> > > ID  Date TimeLATLON   Conc
> > > Leg.SpeedCO2  H2O BC61 Hr Min Sec
> > > 1   76 4/19/2021 21:25:38 42.40066 -70.98802 99300   0.0 mph 428.39 9.57
> > > 578 21  25  38
> > > 2   77 4/19/2021 21:25:39 42.40066 -70.98802 96730   0.0 mph 428.04 9.57
> > > 617 21  25  39
> > > 3   79 4/19/2021 21:25:41 42.40066 -70.98802 98800   0.2 mph 427.10 9.57
> > > 1027 21  25  41
> > > 4   80 4/19/2021 21:25:42 42.40066 -70.98802 96510 2 mph 427.99 9.58
> > > 1381 21  25  42
> > > 5   81 4/19/2021 21:25:43 42.40067 -70.98801 95540 3 mph 427.99 9.58
> > > 1271 21  25  43
> > > 6   82 4/19/2021 21:25:44 42.40068 -70.98799 94720 4 mph 427.20 9.57
> > > 910 21  25  44
> > > 7   83 4/19/2021 21:25:45 42.40069 -70.98797 94040 5 mph 427.18 9.57
> > > 652 21  25  45
> > > 8   84 4/19/2021 21:25:46 42.40072 -70.98795 95710 7 mph 427.07 9.57
> > > 943 21  25  46
> > > 9   85 4/19/2021 21:25:47 42.40074 -70.98792 96200 8 mph 427.44 9.56
> > > 650 21  25  47
> > > 10  86 4/19/2021 21:25:48 42.40078 -70.98789 9375010 mph 428.76 9.57
> > > 761 21  25  48
> > > 11  87 4/19/2021 21:25:49 42.40081 -70.98785 9336011 mph 429.25 9.56
> > > 1158 21  25  49
> > > 12  88 4/19/2021 21:25:50 42.40084 -70.98781 9434012 mph 429.56 9.57
> > > 107 21  25  50
> > > 13  89 4/19/2021 21:25:51 42.40087 -70.98775 9278012 mph 428.62 9.56
> > > 720 21  25  51
> > >
> > >
> > > What I want to do is, for each point, identify all points within 50m of
> > > that point, find the minimum value of the "Conc" attribute of each nearby
> > > set of points (including the original point) and then create a new 
> > > variable
> > > ("Conc_min") and assign this minimum value to a new variable added to
> > > "data".
> > >
> > > So far, I have the following code:
> > >
> > > library(spdep)
> > > library(sf)
> > >
> > > setwd("C:\\mydirectory\\")
> > > data<- read.csv("R_find_pts_testdata.csv")
> > >
> > > #make sure the data is a data frame
> > > pts <- data.frame(data)
> > >
> > > #create spatial data frame and define projection
> > > pts_coords <- cbind(pts$LON, pts$LAT)
> > > data_pts <- SpatialPointsDataFrame(coords= pts_coords,
> > > data=pts, proj4string = CRS("+proj=longlat +datum=WGS84"))
> > >
> > 

Re: [R] Selecting a minimum value of an attribute associated with point values neighboring a given point and assigning it as a new attribute

2022-11-06 Thread Eric Berger
Hi Tiffany,
Here is some code that might help with your problem. I solve a "toy"
problem that is conceptually the same.
Part 1 sets up my toy problem. You would have to replace Part 1 with
your real case. The main point is to define
a function f(i, j, data) which returns 0 or 1 depending on whether the
observations in rows i and j in your dataset 'data'
are within your cutoff distance (i.e. 50m).

You can then use Part 2 almost without changes (except for changing
'myData' to the correct name of your data).

I hope this helps,
Eric

library(dplyr)

## PART 1: create fake data for minimal example
set.seed(123) ## for reproducibility
N <- 5   ## replace by number of locations (approx 9000 in your case)
MAX_DISTANCE <- 2  ## 50 in your case
myData <- data.frame(x=rnorm(N),y=rnorm(N),Conc=sample(1:N,N))

## The function which you must re-define for your actual case.
f <- function(i,j,a) {
 dist <- sqrt(sum((a[i,1:2] - a[j,1:2])^2)) ## Euclidean distance
 as.integer(dist < MAX_DISTANCE)
}

## PART 2: You can use this code on the real data with f() defined appropriately
A <- matrix(0,N,N)
## get the indices (j,k) where j < k (as columns in a data.frame)
idx <- expand.grid(v,v) |> rename(j=Var1,k=Var2) |> filter(j < k)
u <- sapply(1:nrow(idx),\(i){ j <- idx$j[i]; k <- idx$k[i]; A[j,k] <<-
f(j,k,myData) })
B <- A + t(A) + diag(N)
C <- diag(myData$Conc)
D <- B %*% C
D[D==0] <- NA
myData$Conc_min <- apply(D,MAR=1,\(v){min(v,na.rm=TRUE)})
print(head(myData))


On Sat, Nov 5, 2022 at 5:14 PM Bert Gunter  wrote:
>
> Probably better posted on R-sig-geo.
>
> -- Bert
>
> On Sat, Nov 5, 2022 at 12:36 AM Duhl, Tiffany R. 
> wrote:
>
> > Hello,
> >
> > I have sets of spatial points with LAT, LON coords (unprojected, WGS84
> > datum) and several value attributes associated with each point, from
> > numerous csv files (with an average of 6,000-9,000 points in each file) as
> > shown in the following example:
> >
> > data<- read.csv("R_find_pts_testdata.csv")
> >
> > > data
> > ID  Date TimeLATLON   Conc
> > Leg.SpeedCO2  H2O BC61 Hr Min Sec
> > 1   76 4/19/2021 21:25:38 42.40066 -70.98802 99300   0.0 mph 428.39 9.57
> > 578 21  25  38
> > 2   77 4/19/2021 21:25:39 42.40066 -70.98802 96730   0.0 mph 428.04 9.57
> > 617 21  25  39
> > 3   79 4/19/2021 21:25:41 42.40066 -70.98802 98800   0.2 mph 427.10 9.57
> > 1027 21  25  41
> > 4   80 4/19/2021 21:25:42 42.40066 -70.98802 96510 2 mph 427.99 9.58
> > 1381 21  25  42
> > 5   81 4/19/2021 21:25:43 42.40067 -70.98801 95540 3 mph 427.99 9.58
> > 1271 21  25  43
> > 6   82 4/19/2021 21:25:44 42.40068 -70.98799 94720 4 mph 427.20 9.57
> > 910 21  25  44
> > 7   83 4/19/2021 21:25:45 42.40069 -70.98797 94040 5 mph 427.18 9.57
> > 652 21  25  45
> > 8   84 4/19/2021 21:25:46 42.40072 -70.98795 95710 7 mph 427.07 9.57
> > 943 21  25  46
> > 9   85 4/19/2021 21:25:47 42.40074 -70.98792 96200 8 mph 427.44 9.56
> > 650 21  25  47
> > 10  86 4/19/2021 21:25:48 42.40078 -70.98789 9375010 mph 428.76 9.57
> > 761 21  25  48
> > 11  87 4/19/2021 21:25:49 42.40081 -70.98785 9336011 mph 429.25 9.56
> > 1158 21  25  49
> > 12  88 4/19/2021 21:25:50 42.40084 -70.98781 9434012 mph 429.56 9.57
> > 107 21  25  50
> > 13  89 4/19/2021 21:25:51 42.40087 -70.98775 9278012 mph 428.62 9.56
> > 720 21  25  51
> >
> >
> > What I want to do is, for each point, identify all points within 50m of
> > that point, find the minimum value of the "Conc" attribute of each nearby
> > set of points (including the original point) and then create a new variable
> > ("Conc_min") and assign this minimum value to a new variable added to
> > "data".
> >
> > So far, I have the following code:
> >
> > library(spdep)
> > library(sf)
> >
> > setwd("C:\\mydirectory\\")
> > data<- read.csv("R_find_pts_testdata.csv")
> >
> > #make sure the data is a data frame
> > pts <- data.frame(data)
> >
> > #create spatial data frame and define projection
> > pts_coords <- cbind(pts$LON, pts$LAT)
> > data_pts <- SpatialPointsDataFrame(coords= pts_coords,
> > data=pts, proj4string = CRS("+proj=longlat +datum=WGS84"))
> >
> > #Re-project to WGS 84 / UTM zone 18N, so the analysis is in units of m
> > ptsUTM  <- sf::st_as_sf(data_pts, coords = c("LAT", "LON"), remove = F)%>%
> > st_transform(32618)
> >
> > #create 50 m buffer around each point then intersect with points and
> > finally find neighbors within the buffers
> > pts_buf <- sf::st_buffer(ptsUTM, 50)
> > coords  <- sf::st_coordinates(ptsUTM)
> > int <- sf::st_intersects(pts_buf, ptsUTM)
> > x   <- spdep::dnearneigh(coords, 0, 50)
> >
> > Now at this point, I'm not sure what to either the "int" (a sgbp list) or
> > "x" (nb object) objects (or even if I need them both)
> >
> > > int
> > Sparse geometry binary predicate list of length 974, where the predicate
> > was `intersects'
> > first 10 elements:
> >  1: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
> >  2: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
> >  3: 1, 2, 

Re: [R] Associate a .R file with the RGui

2022-11-06 Thread Uwe Ligges




On 06.11.2022 01:40, David Winsemius wrote:


On 11/5/22 09:58, Amarjit Chandhial via R-help wrote:

Hi Jeff,


Please see my original question.


You were told that RGui is not an editor.

Are you implying that your initial message contained an implicit request 
for instructions on how to get R code in an .R file to be opened 
automagically when double-clicked or to have "open in " 
appear when right-clicked? (I didn't see that clearly expressed.)


If you want something else to happen with a file that has a .R extension 
when double-clicked or right-clicked in a GUI file manager, then you 
need to configure your OS to do whatever else it is that you expect. 
This is not really an R question. It's an OS question. There are many 
editors that can also bring up R consoles when the right  key combo is 
pressed. They do require some study for their specific actions, but this 
is not really the place to get guidance on the fine details.




Friends, RGui contains an editor. It allows to send lines / code blocks 
to the R concole. We know users who need braille displays use the RGui 
internal editor as that apparently cooperates better with braille 
displays + R as many other editors.
And as it does not hide half of R by its own functions, I'd pefer that 
over some very popular other editors if I had no other choice.



To answer the OP's question, R does not have a built in way to get this 
task directly done, but searching the web suggests a rather simple way 
(well,m a hack as starting R with other command args may fail now, but 
you can extend this and look for a specific naming scheme):




let is adapt this for the recent version of R:


1. Add the line

if ( length(z <- commandArgs(TRUE)) ) utils::file.edit(z[1])

to the Rprofile.site file; and

2. Edit the registry to associate the .R extension with the command

C:\Program Files\R\R-4.2.2\bin\x64\Rgui.exe --args "%1"


I think we should implement this in R anyway.

Best,
Uwe Ligges

__
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] Associate a .R file with the RGui

2022-11-06 Thread Amarjit Chandhial via R-help
David,

Thanks.

Amarjiit 


> On 6 Nov 2022, at 00:40, David Winsemius  wrote:
> 
> 
>> On 11/5/22 09:58, Amarjit Chandhial via R-help wrote:
>> Hi Jeff,
>> 
>> 
>> Please see my original question.
> 
> You were told that RGui is not an editor.
> 
> Are you implying that your initial message contained an implicit request for 
> instructions on how to get R code in an .R file to be opened automagically 
> when double-clicked or to have "open in " appear when 
> right-clicked? (I didn't see that clearly expressed.)
> 
> If you want something else to happen with a file that has a .R extension when 
> double-clicked or right-clicked in a GUI file manager, then you need to 
> configure your OS to do whatever else it is that you expect. This is not 
> really an R question. It's an OS question. There are many editors that can 
> also bring up R consoles when the right  key combo is pressed. They do 
> require some study for their specific actions, but this is not really the 
> place to get guidance on the fine details.
> 
> -- 
> 
> David.
> 
>> 
>> 
>> Thanks,
>> Amarjiit
>> 
>> 
>> 
>>> On 5 Nov 2022, at 15:03, Jeff Newmiller  wrote:
>>> 
>>> RGui is not an editor. It is a console (aka REPL, 
>>> https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop).
>>> 
>>> When using RGui, it is up to you to edit your R file in an external editor 
>>> like Notepad++ and copy paste code snippets or use source("yourfile.R") as 
>>> desired.
>>> 
 On November 5, 2022 6:47:54 AM PDT, Amarjit Chandhial via R-help 
  wrote:
 
 
 
 Hi Andrew/Petr,
 
 
 Thanks for the replies.
 
 In R Console if I run:
 
 R.home("bin")
 
 I get the following
 
 "C:/PROGRA~1/R/R-42~1.2/bin/x64"
 
 which is where
 
 Rgui.exe is (within the x64 folder there are 13 files in total: 8 . exe
 and 5 .dll).
 
 
 In file Explorer if I right-click on a .R file -> Open With -> R for
 Windows GUI Front-End
 
 RGui (64-bit) opens but the .R file does not appear in the editor.
 
 
 Amarjit
 
 
 -- Original Message --
 From: "Andrew Simmons" 
 To: "Amarjit Chandhial" 
 Cc: "R-help Mailing List" 
 Sent: Friday, 4 Nov, 2022 At 09:08
 Subject: Re: [R] Associate a .R file with the RGui
 
 In an R session, run this:
 
 writeLines(normalizePath(R.home("bin")))
 
 
 Right click your .R file > Open with > Choose another app > Check the
 box "Always use this app to open .R files" > Look for another app on
 this PC
 Paste the directory found above, then select "Rgui.exe"
 
 
 On Fri, Nov 4, 2022, 04:49 Amarjit Chandhial via R-help
 mailto:r-help@r-project.org> > wrote:
 
 Hi,
 
 
 My OS is Windows 11 Pro 64-Bit, I have R 4.2.2 and RStudio installed.
 
 If I double-click on a .R file in File Explorer the OS gives me the
 option of opening the .R in RStudio, or Look for an app in the
 Microsoft
 Store, or More Apps. Similarly with a right-click.
 
 I would like to associate a .R file with the RGui, not RStudio, thus
 when I double-click on a .R file in File Explorer the .R file opens in
 the R Editor in RGui.
 
 On my PC R 4.2.2 is located in "C:/Program Files/R/R-4.2.2/etc"
 
 Please can someone provide step-by-step instructions on how to
 associate?
 
 
 thanks,
 Amarjit
 
 [[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.
>>> -- 
>>> 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.

__
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