[R-es] inscribir

2024-06-13 Thread David López



[[alternative HTML version deleted]]

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


Re: [R] Can someone please have a look at my query on stackoverflow ?

2024-05-27 Thread David Winsemius
If I had seen that post before it got a bounty, I would have voted to migrate 
it to https://stats.stackexchange.com since it is a request for advice on 
methods as well as an implicit request for a package recommendation. 

— 
David
Sent from my iPhone

> On May 27, 2024, at 5:40 AM, Ashim Kapoor  wrote:
> 
> Dear experts,
> 
> I am having difficulty with computing spectrum of seasonal ARMA models.
> 
> My query is posted here :
> 
> https://stackoverflow.com/questions/78526800/computing-the-spectrum-of-a-seasonal-model-in-r
> 
> Will be grateful if someone has a look at it and responds.
> 
> Many thanks,
> Ashim.
> 
>[[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] Question regarding reservoir volume and water level

2024-04-09 Thread David Stevens via R-help
Water engineer here. The standard approach is to 1) get the storage vs. 
elevation data from the designers of the reservoir or, barring that, 2) 
get the bathymetry data from USBR or state DWR, or, if available, get 
the DEM data from USGS if the survey was done before the reservoir was 
built or 3) get a boat+sonar with GPS  +lots of time and survey the 
bottom elevation yourself. Put the xyz data into ArcGIS and have it 
create the bottom surface, then, with several elevations, integrate the 
xyz data from Z to the bottom to find the storage. Plot the storage at 
each water surface to get an idea of the shape and then use 
lm(Elevation~f(Storage) where f(Storage) may be a cubic or quartic 
polynomial. Then double the Storage and calculate Elevation. This type 
of thing is done everyday by hydrologists.

Good luck

David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu
(435) 797-3229 (office)

On 4/9/2024 8:01 AM, peter dalgaard wrote:
> So, you know how to get volume for given water level.
>
> For the reverse problem, you get in trouble because of the nonlinearity 
> inherent in the dependence of surface area on the level.
>
> I don't think there is a simple solution to this, save for mapping out the 
> volume as a function of water level and solving equations for the water level 
> using (say) uniroot(). Which may actually suffice for practical purposes.
>
> For small changes, finding the derivative of the relation is easy: d(volume) 
> = Area * d(level) and this can be used as an approximate relation as long as 
> the Area remains nearly constant.
>
> However generic questions like doubling the volume are impossible to answer 
> without knowledge of the reservoir shape. E.g. in a cylindrical reservoir 
> halving the water level also halves the volume, but in a conical reservoir, 
> halving the level leaves only 1/8 of the volume.
>
> -pd
>
>
>
>> On 8 Apr 2024, at 05:55 , javad bayat  wrote:
>>
>> Dear all;
>> Many thanks for your replies. This was not homework. I apologize.
>> Let me explain more.
>> There is a dam constructed in a valley with the highest elevation of 1255
>> m. The area of its reservoir can be calculated by drawing a polygon around
>> the water and it is known.
>> I have the Digital Elevation Model (DEM) of the region (reservoir and its
>> surrounding area). I have calculated the volume of the current reservoir
>> (7e6 m3) using the following codes.
>> library(raster)
>> library(terra)
>> library(exactextractr)
>> library(dplyr)
>> library(sf)
>> # Calculate volume for polygon
>> # Read the DEM raster file
>> r <- rast("E:/...DEM.tif")
>> # Read the polygon shapefile
>> p <- st_read("E:/...Dam.shp")
>>
>> r <- crop(r, extent(p))
>> r <- mask(r, p)
>>
>> # Extract the cells in each polygon and calculate the area of each cell
>> x <- exact_extract(r, p, coverage_area = TRUE)
>> # Extract polygon values as a dataframe
>> x1 = as.data.frame(x[1])
>> head(x1)
>> x1 = na.omit(x1)
>> # Calculate the height above the minimum elevation in the polygon
>> x1$Height = max(x1[,1]) - x1[,1]
>> # Calculate the volume of each cell
>> x1$Vol = x1[,2] * x1[,3]
>> sum(x1$Vol)
>> x2 = x1[,c(1,2,4)]
>> x2 = sort(x2,'value')
>> head(x2)
>> x3 <- aggregate(Vol ~ value, data = x2, FUN = sum)
>> x4 <- aggregate(coverage_area ~ value, data = x2, FUN = sum)
>> x5 = cbind(x3, Area = x4[,2])
>> library(dplyr)
>> x6 <- x5 %>%
>>   mutate(V_sum = cumsum(Vol)) %>%
>>   mutate(A_sum = cumsum(Area))
>> plot(x6$value~x6$V_sum)
>>
>> And I thought that it is possible to get the elevation for a specific
>> volume by linear model between elevation and volume, as follow:
>>
>> # Get a linear model between elevation and the volume
>> lm1 <- lm(value ~ V_sum, data = x6)
>> d <- data.frame(V_sum = 14e6)  #
>> predict(lm1, newdata = d)
>>
>> But it is not possible through the LM.
>> Now I want to know what would be the water level in the reservoir if the
>> reservoir volume doubled or we adding a known volume to it?
>> Also what would be the volume if the water level increases to 1250 m?
>>
>> I would be more than happy if you help me to do this.
>> Sincerely
>>
>> On Mon, Apr 8, 2024 at 12:23 AM  wrote:
>>
>>> John,
>>>
>>> Your reaction was what my original reaction was until I realized I had to
>>> find out what a DEM file was and that contain

[R] Default t test in R is Welch's test, not Student's, and can be very problematic

2024-03-04 Thread Curtis, David
Hi all.

I'm just writing to draw your attention to this paper, which is Open Access:

Curtis, D. Welch�s t test is more sensitive to real world violations of 
distributional assumptions than student�s t test but logistic regression is 
more robust than either. Stat Papers (2024). 
https://doi.org/10.1007/s00362-024-01531-7
https://link.springer.com/article/10.1007/s00362-024-01531-7?utm_source=rct_congratemailt_medium=email_campaign=oa_20240304_content=10.1007/s00362-024-01531-7

I hadn't really noticed that the default implementation of the t test in R uses 
Welch's method rather than Student's. I know some people prefer Welch's method 
but the paper describes how it can be systematically biased and produce 
extremely low p values in real world scenarios.

If you agree with me, you might want to consider generally using Student's test 
instead, by using t.test(x, y, var.equal = TRUE).

Code to demonstrate the problem and play around with different scenarios, as 
described in the paper, is at: 
https://github.com/davenomiddlenamecurtis/TestTTest

Regards


  *   Dave Curtis

--
Professor David Curtis MD PhD
UCL Genetics Institute
University College London



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

2024-02-24 Thread David Winsemius



On 2/24/24 12:10, Kimmo Elo wrote:

Hi,

first of all, your example was not reproducible! But once I added
"library(igraph)" and "library(scico)" plus generally replaced
"aes_collapsed" by "edge_list", I started to work :-)



After copying your lead in that replacement the error I got was:


network <- graph_from_data_frame(edge_list, directed= FALSE, + vertices 
= details) #Error: object 'details' not found Same conclusion, though. 
Incomplete presentation of code. -- David.




Anyway, the error is produced by this line:

+ edge.width= network,

It seems to me that you have forgotten to name a variable here (you now
use the whole network object as variable, which most probably won't
work).

Just as a kind advice for the future: if you encounter errors like
this, it is always a good idea to debug the problematic code by
commenting it out line by line. So you will - most probably - find our
those sections resulting in errors.

HTH,

Kimmo

la, 2024-02-24 kello 12:09 +0100, SIBYLLE STÖCKLI via R-help kirjoitti:

Dear R-community

  


It would be nice to get some input how to find a solution for the
following
error in igraph and vertex setting.

  


Thank you very much

Sibylle

  


par(bg="black")
network %>% plot(

+ vertex.color=clrs[V(.)$community],

+ vertex.size=V(.)$hub_score*1,

+ vertex.frame.color=V(.)$color,

+ vertex.label.color="white",

+ vertex.label.cex=0.5,

+ vertex.label.family="Helvetica",

+ vertex.label.font=1,

+ edge.curved=0.5,

+ edge.width= network,

+ layout=layout_with_mds(.))

Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) :

   Index gr��er als maximales 6

  

  


Reproducible example:

  


edge_list<-read.csv("edges_table_Test.csv")

  


#create network and add some necessary attributes (vertices) for the
plot

network <- graph_from_data_frame(aes_collapsed, directed= FALSE,

  vertices = details)

  

  


temp<-cluster_optimal(network)

temp<-cbind(membership=temp$membership, Names=temp$name)

aes_collapsed <- aes_collapsed %>%

   merge(temp, by="Names")

  

  


network <- network %>%

   set_edge_attr(name = "type", value = factor(aes_collapsed$Names,

  ordered =
is.ordered(V(network)$name))) %>%

   set_edge_attr(name = "membership", value =
aes_collapsed$membership) %>%

   set_edge_attr(name = "color",

   value = c(viridis::viridis(5))

   [match(E(.)$type, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name = "trans_v_net", value = c(transitivity(.,
type =
"local"))) %>%

   set_vertex_attr(name = "hub_score", value = c(hub_score(.)$vector))
%>%

   set_vertex_attr(name = "color",

   value = c(viridis::viridis((5)))

   [match(V(.)$name, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name= "community",
value=cluster_optimal(.)$membership)

  


clrs<-scico(3, palette = "batlow")

  


par(bg="black")

network %>% plot(

  vertex.color=clrs[V(.)$community],

  vertex.size=V(.)$hub_score*5,

  vertex.frame.color=V(.)$color,

  vertex.label.color="white",

  vertex.label.cex=0.5,

  vertex.label.family="Helvetica",

  vertex.label.font=1,

  edge.curved=0.5,

  edge.width= network,

  layout=layout_with_mds(.))

  

  


edges_table_Test.csv

  



Names

target

weight


B.B

A.A

4


C.C

A.A

5


D.D

A.A

5


E.E

A.A

5


F.F

A.A

1


C.C

B.B

5


E.E

B.B

1


F.F

B.B

2


A.A

C.C

5


B.B

C.C

1


D.D

C.C

5


E.E

C.C

5


F.F

C.C

3


A.A

D.D

5


B.B

D.D

1


C.C

D.D

5


E.E

D.D

5


F.F

D.D

4


A.A

E.E

5


B.B

E.E

1


C.C

E.E

4


D.D

E.E

5


F.F

E.E

5


A.A

F.F

5


B.B

F.F

1


C.C

F.F

2


D.D

F.F

3


E.E

F.F

4


F.F

F.F

5

  



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

2024-02-24 Thread David Winsemius
The reason html is specifically advised against as a format is that it 
does things like mangling data such as is happening in your example. You 
should repost using settings on you mail client for plain-text. Your 
code should start by loading necessary packages. You should also not 
post screen output versions of code since that will insert lots of 
superfluous "+"'s. Some but not all API will be able to strip those 
characters.



--

David.

On 2/24/24 03:09, SIBYLLE STÖCKLI via R-help wrote:

Dear R-community

  


It would be nice to get some input how to find a solution for the following
error in igraph and vertex setting.

  


Thank you very much

Sibylle


par(bg="black")
network %>% plot(

+ vertex.color=clrs[V(.)$community],

+ vertex.size=V(.)$hub_score*1,

+ vertex.frame.color=V(.)$color,

+ vertex.label.color="white",

+ vertex.label.cex=0.5,

+ vertex.label.family="Helvetica",

+ vertex.label.font=1,

+ edge.curved=0.5,

+ edge.width= network,

+ layout=layout_with_mds(.))

Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) :

   Index gr��er als maximales 6

  

  


Reproducible example:

  


edge_list<-read.csv("edges_table_Test.csv")

  


#create network and add some necessary attributes (vertices) for the plot

network <- graph_from_data_frame(aes_collapsed, directed= FALSE,

  vertices = details)

  

  


temp<-cluster_optimal(network)

temp<-cbind(membership=temp$membership, Names=temp$name)

aes_collapsed <- aes_collapsed %>%

   merge(temp, by="Names")

  

  


network <- network %>%

   set_edge_attr(name = "type", value = factor(aes_collapsed$Names,

  ordered =
is.ordered(V(network)$name))) %>%

   set_edge_attr(name = "membership", value = aes_collapsed$membership) %>%

   set_edge_attr(name = "color",

   value = c(viridis::viridis(5))

   [match(E(.)$type, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name = "trans_v_net", value = c(transitivity(., type =
"local"))) %>%

   set_vertex_attr(name = "hub_score", value = c(hub_score(.)$vector)) %>%

   set_vertex_attr(name = "color",

   value = c(viridis::viridis((5)))

   [match(V(.)$name, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name= "community", value=cluster_optimal(.)$membership)

  


clrs<-scico(3, palette = "batlow")

  


par(bg="black")

network %>% plot(

  vertex.color=clrs[V(.)$community],

  vertex.size=V(.)$hub_score*5,

  vertex.frame.color=V(.)$color,

  vertex.label.color="white",

  vertex.label.cex=0.5,

  vertex.label.family="Helvetica",

  vertex.label.font=1,

  edge.curved=0.5,

  edge.width= network,

  layout=layout_with_mds(.))

  

  


edges_table_Test.csv

  



Names

target

weight


B.B

A.A

4


C.C

A.A

5


D.D

A.A

5


E.E

A.A

5


F.F

A.A

1


C.C

B.B

5


E.E

B.B

1


F.F

B.B

2


A.A

C.C

5


B.B

C.C

1


D.D

C.C

5


E.E

C.C

5


F.F

C.C

3


A.A

D.D

5


B.B

D.D

1


C.C

D.D

5


E.E

D.D

5


F.F

D.D

4


A.A

E.E

5


B.B

E.E

1


C.C

E.E

4


D.D

E.E

5


F.F

E.E

5


A.A

F.F

5


B.B

F.F

1


C.C

F.F

2


D.D

F.F

3


E.E

F.F

4


F.F

F.F

5

  



[[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] Rtools and things dependent on it

2024-02-23 Thread David Winsemius


Sent from my iPhone

> On Feb 23, 2024, at 18:19, Sorkin, John  wrote:
> 
> David,
> 
> I greatly appreciate the explanation you gave regarding R tools providing 
> tools available in Linux distros, but not found in Windows. (I am using a 
> windows system). Does this mean that Linux users don't need to use R tools 
> when they want to compile R code. 

Yes. That’s been true for me anyway. On a Mac I need to make sure I have the 
proper C and Fortran compilers and the proper environment variables , which are 
always provided by Saint  Simon Urbanek at the att.research site. 

— 
David. 
> 
> Additionally, thank you for the information about what I should read. I will 
> look at the material again, and hopefully things the material you suggest I 
> read will be more understandable.
> 
> John
> 
> P.S. This email should be in txt format, not html. I sent if from my desktop 
> windows machine which provides more options than does my iPhone.
> 
> 
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine, University of Maryland School of Medicine;
> Associate Director for Biostatistics and Informatics, Baltimore VA Medical 
> Center Geriatrics Research, Education, and Clinical Center;
> PI Biostatistics and Informatics Core, University of Maryland School of 
> Medicine Claude D. Pepper Older Americans Independence Center;
> Senior Statistician University of Maryland Center for Vascular Research;
> 
> Division of Gerontology and Paliative Care,
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> Cell phone 443-418-5382
> 
> 
> 
> 
> 
> From: David Winsemius 
> Sent: Friday, February 23, 2024 8:14 PM
> To: Sorkin, John
> Cc: avi.e.gr...@gmail.com; r-help@r-project.org
> Subject: Re: [R] Rtools and things dependent on it
> 
> 
> On 2/23/24 16:28, Sorkin, John wrote:
> David,
> My apologies regarding the format of my email. I am replying using my iPhone, 
> and I can’t find a way to switch from what I suspect is html to txt format.
> The link you sent told me that R tools allows compilation of code.
> 
> 
> It's specifically designed to provide the code tools missing in Windows that 
> would other wise have been provided by a typical Linux distro. More 
> expansively, it allows compilation of code written in C and/or Fortran using 
> the version that was used to build the matching R version and allows it to be 
> called by the routines written in R that bind a package together.
> 
> This is good to know, but beyond this important fact, the rest of the 
> material was close to unintelligible.
> 
> The phrase "the rest of the material" is not specific enough to offer more 
> explanation. You should quote material that is beyond your understanding. You 
> should only be reading the sections named: "Installing Rtools43" and 
> "Building packages from source using Rtools43". I doubt that material further 
> on would be relevant.
> 
> --
> 
> David
> 
> I doubt this is the fault of the author, it is probably because I lack some 
> basic knowledge. Can you suggest some more basic material I can read. Please 
> note. I am not computer naive, I am simply missing basic knowledge of the 
> material discussed in the web page.
> Thank you,
> John
> 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)
> 
> On Feb 23, 2024, at 7:01 PM, David Winsemius 
> <mailto:dwinsem...@comcast.net> wrote:
> 
> 
> On 2/23/24 14:34, avi.e.gr...@gmail.com<mailto:avi.e.gr...@gmail.com> wrote:
> This may be a dumb question and the answer may make me feel dumber.
> 
> I have had trouble for years with R packages wanting Rtools on my machine
> and not being able to use it. Many packages are fine as binaries are
> available. I have loaded Rtools and probably need to change my PATH or
> something.
> 
> 
> I suppose making sure that whatever directory holds your Rtools code is
> on your path would be a good idea. I wondered if there's an environment
> variable that could be set, but reading the page on using Rtools did not
> mention one until I got down to the section on building R from source
> which is surely NOT what you want to do.. You should read the
> information on installation and building packages from source.
> https://cran.r-project.org/bin/windows/base/howto-R-devel.html<https://c

Re: [R] Rtools and things dependent on it

2024-02-23 Thread David Winsemius


On 2/23/24 16:28, Sorkin, John wrote:
> David,
> My apologies regarding the format of my email. I am replying using my 
> iPhone, and I can’t find a way to switch from what I suspect is html 
> to txt format.
> The link you sent told me that R tools allows compilation of code.


It's specifically designed to provide the code tools missing in Windows 
that would other wise have been provided by a typical Linux distro. More 
expansively, it allows compilation of code written in C and/or Fortran 
using the version that was used to build the matching R version and 
allows it to be called by the routines written in R that bind a package 
together.

> This is good to know, but beyond this important fact, the rest of the 
> material was close to unintelligible.

The phrase "the rest of the material" is not specific enough to offer 
more explanation. You should quote material that is beyond your 
understanding. You should only be reading the sections named:"Installing 
Rtools43" and "Building packages from source using Rtools43". I doubt 
that material further on would be relevant.

-- 

David

> I doubt this is the fault of the author, it is probably because I lack 
> some basic knowledge. Can you suggest some more basic material I can 
> read. Please note. I am not computer naive, I am simply missing basic 
> knowledge of the material discussed in the web page.
> Thank you,
> John
>> 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-711 9
>> (Fax)410-605-7913  (Please call phone number above 
>> prior to faxing)
>
>> On Feb 23, 2024, at 7:01 PM, David Winsemius  
>> wrote:
>>
>> 
>> On 2/23/24 14:34, avi.e.gr...@gmail.com wrote:
>>> This may be a dumb question and the answer may make me feel dumber.
>>>
>>> I have had trouble for years with R packages wanting Rtools on my 
>>> machine
>>> and not being able to use it. Many packages are fine as binaries are
>>> available. I have loaded Rtools and probably need to change my PATH or
>>> something.
>>
>>
>> I suppose making sure that whatever directory holds your Rtools code is
>> on your path would be a good idea. I wondered if there's an environment
>> variable that could be set, but reading the page on using Rtools did not
>> mention one until I got down to the section on building R from source
>> which is surely NOT what you want to do.. You should read the
>> information on installation and building packages from source.
>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran.r-project.org%2Fbin%2Fwindows%2Fbase%2Fhowto-R-devel.html=05%7C02%7CJSorkin%40som.umaryland.edu%7C7000449b5bd74e1d6cbb08dc34cbcba8%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638443297110517980%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=%2B1tC1ROo11Bj1dPg7Ho9lDcVfL31Y3mCYUYqwDcyKs4%3D=0
>>  
>> which
>> includes this sentence:
>>
>> "It is recommended to use the defaults and install into|c:/rtools43|.
>> When done that way, Rtools43 may be used in the same R session which
>> installed it or which was started before Rtools43 was installed."
>>
>>>
>>> But I recently suggested to someone that they might want to use the 
>>> tabyl()
>>> function in the janitor package that I find helpful. I get a warning 
>>> when I
>>> install it about Rtools but it works fine. When they install it, it 
>>> fails. I
>>> assumed they would get it from CRAN the same way I did as we are 
>>> both using
>>> Windows and from within RSTUDIO.
>>>
>>> In the past, I have run into other packages I could not use and just 
>>> moved
>>> on but it seems like time to see if this global problem has a 
>>> work-around.
>>>
>>> And, in particular, I have the latest versions of both R and RSTUDIO 
>>> which
>>> can be a problem when other things are not as up-to-date.
>>>
>>> Or, maybe some people with R packages could be convinced to make 
>>> binaries
>>> available in the first place?
>>
>> Binaries are automatically produced by CRAN but perhaps you are trying
>> to install from some other source? It would help if you could be
>> specific about several missing pieces of information: Operating syst

Re: [R] Rtools and things dependent on it

2024-02-23 Thread David Winsemius



On 2/23/24 15:39, Sorkin, John wrote:

Avi ,
Your question is not dumb. Let me ask a more fundamental question. What is R 
tools, what does it do, and how is it used. From time to time, I receive a 
message when I down load a package saying I need R tools. When I receive the 
message, I don’t know what I should do, other than down load R tools.


https://cran.r-project.org/bin/windows/base/howto-R-devel.html


And do configure your client to send only plain-text.


--

David.


John
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)

On Feb 23, 2024, at 5:34 PM, avi.e.gr...@gmail.com wrote:

This may be a dumb question and the answer may make me feel dumber.


__
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] Rtools and things dependent on it

2024-02-23 Thread David Winsemius


On 2/23/24 14:34, avi.e.gr...@gmail.com wrote:
> This may be a dumb question and the answer may make me feel dumber.
>   
> I have had trouble for years with R packages wanting Rtools on my machine
> and not being able to use it. Many packages are fine as binaries are
> available. I have loaded Rtools and probably need to change my PATH or
> something.


I suppose making sure that whatever directory holds your Rtools code is 
on your path would be a good idea. I wondered if there's an environment 
variable that could be set, but reading the page on using Rtools did not 
mention one until I got down to the section on building R from source 
which is surely NOT what you want to do.. You should read the 
information on installation and building packages from source. 
https://cran.r-project.org/bin/windows/base/howto-R-devel.html which 
includes this sentence:

"It is recommended to use the defaults and install into|c:/rtools43|. 
When done that way, Rtools43 may be used in the same R session which 
installed it or which was started before Rtools43 was installed."

>   
> But I recently suggested to someone that they might want to use the tabyl()
> function in the janitor package that I find helpful. I get a warning when I
> install it about Rtools but it works fine. When they install it, it fails. I
> assumed they would get it from CRAN the same way I did as we are both using
> Windows and from within RSTUDIO.
>   
> In the past, I have run into other packages I could not use and just moved
> on but it seems like time to see if this global problem has a work-around.
>   
> And, in particular, I have the latest versions of both R and RSTUDIO which
> can be a problem when other things are not as up-to-date.
>   
> Or, maybe some people with R packages could be convinced to make binaries
> available in the first place?

Binaries are automatically produced by CRAN but perhaps you are trying 
to install from some other source? It would help if you could be 
specific about several missing pieces of information: Operating system, 
R version, Rtools version, current location of Rtools, names of packages 
and where they were obtained.


Regards and good luck;

David (a.k.a IRTFM)

> Avi
>
>   [[alternative HTML version deleted]]
Rhelp is a plain text mailing list. You should configure your email 
client to send only plain-text and NOT html.
[[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] Convert character date time to R date-time variable.

2023-12-08 Thread David Winsemius



On 12/7/23 08:21, Sorkin, John wrote:

Colleagues,

I have a matrix of character data that represents date and time. The format of 
each element of the matrix is
"2020-09-17_00:00:00"
How can I convert the elements into a valid R date-time constant?


You will not be able to store these datetime values in an R matrix, at 
least as class POSIXct. You could with class POSIXlt, but I've not seen 
it used before but it does appear possible since matrices can contain 
lists.


R matrices do no provide the capability to assign attributes, so only 
atomic types and lists can be elements. If you wanted to maintain the 
same structure, your first step might be to coerce to a data.frame and 
then proceed, or to first construct a vector and then use as the first 
argument to `matrix`.



Best;

David



Thank you,
John



John David Sorkin M.D., Ph.D.
Professor of Medicine, University of Maryland School of Medicine;

Associate Director for Biostatistics and Informatics, Baltimore VA Medical 
Center Geriatrics Research, Education, and Clinical Center;

PI Biostatistics and Informatics Core, University of Maryland School of 
Medicine Claude D. Pepper Older Americans Independence Center;

Senior Statistician University of Maryland Center for Vascular Research;

Division of Gerontology and Paliative Care,
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
Cell phone 443-418-5382



__
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 can I remove my packages from rdrr.io?

2023-11-01 Thread David Winsemius



> On Nov 1, 2023, at 6:06 AM, Kim Emilia  wrote:
> 
> Hello all,
> 
> I would like to take down my packages posted/created on the website rdrr.io.
> [https://rdrr.io/] Is there any way to take down packages from the website?
> It would be appreciated if you suggested/offered a way to remove the
> package from the website.
> 

The website you are concerned about is not maintained by the R-project. A but 
of link-following suggested to me that the person you need to be addressing 
this to has a "personal" webpage at:  https://ianhowson.com/

There will be many other sites that hold most or all of the extensive list of 
CRAN packages, although it is certainly true that rrio.io has become a favorite 
of Google. 

-- 
David
> Thank you.
> 
>   [[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] running crossvalidation many times MSE for Lasso regression

2023-11-01 Thread David Winsemius



> On Oct 22, 2023, at 4:01 PM, Bert Gunter  wrote:
> 
> No error message shown Please include the error message so that it is
> not necessary to rerun your code. This might enable someone to see the
> problem without running the code (e.g. downloading packages, etc.)
> 
> -- Bert
> 
> On Sun, Oct 22, 2023 at 1:36 PM varin sacha via R-help
>  wrote:
>> 
>> Dear R-experts,
>> 
>> Here below my R code with an error message. Can somebody help me to fix this 
>> error?
>> Really appreciate your help.
>> 
>> Best,
>> 
>> 
>> # MSE CROSSVALIDATION Lasso regression
>> 
>> library(glmnet)
>> 
>> 
>> x1=c(34,35,12,13,15,37,65,45,47,67,87,45,46,39,87,98,67,51,10,30,65,34,57,68,98,86,45,65,34,78,98,123,202,231,154,21,34,26,56,78,99,83,46,58,91)
>> x2=c(1,3,2,4,5,6,7,3,8,9,10,11,12,1,3,4,2,3,4,5,4,6,8,7,9,4,3,6,7,9,8,4,7,6,1,3,2,5,6,8,7,1,1,2,9)
>> y=c(2,6,5,4,6,7,8,10,11,2,3,1,3,5,4,6,5,3.4,5.6,-2.4,-5.4,5,3,6,5,-3,-5,3,2,-1,-8,5,8,6,9,4,5,-3,-7,-9,-9,8,7,1,2)
>> T=data.frame(y,x1,x2)
>> 
>> z=matrix(c(x1,x2), ncol=2)
>> cv_model=glmnet(z,y,alpha=1)
>> best_lambda=cv_model$lambda.min
>> best_lambda
>> 
>> 
>> # Create a list to store the results
>> lst<-list()
>> 
>> # This statement does the repetitions (looping)
>> for(i in 1 :1000) {
>> 
>> n=45
>> 
>> p=0.667
>> 
>> sam=sample(1 :n,floor(p*n),replace=FALSE)
>> 
>> Training =T [sam,]
>> Testing = T [-sam,]
>> 
>> test1=matrix(c(Testing$x1,Testing$x2),ncol=2)
>> 
>> predictLasso=predict(cv_model, newx=test1)
>> 
>> 
>> ypred=predict(predictLasso,newdata=test1)

The error I got was:

Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "c('matrix', 
'array', 'double', 'numeric')"


I'm not sure why the name of the object was cv_model since it was not created 
as a cross-validation result.

The loops called predict() twice and it was the second call that produced the 
error since the predictLasso object was not a glmnet classed object.

If the OP had left out the second use of predict and then subtracted 
predictLasso from the y vector a result would have appeared

y=T[-sam,]$y
MSE = mean((y-predictLasso)^2)
...
> mean(unlist(lst))
[1] 23.39621

Whether this is meaningful is hard to tell. It also makes the fundamental error 
of overwriting the original data object `y` with another intermediate result.

-- 
David
>> y=T[-sam,]$y
>> 
>> MSE = mean((y-ypred)^2)
>> MSE
>> lst[i]<-MSE
>> }
>> mean(unlist(lst))
>> ##
>> 
>> 
>> 
>> 
>> __
>> 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.


[R] Virus alert because of an R-help e-mail

2023-10-31 Thread David Croll

I just received a virus warning from my e-mail provider, GMX. See the
attached image below.

The virus detection can be spurious - but the e-mail was automatically
deleted by GMX.

With the best regards,


David
__
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] How to fix this problem

2023-09-25 Thread Parkhurst, David
I have a matrix, KD6, and I�m trying to get a correlation matrix from it.  When 
I enter cor(KD6), I get the message �Error in cor(KD6) : 'x' must be numeric�.
Here are some early lines from KD6:
Flow  E..coliTNSRP TPTSS
1  38.82,4201.65300 0.0270 0.0630  66.80
2 133.02,4201.39400 0.0670 0.1360   6.80
3  86.2   101.73400 0.0700 0.1720  97.30
4   4.85,3900.40400 0.0060 0.0280   8.50
5   0.32,4900.45800 0.0050 0.0430  19.75
6   0.0  1860.51200 0.0040 0.0470  12.00
7  11.19,8351.25500 0.0660 0.1450  12.20

Why are these not numeric?
There are some NAs later in the matrix, but I get this same error if I ask for 
cor(KD6[1:39,]) to leave out the lines with NAs.  Are they a problem anyway?

[[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] RQuantLib installation problem

2023-09-24 Thread David Winsemius



On 9/24/23 08:23, Ivan Krylov wrote:

On Sun, 24 Sep 2023 02:19:20 +
Naresh Gurbuxani  wrote:


install.packages("RQuantLib", repos = "https://cran.r-project.org;)

Installing package into ‘/usr/local/lib/R/4.1/site-library’
(as ‘lib’ is unspecified)
trying URL
'https://cran.r-project.org/src/contrib/RQuantLib_0.4.17.tar.gz'



Ivan is undoubtedly more knowledgeable on these matters than I, but I 
noticed that you are trying to install the current version of RQuantLib 
into a library that appears associated with a significantly older 
version of R than is current the current version. (And I second the 
advice that this is a question properly addressed to the R_SIG-mac 
mailing list but only with a much better description of version of your 
setup and how R was installed. You might want to install RQuantLib for a 
time frame that matched R 4.1.x. The archive is here:


https://cran.r-project.org/src/contrib/00Archive/RQuantLib/

You may also want to set the compile flags so that R can find your 
version of gfortran. That can be done within install.packages but most 
experts would prefer that you do it from a system terminal session with 
$ R CMD INSTALL. You can find details at the r help page `


?INSTALL -- David

  

dyld[29996]: Library not loaded:
/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
Referenced from: <383F3774-06DE-3792-AA2C-C9D6B37A2D89>
/usr/local/Cellar/r/4.1.2/lib/R/lib/libR.dylib

So you're installing source packages into a Homebrew-built R, and they
fail to load after being compiled?

If you don't get an answer here, try r-sig-...@r-project.org or
<https://github.com/orgs/Homebrew/discussions>.



__
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] Odd result

2023-09-24 Thread Parkhurst, David
With help from several people, I used file.choose() to get my file name, and 
read.csv() to read in the file as KurtzData.  Then when I print KurtzData, the 
last several lines look like this:
39   5/31/22  16.0  3411.75525 0.0201 0.0214   7.00
40   6/28/22  2:00 PM  0.0  2150.67950 0.0156 0.0294 NA
41   7/25/22 11:00 AM  11.9   1943.5NA NA 0.0500   7.80
42   8/31/22  0220.5NA NA 0.0700  30.50
43   9/28/22  0.067 10.9NA NA 0.0700  10.20
44  10/26/22  0.086  237NA NA 0.1550  45.00
45   1/12/23  1:00 PM 36.2624196NA NA 0.7500 283.50
46   2/14/23  1:00 PM 20.71   55NA NA 0.0500   2.40
47  NA NA NA NA
48  NA NA NA NA
49  NA NA NA NA

Then the NA�s go down to one numbered 973.  Where did those extras likely come 
from, and how do I get rid of them?  I assume I need to get rid of all the 
lines after #46,  to do calculations and graphics, no?

David

[[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] predict function type class vs. prob

2023-09-23 Thread David Winsemius
That's embarrassing. Apologies for the garbles HTML posting. I'll see if 
this is more readable:


On 9/23/23 05:30, Rui Barradas wrote:

Às 11:12 de 22/09/2023, Milbert, Sabine (LGL) escreveu:

Dear R Help Team,

My research group and I use R scripts for our multivariate data 
screening routines. During routine use, we encountered some 
inconsistencies within the predict() function of the R Stats Package. 





On 9/23/23 05:30, Rui Barradas wrote:
> Às 11:12 de 22/09/2023, Milbert, Sabine (LGL) escreveu:
>> Dear R Help Team,
>>
>> My research group and I use R scripts for our multivariate data 
screening routines. During routine use, we encountered some 
inconsistencies within the predict() function of the R Stats Package.


In addition to Rui's correction to this misstatement, the caret package 
is really a meta package that attempts to implement an umbrella 
framework for a vast array of tools from a wide variety of sources. It 
is an immense effort but not really a part of the core R project. The 
correct place to file issues is found in the DESCRIPTION file:



URL: https://github.com/topepo/caret/
BugReports: https://github.com/topepo/caret/issues

 If you use `str` on an object constructed with caret, you discover 
that the `predict` function is actually not in the main workspace but 
rather embedded in the fit-object itself. I think this is a rather 
general statement regarding the caret universe, and so I expect that 
your fit -objects can be examined for the code that predict.train will 
use with this approach. Your description of your analysis methods was 
rather incompletely specified, and I will put an appendix of "svm" 
methods that might be specified after my demonstration using code. (Note 
that I do not see a caret "weights" hyper-parameter for the "svmLinear" 
method which is actually using code from pkg:kernlab.)



library(caret)
svmFit <- train(Species ~ ., data = iris, method = "svmLinear",
 trControl = trainControl(method = "cv"))

 class(svmFit)
#[1] "train" "train.formula"
str(predict(svmFit))
 Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
str(svmFit)
#---screen output-
List of 24
 $ method  : chr "svmLinear"
 $ modelInfo   :List of 13
  ..$ label : chr "Support Vector Machines with Linear Kernel"
  ..$ library   : chr "kernlab"
  ..$ type  : chr [1:2] "Regression" "Classification"
  ..$ parameters:'data.frame':    1 obs. of  3 variables:
  .. ..$ parameter: chr "C"
  .. ..$ class    : chr "numeric"
  .. ..$ label    : chr "Cost"
  ..$ grid  :function (x, y, len = NULL, search = "grid")
  ..$ loop  : NULL
  ..$ fit   :function (x, y, wts, param, lev, last, classProbs, ...)
  ..$ predict   :function (modelFit, newdata, submodels = NULL)
  ..$ prob  :function (modelFit, newdata, submodels = NULL)
  ..$ predictors:function (x, ...)
  ..$ tags  : chr [1:5] "Kernel Method" "Support Vector Machines" 
"Linear Regression" "Linear Classifier" ...

  ..$ levels    :function (x)
  ..$ sort  :function (x)
 $ modelType   : chr "Classification"
#   large amount of screen output omitted--

# note that the class of svmFit$modelInfo$predict is 'function'
# and its code at least to this particular svm method of which there are 
about 10!



svmFit$modelInfo$predict

# screen output --
function (modelFit, newdata, submodels = NULL)
{
    svmPred <- function(obj, x) {
    hasPM <- !is.null(unlist(obj@prob.model))
    if (hasPM) {
    pred <- kernlab::lev(obj)[apply(kernlab::predict(obj,
    x, type = "probabilities"), 1, which.max)]
    }
    else pred <- kernlab::predict(obj, x)
    pred
    }
    out <- try(svmPred(modelFit, newdata), silent = TRUE)
    if (is.character(kernlab::lev(modelFit))) {
    if (class(out)[1] == "try-error") {
    warning("kernlab class prediction calculations failed; 
returning NAs")

    out <- rep("", nrow(newdata))
    out[seq(along = out)] <- NA
    }
    }
    else {
    if (class(out)[1] == "try-error") {
    warning("kernlab prediction calculations failed; returning 
NAs")

    out <- rep(NA, nrow(newdata))
    }
    }
    if (is.matrix(out))
    out <- out[, 1]
    out
}


--
David


>> Through internal research, we were unable to find the reason for 
this and have decided to contact your help team with the following issue:

>>
>> The predict() function is used once to predict the class membership 
of a new sample (type = "class") on a trained linear SVM model for 
distinguishing two classes (u

Re: [R] predict function type class vs. prob

2023-09-23 Thread David Winsemius


On 9/23/23 05:30, Rui Barradas wrote:
> Às 11:12 de 22/09/2023, Milbert, Sabine (LGL) escreveu:
>> Dear R Help Team,
>>
>> My research group and I use R scripts for our multivariate data 
>> screening routines. During routine use, we encountered some 
>> inconsistencies within the predict() function of the R Stats Package.

In addition to Rui's correction to this misstatement, the caret package 
is really a meta package that attempts to implement an umbrella 
framework for a vast array of tools from a wide variety of sources. It 
is an immense effort but not really a part of the core R project. The 
correct place to file issues is found in the DESCRIPTION file:


URL: https://github.com/topepo/caret/ BugReports: 
https://github.com/topepo/caret/issues

  If you use `str` on an object constructed with caret, you discover 
that the `predict` function is actually not in the main workspace but 
rather embedded in the fit-object itself. I think this is a rather 
general statement regarding the caret universe, and so I expect that 
your fit -objects can be examined for the code that predict.train will 
use with this approach. Your description of your analysis methods was 
rather incompletely specified, and I will put an appendix of "svm" 
methods that might be specified after my demonstration using code. (Note 
that I do not see a caret "weights" hyper-parameter for the "svmLinear" 
method which is actually using code from pkg:kernlab.)


library(caret) svmFit <- train(Species ~ ., data = iris, method = 
"svmLinear", trControl = trainControl(method = "cv")) class(svmFit) #[1] 
"train" "train.formula" str(predict(svmFit)) Factor w/ 3 levels 
"setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ... str(svmFit) #---screen 
output- List of 24 $ method : chr "svmLinear" $ modelInfo 
:List of 13 ..$ label : chr "Support Vector Machines with Linear Kernel" 
..$ library : chr "kernlab" ..$ type : chr [1:2] "Regression" 
"Classification" ..$ parameters:'data.frame': 1 obs. of 3 variables: .. 
..$ parameter: chr "C" .. ..$ class : chr "numeric" .. ..$ label : chr 
"Cost" ..$ grid :function (x, y, len = NULL, search = "grid") ..$ loop : 
NULL ..$ fit :function (x, y, wts, param, lev, last, classProbs, ...) 
..$ predict :function (modelFit, newdata, submodels = NULL) ..$ prob 
:function (modelFit, newdata, submodels = NULL) ..$ predictors:function 
(x, ...) ..$ tags : chr [1:5] "Kernel Method" "Support Vector Machines" 
"Linear Regression" "Linear Classifier" ... ..$ levels :function (x) ..$ 
sort :function (x) $ modelType : chr "Classification" #  large 
amount of screen output omitted-- # note that the class of 
svmFit$modelInfo$predict is 'function' # and its code at least to this 
particular svm method of which there are about 10!
svmFit$modelInfo$predict # screen output -- function (modelFit, 
newdata, submodels = NULL) { svmPred <- function(obj, x) { hasPM <- 
!is.null(unlist(obj@prob.model)) if (hasPM) { pred <- 
kernlab::lev(obj)[apply(kernlab::predict(obj, x, type = 
"probabilities"), 1, which.max)] } else pred <- kernlab::predict(obj, x) 
pred } out <- try(svmPred(modelFit, newdata), silent = TRUE) if 
(is.character(kernlab::lev(modelFit))) { if (class(out)[1] == 
"try-error") { warning("kernlab class prediction calculations failed; 
returning NAs") out <- rep("", nrow(newdata)) out[seq(along = out)] <- 
NA } } else { if (class(out)[1] == "try-error") { warning("kernlab 
prediction calculations failed; returning NAs") out <- rep(NA, 
nrow(newdata)) } } if (is.matrix(out)) out <- out[, 1] out }  -- David


>> Through internal research, we were unable to find the reason for this 
>> and have decided to contact your help team with the following issue:
>>
>> The predict() function is used once to predict the class membership 
>> of a new sample (type = "class") on a trained linear SVM model for 
>> distinguishing two classes (using the caret package). It is then used 
>> to also examine the probability of class membership (type = "prob"). 
>> Both are then presented in an R shiny output. Within the routine, we 
>> noticed two samples (out of 100+) where the class prediction and 
>> probability prediction did not match. The prediction probabilities of 
>> one class (52%) did not match the class membership within the predict 
>> function. We use the same seed and the discrepancy is reproducible in 
>> this sample. The same problem did not occur in other trained models 
>> (lda, random forest, radial SVM...).

*Support Vector Machines with Bou

[R] How to import an excel data file

2023-09-23 Thread Parkhurst, David
I know I should save it as a .csv file, which I have done.
I�m told I should use the read_excel() function from the readxl package.
My question is, how do I express the location of the file.  The file is named 
KurtzData.csv.
Its location in my Mac files is DFPfiles/ae/FriendsMonroe/KurtzData.csv
How exactly---What �, etc.---do I type with its name in the read_excel() 
function?
It�s been a long time since I�ve used R.
Thanks for any help.






[[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] col2rgb() function

2023-07-23 Thread David Stevens via R-help
Nick,

I've also made colors transparent by pasting the hex equivalent of, say, 
0.3*256 = 76.9 to the hex color code. e.q. for black it might be 
"#004d" and the 4d is 77 in hex. That way you don't need to convert 
back and forth so much. If col is "#00" the transparent version is

tcol <- paste0(col,"4d")

This would work in one step on a whole palette.

David

David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu
(435) 797-3229 (office)

On 7/23/2023 1:00 PM, Nick Wray wrote:
> Thanks That works nicely  Nick
>
> On Sun, 23 Jul 2023 at 19:26, Ben Bolker  wrote:
>
>> Does adjustcolor() help?
>>
>> cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
>>  "#D55E00", "#CC79A7")
>> plot(0,0,xlim=c(1,8),ylim=c(0,1))
>> points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)
>> points(1:8,rep(0.75,8),col=adjustcolor(cb8, alpha.f = 0.3), pch=19,cex=2)
>>
>> On 2023-07-23 2:15 p.m., Nick Wray wrote:
>>> Hello  I have a palette vector of colour blind colours (in hexadecimal)
>>> which I’m using for plots, but they are not see-through, and as I wanted
>> to
>>> overlay some histograms I wanted to convert these colours to rgb, when
>> you
>>> can set the opacity.
>>>
>>> I have found the function col2rgb(), which works in the sense that it
>> gives
>>> a vector of numbers but these don’t work directly in rgb because they are
>>> too big.  If I divide through to make them all less than 1 I don’t get
>> the
>>> corresponding colour-blind hue, but something somewhat off.
>>>
>>> Here is the colour-blind palette in a plot:
>>>
>>>
>>> *cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
>>> "#D55E00", "#CC79A7")*
>>>
>>> *plot(0,0,xlim=c(1,8),ylim=c(0,1))*
>>>
>>> *points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*
>>>
>>>
>>>
>>> so if I try to convert the red dot ("#D55E00") (number 7) I get
>>>
>>> *col2rgb("#D55E00"*
>>>
>>> [,1]
>>>
>>> red213
>>>
>>> green   94
>>>
>>> blue 0
>>>
>>> *points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*
>>>
>>> gives me an error message and although if  I divide through
>>>
>>> *points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*
>>>
>>> gives me a reddish dot, but not the same as in the colour-blind palette
>>>
>>>
>>>
>>> Somewhat mystified.  Can anyone help?? 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.
>> __
>> 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] how to change the y-axis to logarithmic in a barplot ggplot

2023-07-16 Thread David Winsemius



On 7/16/23 14:51, Maria Lathouri via R-help wrote:

Dear all,


I am having the following dataset
fc<-
ID    values    databases
Al    0.15    phreeqc
Al    0.6    carbfix
Al    0.47    actual
Ca    7.2    phreeqc
Ca    7.2    carbfix
Ca    0.3    actual
Na    14.4    phreeqc
Na    84    carbfix
Na    106    actual
Cl    22    phreeqc
Cl    21.9    carbfix
Cl    72.1    actual
Fe    0.05    phreeqc
Fe    0.43    carbfix
Fe    1.25    actual
Mg    0.35    phreeqc
Mg    0.17    carbfix
Mg    0.08    actual
SO4    0    phreeqc
SO4    0    carbfix
SO4    416    actual


As you can see, the values range from 0 to 400. I want it to plot it in bars; 
when I am plotting it as you can imagine the values near zero don't show at 
all. So I am trying to make the y axis logarithmic. I have created the 
following code but it doesn't work. I get the bars with zero above and the 
others on top.


ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +



None of those aes() names are in your data object. They should be one of

ID    values    databases



geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))


What are you intending with `

aes(y=log(mean)

`

+ theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = 
element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title = 
element_blank())
+ scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette = "Dark2")


--

David.



I would very much appreciate your help. I am stuck.


Kind regards,
Maria

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


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


Re: [R-es] Opciones de guardado - gráfico en png

2023-06-16 Thread David Camilo Gomez Medina
Muchísimas gracias, funcionó correctamente.

David.

On Fri, 16 Jun 2023 at 15:27, Marcelino de la Cruz Rot <
marcelino.delac...@urjc.es> wrote:

>
> Más o menos así:
>
> png(filename = "Rplot.png",  width = 607, height = 367,  res = 300)
> levelplot(lo_que_sea)
> dev.off()
>
> Saludos,
> Marcelino
>
> El 16/06/2023 a las 22:16, David Camilo Gomez Medina escribió:
> > Buen día,
> >
> > Quiero guardar un gráfico que hice en R en formato PNG, quiero
> > asegurarme de que esté por encima de los 300 dpi. El gráfico no lo
> > hice con ggplot, sino con la función levelplot por lo que no puedo
> > utilizar la función ggsave para definir los dpi. ¿Cómo puedo definir
> > el número de dpi manualmente? Quisiera guardar el gráfico en pdf, pero
> > lamentablemente me lo exigen en formato png.
> >
> > Agradezco cualquier colaboración. Muchas gracias de antemano.
> >
> > David.
> >
> > image.png
> >
> > *Aviso legal:* El contenido de este mensaje y los archivos adjuntos
> > son confidenciales y de uso exclusivo de la Universidad Nacional de
> > Colombia. Se encuentran dirigidos sólo para el uso del destinatario al
> > cual van enviados. La reproducción, lectura y/o copia se encuentran
> > prohibidas a cualquier persona diferente a este y puede ser ilegal. Si
> > usted lo ha recibido por error, infórmenos y elimínelo de su correo.
> > Los Datos Personales serán tratados conforme a la Ley 1581 de 2012 y a
> > nuestra Política de Datos Personales que podrá consultar en la página
> > web www.unal.edu.co <http://www.unal.edu.co/>.__Las opiniones,
> > informaciones, conclusiones y cualquier otro tipo de dato contenido en
> > este correo electrónico, no relacionados con la actividad de la
> > Universidad Nacional de Colombia, se entenderá como personales y de
> > ninguna manera son avaladas por la Universidad.
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
> --
> Marcelino de la Cruz Rot
> Depto. de Biología y Geología
> Física y Química Inorgánica
> Universidad Rey Juan Carlos
> Móstoles España
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


[R-es] Opciones de guardado - gráfico en png

2023-06-16 Thread David Camilo Gomez Medina
Buen día,

Quiero guardar un gráfico que hice en R en formato PNG, quiero asegurarme
de que esté por encima de los 300 dpi. El gráfico no lo hice con ggplot,
sino con la función levelplot por lo que no puedo utilizar la función
ggsave para definir los dpi. ¿Cómo puedo definir el número de dpi
manualmente? Quisiera guardar el gráfico en pdf, pero lamentablemente me lo
exigen en formato png.

Agradezco cualquier colaboración. Muchas gracias de antemano.

David.

[image: image.png]

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] log transform a data frame

2023-06-13 Thread David Carlson via R-help
Try this
pdf("~/graph.pdf")
par(mar=c(8, 4, 4, 2))
barplot(d2, legend= c("SYCL", "CUDA"), beside=
TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8",
"#6a51a3"))
dev.off()

See ?par to see the details for adjusting margins and other plot features.

David


On Tue, Jun 13, 2023 at 5:20 PM Ana Marija 
wrote:

> Thank you so much David, here is correction: d1=suppressWarnings(read.
> csv("/Users/anamaria/Downloads/B1. csv", stringsAsFactors=FALSE,
> header=TRUE)) d1$X <- NULL d2=as. matrix(sapply(d1, as. numeric))
> pdf("~/graph. pdf")b<-barplot(d2,
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
> Thank you so much David, here is correction:
>
> d1=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv",
> stringsAsFactors=FALSE, header=TRUE))
> d1$X <- NULL
> d2=as.matrix(sapply(d1, as.numeric))
> pdf("~/graph.pdf")
> b<-barplot(d2, legend= c("SYCL", "CUDA"), beside=
> TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8",
> "#6a51a3"))
> dev.off()
>
>  > dput(head(d1))
> structure(list(Domain.decomp. = c("2. 1", "2"), DD.com..load = c(0L,
> 0L), Neighbor.search = c("3.7", "3. 1"), Launch.PP.GPU.ops. = c("0. 1",
> "0"), Comm..coord. = c("1 .6", "1 .0"), Force = c("1 . 5", "1 .2"
> ), Wait...Comm..F = c("1 .3", "1 .7"), PIE.mesh = c(65.6, 70.9
> ), Wait.Bonded.GPU = c(0L, 0L), wait.GPU.NB.nonloc. = c(0L, 0L
> ), Wait.GPU.NB.local = c(0L, 0L), NB.X.F.buffer.ops. = c(7.3,
> 4.4), Write.traje = c(0.3, 0.3), Update = c(6.3, 4.3), Constraints =
> c(8.9,
> 9.7), Comm..energies = c(0.9, 0.9), PIE.redist..X.F = c("8. 1",
> "8.7"), PIE.spread = c(29.7, 30.6), PIE.gather = c("19.9", "21 .3"
> ), PIE.3D.FFT = c(6, 8.6), PIE.3D.FFT.comm. = c("1 .2", "1 .0"
> ), PIE.solve.Elec = c(0.7, 0.5)), row.names = 1:2, class = "data.frame")
>
> Now my problem is that when I save my plot as PDF my labels on X axis are
> cut off. Any advice about that?
>
>
>
> On Tue, Jun 13, 2023 at 5:14 PM David Carlson  wrote:
>
>> Your first data column appears to contain character data (e.g. SYCL) which
>> cannot be converted to numeric. You also appear to have 0's in the numeric
>> columns which will cause problems since log(0) is -Inf. Barplots are useful
>> for categorical data, but not continuous, numeric data which are better
>> handled with box plots or strip charts.
>>
>> Do not use printouts of your data since it hides important information.
>> Use str(a11) and dput(a11) or dput(head(a11)) to provide useful information
>> about your data.
>>
>> David L Carlson
>> Texas A University
>>
>>
>> On Tue, Jun 13, 2023 at 4:08 PM Ana Marija 
>> wrote:
>>
>>> Hello, I have a data frame like this: d11=suppressWarnings(read.
>>> csv("/Users/anamaria/Downloads/B1. csv", stringsAsFactors=FALSE,
>>> header=TRUE)) > d11 X Domain. decomp. DD. com. . load Neighbor. search
>>> Launch. PP. GPU. ops. Comm. . coord. 1 SYCL 2. 1
>>> ZjQcmQRYFpfptBannerStart
>>> This Message Is From an External Sender
>>> This message came from outside your organization.
>>>
>>> ZjQcmQRYFpfptBannerEnd
>>>
>>> Hello,
>>>
>>> I have a data frame like this:
>>>
>>> d11=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv",
>>> stringsAsFactors=FALSE, header=TRUE))
>>>
>>> > d11
>>>  X Domain.decomp. DD.com..load Neighbor.search Launch.PP.GPU.ops.
>>> Comm..coord.
>>> 1 SYCL   2. 10 3.7   0. 1
>>>   1 .6
>>> 2 CUDA  203. 1  0
>>>   1 .0
>>>   Force Wait...Comm..F PIE.mesh Wait.Bonded.GPU wait.GPU.NB.nonloc.
>>> 1 1 . 5   1 .3 65.6   0   0
>>> 2  1 .2   1 .7 70.9   0   0
>>>   Wait.GPU.NB.local NB.X.F.buffer.ops. Write.traje Update Constraints
>>> Comm..energies
>>> 1 07.3 0.36.3 8.9
>>>  0.9
>>> 2 04.4 0.34.3 9.7
>>>  0.9
>>>   PIE.redist..X.F PIE.spread PIE.gather PIE.3D.

Re: [R] log transform a data frame

2023-06-13 Thread David Carlson via R-help
Your first data column appears to contain character data (e.g. SYCL) which
cannot be converted to numeric. You also appear to have 0's in the numeric
columns which will cause problems since log(0) is -Inf. Barplots are useful
for categorical data, but not continuous, numeric data which are better
handled with box plots or strip charts.

Do not use printouts of your data since it hides important information. Use
str(a11) and dput(a11) or dput(head(a11)) to provide useful information
about your data.

David L Carlson
Texas A University


On Tue, Jun 13, 2023 at 4:08 PM Ana Marija 
wrote:

> Hello, I have a data frame like this: d11=suppressWarnings(read.
> csv("/Users/anamaria/Downloads/B1. csv", stringsAsFactors=FALSE,
> header=TRUE)) > d11 X Domain. decomp. DD. com. . load Neighbor. search
> Launch. PP. GPU. ops. Comm. . coord. 1 SYCL 2. 1
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
>
> Hello,
>
> I have a data frame like this:
>
> d11=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv",
> stringsAsFactors=FALSE, header=TRUE))
>
> > d11
>  X Domain.decomp. DD.com..load Neighbor.search Launch.PP.GPU.ops.
> Comm..coord.
> 1 SYCL   2. 10 3.7   0. 1
>   1 .6
> 2 CUDA  203. 1  0
>   1 .0
>   Force Wait...Comm..F PIE.mesh Wait.Bonded.GPU wait.GPU.NB.nonloc.
> 1 1 . 5   1 .3 65.6   0   0
> 2  1 .2   1 .7 70.9   0   0
>   Wait.GPU.NB.local NB.X.F.buffer.ops. Write.traje Update Constraints
> Comm..energies
> 1 07.3 0.36.3 8.9
>  0.9
> 2 04.4 0.34.3 9.7
>  0.9
>   PIE.redist..X.F PIE.spread PIE.gather PIE.3D.FFT PIE.3D.FFT.comm.
> PIE.solve.Elec
> 18. 1   29.7   19.96.0 1 .2
>0.7
> 2 8.7   30.6  21 .38.6 1 .0
>0.5
>
> I am trying to log transform the whole data frame, but I get this error:
>
> > d1=log(d11)
> Error in Math.data.frame(d11) :
>   non-numeric variable(s) in data frame: X, Domain.decomp.,
> Neighbor.search, Launch.PP.GPU.ops., Comm..coord., Force, Wait...Comm..F,
> PIE.redist..X.F, PIE.gather, PIE.3D.FFT.comm
>
>
> My goal is to make a stacked barplot like this:
> d2=as.matrix(sapply(d1, as.numeric))
> b<-barplot(d2, legend= rownames(data2), beside=
> TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8",
> "#6a51a3"))
>
> If I don't log transform  my code runs.
>
> Please advise,
> Ana
>
>   [[alternative HTML version deleted]]
>
> __r-h...@r-project.org mailing 
> list -- To UNSUBSCRIBE and more, 
> seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czR4zGIstg$
> PLEASE do read the posting guide 
> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czRLvLqcYM$
> 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-es] Marcas secundarias ejes ggplot2

2023-06-10 Thread David Camilo Gomez Medina
Hola Javier, mira el siguiente enlace:
https://cran.r-project.org/web/packages/ggprism/vignettes/axes.html

Con minor_breaks puedes lograr lo que deseas.

Cordialmente,

David.

On Sat, 10 Jun 2023 at 20:05, Javier Gómez Gonzalez 
wrote:

> Muchas gracias Carlos por los enlaces.
>
> Estimado Javier Marcuzzi lo que yo quiero es poner las marcas secundarias a
> mis ejes sin etiquetas como se puede hacer en matplotlib. Un ejemplo se
> puede ver en el siguiente enlace
>
> https://interactivechaos.com/es/manual/tutorial-de-matplotlib/marcas-principales-y-secundarias
>
>
>
> El sáb, 10 jun 2023 a las 22:56, Carlos Ortega ( >)
> escribió:
>
> > Hola,
> >
> > Sí, puedes ver varias soluciones aquí:
> >
> >-
> >
> https://stackoverflow.com/questions/14490071/adding-minor-tick-marks-to-the-x-axis-in-ggplot2-with-no-labels
> >-
> >
> https://statisticsglobe.com/add-minor-tick-marks-without-labels-ggplot2-plot-r
> >
> > Gracias,
> > Carlos.
> > www.qualityexcellence.es
> >
> > El sáb, 10 jun 2023 a las 5:29, Javier Gómez Gonzalez (<
> > zaraga...@gmail.com>) escribió:
> >
> >> Estimados amigos:
> >> Quisiera saber si hay alguna forma en ggplot2 de establecer marcas
> >> secundarias en los ejes y que estas marcas secundarias no muestren
> >> etiquetas, pero sin que se dibuje las líneas minor grid.
> >>
> >>  Javier Gómez González
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> ___
> >> R-help-es mailing list
> >> R-help-es@r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-help-es
> >>
> >
> >
> > --
> > Saludos,
> > Carlos Ortega
> > www.qualityexcellence.es
> >
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


Re: [R] InformationValue package

2023-05-26 Thread David Winsemius
If it was in CRAN you will find it in the Archives. 

Sent from my iPhone

> On May 26, 2023, at 1:37 PM, Jeff Reichman  wrote:
> 
> R Help
> 
> 
> 
> 
> 
> There use to be a package called "InformationValue" which was used to
> calculate the optimal probability cutoff for a ROC plot.  That package was
> archived some time ago and I was wondering if there is another function (in
> another package) that would perform the calculation.  I can always recall
> the archived package too.
> 
> 
> 
> 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] Split String in regex while Keeping Delimiter

2023-04-12 Thread David Winsemius
I thought replacing the spaces following instances of +++,++,+,- with "\n" and 
then reading with scan should succeed. Like Ivan Krylov I was fairly sure that 
you meant the minus sign to be "-" rather than "–", but perhaps your were using 
MS Word as an editor which is inconsistent with effective use of R. If so, 
learn to use a proper programming editor, and in any case learn to post to 
rhelp in plain text.

-- 
David

scan(text=gsub("([-+]){1}\\s", "\\1\n", dat), what="", sep="\n")



> On Apr 12, 2023, at 2:29 AM, Emily Bakker  wrote:
> 
> Hello List,
>  
> I have a dataset consisting of strings that I want to split while saving the 
> delimiter.
>  
> Some example data:
> “leucocyten + gramnegatieve staven +++ grampositieve staven ++”
> “leucocyten – grampositieve coccen +”
>  
> I want to split the strings such that I get the following result:
> c(“leucocyten +”,  “gramnegatieve staven +++”,  “grampositieve staven ++”)
> c(“leucocyten –“, “grampositieve coccen +”)
>  
> I have tried strsplit with a regular expression with a positive lookahead, 
> but I am not able to achieve the results that I want.
>  
> I have tried:
> as.list(strsplit(x, split = “(?=[\\+-]{1,3}\\s)+, perl=TRUE)
>  
> Which results in:
> c(“leucocyten “, “+”,  “gramnegatieve staven “, “+”, “+”, “+”,  
> “grampositieve staven ++”)
> c(“leucocyten “, “–“, “grampositieve coccen +”)
>  
>  
> Is there a function or regular expression that will make this possible?
>  
> Kind regards,
> Emily 
>  
> __
> 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] simultaneous confidence intervals for multinomial proportions: sample size

2023-04-09 Thread David Winsemius



> On Apr 9, 2023, at 5:46 AM, palad...@trustindata.de wrote:
> 
> Hello!
> I want to calculate simultaneous confidence intervals for a nominal variable 
> with three categories: "yes", "no", "partially" and I expect that far more 
> than 5 samples fall into each category.
> I have read that Glaz & Sison's method is only appropriate for variables with 
> 7 or more categories. Therefore, the Goodman method seems like a good idea.
> I have found the R function "MultinomCI" {DescTools} to calculate these CIs.
> However, I have not found a way to calculate in advance the required sample 
> size for the Goodman method at a fixed confidence level and length of the 
> intervall.



Seems very unlikely that you can achieve both of those goals simultaneously. I 
would expect the CI width t vary with the size of the sample in each category 
in any case. So I'm wondering if your failure at searching derives from the 
impossibility of your goal. Why would you desire such a result?


-- 
David.
> I would be very grateful for any suggestion.
> 
> 
> Many thanks in advance!
> 
> Claudia
> 
> 
>   [[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] "prob" package alternative

2023-04-06 Thread David Winsemius


On 4/6/23 02:15, Martin Maechler wrote:
>>>>>> peter murage
>>>>>>  on Tue, 4 Apr 2023 06:24:56 + writes:
>  > Which package in R replaced package prob?
>
> Well, if you google that you should quickly be lead to
> (something I even think makes sense to memorize as "rule"
>package= ) :
>
>https://CRAN.R-project.org/package=prob
>
> which now says that the package was archived as it depended on
> another package that was archived.
>
> Both are still there -- in the CRAN archive --
> but to install them may be a bit of work

I suspect Martin is referring to the need to have an OS-specific 
toolchain for compiling packages. In this case however the DESCRIPTION 
files says:


NeedsCompilation: no


So it is probably a simple matter to install. Err not quite 
correctOr it would have been if there hadn't been several dependencies, 
some of which required compilation. Here's what finally worked on a 
machine that has a working toolchain.

install.packages("fBasics")

install.packages("http://cran.nexr.com/src/contrib/fOptions_3042.86.tar.gz;, 
repo=NULL)

install.packages("http://cran.nexr.com/src/contrib/fAsianOptions_3042.82.tar.gz;,
 
repo=NULL)

install.packages("https://cran.r-project.org/src/contrib/Archive/prob/prob_1.0-1.tar.gz;,
 
repo=NULL)


I think I could have changed my repo to cran.nexr.com and they might 
have even had binaries. I'll check. Yep, they do have source and 
binaries. So that might be the easiest. You could try just this:


install.packages("fAsianOptions", repo="http://cran.nexr.com/;, 
dependencies=TRUE)


-- 

David.

> particularly if you are
> on Windows (as it suggeested you are via a Microsoft "add" at
> the end of your R-help post ..).
> One way I'd use is Winbuilder
> (which will require you to set yourself as formal "Maintainer" of
>   the package before submission).
>
> An alternative may be to use Rhub ..
> or then learn to do it yourself, by installing the "Rtools" (for Windows):
> --->https://cran.r-project.org/bin/windows/Rtools/
>   
> With best regards,
> Martin
>
> __
> 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 guidehttp://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] R does not run under latest RStudio

2023-04-06 Thread David Winsemius



On 4/6/23 03:49, Steven Yen wrote:

The RStudio list generally does not respond to free version users. I was hoping 
someone one this (R) list would be kind enough to help me.



I don't think that is true. It is perhaps true that you cannot get 
personalized help from employed staff, but you can certainly submit to 
the Q forum.



--

David



Steven from iPhone


On Apr 6, 2023, at 6:22 PM, Uwe Ligges  wrote:

No, but you need to ask on an RStudio mailing list.
This one is about R.

Best,
Uwe Ligges





On 06.04.2023 11:28, Steven T. Yen wrote:
I updated to latest RStudio (RStudio-2023.03.0-386.exe) but
R would not run. Error message:
Error Starting R
The R session failed to start.
RSTUDIO VERSION
RStudio 2023.03.0+386 "Cherry Blossom " (3c53477a, 2023-03-09) for Windows
[No error available]
I also tried RStudio 2022.12.0+353 --- same problem.
I then tried another older version of RStudio (not sure version
as I changed file name by accident) and R ran.
Any clues? Please help. Thanks.
__
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-es] Extraer texto de una columna en Excel

2023-03-31 Thread David Camilo Gomez Medina
Muchas gracias por la alternativa de utilizar la librería stringi, Carlos,
no la conocía.

On Fri, 31 Mar 2023 at 12:11, David Camilo Gomez Medina <
dcgome...@unal.edu.co> wrote:

> Muchas gracias Carlos, lo que quiero hacer es lo siguiente: extraer el
> texto que hay entre textura/s hasta el punto final.
> Ejemplo:
> *Moderadamente profundos, bien drenados, de textura franco arenosa a
> franco arcillo arenosa. Fertilidad natural media*
> Lo que quiero extraer sería:  *franco arenosa a franco arcillo arenosa *
>
> Al final lo pude realizar de la siguiente manera:
>
> df <- read_excel("Agrologia.xlsx")
>
> df$Extracted_Text <- trimws(str_extract(df$CARACTERIS,
> "(?<=textura?(?:[^a-zA-Z]|s)).*?(?=\\.)"))
>
> Estoy abierto a cualquier sugerencia o comentario.
>
> Muchas gracias.
>
> On Fri, 31 Mar 2023 at 12:03, Carlos Ortega 
> wrote:
>
>> Hola,
>>
>> Como no sé lo que querías, veo dos alternativas...
>> Yo suelo usar "stringi" en vez de "stringr"
>>
>> #-
>> library(readxl)
>> library(stringi)
>> datos <- read_excel("Agrologia.xlsx")
>> toextract <- unlist(stri_extract_all_fixed(datos$CARACTERIS, "textura"))
>>
>> #--- Si quiero un dataframe completo donde CARACTERIS tenga "textura" o
>> "texturas"
>> lineas_textura <- datos[ !is.na(toextract), ]
>> #--- Si quiero los elementos de CARACTERIS que tiene "textura" o
>> "texturas"
>> campo_textura <- datos$CARACTERIS[ !is.na((toextract))]
>> #---
>>
>> Gracias,
>>
>> Carlos Ortega
>> www.qualityexcellence.es
>>
>> El vie, 31 mar 2023 a las 17:20, David Camilo Gomez Medina (<
>> dcgome...@unal.edu.co>) escribió:
>>
>>> Buen día,
>>>
>>> Estoy extrayendo solo una parte de texto de una celda en Excel, pero
>>> tengo un inconveniente. Quiero extraer el texto desde donde dice
>>> *textura* hasta el siguiente punto, pero hay unas celdas que dicen
>>> *texturas* y me está extrayendo también ésta *s*, cómo podría cambiar
>>> el siguiente código para que me extraiga tanto textura como texturas. Quedo
>>> muy atento, gracias.
>>>
>>> rm(list = ls())
>>>
>>> library(readxl)
>>> library(stringr)
>>> library(openxlsx)
>>>
>>> setwd("~/INFO_DIEGO/R")
>>>
>>> df <- read_excel("Agrologia.xlsx")
>>>
>>> df$Extracted_Text <- str_extract(df$CARACTERIS, "(<=?textura?).*?\\.")
>>>
>>> write.xlsx(df, "modified_file.xlsx")
>>>
>>>
>>>
>>>
>>> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos son
>>> confidenciales y de uso exclusivo de la Universidad Nacional de Colombia.
>>> Se encuentran dirigidos sólo para el uso del destinatario al cual van
>>> enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
>>> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
>>> recibido por error, infórmenos y elimínelo de su correo. Los Datos
>>> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
>>> Política de Datos Personales que podrá consultar en la página web
>>> www.unal.edu.co. Las opiniones, informaciones, conclusiones y cualquier
>>> otro tipo de dato contenido en este correo electrónico, no relacionados con
>>> la actividad de la Universidad Nacional de Colombia, se entenderá como
>>> personales y de ninguna manera son avaladas por la Universidad.
>>> ___
>>> R-help-es mailing list
>>> R-help-es@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>>
>>
>>
>> --
>> Saludos,
>> Carlos Ortega
>> www.qualityexcellence.es
>>
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


Re: [R-es] Extraer texto de una columna en Excel

2023-03-31 Thread David Camilo Gomez Medina
Muchas gracias Carlos, lo que quiero hacer es lo siguiente: extraer el
texto que hay entre textura/s hasta el punto final.
Ejemplo:
*Moderadamente profundos, bien drenados, de textura franco arenosa a franco
arcillo arenosa. Fertilidad natural media*
Lo que quiero extraer sería:  *franco arenosa a franco arcillo arenosa *

Al final lo pude realizar de la siguiente manera:

df <- read_excel("Agrologia.xlsx")

df$Extracted_Text <- trimws(str_extract(df$CARACTERIS,
"(?<=textura?(?:[^a-zA-Z]|s)).*?(?=\\.)"))

Estoy abierto a cualquier sugerencia o comentario.

Muchas gracias.

On Fri, 31 Mar 2023 at 12:03, Carlos Ortega 
wrote:

> Hola,
>
> Como no sé lo que querías, veo dos alternativas...
> Yo suelo usar "stringi" en vez de "stringr"
>
> #-
> library(readxl)
> library(stringi)
> datos <- read_excel("Agrologia.xlsx")
> toextract <- unlist(stri_extract_all_fixed(datos$CARACTERIS, "textura"))
>
> #--- Si quiero un dataframe completo donde CARACTERIS tenga "textura" o
> "texturas"
> lineas_textura <- datos[ !is.na(toextract), ]
> #--- Si quiero los elementos de CARACTERIS que tiene "textura" o "texturas"
> campo_textura <- datos$CARACTERIS[ !is.na((toextract))]
> #---
>
> Gracias,
>
> Carlos Ortega
> www.qualityexcellence.es
>
> El vie, 31 mar 2023 a las 17:20, David Camilo Gomez Medina (<
> dcgome...@unal.edu.co>) escribió:
>
>> Buen día,
>>
>> Estoy extrayendo solo una parte de texto de una celda en Excel, pero
>> tengo un inconveniente. Quiero extraer el texto desde donde dice
>> *textura* hasta el siguiente punto, pero hay unas celdas que dicen
>> *texturas* y me está extrayendo también ésta *s*, cómo podría cambiar el
>> siguiente código para que me extraiga tanto textura como texturas. Quedo
>> muy atento, gracias.
>>
>> rm(list = ls())
>>
>> library(readxl)
>> library(stringr)
>> library(openxlsx)
>>
>> setwd("~/INFO_DIEGO/R")
>>
>> df <- read_excel("Agrologia.xlsx")
>>
>> df$Extracted_Text <- str_extract(df$CARACTERIS, "(<=?textura?).*?\\.")
>>
>> write.xlsx(df, "modified_file.xlsx")
>>
>>
>>
>>
>> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos son
>> confidenciales y de uso exclusivo de la Universidad Nacional de Colombia.
>> Se encuentran dirigidos sólo para el uso del destinatario al cual van
>> enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
>> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
>> recibido por error, infórmenos y elimínelo de su correo. Los Datos
>> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
>> Política de Datos Personales que podrá consultar en la página web
>> www.unal.edu.co. Las opiniones, informaciones, conclusiones y cualquier
>> otro tipo de dato contenido en este correo electrónico, no relacionados con
>> la actividad de la Universidad Nacional de Colombia, se entenderá como
>> personales y de ninguna manera son avaladas por la Universidad.
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


[R-es] Extraer texto de una columna en Excel

2023-03-31 Thread David Camilo Gomez Medina
Buen día,

Estoy extrayendo solo una parte de texto de una celda en Excel, pero tengo
un inconveniente. Quiero extraer el texto desde donde dice *textura* hasta
el siguiente punto, pero hay unas celdas que dicen *texturas* y me está
extrayendo también ésta *s*, cómo podría cambiar el siguiente código para
que me extraiga tanto textura como texturas. Quedo muy atento, gracias.

rm(list = ls())

library(readxl)
library(stringr)
library(openxlsx)

setwd("~/INFO_DIEGO/R")

df <- read_excel("Agrologia.xlsx")

df$Extracted_Text <- str_extract(df$CARACTERIS, "(<=?textura?).*?\\.")

write.xlsx(df, "modified_file.xlsx")

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co .* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.


Agrologia.xlsx
Description: MS-Excel 2007 spreadsheet
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Problems with foreign

2023-03-30 Thread David Winsemius



On 3/30/23 10:36, José Oscar Delgado Bautista wrote:

  Good day
My name is José Oscar, I'm from Mexico and I have some questions about
foreign in your write.foreig( ) function. We know that this function
generates the inputs to be able to run them or execute them in another
program like SPSS, SAS or Stata. In these cases, when creating an example
file, a matrix and using the function to execute the .sps file directly
from SPSS, I don't care or work based on the SPSS environment. With Stata
the problem does not arise, but this same problem also arises with SAS, in
that sense or question, how could I solve this? Do you have any guides or
tutorials on the correct use of the function?


I don't really understand the question. Not sure what the problem you 
are seeing when you attempt to get SAS-style output. I went to the help 
page for `write.foreign`:


?write.foreign

...  and the Arguments section clearly shows that although "SPSS" is the 
default value, that any of the other recognized values for the format of 
the output would be accepted.


Perhaps you are so inexperienced with R that you don't even know how to 
access the help system?



This is the code:
x<- matrix(data = sample(1:100,
  100),
nrow = 10, ncol = 10)

x2<- as.data.frame(x)

write.foreign(x2, "x2_spss.txt", "x2_spss.sps", package = "SPSS")


When I changed the "package" argument to "SAS", ...  I get SAS code:

* Written by R;
*  write.foreign(esoph, datafile, codefile, package = "SAS") ;

PROC FORMAT;
value agegp
 1 = "25-34"
 2 = "35-44"
 3 = "45-54"
 4 = "55-64"
 5 = "65-74"
 6 = "75+"
;

value alcgp
 1 = "0-39g/day"
 2 = "40-79"
 3 = "80-119"
 4 = "120+"
;

value tobgp
 1 = "0-9g/day"
 2 = "10-19"
 3 = "20-29"
 4 = "30+"
;

DATA  rdata ;
INFILE  "/tmp/RtmpFcHZ9L/file6a7222461f1c"
 DSD
 LRECL= 15 ;
INPUT
 agegp
 alcgp
 tobgp
 ncases
 ncontrols
;
FORMAT agegp agegp. ;
FORMAT alcgp alcgp. ;
FORMAT tobgp tobgp. ;
RUN;

--

David.



[[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-es] Función aggregate en dataframe

2023-03-29 Thread David Camilo Gomez Medina
Listo, gracias.

On Wed, 29 Mar 2023 at 15:19, Carlos Ortega 
wrote:

> Ah... veo que tienes algunos valores nulos...
> Entonces para calcular la media, habría que incluir este otro cambio:
>
> *+   mutate(mes_avg = mean(value, na.rm = TRUE), .by = c(month, vars)) %>%*
>
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>
>
>
> El mié, 29 mar 2023 a las 22:17, Carlos Ortega ()
> escribió:
>
>> Ah...
>> Sí, de esta forma...
>>
>> > resout <- df %>%
>> +   mutate(year = year(ym(yearmon))) %>%
>> +   mutate(month = month(ym(yearmon))) %>%
>> +   select(-year) %>%
>> +   relocate(month, .after = yearmon) %>%
>> +
>>
>> *  pivot_longer( cols = X1:X5, names_to = "vars" ) %>%+   mutate(mes_avg
>> = mean(value), .by = c(month, vars)) %>%+   select(month, vars, mes_avg)
>> %>%*
>> +   distinct() %>%
>> +   as.data.frame
>> > resout
>>month vars   mes_avg
>> 1  1   X1 0.5063388
>> 2  1   X2 0.6054863
>> 3  1   X3 0.4747568
>> 4  1   X4 0.6525521
>> 5  1   X5 0.3378098
>> 6  2   X1 0.6480751
>> 7  2   X2 0.3866987
>> 8  2   X3 0.5628610
>> 9  2   X4 0.2965187
>> 10 2   X5 0.5039561
>> 11 3   X1 0.3565034
>> 12 3   X2 0.5595157
>> 13 3   X3 0.4526992
>> 14 3   X4 0.5256429
>> 15 3   X5 0.5396339
>> 16 4   X1 0.3492785
>> 17 4   X2 0.4719472
>> 18 4   X3 0.6069615
>> 19 4   X4 0.5099684
>> 20 4   X5 0.5375129
>> 21 5   X1 0.6083371
>> 22 5   X2 0.6986131
>> 23 5   X3 0.3419662
>> 24 5   X4 0.4950851
>> 25 5   X5 0.5467911
>> 26 6   X1 0.2031233
>> 27 6   X2 0.4891435
>> 28 6   X3 0.3186853
>> 29 6   X4 0.7101540
>> 30 6   X5 0.4964806
>> 31 7   X1 0.4853932
>> 32 7   X2 0.5883874
>> 33 7   X3 0.8781151
>> 34 7   X4 0.4065725
>> 35 7   X5 0.3009754
>> 36 8   X1 0.4974401
>> 37 8   X2 0.6118529
>> 38 8   X3 0.6042984
>> 39 8   X4 0.3386884
>> 40 8   X5 0.6710002
>> 41 9   X1 0.6392356
>> 42 9   X2 0.4150898
>> 43 9   X3 0.5861839
>> 44 9   X4 0.4325483
>> 45 9   X5 0.6310271
>> 4610   X1 0.4523220
>> 4710   X2 0.5130199
>> 4810   X3 0.3362966
>> 4910   X4 0.5372736
>> 5010   X5 0.5077318
>> 5111   X1 0.4055051
>> 5211   X2 0.4510812
>> 5311   X3 0.2245734
>> 5411   X4 0.7682052
>> 5511   X5 0.3541822
>> 5612   X1 0.6346173
>> 5712   X2 0.5956540
>> 5812   X3 0.3881634
>> 5912   X4 0.6156253
>> 6012   X5 0.6732854
>> >
>>
>> #-
>>
>> Gracias,
>> Carlos Ortega
>> www.qualityexcellence.es
>>
>>
>> El mié, 29 mar 2023 a las 22:12, David Camilo Gomez Medina (<
>> dcgome...@unal.edu.co>) escribió:
>>
>>> Muchísimas gracias Carlos, aunque yo quiero conservar las columnas. Por
>>> ejemplo, tú creaste información del año 2019 a 2022, para la columna X1
>>> quiero calcular el promedio de enero para esos años y así con las demás
>>> columnas. ¿Cómo podría cambiar tu código?
>>>
>>> On Wed, 29 Mar 2023 at 15:05, Carlos Ortega 
>>> wrote:
>>>
>>>> Ah, gracias..
>>>>
>>>> Me he creado uno de forma sintética...
>>>> Esta es una forma...
>>>>
>>>> #-
>>>> > library(dplyr)
>>>> > library(tidyr)
>>>> > library(lubridate)
>>>> >
>>>> >
>>>> > crear_data_frame <- function(anios_inicio, anios_fin) {
>>>> +   anios_meses <- expand.grid(Year = anios_inicio:anios_fin, Month =
>>>> 1:12)
>>>> +   anios_meses$yearmon <- paste0(anios_meses$Year, "-",
>>>> sprintf("%02d", anios_meses$Month))
>>>> +   vars <- replicate(5, runif(nrow(anios_meses)))
>>>> +   data.frame(anios_meses, vars, stringsAsFactors = FALSE) %>%
>>>> + select(-Year, -Month) %>%
>>>> + arrange(yearmon)
>>>> + }
>>>> >
>>>> > df <- crear_data_frame(2019, 2022)
>>>> >
>>>> > head(df)
>>>>   yearmonX1X2  X3X4 X5
>>>> 1 2019

Re: [R-es] Función aggregate en dataframe

2023-03-29 Thread David Camilo Gomez Medina
Muchas gracias Carlos, muy amable.

On Wed, 29 Mar 2023 at 15:18, Carlos Ortega 
wrote:

> Ah...
> Sí, de esta forma...
>
> > resout <- df %>%
> +   mutate(year = year(ym(yearmon))) %>%
> +   mutate(month = month(ym(yearmon))) %>%
> +   select(-year) %>%
> +   relocate(month, .after = yearmon) %>%
> +
>
> *  pivot_longer( cols = X1:X5, names_to = "vars" ) %>%+   mutate(mes_avg =
> mean(value), .by = c(month, vars)) %>%+   select(month, vars, mes_avg) %>%*
> +   distinct() %>%
> +   as.data.frame
> > resout
>month vars   mes_avg
> 1  1   X1 0.5063388
> 2  1   X2 0.6054863
> 3  1   X3 0.4747568
> 4  1   X4 0.6525521
> 5  1   X5 0.3378098
> 6  2   X1 0.6480751
> 7  2   X2 0.3866987
> 8  2   X3 0.5628610
> 9  2   X4 0.2965187
> 10 2   X5 0.5039561
> 11 3   X1 0.3565034
> 12 3   X2 0.5595157
> 13 3   X3 0.4526992
> 14 3   X4 0.5256429
> 15 3   X5 0.5396339
> 16 4   X1 0.3492785
> 17 4   X2 0.4719472
> 18 4   X3 0.6069615
> 19 4   X4 0.5099684
> 20 4   X5 0.5375129
> 21 5   X1 0.6083371
> 22 5   X2 0.6986131
> 23 5   X3 0.3419662
> 24 5   X4 0.4950851
> 25 5   X5 0.5467911
> 26 6   X1 0.2031233
> 27 6   X2 0.4891435
> 28 6   X3 0.3186853
> 29 6   X4 0.7101540
> 30 6   X5 0.4964806
> 31 7   X1 0.4853932
> 32 7   X2 0.5883874
> 33 7   X3 0.8781151
> 34 7   X4 0.4065725
> 35 7   X5 0.3009754
> 36 8   X1 0.4974401
> 37 8   X2 0.6118529
> 38 8   X3 0.6042984
> 39 8   X4 0.3386884
> 40 8   X5 0.6710002
> 41 9   X1 0.6392356
> 42 9   X2 0.4150898
> 43 9   X3 0.5861839
> 44 9   X4 0.4325483
> 45 9   X5 0.6310271
> 4610   X1 0.4523220
> 4710   X2 0.5130199
> 4810   X3 0.3362966
> 4910   X4 0.5372736
> 5010   X5 0.5077318
> 5111   X1 0.4055051
> 5211   X2 0.4510812
> 5311   X3 0.2245734
> 5411   X4 0.7682052
> 5511   X5 0.3541822
> 5612   X1 0.6346173
> 5712   X2 0.5956540
> 5812   X3 0.3881634
> 5912   X4 0.6156253
> 6012   X5 0.6732854
> >
>
> #-
>
> Gracias,
> Carlos Ortega
> www.qualityexcellence.es
>
>
> El mié, 29 mar 2023 a las 22:12, David Camilo Gomez Medina (<
> dcgome...@unal.edu.co>) escribió:
>
>> Muchísimas gracias Carlos, aunque yo quiero conservar las columnas. Por
>> ejemplo, tú creaste información del año 2019 a 2022, para la columna X1
>> quiero calcular el promedio de enero para esos años y así con las demás
>> columnas. ¿Cómo podría cambiar tu código?
>>
>> On Wed, 29 Mar 2023 at 15:05, Carlos Ortega 
>> wrote:
>>
>>> Ah, gracias..
>>>
>>> Me he creado uno de forma sintética...
>>> Esta es una forma...
>>>
>>> #-
>>> > library(dplyr)
>>> > library(tidyr)
>>> > library(lubridate)
>>> >
>>> >
>>> > crear_data_frame <- function(anios_inicio, anios_fin) {
>>> +   anios_meses <- expand.grid(Year = anios_inicio:anios_fin, Month =
>>> 1:12)
>>> +   anios_meses$yearmon <- paste0(anios_meses$Year, "-", sprintf("%02d",
>>> anios_meses$Month))
>>> +   vars <- replicate(5, runif(nrow(anios_meses)))
>>> +   data.frame(anios_meses, vars, stringsAsFactors = FALSE) %>%
>>> + select(-Year, -Month) %>%
>>> + arrange(yearmon)
>>> + }
>>> >
>>> > df <- crear_data_frame(2019, 2022)
>>> >
>>> > head(df)
>>>   yearmonX1X2  X3X4 X5
>>> 1 2019-01 0.2783405 0.1556831 0.007564986 0.9981701 0.35200632
>>> 2 2019-02 0.3906244 0.1525354 0.794696565 0.6935012 0.15611665
>>> 3 2019-03 0.3607439 0.2350400 0.208026463 0.1175302 0.84753470
>>> 4 2019-04 0.7787032 0.371 0.697207166 0.3701457 0.04013776
>>> 5 2019-05 0.4973347 0.6898472 0.603442922 0.5696876 0.63328772
>>> 6 2019-06 0.5392983 0.9604180 0.45617 0.7767546 0.62486765
>>> >
>>> > resout <- df %>%
>>> +   mutate(year = year(ym(yearmon))) %>%
>>> +   mutate(month = month(ym(yearmon))) %>%
>>> +   select(-year) %>%
>>> +   relocate(month, .after = yearmon) %>%
>>> +   pivot_longer( cols = X1:X5) %>%
>>> +   mutate(mes_avg = mean(value), .by = month) %>%
>>> +   select(month, mes_avg) %>%
>>> +   distinct(

Re: [R-es] Función aggregate en dataframe

2023-03-29 Thread David Camilo Gomez Medina
Muchísimas gracias Carlos, aunque yo quiero conservar las columnas. Por
ejemplo, tú creaste información del año 2019 a 2022, para la columna X1
quiero calcular el promedio de enero para esos años y así con las demás
columnas. ¿Cómo podría cambiar tu código?

On Wed, 29 Mar 2023 at 15:05, Carlos Ortega 
wrote:

> Ah, gracias..
>
> Me he creado uno de forma sintética...
> Esta es una forma...
>
> #-
> > library(dplyr)
> > library(tidyr)
> > library(lubridate)
> >
> >
> > crear_data_frame <- function(anios_inicio, anios_fin) {
> +   anios_meses <- expand.grid(Year = anios_inicio:anios_fin, Month = 1:12)
> +   anios_meses$yearmon <- paste0(anios_meses$Year, "-", sprintf("%02d",
> anios_meses$Month))
> +   vars <- replicate(5, runif(nrow(anios_meses)))
> +   data.frame(anios_meses, vars, stringsAsFactors = FALSE) %>%
> + select(-Year, -Month) %>%
> + arrange(yearmon)
> + }
> >
> > df <- crear_data_frame(2019, 2022)
> >
> > head(df)
>   yearmonX1X2  X3X4 X5
> 1 2019-01 0.2783405 0.1556831 0.007564986 0.9981701 0.35200632
> 2 2019-02 0.3906244 0.1525354 0.794696565 0.6935012 0.15611665
> 3 2019-03 0.3607439 0.2350400 0.208026463 0.1175302 0.84753470
> 4 2019-04 0.7787032 0.371 0.697207166 0.3701457 0.04013776
> 5 2019-05 0.4973347 0.6898472 0.603442922 0.5696876 0.63328772
> 6 2019-06 0.5392983 0.9604180 0.45617 0.7767546 0.62486765
> >
> > resout <- df %>%
> +   mutate(year = year(ym(yearmon))) %>%
> +   mutate(month = month(ym(yearmon))) %>%
> +   select(-year) %>%
> +   relocate(month, .after = yearmon) %>%
> +   pivot_longer( cols = X1:X5) %>%
> +   mutate(mes_avg = mean(value), .by = month) %>%
> +   select(month, mes_avg) %>%
> +   distinct() %>%
> +   as.data.frame
> > resout
>month   mes_avg
> 1  1 0.4305554
> 2  2 0.4485030
> 3  3 0.4451672
> 4  4 0.4101606
> 5  5 0.4715812
> 6  6 0.5428447
> 7  7 0.5350282
> 8  8 0.4792279
> 9  9 0.5052422
> 1010 0.4272948
> 1111 0.5197938
> 1212 0.3883511
>
> #
>
> El mié, 29 mar 2023 a las 21:54, David Camilo Gomez Medina (<
> dcgome...@unal.edu.co>) escribió:
>
>> Claro Carlos, gracias, exporté el dataframe a Excel.
>>
>>
>>
>> On Wed, 29 Mar 2023 at 14:44, Carlos Ortega 
>> wrote:
>>
>>> Hola,
>>>
>>> Puedes pasar una pequeña muestra del conjunto para darte la solución...
>>>
>>> Gracias,
>>> Carlos Ortega
>>> www.qualityexcellence.es
>>>
>>> El mié, 29 mar 2023 a las 21:38, David Camilo Gomez Medina (<
>>> dcgome...@unal.edu.co>) escribió:
>>>
>>>> Buen día a todos,
>>>>
>>>> Tengo un dataframe donde está almacenada la información por año y mes,
>>>> deseo calcular el promedio de todos los meses, es decir, obtener el
>>>> promedio mensual multianual de cada columna. He intentado realizarlo con la
>>>> función aggregate, pero no sé cómo seleccionar solamente el mes. Por
>>>> ejemplo, coger solo el mes de enero ('01') de cada año y promediarlo.
>>>>
>>>> Quedo muy atento, muchas gracias.
>>>>
>>>> [image: image.png]
>>>>
>>>> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos
>>>> son confidenciales y de uso exclusivo de la Universidad Nacional de
>>>> Colombia. Se encuentran dirigidos sólo para el uso del destinatario al cual
>>>> van enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
>>>> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
>>>> recibido por error, infórmenos y elimínelo de su correo. Los Datos
>>>> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
>>>> Política de Datos Personales que podrá consultar en la página web
>>>> www.unal.edu.co. Las opiniones, informaciones, conclusiones y
>>>> cualquier otro tipo de dato contenido en este correo electrónico, no
>>>> relacionados con la actividad de la Universidad Nacional de Colombia, se
>>>> entenderá como personales y de ninguna manera son avaladas por la
>>>> Universidad.
>>>> ___
>>>> R-help-es mailing list
>>>> R-help-es@r-project.org
>>>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>>>
>>>
>

Re: [R-es] Función aggregate en dataframe

2023-03-29 Thread David Camilo Gomez Medina
Claro Carlos, gracias, exporté el dataframe a Excel.



On Wed, 29 Mar 2023 at 14:44, Carlos Ortega 
wrote:

> Hola,
>
> Puedes pasar una pequeña muestra del conjunto para darte la solución...
>
> Gracias,
> Carlos Ortega
> www.qualityexcellence.es
>
> El mié, 29 mar 2023 a las 21:38, David Camilo Gomez Medina (<
> dcgome...@unal.edu.co>) escribió:
>
>> Buen día a todos,
>>
>> Tengo un dataframe donde está almacenada la información por año y mes,
>> deseo calcular el promedio de todos los meses, es decir, obtener el
>> promedio mensual multianual de cada columna. He intentado realizarlo con la
>> función aggregate, pero no sé cómo seleccionar solamente el mes. Por
>> ejemplo, coger solo el mes de enero ('01') de cada año y promediarlo.
>>
>> Quedo muy atento, muchas gracias.
>>
>> [image: image.png]
>>
>> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos son
>> confidenciales y de uso exclusivo de la Universidad Nacional de Colombia.
>> Se encuentran dirigidos sólo para el uso del destinatario al cual van
>> enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
>> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
>> recibido por error, infórmenos y elimínelo de su correo. Los Datos
>> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
>> Política de Datos Personales que podrá consultar en la página web
>> www.unal.edu.co. Las opiniones, informaciones, conclusiones y cualquier
>> otro tipo de dato contenido en este correo electrónico, no relacionados con
>> la actividad de la Universidad Nacional de Colombia, se entenderá como
>> personales y de ninguna manera son avaladas por la Universidad.
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.


conjunto.xlsx
Description: MS-Excel 2007 spreadsheet
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R-es] Función aggregate en dataframe

2023-03-29 Thread David Camilo Gomez Medina
Buen día a todos,

Tengo un dataframe donde está almacenada la información por año y mes,
deseo calcular el promedio de todos los meses, es decir, obtener el
promedio mensual multianual de cada columna. He intentado realizarlo con la
función aggregate, pero no sé cómo seleccionar solamente el mes. Por
ejemplo, coger solo el mes de enero ('01') de cada año y promediarlo.

Quedo muy atento, muchas gracias.

[image: image.png]

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co .* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Resultado operación entre dataframes

2023-03-15 Thread David Camilo Gomez Medina
Hola a todos,

Muchísimas gracias por sus comentarios y ayuda. Me sirvió mucho las maneras
que me mostraron de solucionar el problema. Encontré otra manera de
resolverlo utilizando la librería dplyr, me gustaría compartirles esta
forma:

df_1 %>%
  mutate(across(all_of(df_2$nombre), ~ . - df_2$valor[match(cur_column(),
df_2$nombre)]))

Cordialmente,

David.


On Tue, 14 Mar 2023 at 14:45, David Camilo Gomez Medina <
dcgome...@unal.edu.co> wrote:

> Buen día estimados,
>
> Tengo el siguiente código:
>
> df_1 <- data.frame(ana = c(15, 20, 30), maria = c(15,20,30), jose = c(15,
> 20, 30))
>
> df_2 <- data.frame(nombre = c("jose", "ana", "maria"), valor = c(1,2,3))
>
> # Find the corresponding columns in df_1 based on the values in df_2$nombre
> cols <- match(df_2$nombre, names(df_1))
>
> # Subtract the values of df_2$valor from the corresponding columns of df_1
> df_1[,cols] <- df_1[,cols] - (df_2$valor)
>
> # Print the resulting data frame
> df_1
>
> y mi resultado es el siguiente:
>
>   ana maria jose
> 1  1414   14
> 2  1818   18
> 3  2727   27
>
> Pero el resultado debería ser:
>
>   ana maria jose
> 1  1312   14
> 2  1817   19
> 3  2827   29
>
> ¿Saben qué podría estar pasando?
>
> Quedo muy atento, gracias.
>
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


[R-es] Resultado operación entre dataframes

2023-03-14 Thread David Camilo Gomez Medina
Buen día estimados,

Tengo el siguiente código:

df_1 <- data.frame(ana = c(15, 20, 30), maria = c(15,20,30), jose = c(15,
20, 30))

df_2 <- data.frame(nombre = c("jose", "ana", "maria"), valor = c(1,2,3))

# Find the corresponding columns in df_1 based on the values in df_2$nombre
cols <- match(df_2$nombre, names(df_1))

# Subtract the values of df_2$valor from the corresponding columns of df_1
df_1[,cols] <- df_1[,cols] - (df_2$valor)

# Print the resulting data frame
df_1

y mi resultado es el siguiente:

  ana maria jose
1  1414   14
2  1818   18
3  2727   27

Pero el resultado debería ser:

  ana maria jose
1  1312   14
2  1817   19
3  2827   29

¿Saben qué podría estar pasando?

Quedo muy atento, gracias.

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co .* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


Re: [R-es] Interpolación IDW

2023-02-21 Thread David Camilo Gomez Medina
Emilio, muchas gracias. Tuve que rehacer el código para entender mejor
todo, pero me sale el siguiente error:


*Error in as.data.frame.default(x[[i]], optional = TRUE) :   cannot coerce
class ‘structure("RasterLayer", package = "raster")’ to a data.frame*

El código es el siguiente:


























*for (i in 1:nrows_mt) {data_it_mt <-
as.numeric(as.vector(data_y_mt[i,]))it_data_mt <- idw(data_it_mt,
sta_mt, grid, p = 1)grid <- data.frame(grid, valores = it_data_mt[ ,
1])coordinates(grid) <- ~x+ygridded(grid) <- Tgrid <-
raster(grid, "valores")projection(grid) <- crs("+init=epsg:9377")
path <- 'C:/Users/David Gomez/Desktop/TESIS/DATOS/RESULTS/'numeration
<- as.character(i)name <- "MEAN_TEMP"exten <- ".tif"
writeRaster(grid, paste(path, name, numeration, exten), overwrite = T)}*

No entiendo muy bien a qué parte hace énfasis el error.

Quedo atento, gracias.

Saludos.

On Mon, 20 Feb 2023 at 02:11, Emilio L. Cano  wrote:

> Hola,
> Es difícil responder con un ejemplo no reproducible y sin el mensaje de
> error, pero te diría que intentes primero comprobar que puedes ajustar un
> único modelo fuera del bucle.
>
> Dicho esto, parece que estás pasando como primer argumento de la función
> un “string”, el nombre de la variable, y debe ser una fórmula. Tal vez
> as.formula(current_var, “~1”) te funcione.
>
> En cuanto a los NA, puedes usar en cada iteración current_df <-
> tidyr::drop_na(current_var) y usar current_df en vez de sta_mt
>
> Saludos,
> Emilio
>
>
>
> El 17 feb 2023, a las 19:56, David Camilo Gomez Medina <
> dcgome...@unal.edu.co> escribió:
>
> Hola, buen día a todos.
>
> He estado mirando cómo interpolar unos datos anuales con el método IDW,
> pero no consigo aún realizarlo.
>
> idw_models <- list()
>
> for (i in 1:ncol(data_y_mt)) {
>   #Extract the current variable
>   current_var <- names(data_y_mt)[i]
>
>   #Create an IDW model for the current variable
>   idw_model <- idw(current_var, sta_mt, grid, p = 1)
>
>   idw_models[[i]] <- idw_model
> }
>
> Ese es el código que llevo, pero me siento muy perdido. La variable*
> data_y_mt* es el dataframe donde tengo los valores, *sta_mt* son las
> coordenadas de los puntos, *grid* es la malla coordenada.
>
> Me gustaría también eliminar los datos con valores NA. Adjunto imagen del
> dataframe.
>
> Quedo muy atento, gracias.
>
> 
>
> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos son
> confidenciales y de uso exclusivo de la Universidad Nacional de Colombia.
> Se encuentran dirigidos sólo para el uso del destinatario al cual van
> enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
> recibido por error, infórmenos y elimínelo de su correo. Los Datos
> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
> Política de Datos Personales que podrá consultar en la página web
> www.unal.edu.co. Las opiniones, informaciones, conclusiones y cualquier
> otro tipo de dato contenido en este correo electrónico, no relacionados con
> la actividad de la Universidad Nacional de Colombia, se entenderá como
> personales y de ninguna manera son avaladas por la Universidad.
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


[R-es] Interpolación IDW

2023-02-17 Thread David Camilo Gomez Medina
Hola, buen día a todos.

He estado mirando cómo interpolar unos datos anuales con el método IDW,
pero no consigo aún realizarlo.

idw_models <- list()

for (i in 1:ncol(data_y_mt)) {
  #Extract the current variable
  current_var <- names(data_y_mt)[i]

  #Create an IDW model for the current variable
  idw_model <- idw(current_var, sta_mt, grid, p = 1)

  idw_models[[i]] <- idw_model
}

Ese es el código que llevo, pero me siento muy perdido. La variable*
data_y_mt* es el dataframe donde tengo los valores, *sta_mt* son las
coordenadas de los puntos, *grid* es la malla coordenada.

Me gustaría también eliminar los datos con valores NA. Adjunto imagen del
dataframe.

Quedo muy atento, gracias.

[image: image.png]

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co .* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Cambiar nombre columnas de un dataframe

2023-02-09 Thread David Camilo Gomez Medina
Muchas gracias Emilio, usando chek.names pude solucionarlo.

Cordialmente,

David.

On Thu, 9 Feb 2023 at 10:48, Emilio L. Cano  wrote:

> Hola,
>
> Para que sean nombres válidos de columna no pueden empezar con un número,
> por eso se le pone el prefijo de la X cuando es necesario.
>
> En algunas funciones (como data.frame) se puede evitar ese comportamiento
> con el argumento check.names, y entonces a las variables hay que hacer
> referencia poniendo el nombre entre acentos graves, por ejemplo `123`.
> Comprueba si este argumento o parecido está en las funciones que usas para
> las operaciones que comentas.
>
> Saludos,
> Emilio
>
>
>
>
>
> El 9 feb 2023, a las 16:27, David Camilo Gomez Medina <
> dcgome...@unal.edu.co> escribió:
>
> Buen día,
>
> Es que al realizar diferentes operaciones con un dataframe, el nombre de
> las columnas aparece con una *X*. ¿Alguien sabe cómo podría solucionarlo?
>
> Quedo atento a sus comentarios. Gracias.
>
> 
>
> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos son
> confidenciales y de uso exclusivo de la Universidad Nacional de Colombia.
> Se encuentran dirigidos sólo para el uso del destinatario al cual van
> enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
> recibido por error, infórmenos y elimínelo de su correo. Los Datos
> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
> Política de Datos Personales que podrá consultar en la página web
> www.unal.edu.co. Las opiniones, informaciones, conclusiones y cualquier
> otro tipo de dato contenido en este correo electrónico, no relacionados con
> la actividad de la Universidad Nacional de Colombia, se entenderá como
> personales y de ninguna manera son avaladas por la Universidad.
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.

[[alternative HTML version deleted]]

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


[R-es] Cambiar nombre columnas de un dataframe

2023-02-09 Thread David Camilo Gomez Medina
Buen día,

Es que al realizar diferentes operaciones con un dataframe, el nombre de
las columnas aparece con una *X*. ¿Alguien sabe cómo podría solucionarlo?

Quedo atento a sus comentarios. Gracias.

[image: image.png]

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co .* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R] Bug in internal 'tar' implementation?

2023-01-31 Thread David Engster
I think I found a bug in the internal implementation of 'tar', but
before bothering the R maintainers, I was advised to ask here to make
sure I'm not missing something.

Fortunately, it can be very easily reproduced on a Linux system. In an
empty temporary directory, execute the following code:

cat("foobar", file="test.txt")
file.symlink("test.txt", "test_link.txt")
tar("test.tar", c("test_link.txt", "test.txt"), tar="internal")
system2("tar", c("tf", "test.tar"))

This file create a file "test.txt" and a symbolic link "test_link.txt"
pointing to that file. Those two are then put into "test.tar" using R's
internal tar implementation, and then the system's 'tar' binary (usually
GNU tar) will be used to display the contents of that archive.

On my system (Debian 11, GNU tar 1.34), this gives me the following
output:

[1] TRUE
test_link.txt
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

Not that *extracting* the archive with 'tar xf' (fortunately) works
fine, it's just displaying its contents that fails. After looking into
the hexdump of 'test.tar' and R's internal tar() code, I found out the
reason for this is that a wrong size for the link is put into the tar
header: it should be zero, but the size of the linked file is put in
there instead. This leads to 'tar tf' jumping over too many blocks after
displaying the link filename and hence aborting.

While I'm aware the 'tar()' help says to avoid links for portability
reasons, it also says that it supports symbolic links on OSes that
support them, which Linux of course does, so do you agree this should be
fixed? (It's a very simple one-line change.)

Best,
David

__
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] Failing to install the rgl package

2023-01-26 Thread David Winsemius



On 1/26/23 11:04, Tunga Kantarcı wrote:

Hi,

I try to execute the seven lines of code below to plot a graph. But I
am failing as the messages below show. Where am I going wrong?


install.packages("rgl")
library(rgl)
y_hat = X%*%B_hat
open3d(windowRect = c(100,100,900,900),family = "serif")
color = rainbow(length(y_hat))[rank(y_hat)]
plot3d(educ,exper,wage,col = color,type = "s",size = 0.5,xlim =
c(0,20),ylim = c(0,60),zlim = c(-10,70),box = FALSE,axes = TRUE)
planes3d(B_hat[2],B_hat[3],-1,B_hat[1],alpha = 0.5,col = "azure")


  -

install.packages("rgl")

trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/rgl_1.0.1.tgz'
Content type 'application/x-gzip' length 9425401 bytes (9.0 MB)
==
downloaded 9.0 MB

The downloaded binary packages are in
/var/folders/fx/_msf5ycn14g59c3vlc4pc7b8gn/T//RtmpfaezHX/downloaded_packages

library(rgl)

Registered S3 methods overwritten by 'rgl':
   method   from
   knit_print.rglId
   knit_print.rglOpen3d
   sew.rglRecordedplot
Error in dyn.load(dynlib <- getDynlib(dir)) :
   unable to load shared object
'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so':
   
dlopen(/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so,
0x0006): Library not loaded: /opt/X11/lib/libGLU.1.dylib
   Referenced from: <82C7D9AE-E1B2-39EA-A909-163B033CF7B1>



So It appears that X11, a.k.a. XQuartz on a Mac, is failing to load. You 
probably need to reinstall XQuartz with a current version that matches 
your version of R. You are also getting a message saying Java sdk cannot 
be found.



You also appear to be attempting to load the version for R 4.1 while the 
current version of R is 4.2. The R "ecosystem" needs consistency in 
versions of R, XQuartz, Java, and R packages. You will probably get 
better success if you first upgrade R, then reinstall XQuartz,  then 
reinstall or update Java, and finally update all your installed packages 
including rgl and then give it another go.


Finally, this is Rhelp. There is a SIG for R-Mac users. This question 
would have been more on-topic for  that help mailing list.


--

David


/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so
   Reason: tried: '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libGLU.1.dylib' (no
such file), '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/Library/Frameworks/R.framework/Resources/lib/libGLU.1.dylib' (no
such file), '/Users/tunga/lib/libGLU.1.dylib' (no such file),
'/usr/local/lib/libGLU.1.dylib' (no such file),
'/usr/lib/libGLU.1.dylib' (no such file, not in dyld cache),
'/lib/libGLU.1.dylib' (no such file),
'/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre/lib/server/libGLU.1.dylib'
(no such file), '/var/folders/fx/_msf5ycn
In addition: Warning message:
package ‘rgl’ was built under R version 4.1.2
Error: package or namespace load failed for ‘rgl’:
  .onLoad failed in loadNamespace() for 'rgl', details:
   call: rgl.init(initValue, onlyNULL)
   error: OpenGL is not available in this build
In addition: Warning messages:
1: Loading rgl's DLL failed.
This build of rgl depends on XQuartz, which failed to load.
  See the discussion in https://stackoverflow.com/a/66127391/2554330
2: Trying without OpenGL...

__
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] Plotmath isn't working for special characters

2023-01-25 Thread David Stevens
A more extensive test (no=produced an empty box on the plot, yes=produced the 
intended plotmath result). It appears that plotmath is not producing the 
special math characters. Greek symbols are produced. I'll try to reinstall R 
and report back.

David

plot(1,1, main = parse(text = "x >= y")) - no
plot(1,1, main = parse(text = "x == y")) - yes
plot(1,1, main = parse(text = "x <= y")) - no
plot(1,1, main = parse(text = "x ~ y")) - yes
plot(1,1, main = parse(text = "x * y")) - yes
plot(1,1, main = parse(text = "x %~~% y")) - no

plot(1,1, main = bquote(x %~~% y)) - no
plot(1,1, main = bquote(x  %prop% y)) - no

plot(1,1, main = expression(x  %prop% y)) - no
plot(1,1, main = expression(x == y)) - yes
plot(1,1, main = expression(x %+-% y)) - no
plot(1,1, main = expression(integral(f(x)*dx, a, b))) - no
plot(1,1, main = expression(sum(x[i], i==1, n))) - no
plot(1,1, main = expression(x^(y + z))) - yes
plot(1,1, main = expression(inf(x))) - no
plot(1,1, main = expression(x[(y + z)])) - yes

David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu<mailto:david.stev...@usu.edu>
(435) 797-3229 (office)

On 1/24/2023 3:33 PM, Bert Gunter wrote:
Also works for me on a Mac Ventura in the RStudio graphics device. Just for the 
heckuva it, does
plot(1,1,main= quote( x >= y ))
work? I shouldn't think so, but ...

Cheers,
Bert



On Tue, Jan 24, 2023 at 1:43 PM David Stevens 
mailto:david.stev...@usu.edu>> wrote:
Simple expressions on plots, such as parse(text='x >= y') have been
resulting in just a placeholder box (x box y and not the symbol) in my R
plot labels in windows, R v 4.2.2. I haven't down an exhaustive test but
<= and >= have this behavior.

plot(1,1,main=parse(text="x >= y"))

Has anyone else seen this?

best

David

--
David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu<mailto:david.stev...@usu.edu>
(435) 797-3229 (office)

__
R-help@r-project.org<mailto: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] Plotmath isn't working for special characters

2023-01-24 Thread David Stevens
Simple expressions on plots, such as parse(text='x >= y') have been 
resulting in just a placeholder box (x box y and not the symbol) in my R 
plot labels in windows, R v 4.2.2. I haven't down an exhaustive test but 
<= and >= have this behavior.

plot(1,1,main=parse(text="x >= y"))

Has anyone else seen this?

best

David

-- 
David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu
(435) 797-3229 (office)

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


Re: [R-es] Suma de datos de una tabla

2023-01-19 Thread David Camilo Gomez Medina
Muchas gracias Carlos y Manuel por el aporte, me ayudó bastante.

On Thu, 19 Jan 2023 at 04:12, Carlos Ortega 
wrote:

> Hola,
>
> Sí, he cambiado de forma de hacerlo, así lo tienes directo en un
> data.table...
> Y sale el 2000 que no sé porqué no salía antes.
>
> #-
> library(readxl)
> library(data.table)
> library(tidytable)
> library(lubridate)
>
> datos <- read_excel("PPT.xlsx") %>%
>   as.data.table() %>%
>   rename.(fecha = Fecha) %>%
>   mutate.( year = as.factor(year(ymd(fecha)) )) %>%
>   select.(-fecha) %>%
>   as.data.table()
>
> # Crear vectores con nombres de columnas y factores
> cols_to_sum <- datos %>% select.(where(is.numeric)) %>% names()
> resultado <- datos[, lapply(.SD, function(x) sum(x, na.rm = TRUE )),
> .SDcols = cols_to_sum, by = year]
> #----
>
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>
> El mié, 18 ene 2023 a las 23:57, David Camilo Gomez Medina (<
> dcgome...@unal.edu.co>) escribió:
>
>> Hola Carlos, muchísimas gracias. Me sirvió muchísimo y me hiciste caer en
>> cuenta en que es mejor dejarlo en un dataframe y no en lista. Estoy
>> iniciando en esto porque manejar ese volumen de datos en Excel es muy
>> tedioso.
>>
>> Seguí tu código y lo apliqué, pero mira que no me está dando la suma de
>> manera correcta y también no me aparece el año 2000 y 2020. Adjunto una
>> captura del resultado, de cómo apliqué el código y también el archivo con
>> el que estoy trabajando.
>>
>> library(readxl)
>> library(tidyverse)
>>
>> ppt <- read_excel("PPT.xlsx")
>>
>> ppt <- transform(ppt, Fecha = as.Date(Fecha))
>>
>> ppt$year <- as.integer(format(as.Date(ppt$Fecha), "%Y"))
>>
>> result <- aggregate(. ~ year, data = ppt[, -1], sum, na.rm = T)
>>
>> Saludos,
>>
>> [image: image.png]
>>
>> On Wed, 18 Jan 2023 at 16:10, Carlos Ortega 
>> wrote:
>>
>>> Hola,
>>>
>>> De esta forma se aproxima bastante a lo que quieres...
>>>
>>> #-
>>> #--- Generar datos de forma sintética.
>>> library(dplyr)
>>>
>>> # número de sitios
>>> N <- 5
>>>
>>> # número de fechas
>>> num_dates <- 365
>>>
>>> # generar fechas para 2019, 2021 y 2022
>>> dates_2019 <- seq(as.Date("2019-01-01"), as.Date("2019-12-31"), by =
>>> "day")
>>> dates_2021 <- seq(as.Date("2021-01-01"), as.Date("2021-12-31"), by =
>>> "day")
>>> dates_2022 <- seq(as.Date("2022-01-01"), as.Date("2022-12-31"), by =
>>> "day")
>>> dates <-
>>> c(rep(dates_2019,num_dates),rep(dates_2021,num_dates),rep(dates_2022,num_dates))
>>>
>>> # generar nombres de columnas
>>> colnames <- c("fecha", paste0("Sitio_", 1:N))
>>>
>>> # generar dataframe vacío
>>> df <- data.frame(matrix(nrow = length(dates), ncol = N + 1))
>>> colnames(df) <- colnames
>>> df$fecha <- dates
>>>
>>> # generar valores aleatorios
>>> for (i in 2:(N + 1)) {
>>>   df[,i] <- rnorm(length(dates), mean = 50, sd = 10)
>>> }
>>>
>>> #- Cálculo como dataframe.
>>> df$year <- as.integer(format(as.Date(df$fecha), "%Y"))
>>> result <- aggregate(. ~ year, data=df[, -1], sum)
>>>
>>> #- Como lista...
>>> result_list <- list()
>>> # Aplicar aggregate() a cada columna de sitio
>>> agg_list <- lapply(df[,-1], function(x) aggregate(x ~ year, data =
>>> df[,-1], sum))
>>>
>>> # Aplicar split() a cada elemento de la lista de aggregate()
>>> result_list <- lapply(agg_list, function(x) split(x, x$year))
>>>
>>>
>>> Saludos,
>>> Carlos Ortega
>>> www.qualityexcellence.es
>>>
>>> El mié, 18 ene 2023 a las 20:14, David Camilo Gomez Medina (<
>>> dcgome...@unal.edu.co>) escribió:
>>>
>>>> No sé si olvidé aclarar, pero quiero crear una lista para cada columna
>>>> y así almacenar esos valores.
>>>>
>>>> On Wed, 18 Jan 2023 at 14:13, David Camilo Gomez Medina <
>>>> dcgome...@unal.edu.co> wrote:
>>>>
>>>>> Hola Carlos.
>>>>>
>>>>> Por ejemplo 

Re: [R-es] Suma de datos de una tabla

2023-01-18 Thread David Camilo Gomez Medina
No sé si olvidé aclarar, pero quiero crear una lista para cada columna y
así almacenar esos valores.

On Wed, 18 Jan 2023 at 14:13, David Camilo Gomez Medina <
dcgome...@unal.edu.co> wrote:

> Hola Carlos.
>
> Por ejemplo la segunda columna (16040050), quiero sumar todos los datos de
> esa columna correspondientes al año 2000 (quiero relacionarlos con la
> primera columna donde está la fecha) y ese valor almacenarlo en una lista y
> así sucesivamente con los demás años y con las demás columnas.
>
> Tengo pensado una lista así:
>
> est_16040050
>
> [[2000]]
> [1] 2.3
>
> [[2001]]
> [1] 1.7
>
> [[2002]]
> [1] 4.8
>
> Quedo muy atento a sus sugerencias o guías.
>
> Saludos.
>
> On Wed, 18 Jan 2023 at 13:52, Carlos Ortega 
> wrote:
>
>> Hola,
>>
>> Por entenderlo mejor, quieres que para las filas, para cada año:
>>
>>1. se sumen las columnas y por tanto tengas tantas sumas como
>>columnas.
>>2. o sumar todas las columnas y obtener una única suma.
>>
>> Gracias,
>> Carlos Ortega
>> www.qualityexcellence.es
>>
>> El mié, 18 ene 2023 a las 19:29, David Camilo Gomez Medina (<
>> dcgome...@unal.edu.co>) escribió:
>>
>>> Hola, espero que se encuentren muy bien.
>>>
>>> Tengo una tabla de datos de precipitación y quiero sumar por columnas y
>>> así obtener la precipitación anual. Es decir, quiero sumar solo los datos
>>> del año 2000 y guardarlos en una lista y así sucesivamente con los demás
>>> años, pero no encuentro todavía una función o una manera eficiente de
>>> hacerlo.
>>>
>>> Agradecería mucho si alguien me puede guiar.
>>>
>>> Saludos
>>>
>>> [image: image.png]
>>>
>>> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos son
>>> confidenciales y de uso exclusivo de la Universidad Nacional de Colombia.
>>> Se encuentran dirigidos sólo para el uso del destinatario al cual van
>>> enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
>>> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
>>> recibido por error, infórmenos y elimínelo de su correo. Los Datos
>>> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
>>> Política de Datos Personales que podrá consultar en la página web
>>> www.unal.edu.co. Las opiniones, informaciones, conclusiones y cualquier
>>> otro tipo de dato contenido en este correo electrónico, no relacionados con
>>> la actividad de la Universidad Nacional de Colombia, se entenderá como
>>> personales y de ninguna manera son avaladas por la Universidad.
>>> ___
>>> R-help-es mailing list
>>> R-help-es@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>>
>>
>>
>> --
>> Saludos,
>> Carlos Ortega
>> www.qualityexcellence.es
>>
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Suma de datos de una tabla

2023-01-18 Thread David Camilo Gomez Medina
Hola Carlos.

Por ejemplo la segunda columna (16040050), quiero sumar todos los datos de
esa columna correspondientes al año 2000 (quiero relacionarlos con la
primera columna donde está la fecha) y ese valor almacenarlo en una lista y
así sucesivamente con los demás años y con las demás columnas.

Tengo pensado una lista así:

est_16040050

[[2000]]
[1] 2.3

[[2001]]
[1] 1.7

[[2002]]
[1] 4.8

Quedo muy atento a sus sugerencias o guías.

Saludos.

On Wed, 18 Jan 2023 at 13:52, Carlos Ortega 
wrote:

> Hola,
>
> Por entenderlo mejor, quieres que para las filas, para cada año:
>
>1. se sumen las columnas y por tanto tengas tantas sumas como columnas.
>2. o sumar todas las columnas y obtener una única suma.
>
> Gracias,
> Carlos Ortega
> www.qualityexcellence.es
>
> El mié, 18 ene 2023 a las 19:29, David Camilo Gomez Medina (<
> dcgome...@unal.edu.co>) escribió:
>
>> Hola, espero que se encuentren muy bien.
>>
>> Tengo una tabla de datos de precipitación y quiero sumar por columnas y
>> así obtener la precipitación anual. Es decir, quiero sumar solo los datos
>> del año 2000 y guardarlos en una lista y así sucesivamente con los demás
>> años, pero no encuentro todavía una función o una manera eficiente de
>> hacerlo.
>>
>> Agradecería mucho si alguien me puede guiar.
>>
>> Saludos
>>
>> [image: image.png]
>>
>> *Aviso legal:* El contenido de este mensaje y los archivos adjuntos son
>> confidenciales y de uso exclusivo de la Universidad Nacional de Colombia.
>> Se encuentran dirigidos sólo para el uso del destinatario al cual van
>> enviados. La reproducción, lectura y/o copia se encuentran prohibidas a
>> cualquier persona diferente a este y puede ser ilegal. Si usted lo ha
>> recibido por error, infórmenos y elimínelo de su correo. Los Datos
>> Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra
>> Política de Datos Personales que podrá consultar en la página web
>> www.unal.edu.co. Las opiniones, informaciones, conclusiones y cualquier
>> otro tipo de dato contenido en este correo electrónico, no relacionados con
>> la actividad de la Universidad Nacional de Colombia, se entenderá como
>> personales y de ninguna manera son avaladas por la Universidad.
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co <http://www.unal.edu.co/>.* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R-es] Suma de datos de una tabla

2023-01-18 Thread David Camilo Gomez Medina
Hola, espero que se encuentren muy bien.

Tengo una tabla de datos de precipitación y quiero sumar por columnas y así
obtener la precipitación anual. Es decir, quiero sumar solo los datos del
año 2000 y guardarlos en una lista y así sucesivamente con los demás años,
pero no encuentro todavía una función o una manera eficiente de hacerlo.

Agradecería mucho si alguien me puede guiar.

Saludos

[image: image.png]

-- 
*Aviso legal:* El contenido de este mensaje y los archivos adjuntos son 
confidenciales y de uso exclusivo de la Universidad Nacional de Colombia. 
Se encuentran dirigidos sólo para el uso del destinatario al cual van 
enviados. La reproducción, lectura y/o copia se encuentran prohibidas a 
cualquier persona diferente a este y puede ser ilegal. Si usted lo ha 
recibido por error, infórmenos y elimínelo de su correo. Los Datos 
Personales serán tratados conforme a la Ley 1581 de 2012 y a nuestra 
Política de Datos Personales que podrá consultar en la página web 
www.unal.edu.co .* *Las opiniones, informaciones, 
conclusiones y cualquier otro tipo de dato contenido en este correo 
electrónico, no relacionados con la actividad de la Universidad Nacional de 
Colombia, se entenderá como personales y de ninguna manera son avaladas por 
la Universidad.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Error 3221226505

2022-12-18 Thread David Winsemius
I cannot tell whether it would happen to me for two reasons: I don't use 
Windows anymore and R's current version is 4.2.1.



You can determine whether it is the core packages that are throwing the 
error (rather unlikely) or perhaps something you have in your 
(invisible) .Rdata file. You should probably update your installation of 
R and throw away the .Rdata file that I suspect has gotten corrupted or 
is loading a flaky package. If you don't want to update R, then you 
should at the very least try to run R from a command line with



>  R --vanilla

At least that's I what I remember from my Windows daze. You should also 
review the Win-R-FAQ which I think has similar advice.



--

David

On 12/18/22 16:20, Jeff Newmiller wrote:

Doesn't happen to me.

On December 16, 2022 12:44:17 AM PST, "Mathurin, Gottfried via R-help" 
 wrote:

Hello,
I currently face the issue of Windows 10 throwing a code 3221226505
whenever I try to use R-4.1.3.
Is this issue known and could you possibly share a fix?

Thank you in advance,

*Gottfried*



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


[R] [R-pkgs] onetime 0.1.0: Run Code Only Once

2022-12-09 Thread David Hugh-Jones
Dear all,

Onetime 0.1.0, a utility package of interest to package developers, is now
on CRAN:

https://cran.r-project.org/package=onetime

Onetime uses lockfiles to perform an action only once (ever, or with an
expiry date) on a given computer. For example, it can send a message or
warning:

for (i in 1:10) {
  onetime_message("This will be shown only once", id = "my-message")
}

It also lets you send a message and confirm the user doesn't need to see it
again:

onetime_message_confirm("User can opt not to show this message again",
 id = "my-confirm-message")

Onetime checks that you have permission to store files on the user's
computer, and allows package authors to ask for this permission using
check_ok_to_store().

Package authors can use onetime to print one-off informative messages for
new users, or to do other one-off actions.

Documentation is available at https://hughjonesd.github.io/onetime/.

Cheers,
David

[[alternative HTML version deleted]]

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

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


Re: [R] What is new in R especially about Tidyverse.

2022-11-29 Thread David Winsemius
The OP should familiarize him/her-self with the `news()` function. It 
would allow reading what the authors of packages including those of the 
base packages have to say about material changes.



#First, type:

?news

#Then perhaps:

news(package="R") news(package="tidyverse") -- David.

On 11/27/22 06:26, Ebert,Timothy Aaron wrote:

I suggest starting with a browser (I used Google), and search for "Tidyverse". 
Some pages there should help. I would check out the github link. Before going too far I 
would also check out the Wikipedia page, and the references cited therein. Using key 
words from these resources and using citations in these resources should get you much 
closer to your goal.
I had thought that github kept track of versions. I am not super familiar with 
github. While I could not find the version histories, I might not have general access to 
that information or I simply did not know where to look. There is a possibility that the 
detailed version histories might be information overload and you will have to sift 
through many small tweaks to find important developments. You might need to clearly 
define what constitutes an "important update" or the audience that found the 
update important.

Tim

-Original Message-
From: R-help  On Behalf Of Eric Berger
Sent: Sunday, November 27, 2022 3:50 AM
To: Abdullah DOĞRUL 
Cc: r-help@r-project.org
Subject: Re: [R] What is new in R especially about Tidyverse.

[External Email]

Hi Abdullah,
The Tidyverse is a set of R packages that are designed to work well together 
for handling a variety of common tasks in data science. Many of these packages 
are written by Hadley Wickham, chief scientist at RStudio.com.

https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHadley_Wickhamdata=05%7C01%7Ctebert%40ufl.edu%7Ca473eece3c93493f8b7d08dad0546547%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638051358176015383%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=yWWonY9jWhq9NE9I7BQ7eEQ%2B8u39hjxktaQvtXTkQoY%3Dreserved=0

RStudio.com is a commercial company which provides both free and non-free 
products for data science. Many R users use the free IDE RStudio provided by 
them. The company recently changed its name from RStudio.com to Posit, as it 
wants to emphasize that its tools are not restricted to R (e.g.
Python is supported, Quarto for documents, etc)

I suggest you look at the resources available at https::/posit.co as a start.

Besides the tidyverse packages, you might want to investigate how different 
groups have used the tidyverse philosophy (and packages) to provide groups of 
packages for handling specific sub-disciplines in data science. For example, 
Rob Hyndman's group has created the tidyverts (the 'ts' refers to time series) 
which extends the tidyverse packages and also contributed additional packages. 
The tidyverts facilitates time series forecasting.

Good luck,
Eric



On Sun, Nov 27, 2022 at 10:16 AM Abdullah DOĞRUL 
wrote:


To whom it may concern,

Currently I'm doing my MSc in Turkey. My department is Industrial
Engineering. I'm going to do my thesis about Tidyverse in R. I'm
looking for articles which contain what is new, what changed and what
is Tidyverse's contributions?

I need a help about how to find those articles. I have found some of
articles. But, probably they'll not help much.

Thank you for your help.
Best regards.

Abdullah DOĞRUL

 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat
.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl
.edu%7Ca473eece3c93493f8b7d08dad0546547%7C0d4da0f84a314d76ace60a62331e
1b84%7C0%7C0%7C638051358176015383%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w
LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
sdata=cPJFkNJfLjyipJXzJSsgP6tsZbuxoZSDSKicG4jrBqg%3Dreserved
=0
PLEASE do read the posting guide
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r
-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%
7Ca473eece3c93493f8b7d08dad0546547%7C0d4da0f84a314d76ace60a62331e1b84%
7C0%7C0%7C638051358176015383%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM
DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
sdata=GJRLQ9rc9R71FWpzrc0RA1z87sNvh6jhBIVKlws1HeE%3Dreserved=0
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://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl.edu%7Ca473eece3c93493f8b7d08dad0546547%7C0d4da0f84a314d76ace60a62331e1b8

[R] unmet dependency for r-base-core ... was Re: ubuntu 22

2022-11-14 Thread David Winsemius


On 11/14/22 15:22, Ragia . wrote:
>dear group ,
> cant install r base into ubuntu 22.
> the msg is
> The following packages have unmet dependencies:
>   r-base-core : Depends: libicu70 (>= 70.1-1~) but it is not installable


Have you tried looking up the package that would contain libicu70?  I 
had no problem locating a copy of libicu70_70.1-2_amd64.deb 
<https://ubuntu.pkgs.org/22.04/ubuntu-main-amd64/libicu70_70.1-2_amd64.deb.html>
 
with search terms: "libicu70 ubuntu 22".


> Recommends: r-recommended but it is not going to be installed
> Recommends: r-doc-html but it is not going to be installed
> E: Unable to correct problems, you have held broken packages.
> thanks in advance
>
>   [[alternative HTML version deleted]]


Do note that Rhelp is a plain text mailing list. And further note that 
the proper mailing list (also plain text) would have been R-SIG-debian.


-- 

David.

>
> __
> 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 guidehttp://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] Logistic regression for large data

2022-11-11 Thread David Winsemius
That’s not a large data set. Something else besides memory limits is going on. 
You should post output of summary(Base). 

— 
David
Sent from my iPhone

> On Nov 11, 2022, at 11:29 PM, George Brida  wrote:
> 
> Dear R users,
> 
> I have a database  called Base.csv   (attached to this email) which
> contains 13 columns and 8257 rows and whose the first 8 columns are dummy
> variables which take 1 or 0. The problem is when I wrote the following
> instructions to do a logistic regression , R runs for hours and hours
> without giving an output:
> 
> Base=read.csv("C:\\Users\\HP\\Desktop\\New\\Base.csv",header=FALSE,sep=";")
> fit_1=glm(Base[,2]~Base[,1]+Base[,10]+Base[,11]+Base[,12]+Base[,13],family=binomial(link="logit"))
> 
> Apparently, there is not enough memory to have the requested output. Is
> there any other function for logistic regression that handle large data and
> return output in reasonable time.
> 
> Many thanks
> 
> Kind regards
> 
> George
> __
> 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] Plotting a triangular prism

2022-11-10 Thread David Winsemius
One might think that after all these years you would have understood that “it’s 
not working” is an excessively imprecise description of, well, anything. 

Also html is deprecated severely on Rhelp. 

— 
David. 

Sent from my iPhone

> On Nov 10, 2022, at 5:46 PM, Erin Hodgess  wrote:
> 
> Hello!
> 
> I’m trying to draw a triangular prism.  I have used rgl, plot3d, and it’s
> still not working as I would like.
> 
> Has anyone done this, please?
> 
> Thanks for any help.
> 
> Sincerely,
> Erin
> -- 
> Erin Hodgess, PhD
> mailto: erinm.hodg...@gmail.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.

__
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] 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.


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

2022-11-05 Thread David Winsemius



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


Re: [R] [EXT] Re: Linestring values to vector

2022-10-21 Thread David Stevens
The way I did this recently is to look into the .dbf file that comes 
with the shapefile group from ESRI or your feature site, and search the 
feature names for the one I want. This gives you an index to use to 
search for the feature in the actual shapefile. Then, once the shapefile 
is loaded into R using the shapefiles package, you can get the vectors 
of polygon vertices by

lr <- shapefiles::read.shapefile(myFile) # lr is the shapefile object

sfs <- lr$shp[myIndex] #sfs will be a list and the first element is the 
geometry
sfp <- sfs[[1]]$points #sfp is the set of X and Y vertices

lines(sfp$X],sfp$Y,col='red',lwd=2)

David

David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu
(435) 797-3229 (office)

On 10/21/2022 12:01 PM, Jeff Newmiller wrote:
> As the Posting Guide would have warned you, you will probably have better 
> luck asking this kind of question on the R-sig-geo mailing list.
>
> On October 21, 2022 10:45:30 AM PDT, Nick Wray  wrote:
>> Hello I have downloaded a large shapefile dataset of UK rivers and I want
>> to isolate (as an ordinary R string) the LINESTRING values for particular
>> lines, corresponding to rivers
>> Looking at the first line I can isolate the geometry by
>>
>> Hello I have downloaded a large shapefile dataset of UK rivers and I want
>> to isolate (as an ordinary R string) the LINESTRING values for particular
>> lines, corresponding to rivers
>>
>> Looking at the first line I can isolate the geometry by
>>
>>
>>
>> st_geometry(rivers[1,8])
>>
>>
>>
>> Geometry set for 1 feature
>> Geometry type: LINESTRING
>> Dimension: XYZ
>> Bounding box:  xmin: 462010.6 ymin: 1213039 xmax: 462306.5 ymax: 1213199
>> z_range:   zmin: 0 zmax: 0
>> Projected CRS: OSGB 1936 / British National Grid
>>
>> LINESTRING Z (462306.5 1213048 0, 462275.4 1213...
>>
>>
>> What I need is all the values in the LINESTRING as a common or garden R
>> vector, but I cannot find a way to do this.
>>
>> Does anyone know how?  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.
> --
> 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.
> CAUTION: This email originated from outside of USU. If this appears to be a 
> USU employee, beware of impersonators. Do not click links, reply, download 
> images, or open attachments unless you verify the sender’s identity and know 
> the content is safe.
>
__
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] Reading Text files from UK Met Office into R again...

2022-10-12 Thread David Winsemius
First one needs to remove the extraneous line-ends that you created by using an 
editor that inserts those line-ends (or perhaps it was your mail-client that 
added them because you failed to post in plain-text. I removed those files "by 
hand" and then created a text "file".

txt <- "2015-01-01 00:00, 03002, WMO, SYNOP, 1, 12, 1011, 4, 7, 200, 18, 82, , 
, 8, , , , , 100, 450, 1005.4, 5, , 102, 4, , 129, , , , , , , , 8.7, 7.5, 
8.1,1003.6, , , , , , , 1, 1, 1, , , 1, , , , , 1, 1, 1, 1, 1, 1, , 1, , 1, 1, 
, , , , , , , , , 1, , , , , 2014-12-31 23:53, 0, , , , , , , , , , , , K, , , 
, , 91.7, A, , , ,
2015-01-01 00:00, 03005, WMO, SYNOP, 1, 9, 1011, 4, 1, 210, 26, 62, 8, 6, ,8, 
8, , , 8, 30, 700, 1006, 1, 8, 54, 7, 6, 105, , , , , , , , 8.6, 7.3, 8, 996.1, 
, 01, , , , , 1, 1, 1, 1, 1, 1, 1, , , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, , , , , , , , 1, , , , , 2014-12-31 23:55, 0, , , , , , , , , , , , K, , , , 
, 91.7, A, , , 0, 1
2015-01-01 00:00, 03006, WMO, SYNOP, 1, 10, 1011, 4, 6, 210, 23, , , , , , , , 
, , , , , , , , , , , , , , , , , , , , , , , , , , , 1, 1, , , , , , , , , , , 
, , , , , , , , , , , , , , , , , , , , , , , 2014-12-31 23:53, 0, , , , , , , 
, , , , , , , , , , , A, , , ,
2015-01-01 00:00, 03010, WMO, SYNOP, 1, 17, 1011, 4, 6, 230, 21, , , , , , , , 
, , , 1006.1, , , , , , , , , , , , , , 9.4, 6.2, 7.9, , , , , , , , 1, 1, , , 
, , , , , , , , 1, 1, 1, 1, , , , , , , , , , , , , , , , , , , ,"

# Then use `count.fields`
count.fields(file=textConnection(txt))
[1] 104 106 105  81

# So i'm guessing you arbitrarily snipped in the middl of own of the text lines

dat <- read.table(text=txt, sep=",", fill=TRUE, row.names=NULL, head=FALSE)
 str(dat)
'data.frame':   4 obs. of  105 variables:
 $ V1  : chr  "2015-01-01 00:00" "2015-01-01 00:00" "2015-01-01 00:00" 
"2015-01-01 00:00"
 $ V2  : int  3002 3005 3006 3010
 $ V3  : chr  " WMO" " WMO" " WMO" " WMO"
 $ V4  : chr  " SYNOP" " SYNOP" " SYNOP" " SYNOP"
 $ V5  : int  1 1 1 1
 $ V6  : int  12 9 10 17
 $ V7  : int  1011 1011 1011 1011
 $ V8  : int  4 4 4 4
 $ V9  : int  7 1 6 6
 $ V10 : int  200 210 210 230
 $ V11 : int  18 26 23 21
 $ V12 : int  82 62 NA NA
 $ V13 : int  NA 8 NA NA
 $ V14 : int  NA 6 NA NA
 $ V15 : int  8 NA NA NA
 $ V16 : int  NA 8 NA NA
 $ V17 : int  NA 8 NA NA
 $ V18 : logi  NA NA NA NA
 $ V19 : logi  NA NA NA NA
 $ V20 : int  100 8 NA NA
 #snipped about 80 lines ...
 $ V99 : num  91.7 NA NA NA
  [list output truncated]


ALWAYS use a programming editor and always post in plain-text.

-- David.

> On Oct 9, 2022, at 4:50 PM, Ivan Krylov  wrote:
> 
> On Sun, 9 Oct 2022 12:01:27 +0100
> Nick Wray  wrote:
> 
>> Error in read.table("midas_wxhrly_201501-201512.txt", fill = T) :
>>  duplicate 'row.names' are not allowed
> 
> Since you don't pass the `header` argument, I think that the automatic
> header detection is here at play. This is what ?read.table has to say
> about row names:
> 
>>> If there is a header and the first row contains one fewer field than
>>> the number of columns, the first column in the input is used for the
>>> row names.  Otherwise if ‘row.names’ is missing, the rows are
>>> numbered.
> 
> Perhaps the "one fewer field in the header than the number of columns"
> condition is true for files after 2010? I'm too lazy to sign up for a
> CEDA account and I'm not sure I'd be given access to hourly datasets
> anyway.
> 
> If this is the reason for the failure (first column used as rownames()
> and turns out to be non-unique), there's an easy way to fix that:
> 
>>> Using ‘row.names = NULL’ forces row numbering.
> 
> I don't see a header in your example. If there's actually no header
> containing column names, passing `header = FALSE` will both prevent the
> error and avoid eating the first line of the file.
> 
> -- 
> Best regards,
> Ivan
> 
> __
> 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 steam graph

2022-10-02 Thread David Winsemius
I think you are being dishonest. That code does not appear on hrbrmstr's 
vignette at least in a form that I recognize.


When I run your code from the first posting with all the instances of 
`com_num` replaced by `com_name` and removing the `pointer` entry in dat 
which throws an error when trying to define dat, I get


Error in `group_by()`: ! Must group by variables found in `.data`. ✖ 
Column `com_name` is not found. So I "rewind the process to the point 
where the error is reported and find


dat %>%+ select(year, month, company, share, com_name) %>% + 
tidyr::gather(company, share, -year) # A tibble: 148 × 3 year company 
share1 2018 month 12 2 2019 month 1 3 2019 month 2 4 
2019 month 3 5 2019 month 4 6 2019 month 5 7 2019 month 6 8 2019 month 7 
9 2017 month 1 10 2017 month 2 # … with 138 more rows # ℹ Use `print(n = 
...)` to see more rows So the "gathering" process seems to have removed 
the `com_name` column. Can exit R without saving your workspace and then 
construct a series of R commands that will create a reproducible 
example? -- David.


On 10/2/22 10:03, Tariq Khasiri wrote:
Actually in my main data the column name is com_num ( where 
mistakenly I pasted the sample data here under the com_name ). So, 
when I run the command successfully this is the error shows up -


    ▆
  1. ├─... %>% sg_legend(show = TRUE, label = "Share: ")
  2. ├─streamgraph::sg_legend(., show = TRUE, label = "Share: ")
  3. ├─streamgraph::sg_fill_brewer(., "PuOr")
  4. ├─streamgraph::sg_axis_x(., 0.8)
  5. ├─streamgraph::streamgraph(., "com_num", "n", "year")
  6. │ └─base::data.frame(data)
  7. ├─dplyr::ungroup(.)
  8. ├─dplyr::tally(., wt = share)
  9. ├─dplyr::group_by(., year, com_num)
 10. └─dplyr:::group_by.data.frame(., year, com_num)
 11.   └─dplyr::group_by_prepare(.data, ..., .add = .add, caller_env = 
caller_env())

 12.     └─rlang::abort(bullets, call = error_call)

Any suggestions on how I can fix it ??

On Sun, 2 Oct 2022 at 09:12, David Winsemius  
wrote:


I don’t see a column with the name ‘com_num’, so the error message
makes complete sense.

—
David

Sent from my iPhone

> On Oct 2, 2022, at 5:06 AM, Tariq Khasiri
 wrote:
>
> Hi, i'm trying to create a steamgraph with the following data
by creating a
> unit indicator by combing the year and month. But, I'm getting
error as :
>
> Error in `group_by()`:
> ! Must group by variables found in `.data`.
> ✖ Column `com_num` is not found.
> Run `rlang::last_error()` to see where the error occurred.
>
> ### Packages needed for the code
> devtools::install_github("hrbrmstr/streamgraph")
>
> library(tidyverse)
> library(ggplot2)
> library(dplyr)
> library(steamgraph)
>
> ### Code ( The following code can be found on creator's account
> https://hrbrmstr.github.io/streamgraph/ )
>
> dat %>%
> select(year, month, company, share, com_num) %>%
>  tidyr::gather(company, share, -year) %>%
>  group_by(year, com_num) %>%
>  tally(wt=share) %>%
>  ungroup %>%
>  streamgraph("com_num", "n", "year") %>%
>  sg_axis_x(0.8) %>%
>  sg_fill_brewer("PuOr") %>%
>  sg_legend(show=TRUE, label="Share: ")
>
>
> ### data is like the following
>
> dput(dat)
> structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019,
> 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017,
> 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
> 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12,
> 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
> 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company =
c("ABC",
> "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH"
> ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55,
> 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53,
> 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1,
> 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,

Re: [R] Help with steam graph

2022-10-02 Thread David Winsemius
I don’t see a column with the name ‘com_num’, so the error message makes 
complete sense. 

— 
David

Sent from my iPhone

> On Oct 2, 2022, at 5:06 AM, Tariq Khasiri  wrote:
> 
> Hi, i'm trying to create a steamgraph with the following data by creating a
> unit indicator by combing the year and month. But, I'm getting error as :
> 
> Error in `group_by()`:
> ! Must group by variables found in `.data`.
> ✖ Column `com_num` is not found.
> Run `rlang::last_error()` to see where the error occurred.
> 
> ### Packages needed for the code
> devtools::install_github("hrbrmstr/streamgraph")
> 
> library(tidyverse)
> library(ggplot2)
> library(dplyr)
> library(steamgraph)
> 
> ### Code ( The following code can be found on creator's account
> https://hrbrmstr.github.io/streamgraph/  )
> 
> dat %>%
> select(year, month, company, share, com_num) %>%
>  tidyr::gather(company, share, -year) %>%
>  group_by(year, com_num) %>%
>  tally(wt=share) %>%
>  ungroup %>%
>  streamgraph("com_num", "n", "year") %>%
>  sg_axis_x(0.8) %>%
>  sg_fill_brewer("PuOr") %>%
>  sg_legend(show=TRUE, label="Share: ")
> 
> 
> ### data is like the following
> 
> dput(dat)
> structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019,
> 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017,
> 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
> 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12,
> 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
> 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC",
> "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH"
> ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55,
> 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53,
> 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1,
> 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA,
> -37L), spec = structure(list(cols = list(year = structure(list(), class =
> c("collector_double",
> "collector")), month = structure(list(), class = c("collector_double",
> "collector")), company = structure(list(), class = c("collector_character",
> "collector")), share = structure(list(), class = c("collector_double",
> "collector")), com_name = structure(list(), class = c("collector_double",
> "collector"))), default = structure(list(), class = c("collector_guess",
> "collector")), delim = ","), class = "col_spec"), problems =  0x7fd732028680>, class = c("spec_tbl_df",
> "tbl_df", "tbl", "data.frame"))
> 
>[[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] Need help plotting

2022-09-20 Thread Parkhurst, David
I like the looks of what you are doing here.

However, this from my system:
> library(chron)
Error in library(chron) : there is no package called �chron�

How can I get chron?

Also, IU�s tech support told me yesterday that if I responded to a message that 
came as plain text, my response would go out as plain text.  Is that true for 
this response, or is it in HTML?

From: Rui Barradas 
Date: Tuesday, September 20, 2022 at 4:52 AM
To: Jim Lemon , Parkhurst, David , 
r-help mailing list 
Subject: Re: [R] Need help plotting
Hello,

Now with data, here are base R and ggplot2 plots.


b <- read.table(text=
 "Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2
MVOCMpm10 Mpm2.5 Mpm1
  18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.00
  21
  18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.00
  21
  18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.00
  21",
   header=TRUE,stringsAsFactors=FALSE)


# This base R plot needs package chron
library(chron)


[[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] Converting time format

2022-09-20 Thread Parkhurst, David
Thank you.

From: Rui Barradas 
Date: Monday, September 19, 2022 at 1:28 PM
To: Parkhurst, David , R-help@r-project.org 

Subject: Re: [R] Converting time format
Hello,

I will run the examples below with the following data:


x <- c("12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30",
"13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15",
"15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00",
"17:15", "17:30", "17:45", "18:00")
b <- data.frame(time = x, myvar = sin(2*pi*seq_along(x)/length(x)))


Are they are saying is true, the vector b$myvar is a character vector
and that's what is being displayed.

In what follows I will first give examples of base graphics. The times
are first coerced to a proper time class with package chron.



library(chron)

b$time <- as.times(b$time)

# see ?plot.default for the meaning of
# argument 'type'
plot(myvar ~ time, b)
plot(myvar ~ time, b, type = "l")
plot(myvar ~ time, b, type = "b")



With ggplot2, there is no need to load a date/time class package, R can
do it with ?as.POSXct but the labels are datetime_breaks and
datetime_labels.



library(ggplot2)

b |>
   dplyr::mutate(time = paste(Sys.Date(), time),
 time = as.POSIXct(time)) |>
   ggplot(aes(time, myvar)) +
   geom_line() +
   geom_point() +
   scale_x_datetime(date_breaks = "1 hour", date_labels = "%H:%M") +
   theme_bw()



Hope this helps,

Rui Barradas


�s 01:56 de 19/09/2022, Parkhurst, David escreveu:
> I have a dataframe obtained using read.csv from an excel file.  Its first 
> column is times, running from 18:00 to 19:30.  If I want to plot other 
> columns against time, do I need to convert those somehow, and how would I do 
> that?
>
> If I run plot(b$time,b$myvar) I get a decent plot, but a friend suggests that 
> R is just treating those numbers as text, and putting them in alphabetical 
> order.  True?
>
>[[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] Converting time format

2022-09-20 Thread Parkhurst, David
Thank you.  I�ll see what I can do with that.

From: Rui Barradas 
Date: Monday, September 19, 2022 at 1:28 PM
To: Parkhurst, David , r-help@r-project.org 

Subject: Re: [R] Converting time format
Hello,

I will run the examples below with the following data:


x <- c("12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30",
"13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15",
"15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00",
"17:15", "17:30", "17:45", "18:00")
b <- data.frame(time = x, myvar = sin(2*pi*seq_along(x)/length(x)))


Are they are saying is true, the vector b$myvar is a character vector
and that's what is being displayed.

In what follows I will first give examples of base graphics. The times
are first coerced to a proper time class with package chron.



library(chron)

b$time <- as.times(b$time)

# see ?plot.default for the meaning of
# argument 'type'
plot(myvar ~ time, b)
plot(myvar ~ time, b, type = "l")
plot(myvar ~ time, b, type = "b")



With ggplot2, there is no need to load a date/time class package, R can
do it with ?as.POSXct but the labels are datetime_breaks and
datetime_labels.



library(ggplot2)

b |>
   dplyr::mutate(time = paste(Sys.Date(), time),
 time = as.POSIXct(time)) |>
   ggplot(aes(time, myvar)) +
   geom_line() +
   geom_point() +
   scale_x_datetime(date_breaks = "1 hour", date_labels = "%H:%M") +
   theme_bw()



Hope this helps,

Rui Barradas


�s 01:56 de 19/09/2022, Parkhurst, David escreveu:
> I have a dataframe obtained using read.csv from an excel file.  Its first 
> column is times, running from 18:00 to 19:30.  If I want to plot other 
> columns against time, do I need to convert those somehow, and how would I do 
> that?
>
> If I run plot(b$time,b$myvar) I get a decent plot, but a friend suggests that 
> R is just treating those numbers as text, and putting them in alphabetical 
> order.  True?
>
>[[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 help plotting

2022-09-20 Thread Parkhurst, David
Thank you.

DFP (iPad)

> On Sep 19, 2022, at 8:15 AM, Ebert,Timothy Aaron  wrote:
> 
> My version of this email has a bunch of ? that I do not know how to 
> interpret. Emails to this group need to be in plain text. HTML content is 
> deleted or converted and impossible or at least difficult to interpret.
> 
> Do not share confidential data. Please change some numbers or variable names 
> and share that.
> If this helps:
> 1) Make sure your time variable is a datetime object. 
> 2) At least in ggplot it should now behave as expected.
> ggplot(df, aes(y=NO2, x=datetime)) + geom_point()
> 
> That will be a start as a scatterplot, but the graph can be customized or 
> changed if scatterplot was not desired.
> 
> Tim
> 
> -Original Message-
> From: R-help  On Behalf Of Parkhurst, David
> Sent: Sunday, September 18, 2022 4:27 PM
> To: r-help@r-project.org
> Subject: [R] Need help plotting
> 
> [External Email]
> 
> I�ve been retired since �06 and have forgotten most of R.  Now I have a use 
> for it, with some data from Bloomington�s Environmental Commission.
> 
> I have a dataframe (obtained from read.csv) that contains numerous columns, 
> including time (in Excel�s 18:00 format), and DNO2, and MNO2 from two air 
> quality instruments.
> 
> I�d like a plot of both the NO2 measurements against time.  I be happy to use 
> either ordinary R plots or ggplot2 ones, if that would be a better way.  I�d 
> much appreciate help.
> 
>[[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] Converting time format

2022-09-19 Thread Parkhurst, David
I have a dataframe obtained using read.csv from an excel file.  Its first 
column is times, running from 18:00 to 19:30.  If I want to plot other columns 
against time, do I need to convert those somehow, and how would I do that?

If I run plot(b$time,b$myvar) I get a decent plot, but a friend suggests that R 
is just treating those numbers as text, and putting them in alphabetical order. 
 True?

[[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] Need help plotting

2022-09-19 Thread Parkhurst, David
I�ve been retired since �06 and have forgotten most of R.  Now I have a use for 
it, with some data from Bloomington�s Environmental Commission.

I have a dataframe (obtained from read.csv) that contains numerous columns, 
including time (in Excel�s 18:00 format), and DNO2, and MNO2 from two air 
quality instruments.

I�d like a plot of both the NO2 measurements against time.  I be happy to use 
either ordinary R plots or ggplot2 ones, if that would be a better way.  I�d 
much appreciate help.

[[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] Remove line from data file

2022-09-19 Thread Parkhurst, David
Thank you for your reply.  I meant from the dataframe, but that�s one of the 
terms I had forgotten.  I created that from read.csv, the csv file coming from 
Excel.  Last night I went ahead and made the change(s) using Excel.

For future reference, when I look at your solutions below, what do you mean by 
�value to delete�?  Could that just be a row number?  I was wanting to delete 
something like the 18th row in the dataframe?

From: CALUM POLWART 
Date: Sunday, September 18, 2022 at 7:25 AM
To: Parkhurst, David 
Cc: R-help@r-project.org 
Subject: Re: [R] Remove line from data file
From the file? Or the data frame once its loaded?

What format is the file? CSV?

Do you know the line that needs deleted?

mydf <- read.csv("myfile.csv")

mydf2 <- mydf[-columnName == "valuetodelete", ]
# Note the - infront of column name
# or perhaps columnName != "value to delete", ]

write.csv(mydf2, "mydeletedfile.csv")




On Sun, 18 Sep 2022, 10:33 Parkhurst, David, 
mailto:parkh...@indiana.edu>> wrote:
I�ve been retired since �06 and have forgotten most of R.  Now I have a use for 
it.  I�ve created a data file and need to delete one row from it.  How do I do 
that?

DFP (iPad)
__
R-help@r-project.org<mailto: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] Remove line from data file

2022-09-18 Thread Parkhurst, David
I’ve been retired since ‘06 and have forgotten most of R.  Now I have a use for 
it.  I’ve created a data file and need to delete one row from it.  How do I do 
that?

DFP (iPad)
__
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] Interpreting fa.diagram from package psych

2022-09-11 Thread David Winsemius



On 9/11/22 07:17, Ebert,Timothy Aaron wrote:

It is a bad graphic as the legend that should explain the color coding is 
missing. The next option is to copy the data and code and see if you can 
reproduce the figure. You can then play with the code and read a bit about the 
procedures to figure out what is going on. It should not be too hard. My guess 
is that there is some additional variable with three states that is being used. 
If this were the iris data set I would guess it was the three species: setosa, 
versicolor, and virginica.


Pretty sure that guess is incorrect.

I'm not sure there should be a legend. The colors just indicate group 
membership derived from a mathematical process that has attempted to 
separate case into distinct groups that maximize the correlations within 
individual groupings. And therefore maximizes the distance separating 
the groups. The number of groups is specified in the function call. You 
should go to the earlier results and see if you can construct the 
groupings to maximize internal correlations. Psychometricians do this 
when they don't really have a theoretical basis for doing classification 
and are asking the data do it for them. If they are doing this on a 
questionnaire dataset, they often go back to the specific 
questions/answer pairings within groupings and try to assign meaning to 
them.  They then build post-hoc explanations and often do further 
studies to see if they can replicate the results and achieve some sort 
of stable synthetic construct.  It's a rather theory-free strategy and 
so trying to assign labels automatically would be difficult.


--

David


Tim

-Original Message-
From: R-help  On Behalf Of Luigi Marongiu
Sent: Sunday, September 11, 2022 3:02 AM
To: David Winsemius 
Cc: r-help 
Subject: Re: [R] Interpreting fa.diagram from package psych

[External Email]

Sorry, the file was automatically downloaded and opened with the browser 
instead of pointing to the webpage.
Here is a better link:
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran.r-project.org%2Fweb%2Fpackages%2FpsychTools%2Fvignettes%2Ffactor.pdfdata=05%7C01%7Ctebert%40ufl.edu%7C9d0e49ff1aab4d5db2d308da93c3ac01%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637984765998607455%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=2OxukCvxcx9xFJQiAInt2ulqC23qiBjQRPU128O%2Bjn8%3Dreserved=0
The figure is on page 22.
The question is: The dots have different colors; how do I know what they 
represent?
Is there a way to show an auto-legend?
Thank you

On Sat, Sep 10, 2022 at 11:33 PM David Winsemius  wrote:


On 9/10/22 14:08, Luigi Marongiu wrote:

Hello,
I have plotted data from exploratory factor analysis, and I got a
graph similar to FIGURE 11 (PAGE 36) of this link
file:///home/gigiux/Downloads/An_overview_of_the_psych_package.pdf

This appears to be a link you a file on your personal device rather
than an attachment.

How do I interpret the figure? In particular, how do I know what the
colors represent?
Thank you


--
Best regards,
Luigi

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl.edu%7C9d0e49ff1aab4d5db2d308da93c3ac01%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637984765998607455%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=KfsnfNKp3klZMJcvvuPD4gqI6fffn95FkpaPm8KyEnA%3Dreserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%7C9d0e49ff1aab4d5db2d308da93c3ac01%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637984765998607455%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=7CZst6A76lzHADI4iRNJ%2FVI2%2FMOGLCAVnTL8aRLNjVA%3Dreserved=0
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] confidence intervals

2022-09-08 Thread David Winsemius
The first article had no code and did not describe a formula that I could find 
which matched your code. The second article is behind a paywall. 

— 
David. 

Sent from my iPhone

> On Sep 3, 2022, at 3:39 PM, Bogdan Tanasa  wrote:
> 
> 
> Dear Aaron, David, and everyone,
> 
> Thank you again for your comments on my question related to the confidence 
> intervals. I am sorry for the late reply. 
> 
> The definition of the 95 confidence intervals where our discussion originates 
> from has been proposed by the authors of these two articles (I am including 
> the links to the articles just to show that the formula has been published in 
> a methods article a while ago; the articles are in the field of biology 
> though, where not too many of you are part of, I guess). These authors have 
> written the scripts and they have made those available on github. I have 
> asked a while ago the authors why they have chosen this formula, however, I 
> have not received any reply. In any case, at this moment I will use the 
> mathematical formulas described in the articles :
> 
> https://www.cell.com/molecular-cell/fulltext/S1097-2765(15)00304-4
> 
> https://www.nature.com/articles/s41596-019-0218-7
> 
> Wishing everyone a good weekend, 
> 
> Bogdan
> 
> 
> 
>> On Sun, Aug 28, 2022 at 6:53 PM Ebert,Timothy Aaron  wrote:
>> I have a general dislike of "analysis emergencies." I would like to see a 
>> data emergency wherein someone must cram 3 years of data collection into 18 
>> months so that they have time to work out the correct analysis. I am sure 
>> others would suggest working out how analyze the data before starting the 
>> experiment.
>> 
>> Our business office gives this advice to faculty members: An emergency on 
>> your part is not an emergency on our part. 
>> 
>> How about starting by answering the questions posted by the people you are 
>> hoping will help. Focus on David's middle paragraph. However, if you can 
>> re-code everything to work, then it would seem that you already know the 
>> answer and it might be simpler/faster to write the correct code.
>> 
>> You might spend some time looking for a scientific paper that uses that 
>> equation for the confidence interval and thereby get some context to explain 
>> why the equation is correct.
>> 
>> Tim
>> 
>> -Original Message-
>> From: R-help  On Behalf Of Bogdan Tanasa
>> Sent: Sunday, August 28, 2022 8:55 PM
>> To: David Winsemius 
>> Cc: r-help 
>> Subject: Re: [R] confidence intervals
>> 
>> [External Email]
>> 
>> Hi David,
>> 
>> Thank you for your comments, and feed-back message. I am very happy to learn 
>> from the experience of the people on R mailing list, and without any doubt, 
>> I am very thankful to you and to everyone for sharing their knowledge. I do 
>> apologize for any confusion that I have created unwillingly with my previous 
>> email.
>> 
>> About my previous email related to the confidence intervals: indeed I have 
>> posted the question with a detailed description on stackoverflow, and the 
>> link is listed below.
>> 
>> I have to admit that I have been in rush willing to have the suggestions of 
>> R-help members by Monday (if that would have been possible), as I have to 
>> make a decision at the beginning of this week on whether I need to re-code 
>> the shell script in R. I have a deadline on Wed. The script itself is less 
>> important per se, I have included it just to point our the origin of my 
>> question.
>> 
>> I do certainly respect the principles of online R-help community, and I 
>> would very much appreciate if I could have your advice on the following :
>> shall a "R code related emergency" arise, would it be acceptable to post the 
>> question on stackoverflow with the corresponding data tables and detailed 
>> code, and to refer the posting on R-help mailing list ?
>> 
>> If it is acceptable at least for a single email, and if you do not mind, I 
>> could mention the link to stackoverflow, inviting our members to read it, 
>> shall they be comfortable with this topic.
>> 
>> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F73507697%2Fconfidence-intervals-of-a-biological-assay%3Fnoredirect%3D1%23comment129816241_73507697data=05%7C01%7Ctebert%40ufl.edu%7C0ba5d535471b46c05ec508da89592c20%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637973313343894313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Cs

Re: [R] About spDataLarge Package

2022-08-29 Thread David Winsemius



On 8/29/22 09:30, Paul Bernal wrote:

Dear friends,

I have just installed R version 4.2.1 for Windows on my machine, and was
trying to install package spDataLarge, but the console threw the following
error message:

Warning in install.packages :
   package 'spDataLarge' is not available for this version of R

A version of this package for your version of R might be available
elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

I used the following command to try to install it:

install.packages("spDataLarge", repos = "https://nowosad.github.io/drat/;,
type = "source")



I'm on a Linux box and I get no difficulty using:

install.packages("spDataLarge",repos  =  "https://nowosad.github.io/drat/",type  =  
"source")

That was the third of three options on its webpage at:

https://github.com/Nowosad/spDataLarge


There is an "issue" from Roger Bivand regarding the need for 
type="source: https://github.com/Nowosad/spDataLarge/issues/24


It would seem that `type="source"` might be superfluous since the 
package does not require compilation. At any rate there are two other 
options at that page and you might want to investigate them.



--

David.


I tried with earlier versions of R (4.2.0 and 4.0.3) but I keep getting the
same error. I was searching to see if I could obtain information regarding
the R version or versions that support this package, but haven't found
anything thus far.

Any suggestions on how to successfully install this package?

Something odd is that I was able to install package spData, but not
spDataLarge (in R version 4.2.1)

Best regards,
Paul

[[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] confidence intervals

2022-08-27 Thread David Winsemius
You cross-posted this to StackOverflow and did not say so.  ... and you 
posted in HTML Bad dog squared. I cast one of the close votes on SO, but 
here I can only say ... READ the Posting Guide.


You also give no citation other than someone's Github files with minimal 
comments in that material. You should indicate whether this code has any 
solid support. Why do you think this code is something to depend upon?


After all, you been posting questions on R-help for several months. 
Don't you think you should make a good faith effort to understand the 
principles underlying this resource?



--

David.

On 8/26/22 17:55, Bogdan Tanasa wrote:

Dear all,

Although I know that it is not a statistics mailing list, given my work on
ICeChIP

https://github.com/shah-rohan/icechip/blob/master/Scripts/computeHMDandError

I would appreciate to have the answer to a question :

given two variables a and b (a and b can have 1000 paired-values) and a
calibration number "cal",

why the 95 confidence interval has been calculated as such for each value
a(i) and b(i) :

100 / cal * sqrt (( a/ (b^2) + (a^2) / (b ^3)) * 1.96

Thank you,

Bogdan

[[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] Odd behavior of a function within apply

2022-08-09 Thread David Carlson via R-help
Could you have columns that are not character or integer so that y is never
defined in the function?

count1a(1:5/3)
Error in count1a(1:5/3) : object 'y' not found

David Carlson


On Mon, Aug 8, 2022 at 1:35 PM Erin Hodgess  wrote:

> OK.⁠​ I'm back again.⁠​ So my test1.⁠​df is 236x390 If I put in the
> following:⁠​ lapply(test1.⁠​df,count1a) Error in FUN(X[[i]], .⁠​.⁠​.⁠​) :⁠​
> object 'y' not found > lapply(test1.⁠​df,count1a) Error in FUN(X[[i]],
> .⁠​.⁠​.⁠​) :⁠​ object 'y' not found > sapply(test1.⁠​df,count1a)
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
>
> OK.  I'm back again.
>
> So my test1.df is 236x390
>
> If I put in the following:
>  lapply(test1.df,count1a)
> Error in FUN(X[[i]], ...) : object 'y' not found
> > lapply(test1.df,count1a)
> Error in FUN(X[[i]], ...) : object 'y' not found
> > sapply(test1.df,count1a)
> Error in FUN(X[[i]], ...) : object 'y' not found
> >
> What am I doing wrong, please?
> Thanks,
> Erin
>
>
> Erin Hodgess, PhD
> mailto: erinm.hodg...@gmail.com
>
>
> On Mon, Aug 8, 2022 at 1:41 PM Erin Hodgess  wrote:
>
> > Awesome, thanks so much!!
> >
> > Erin Hodgess, PhD
> > mailto: erinm.hodg...@gmail.com
> >
> >
> > On Mon, Aug 8, 2022 at 1:38 PM John Fox  wrote:
> >
> >> Dear Erin,
> >>
> >> The problem is that the data frame gets coerced to a character matrix,
> >> and the only column with "" entries is the 9th (the second one you
> >> supplied):
> >>
> >> as.matrix(test1.df)
> >> X1_1_HZP1 X1_1_HBM1_mon X1_1_HBM1_yr
> >> 1  "48160"   "December""2014"
> >> 2  "48198"   "June""2018"
> >> 3  "80027"   "August"  "2016"
> >> 4  "48161"   ""NA
> >> 5  NA""NA
> >> 6  "48911"   "August"  "1985"
> >> 7  NA"April"   "2019"
> >> 8  "48197"   "February""1993"
> >> 9  "48021"   ""NA
> >> 10 "11355"   "December""1990"
> >>
> >> (Here, test1.df only contains the three columns you provided.)
> >>
> >> A solution is to use sapply:
> >>
> >>  > sapply(test1.df, count1a)
> >>  X1_1_HZP1 X1_1_HBM1_mon  X1_1_HBM1_yr
> >>  2 3 3
> >>
> >>
> >> I hope this helps,
> >>   John
> >>
> >>
> >> On 2022-08-08 1:22 p.m., Erin Hodgess wrote:
> >> > Hello!
> >> >
> >> > I have the following data.frame
> >> >   dput(test1.df[1:10,8:10])
> >> > structure(list(X1_1_HZP1 = c(48160L, 48198L, 80027L, 48161L,
> >> > NA, 48911L, NA, 48197L, 48021L, 11355L), X1_1_HBM1_mon = c("December",
> >> > "June", "August", "", "", "August", "April", "February", "",
> >> > "December"), X1_1_HBM1_yr = c(2014L, 2018L, 2016L, NA, NA, 1985L,
> >> > 2019L, 1993L, NA, 1990L)), row.names = c(NA, 10L), class = "data.frame")
> >> >
> >> > And the following function:
> >> >> dput(count1a)
> >> > function (x)
> >> > {
> >> >  if (typeof(x) == "integer")
> >> >  y <- sum(is.na(x))
> >> >  if (typeof(x) == "character")
> >> >  y <- sum(x == "")
> >> >  return(y)
> >> > }
> >> > When I use the apply function with count1a, I get the following:
> >> >   apply(test1.df[1:10,8:10],2,count1a)
> >> >  X1_1_HZP1 X1_1_HBM1_mon  X1_1_HBM1_yr
> >> > NA 3NA
> >> > However, when I do use columns 8 and 10, I get the correct response:
> >> >   apply(test1.df[1:10,c(8,10)],2,count1a)
> >> > X1_1_HZP1 X1_1_HBM1_yr
> >> > 23
> >> >>
> >> > I am really baffled.  If I use count1a on a single column, it works
> >> fine.
> >> >
> >> > Any suggestions much appreciated.
> >> > Thanks,
> >> > Sincerely,
> >>

Re: [R] Predicted values from glm() when linear predictor is NA.

2022-07-27 Thread David Winsemius



On 7/27/22 17:26, Rolf Turner wrote:

I have a data frame with a numeric ("TrtTime") and a categorical
("Lifestage") predictor.

Level "L1" of Lifestage occurs only with a single value of TrtTime,
explicitly 12, whence it is not possible to estimate a TrtTime "slope"
when Lifestage is "L1".

Indeed, when I fitted the model

 fit <- glm(cbind(Dead,Alive) ~ TrtTime*Lifestage, family=binomial,
data=demoDat)

I got:


as.matrix(coef(fit))
   [,1]
(Intercept)-0.91718302
TrtTime 0.88846195
LifestageEgg + L1 -45.36420974
LifestageL114.27570572
LifestageL1 + L2   -0.30332697
LifestageL3-3.58672631
TrtTime:LifestageEgg + L1   8.10482459
TrtTime:LifestageL1 NA
TrtTime:LifestageL1 + L20.05662651
TrtTime:LifestageL3 1.66743472

That is, TrtTime:LifestageL1 is NA, as expected.

I would have thought that fitted or predicted values corresponding to
Lifestage = "L1" would thereby be NA, but this is not the case:


predict(fit)[demoDat$Lifestage=="L1"]
   26   65  131
24.02007 24.02007 24.02007

fitted(fit)[demoDat$Lifestage=="L1"]
  26  65 131
   1   1   1

That is, the predicted values on the scale of the linear predictor are
large and positive, rather than being NA.

What this amounts to, it seems to me, is saying that if the linear
predictor in a Binomial glm is NA, then "success" is a certainty.
This strikes me as being a dubious proposition.  My gut feeling is that
misleading results could be produced.


The NA is most likely caused by aliasing, so some other combination of 
factors a perfect surrogate for every case with that level of the 
interaction. The `predict.glm` function always requires a complete set 
of values to construct a case. Whether apparent incremental linear 
prediction of that interaction term is large or small will depend on the 
degree of independent contribution of the surrogate levels of other 
variables..



David.



Can anyone explain to me a rationale for this behaviour pattern?
Is there some justification for it that I am not currently seeing?
Any other comments?  (Please omit comments to the effect of "You are as
thick as two short planks!". :-) )

I have attached the example data set in a file "demoDat.txt", should
anyone want to experiment with it.  The file was created using dput() so
you should access it (if you wish to do so) via something like

 demoDat <- dget("demoDat.txt")

Thanks for any enlightenment.

cheers,

Rolf Turner


__
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] Does the function "c" have a character limit?

2022-07-13 Thread David Winsemius


On 7/12/22 23:26, David Winsemius wrote:

I think the restriction is not specific to `c` but rather is a limitation on 
the length of expressions. My foggy memory is that the limit is in the 450-500 
character vicinity. Pretty sure it’s been discussed here in the past.



One way to get around this limitation is to create a .r file and source 
the material. I just tested with your code and it succeeded.



--

David.



—
David.

Sent from my iPhone


On Jul 12, 2022, at 11:13 PM, core_contingency  wrote:

To Whom it May Concern,

I am creating a vector with the base R function "c", with many arguments as 
shown below:

  $ R
  > MES = c("A2M", "ABRACL", "ACADVL", "ACAP2", "ACTA2", "ACTN1", "ADAM19", "ADAM9", "ADAMTS5", "ADGRE5", "ADGRG6", "AEBP1", "AJUBA", "ALDH1A3", "AMMECR1", "ANTXR1", "ANXA1", "ANXA2", "ANXA5", "ANXA6", "APOE", "APP", "ARHGAP1", "ARHGEF40", "ARL1", "ARL4A", "ARMCX2", "ARPC1B", "ASPH", "ATP10D", "ATP1B1", "ATP2B1", "ATP2B4", "ATP6V0E1", "ATP8B2", "ATXN1", "B2M", "BAG3", "BGN", "BMP5", "BNC2", "BOC", "BTN3A2", "C1orf198", "C1orf54", "C4orf32", "C6orf120", "CALD1", "CALU", "CAPN2", "CAPN6", "CBFB", "CBLB", "CCDC80", "CD164", "CD44", "CD59", "CD63", "CDH11", "CETN2", "CFH", "CFI", "CILP", "CKAP4", "CLIC4", "CMTM3", "CMTM6", "CNN3", "COL11A1", "COL12A1", "COL1A1", "COL27A1", "COL3A1", "COL4A1", "COL4A2", "COL5A1", "COL5A2", "COL6A1", "COL6A2", "COL6A3", "COPA", "CPED1", "CPS1", "CRABP2", "CREB3L2", "CREG1", "CRELD2", "CRISPLD1", "CRTAP", "CSRP1", "CTDSP2", "CTNNA1", "CTSB", "CTSC", "CTSO", "CXCL12", "CYBRD1", "CYFIP1", "CYP26A1", "CYR61", "DCAF6", "DDOST", "DDR2", "DESI2", "DKK3", "DLC1", "DLX1", "DLX2", "DMD", "DNAJC1", "DNAJC10", "DNAJC3", "DNM3OS", "DPY19L1", "DSE", "DUSP14", "DUSP5", "DUSP6", "EDEM1", "EDNRA", "EFEMP2", "EGFR", "EGR1", "EGR3", "EHD2", "ELAVL1", "ELF1", "ELK3", "ELK4", "EMILIN1", "EMP1", "ENAH", "EPHA3", "EPS8", "ERBIN", "ERLIN1", "ERRFI1", "ETS1", "EVA1A", "EXT1", "EXTL2", "F2R", "F2RL2", "FAM102B", "FAM114A1", "FAM120A", "FAM129A", "FAM3C", "FAM43A", "FAM46A", "FAT1", "FBN1", "FBN2", "FGFR1", "FIBIN", "FILIP1L", "FKBP14", "FLNA", "FLRT2", "FMOD", "FN1", "FNDC3B", "FSTL1", "FUCA2", "FZD1", "FZD2", "FZD7", "GABRR1", "GALNT10", "GAS1", "GAS2", "GDF15", "GJA1", "GNAI1", "GNG12", "GNS", "GORAB", "GPC6", "GPR137B", "GPX8", "GRN", "GSN", "HES1", "HEXB", "HIBADH", "HIPK3", "HIST1H2AC", "HIST1H2BK", "HLA-A", "HLA-B", "HLA-C", "HLA-F", "HLX", "HNMT", "HOMER1", "HS3ST3A1", "HSP90B1", "HSPA5", "HSPB1", "HTRA1", "HYOU1", "ID1", "ID3", "IFI16", "IFITM2", "IFITM3", "IGF2R", "IGFBP5", "IGFBP6", "IL13RA1", "IL6ST", "INSIG1", "IQGAP2", "ITGA10", "ITGA4", "ITGAV", "ITGB1", "ITM2B", "ITM2C", "ITPR1", "ITPRIPL2", "JAK1", "JAM3", "KANK2", "KCNK2", "KCT

Re: [R] Does the function "c" have a character limit?

2022-07-13 Thread David Winsemius
I think the restriction is not specific to `c` but rather is a limitation on 
the length of expressions. My foggy memory is that the limit is in the 450-500 
character vicinity. Pretty sure it’s been discussed here in the past. 

— 
David. 

Sent from my iPhone

> On Jul 12, 2022, at 11:13 PM, core_contingency  wrote:
> 
> To Whom it May Concern,
> 
> I am creating a vector with the base R function "c", with many arguments as 
> shown below:
> 
>  $ R
>  > MES = c("A2M", "ABRACL", "ACADVL", "ACAP2", "ACTA2", "ACTN1", 
> "ADAM19", "ADAM9", "ADAMTS5", "ADGRE5", "ADGRG6", "AEBP1", "AJUBA", 
> "ALDH1A3", "AMMECR1", "ANTXR1", "ANXA1", "ANXA2", "ANXA5", "ANXA6", "APOE", 
> "APP", "ARHGAP1", "ARHGEF40", "ARL1", "ARL4A", "ARMCX2", "ARPC1B", "ASPH", 
> "ATP10D", "ATP1B1", "ATP2B1", "ATP2B4", "ATP6V0E1", "ATP8B2", "ATXN1", "B2M", 
> "BAG3", "BGN", "BMP5", "BNC2", "BOC", "BTN3A2", "C1orf198", "C1orf54", 
> "C4orf32", "C6orf120", "CALD1", "CALU", "CAPN2", "CAPN6", "CBFB", "CBLB", 
> "CCDC80", "CD164", "CD44", "CD59", "CD63", "CDH11", "CETN2", "CFH", "CFI", 
> "CILP", "CKAP4", "CLIC4", "CMTM3", "CMTM6", "CNN3", "COL11A1", "COL12A1", 
> "COL1A1", "COL27A1", "COL3A1", "COL4A1", "COL4A2", "COL5A1", "COL5A2", 
> "COL6A1", "COL6A2", "COL6A3", "COPA", "CPED1", "CPS1", "CRABP2", "CREB3L2", 
> "CREG1", "CRELD2", "CRISPLD1", "CRTAP", "CSRP1", "CTDSP2", "CTNNA1", "CTSB", 
> "CTSC", "CTSO", "CXCL12", "CYBRD1", "CYFIP1", "CYP26A1", "CYR61", "DCAF6", 
> "DDOST", "DDR2", "DESI2", "DKK3", "DLC1", "DLX1", "DLX2", "DMD", "DNAJC1", 
> "DNAJC10", "DNAJC3", "DNM3OS", "DPY19L1", "DSE", "DUSP14", "DUSP5", "DUSP6", 
> "EDEM1", "EDNRA", "EFEMP2", "EGFR", "EGR1", "EGR3", "EHD2", "ELAVL1", "ELF1", 
> "ELK3", "ELK4", "EMILIN1", "EMP1", "ENAH", "EPHA3", "EPS8", "ERBIN", 
> "ERLIN1", "ERRFI1", "ETS1", "EVA1A", "EXT1", "EXTL2", "F2R", "F2RL2", 
> "FAM102B", "FAM114A1", "FAM120A", "FAM129A", "FAM3C", "FAM43A", "FAM46A", 
> "FAT1", "FBN1", "FBN2", "FGFR1", "FIBIN", "FILIP1L", "FKBP14", "FLNA", 
> "FLRT2", "FMOD", "FN1", "FNDC3B", "FSTL1", "FUCA2", "FZD1", "FZD2", "FZD7", 
> "GABRR1", "GALNT10", "GAS1", "GAS2", "GDF15", "GJA1", "GNAI1", "GNG12", 
> "GNS", "GORAB", "GPC6", "GPR137B", "GPX8", "GRN", "GSN", "HES1", "HEXB", 
> "HIBADH", "HIPK3", "HIST1H2AC", "HIST1H2BK", "HLA-A", "HLA-B", "HLA-C", 
> "HLA-F", "HLX", "HNMT", "HOMER1", "HS3ST3A1", "HSP90B1", "HSPA5", "HSPB1", 
> "HTRA1", "HYOU1", "ID1", "ID3", "IFI16", "IFITM2", "IFITM3", "IGF2R", 
> "IGFBP5", "IGFBP6", "IL13RA1", "IL6ST", "INSIG1", "IQGAP2", "ITGA10", 
> "ITGA4", "ITGAV", "ITGB1", "ITM2B", "ITM2C", "ITPR1", "ITPRIPL2", "JAK1", 
> "JAM3", "KANK2", "KCN

Re: [R] printing with bothe print and cat...

2022-07-09 Thread David Winsemius
If spaces needed. In first sequences then 

paste( 1:5, collapse=“ “)

Sent from my iPhone

> On Jul 9, 2022, at 9:59 AM, David Winsemius  wrote:
> 
> Skip the for loops:
> 
> cat(paste( seq(1:5), ““, 1:5) )
> 
> — 
> David
> 
> Sent from my iPhone
> 
>> On Jul 9, 2022, at 9:47 AM, akshay kulkarni  wrote:
>> 
>> Dear members,
>>I have the following code:
>> 
>> testprint <- function() {
>> 
>> for(i in 1:5) {for(j in 1:5)
>> {cat(j)}
>>   print(i)}
>> }
>> 
>> And the output is:
>> 
>>> testprint()
>> 12345[1] 1
>> 12345[1] 2
>> 12345[1] 3
>> 12345[1] 4
>> 12345[1] 5
>> 
>> Any idea on how to remove the [1] from the output, and give spaces in the 
>> cat output? The desired output is:
>> 
>> 1 2 3 4 5  1
>> 1 2 3 4 5  2
>> 1 2 3 4 5  3
>> 1 2 3 4 5  4
>> 1 2 3 4 5  5
>> Many thanks in advance.
>> 
>> THanking you,
>> Yours  sincreely,
>> AKSHAY M KULKARNI
>> 
>>   [[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] printing with bothe print and cat...

2022-07-09 Thread David Winsemius
Skip the for loops:

cat(paste( seq(1:5), ““, 1:5) )

— 
David

Sent from my iPhone

> On Jul 9, 2022, at 9:47 AM, akshay kulkarni  wrote:
> 
> Dear members,
> I have the following code:
> 
> testprint <- function() {
> 
>  for(i in 1:5) {for(j in 1:5)
>  {cat(j)}
>print(i)}
> }
> 
> And the output is:
> 
>> testprint()
> 12345[1] 1
> 12345[1] 2
> 12345[1] 3
> 12345[1] 4
> 12345[1] 5
> 
> Any idea on how to remove the [1] from the output, and give spaces in the cat 
> output? The desired output is:
> 
> 1 2 3 4 5  1
> 1 2 3 4 5  2
> 1 2 3 4 5  3
> 1 2 3 4 5  4
> 1 2 3 4 5  5
> Many thanks in advance.
> 
> THanking you,
> Yours  sincreely,
> AKSHAY M KULKARNI
> 
>[[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] if zlib version >= 1.2.5... no

2022-05-30 Thread David Winsemius
Pasting a prior posted thread on the R-Mac list:

Ah, well, I see now that libR.dylib was not built or linked in
tools.so simply because I had not configured with --enable-R-shlib
... 'make' succeeds but only when I build R as a shared library.

The dlopen error isn't seen in the nightly builds, which also use
--enable-R-shlib. It would be good to know if others are able to
reproduce the error when configuring in the _default_ way, i.e.,
without --enable-R-shlib.

Mikael

> On 2022-02-10 4:30 pm, Mikael Jagan wrote:
>> On 2022-02-10 1:42 pm, Mikael Jagan wrote:
>> It seems my first message to mailing list, which had all of the attachments,
>> was caught in the spam filter. In case it helps, I've dumped the config.site,
>> config.log, and build.out on GitHub:
>> 
>> https://github.com/jaganmn/attachments/tree/6a7257014792f5e8cf7bb0bcd3bb27c7fabf7577/r-sig-mac/2022-02-10
>>  
>> 
>>> On 2022-02-10 1:11 pm, Prof Brian Ripley wrote:
 On 10/02/2022 17:28, Mikael Jagan wrote:
 Oops - forgot to mention: I am trying to build R-devel, currently at 
 r81706.
 
 Mikael
 
> On 2022-02-10 12:13 pm, Mikael Jagan wrote:
> Hello,
> 
> I am running Big Sur on an M1 Mac and trying to build R from sources.
> Some system details:
> 
> R> sessionInfo()
>  > Platform: aarch64-apple-darwin20 (64-bit)
>  > Running under: macOS Big Sur 11.6.3
> 
> $ clang --version
>  > Apple clang version 13.0.0 (clang-1300.0.29.30)
>  > Target: arm64-apple-darwin20.6.0
> 
> $ /opt/R/arm64/gfortran/bin/gfortran --version
>  > GNU Fortran (GCC) 11.0.0 20201219 (experimental)
> 
> It has been a few months since I last built R on this machine.
> At the time, I was building with LLVM clang rather than Apple clang
> to obtain OpenMP support. I was recently nudged about the OpenMP
> runtime library made available here:
> 
> https://mac.r-project.org/openmp/
> 
> which would allow me to build "normally" with Apple clang.
> I am trying now to make the switch.
> 
> I have installed all of the binaries hosted here
> 
> https://mac.r-project.org/bin/darwin20/arm64/
> 
> rather than those hosted here
> 
> https://mac.r-project.org/libs-arm64/
> 
> which I had previously installed. (Though: the first URL is missing
> binaries for gfortran, pandoc, tcl, tk, and tkTable. I obtained
> these from the second URL. _Both_ URLs are missing a zlib binary,
> so I reluctantly obtained zlib from Homebrew.)
>>> 
>>> zlib is part of the OS.  For pkg-config you need the zlib stub available 
>>> from https://mac.r-project.org/libs-4/.  That *is* in the R-admin manual.  
>>> Also, that tcl, tk, and tkTable can be installed as part of an R binary 
>>> installation.
>> 
>> Thanks - I wasn't sure whether that zlib stub was suitable for my system.
>> 
>>> 
>>> For pandoc I use the official Intel builds under emulation without any 
>>> problems (including checking all of CRAN).  But you don't need pandoc to 
>>> build R.
>>> 
>>> I understand that the transition to https://mac.r-project.org/bin is work 
>>> in progress, but its newer versions of libs are preferred.
>>> 
> 
> Anyway, I'm running into trouble now... I have attached my
> config.site, config.log, and build.out (from 'make >&') ...
> config.log seems completely normal, but in build.out I see
> many linker warnings of the form
> 
>  > ld: warning: could not create compact unwind for _dchdc_: registers 72 
> and 73 not saved contiguously in frame
>  > ld: warning: could not create compact unwind for _dpoco_: registers 72 
> and 73 not saved contiguously in frame
>  > ld: warning: object file (/opt/R/arm64/lib/libreadline.a(history.o)) 
> was built for newer macOS version (20.0) than being linked (11.0)
>  > ld: warning: object file 
> (/opt/R/arm64/lib/liblzma.a(liblzma_la-alone_decoder.o)) was built for 
> newer macOS version (20.0) than being linked (11.0)
>>> 
>>> Hmm, that's about a binary liblzma.  I'd download again (maybe try both 
>>> sites), and if it is still wrong, build from the sources.
>> If you search build.out, you'll find that this warning is issued
>> for _every_ binary obtained from
>> 
>> https://mac.r-project.org/bin/darwin20/arm64/
>> 
>> I'll try the old site again.
> Reverting to the old binaries resolves all of the version mismatch warnings,
> so perhaps there is just a glitch in the way the new binaries were built.
>> 
> And the build eventually fails for a seemingly unrelated
> reason:
> 
>  > clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names 
> -undefined dynamic_lookup -single_module -multiply_defined suppress 
> -falign-functions=64 -g -O2 -Wall -pedantic 
> -Wno-implicit-function-declaration -flto=thin -fPIC -Wl,-mllvm,-threads=4 
> -L/opt/homebrew/opt/zlib/lib -L/opt/R/arm64/lib -L/usr/local/lib -lomp -o 

Re: [R] categorizing data

2022-05-29 Thread David Carlson via R-help
Here is one way to get the table you are describing. First some made up data:

dta <- structure(list(tree = c(27, 47, 33, 31, 45, 54, 47, 27, 33, 26,
14, 43, 36, 0, 29, 24, 43, 38, 32, 21, 21, 23, 12, 42, 34), shrub = c(19,
29, 27, 31, 5, 24, 6, 37, 4, 6, 59, 7, 23, 15, 32, 1, 31, 37,
30, 44, 40, 10, 28, 23, 32), grass = c(44, 14, 30, 28, 40, 12,
37, 26, 53, 58, 17, 40, 31, 75, 29, 65, 16, 15, 28, 25, 29, 57,
50, 25, 24)), class = "data.frame", row.names = c(NA, -25L))

rnks <- data.frame(t(apply(dta, 1, rank, ties.method="first")))
rnks <- sapply(rnks, factor, labels=c("Low", "Med", "High"))
head(rnks)
 tree   shrub  grass
[1,] "Med"  "Low"  "High"
[2,] "High" "Med"  "Low"
[3,] "High" "Low"  "Med"
[4,] "Med"  "High" "Low"
[5,] "High" "Low"  "Med"
[6,] "High" "Med"  "Low"

table(apply(rnks, 1, paste, collapse="/"))

High/Low/Med High/Med/Low Low/High/Med Low/Med/High Med/High/Low Med/Low/High
   664225

David L Carlson
Texas A University


On Sun, May 29, 2022 at 5:08 PM Roy Mendelssohn - NOAA Federal via
R-help  wrote:
>
> Hi Janet: here is a start to give you the idea, now you need loop either use 
> a "for" or one of the apply functions. 1. Preallocate new data (i am lazy so 
> it is array, for example of size three. 2. order the data and set values. 
> junk <- array(0,
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
>
> Hi Janet:
>
> here is a start to give you the idea,  now you need  loop either use a "for" 
> or one of the apply functions.
>
> 1.  Preallocate new data  (i am lazy so it is array, for example of size 
> three.
>
> 2.  order the data and set values.
>
> junk <- array(0, dim = c(2,3))
> values <- c(10, 30, 50)
> junk[1, order(c(32, 11, 17))] <- values
> junk[1, ]
> [1] 50 10 30
>
>
> This works because order() returns the index of the ordering, not the values.
>
> HTH,
>
> -Roy
> > On May 29, 2022, at 1:31 PM, Janet Choate  wrote:
> >
> > I'm sorry if this has come across as a homework assignment!I was trying to
> > provide a simple example.
> > There are actually 38323 rows of data, each row is an observation of the
> > percent that each of those veg types occupies in a spatial unit - where
> > each line adds to 90 - and values are different every line.
> > I need a way to categorize the data, so I can reduce the number of unique
> > observations.
> >
> > So instead of 38323 unique observations - I can reduce this to
> > X number of High/Med/Low
> > X number of Med/Low/High
> > X number of Low/High/Med
> > etc... for all combinations
> >
> > I hope this makes it more clear..
> > thank you all for your responses,
> > JC
> >
> > On Sun, May 29, 2022 at 1:16 PM Avi Gross via R-help 
> > wrote:
> >
> >> Tom,
> >> You may have a very different impression of what was asked! LOL!
> >> Unless Janet clarifies what seems a bit like a homework assignment, it
> >> seems to be a fairly simple and straightforward assignment with exactly
> >> three rows/columns and asking how to replace the variables, in a sense, by
> >> finding the high and low and perhaps thus identifying the medium, but to do
> >> this for each row without changing the order of the resulting data.frame.
> >> I note most techniques people have used focus on columns, not rows, but an
> >> all-numeric data.frame can be transposed, or converted to a matrix and
> >> later converted back.
> >> If this is HW, the question becomes what has been taught so far and is
> >> supposed to be used in solving it. Can they make their own functions
> >> perhaps to be called three times, once per row or column, to replace that
> >> row/column, or can they use some form of loop to iterate over the columns?
> >> Does it need to sort of be done in place or can they create gradually a
> >> second data.frame and then move the pointer to it and lots of other similar
> >> ideas.
> >> I am not sure, other than as a HW assignment, why this transformation
> >> would need to be done but of course, there may well be a reason.
> >> I note that the particular example shown just happens to create almost a
> >> magic square as the sum of rows and columns and the major diagonal happen
> >&

Re: [R] Suggestions as to how to proceed would be appreciated...............

2022-05-22 Thread David Winsemius
There are several CRAN Task Views. Some of them should intersect with your 
question. I don’t think your description of the problem suggest that 
multivariate correlation is the best approach.  Some sort of optimization or 
numerical simulation would seem to be more fruitful.

— 
David 
Sent from my iPhone

> On May 22, 2022, at 12:01 PM, Bernard Comcast  
> wrote:
> 
> Its simply a query to know what tools/packages R has for correlating single 
> values with multivalued vectors. If that is outside the scope of the PG then 
> so be it.
> 
> Bernard
> 
> Sent from my iPhone so please excuse the spelling!"
> 
>> On May 22, 2022, at 1:52 PM, Bert Gunter  wrote:
>> 
>> 
>> Please read the posting guide(PG) inked below. Your query sounds more like a 
>> project that requires a paid consultant; if so, this is way beyond the scope 
>> of this list as described in the PG. So don't be too surprised if you don't 
>> get a useful response, which this isn't either of course.
>> 
>> 
>> 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 Sun, May 22, 2022 at 10:40 AM Bernard McGarvey 
>>>>  wrote:
>>> I work in aspects of Cold Chain transportation in the pharmaceutical 
>>> industry. These shippers are used to transport temperature sensitive 
>>> products by surrounding the product load box with insulating materials of 
>>> various sorts. The product temperature has lower and upper allowed limits 
>>> so that when the product temperature hits one of these limits, the shipper 
>>> fails and this failure time is teh shipper duration. If the shipper is 
>>> exposed to very low or very high ambient temperatures during a shipment 
>>> then we expect the duration of the shipper to be low.
>>> 
>>> The particular problem I am currently undertaking is to create a fast way 
>>> to predict the duration of a shipping container when it is exposed to a 
>>> given ambient temperature.
>>> 
>>> Currently we have the ability to predict such durations using a calibrated 
>>> 3D model (typically a finite element or finite volume transient 
>>> representation of the heat transfer equations). These models can predict 
>>> the temperature of the pharmaceutical product within the shipper over time 
>>> as it is exposed to an external ambient temperature profile. .
>>> 
>>> The problem with the 3D model is that it takes significant CPU time and the 
>>> software is specialized. What I would like to do is to be able to enter the 
>>> ambient profile into a spreadsheet and then be able to predict the expected 
>>> duration of the shipper using a simple calculation that can be implemented 
>>> in the spreadsheet environment. The idea I had was as follows:
>>> 
>>> 1. Create a selection of ambient temperature profiles covering a wide range 
>>> of ambient behavior. Ensure the profiles are long enough so that the 
>>> shipper is sure to fail at some time during the ambient profile.
>>> 
>>> 2. Use the 3D model to predict the shipper duration for the selection of 
>>> ambient temperature profiles in (1). Each ambient temperature will have its 
>>> own duration.
>>> 
>>> 3. Since only the ambient temperatures up to the duration time are 
>>> relevant, truncate each ambient profile for times greater than the duration.
>>> 
>>> 4. Step (3) means that the ambient temperature profiles will have different 
>>> lengths corresponding to the different durations.
>>> 
>>> 5. Use the truncated ambient profiles and their corresponding durations to 
>>> build some type of empirical model relating the duration to the 
>>> corresponding ambient profile.
>>> 
>>> Some other notes:
>>> 
>>> a. We know from our understanding of how the shippers are constructed and 
>>> the laws of heat transfer that some sections of the ambient profile will 
>>> have more of an impact on determining the duration that other sections.
>>> b. Just correlating the duration with the average temperature of the 
>>> profile can predict the duration for that profile to within 10-15%. We are 
>>> looking for the ability to get within 2% of the shipper duration predicted 
>>> by the 3D model.
>>> 
>>> What I am looking for is suggestions as to how to approach ste

Re: [R] How to obtain named vector from single-column data frame?

2022-05-06 Thread David Carlson via R-help
Just use
names(unlist(df[, "VarY", drop=FALSE]))
# [1] "VarY1" "VarY2" "VarY3" "VarY4" "VarY5"

When you extract a single column from a data frame it converts it to a
vector by default.

David L Carlson



On Fri, May 6, 2022 at 1:05 PM Hooiveld, Guido 
wrote:

> Dear all, I wrote a some code in which I 'convert' a data frame to a named
> vector using the function unlist(). This works very nicely for my use case,
> because each entry of the resulting vector is named after the column name
> of the data frame,
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
>
> Dear all,
>
> I wrote a some code in which I 'convert' a data frame to a named vector using 
> the function unlist(). This works very nicely for my use case, because each 
> entry of the resulting vector is named after the column name of the data 
> frame, with a number automatically appended. I am using these names for the 
> subsequent part of my code.
>
> However, I noticed that when I subset the data frame so it contains only a 
> single column, the naming of the vector (as described above) doesn't occur 
> anymore (i.e. names() = NULL). This breaks my downstream code. Any suggestion 
> on how to still obtain a named vector from such single-column data frame?
>
> Thanks,
> Guido
>
>
> > df <- data.frame("VarX" = c("A",2,"D",2,1) ,
> +  "VarY" = c(5,7,9,8,7) )
> >
> > unlist(df) #nice!
> VarX1 VarX2 VarX3 VarX4 VarX5 VarY1 VarY2 VarY3 VarY4 VarY5
>   "A"   "2"   "D"   "2"   "1"   "5"   "7"   "9"   "8"   "7"
> > names(unlist(df))
>  [1] "VarX1" "VarX2" "VarX3" "VarX4" "VarX5" "VarY1" "VarY2" "VarY3" "VarY4"
> [10] "VarY5"
> >
> >
> >
> > unlist(df[, "VarY"]) #where are the names now? Expected them to be "VarY1" 
> > ... "VarY5"
> [1] 5 7 9 8 7
> > names(unlist(df[, "VarY"]))
> NULL
> >
>
> __r-h...@r-project.org mailing 
> list -- To UNSUBSCRIBE and more, 
> seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!EUndg3P-mraBuPMXbhvgZkIok13frVGjcD2ebHWlTHVrETkmNqEfYu0YPT6BEisdkhcijOfxsGlfsGoPXEBOEqSIog$
> PLEASE do read the posting guide 
> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!EUndg3P-mraBuPMXbhvgZkIok13frVGjcD2ebHWlTHVrETkmNqEfYu0YPT6BEisdkhcijOfxsGlfsGoPXECRkw_-4w$
> 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] legend in plot

2022-05-06 Thread David Carlson via R-help
You can't get exactly what you want with base graphics, but you can get
close by defining line types and colors outside the plot command:

x <- seq(-3, 3, by = 0.01)
lns <- 1:2
clr <- 1:2
matplot(x, cbind(x, x^2), type="l", lty=lns, col=clr)
legend("bottomright", legend = c("x", expression(x^2)), lty = lns, col =
clr, bty = "n")

David L Carlson

legend("bottomright", legend = c("x", expression(x^2)), lty = lns, col =
clr, bty = "n")


On Thu, May 5, 2022 at 4:56 PM Jim Lemon  wrote:

> Hi Naresh, Have a look at the emptyspace function in the plotrix package.
> This returns the center of the largest empty space on the plot. Jim On Thu,
> May 5, 2022 at 10:41 PM Naresh Gurbuxani 
> wrote: >
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
>
> Hi Naresh,
> Have a look at the emptyspace function in the plotrix package. This
> returns the center of the largest empty space on the plot.
>
> Jim
>
> On Thu, May 5, 2022 at 10:41 PM Naresh Gurbuxani
>  wrote:
> >
> > Is it possible to define legend in the plot command?  That will ensure that 
> > legend is correctly associated with the points or lines in the plot.
> >
> > # I can do this
> > x <- seq(-3, 3, by = 0.01)
> > plot(x, x, type = "l")
> > lines(x, x^2, lty = 2, col = 2)
> > # In legend command, I need to remember that x^2 is lty = 2 and col = 2
> > legend("bottomright", legend = c("x", expression(x^2)), lty = c(1, 2), col 
> > = c(1, 2), bty = "n")
> >
> > # I want to do something like this
> > plot(x, x, type = "l", label = "x")
> > lines(x, x^2, lty = 2, col = 2, label = expression(x^2))
> > # legend command already knows the legend for each line
> > legend("bottomright", bty = "n")
> >
> > Thanks,
> > Naresh
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!EYg6PPgiIfAXtUtQ0ynC6qvjRRReVyXbg66szoAq-KGtyrB_Aw3y2jP6nK_opXOaTsRO6SIjfuBoYZCPlaA$
> > PLEASE do read the posting guide 
> > https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!EYg6PPgiIfAXtUtQ0ynC6qvjRRReVyXbg66szoAq-KGtyrB_Aw3y2jP6nK_opXOaTsRO6SIjfuBoIIlYb4A$
> > and provide commented, minimal, self-contained, reproducible code.
>
> __r-h...@r-project.org mailing 
> list -- To UNSUBSCRIBE and more, 
> seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!EYg6PPgiIfAXtUtQ0ynC6qvjRRReVyXbg66szoAq-KGtyrB_Aw3y2jP6nK_opXOaTsRO6SIjfuBoYZCPlaA$
> PLEASE do read the posting guide 
> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!EYg6PPgiIfAXtUtQ0ynC6qvjRRReVyXbg66szoAq-KGtyrB_Aw3y2jP6nK_opXOaTsRO6SIjfuBoIIlYb4A$
> 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] installing an R package

2022-04-28 Thread David Winsemius
Pretty sure the right way to install that package is with the Bioc installer. 

Sent from my iPhone

> On Apr 28, 2022, at 3:35 PM, Bogdan Tanasa  wrote:
> 
> HI everyone,
> 
> I must transfer a package from one platform (AWS) where I was able to
> install the package
> 
> to another platform (local PC), where I am not able to install the package.
> 
> The package is called : BSgenome.Hsapiens.UCSC.hg38
> 
> Is there a way to transfer the files from BSgenome.Hsapiens.UCSC.hg38
> folder (below) from AWS to local PC and get it to run ? Thanks !
> 
> 4.0KDESCRIPTION
> 4.0KINDEX
> 28K Meta
> 4.0KNAMESPACE
> 20K R
> 784Mextdata
> 24K help
> 12K html
> 
>[[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] Model To Simulate Dice Roll

2022-04-22 Thread David Carlson via R-help
Sorry, The last three lines should read:

all <- apply(results, 1, function(x) length(intersect(x,
seq(sides)))==sides)
sum(all)/reps
results <- as.data.frame(results)

To generalize them for values of sides other than 6.

On Fri, Apr 22, 2022 at 11:05 PM Paul Bernal  wrote:

> Thank you so much David! El El vie, 22 de abr. de 2022 a la(s) 11:04 p.
> m., David Carlson  escribió: Since the rolls are
> independent, it is not necessary to separate the rolls into two stages:
> sides <- 6 ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
> Thank you so much David!
>
> El El vie, 22 de abr. de 2022 a la(s) 11:04 p. m., David Carlson <
> dcarl...@tamu.edu> escribió:
>
>> Since the rolls are independent, it is not necessary to separate the
>> rolls into two stages:
>>
>> sides <- 6
>> months <- 12
>> reps <- 100
>>
>> set.seed(2022)
>> results <- matrix(sample.int
>> <https://urldefense.com/v3/__http://sample.int__;!!KwNVnqRv!GvZvIF7bCsJmP-MoZAjpwRSwA0SLF9dwlLokWfsqj07fpKB_yoDtZ64yl90ktreESKpQkxnxfP7vuF2jfsHvZA$>(sides,
>> months*reps, replace=TRUE), reps, months, byrow=TRUE)
>> colnames(results) <- month.name
>> <https://urldefense.com/v3/__http://month.name__;!!KwNVnqRv!GvZvIF7bCsJmP-MoZAjpwRSwA0SLF9dwlLokWfsqj07fpKB_yoDtZ64yl90ktreESKpQkxnxfP7vuF14dyuUpA$>
>> all6 <- apply(results, 1, function(x) length(intersect(x, 1:6))==6)
>> sum(all6)/reps
>> # 0.53 which matches Rui's result
>> results <- as.data.frame(results)
>>
>> David L. Carlson
>>
>>
>>
>> On Thu, Apr 21, 2022 at 4:04 AM Rui Barradas 
>> wrote:
>>
>>> Hello, There's an error in my code, inline. Às 07:55 de 21/04/2022, Rui
>>> Barradas escreveu: > Hello, > > For what I understand of the question, the
>>> followng might answer it. > > The functions below roll dice and simulate R
>>> replicates
>>> ZjQcmQRYFpfptBannerStart
>>> This Message Is From an External Sender
>>> This message came from outside your organization.
>>>
>>> ZjQcmQRYFpfptBannerEnd
>>>
>>> Hello,
>>>
>>> There's an error in my code, inline.
>>>
>>> Às 07:55 de 21/04/2022, Rui Barradas escreveu:
>>> > Hello,
>>> >
>>> > For what I understand of the question, the followng might answer it.
>>> >
>>> > The functions below roll dice and simulate R replicates of dice rolls.
>>> > Then 12 (one per month) 6 sided dice rolls are simulated 100 times.
>>> >
>>> > The colMeans/apply computes the empiric probabilities of having all 6
>>> > sides occur in each row, Jan to Dec and a overall probabilty is the mean
>>> > of those probabilities.
>>> >
>>> > The matrix is coerced to data.frame only at the end.
>>> >
>>> >
>>> >
>>> > dice <- function(rolls = 1, ndice = 1, sides = 6) {
>>> >roll <- function(ndice = 1, sides = 6) {
>>> >  sample(seq_len(sides), ndice, replace = TRUE)
>>> >}
>>> >y <- replicate(rolls, roll(ndice = ndice, sides = sides))
>>> >if(is.null(dim(y))) y else colSums(y)
>>> > }
>>> > dice_simul <- function(rolls = 1, ndice = 1, sides = 6, R) {
>>> >if(missing(R)) {
>>> >  stop("number of simulations 'R' is missing with no default.")
>>> >}
>>> >replicate(R, dice(rolls = rolls, ndice = ndice, sides = sides))
>>> > }
>>> >
>>> > dice_rolls <- 100
>>> > #dice_rolls <- 1e6
>>> > num_dice <- 1
>>> > dice_sides <- 6
>>> > months <- 12
>>> >
>>> > set.seed(2022)
>>> > prob_frame <- t(dice_simul(months, num_dice, dice_sides, R = dice_rolls))
>>> > colnames(prob_frame) <- month.name 
>>> > <https://urldefense.com/v3/__http://month.name__;!!KwNVnqRv!GvZvIF7bCsJmP-MoZAjpwRSwA0SLF9dwlLokWfsqj07fpKB_yoDtZ64yl90ktreESKpQkxnxfP7vuF14dyuUpA$>
>>> > head(prob_frame)
>>> >
>>>
>>> # --- wrong
>>> > p <- colMeans(apply(prob_frame, 1, \(x) 1:6 %in% x))
>>> > mean(p)
>>> > # [1] 0.9116667
>>>
>>> This should be
>>>
>>> yes_no <- apply(prob_frame, 1, \(x) all(1:6 %in% x))
>>> p <- mean(yes_no)
>>> p
>>> # [1] 0.53

Re: [R] What is the intended behavior, when subsetting using brackets [ ], when the subset criterion has NA's?

2022-04-06 Thread David Winsemius



On 4/6/22 16:17, Ebert,Timothy Aaron wrote:

Based on the OP's submission I pasted the following into R and tried to run it.

Here is what I think was posted (comments removed):

my_data <- 1:5
my_data
my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria
equals TRUE my_data[my_subset_criteria == T]
my_subset_criteria == T)

Assuming that this is the right code I tried to run it.
The third line " my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria" 
returns an error.



As it should. You put two commands on the same line with no correct 
separator:Either of these should succeed:


my_subset_criteria <- c( F, F, T, NA, NA)
my_subset_criteria

# OR
 
my_subset_criteria <- c( F, F, T, NA, NA) ; my_subset_criteria


(The original poster had the correct syntax.)

--
David




Error: unexpected symbol in " my_subset_criteria <- c( F, F, T, NA, NA) 
my_subset_criteria"

Regards,
Tim

-Original Message-
From: Jeff Newmiller 
Sent: Wednesday, April 6, 2022 5:22 PM
To: r-help@r-project.org; Ebert,Timothy Aaron ; Kelly Thompson 
; r-help@r-project.org
Subject: Re: [R] What is the intended behavior, when subsetting using brackets 
[ ], when the subset criterion has NA's?

[External Email]

Mmmm, ESP on the blink.

WHAT error? from which line of code?

BTW see The R Inferno, section 8.2.32

On April 6, 2022 1:52:47 PM PDT, "Ebert,Timothy Aaron"  wrote:

I get an error with this:
my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria


Tim

-Original Message-
From: R-help  On Behalf Of Kelly Thompson
Sent: Wednesday, April 6, 2022 4:13 PM
To: r-help@r-project.org
Subject: [R] What is the intended behavior, when subsetting using brackets [ ], 
when the subset criterion has NA's?

[External Email]

I noticed that I get different results when subsetting using subset, compared to 
subsetting using  "brackets" when the subset criteria have NA's.

Here's an example

#START OF EXAMPLE
my_data <- 1:5
my_data

my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria

#subsetting using subset returns the data where my_subset_criteria
equals TRUE my_data[my_subset_criteria == T]

#subsetting using brackets returns the data where my_subset_criteria
equals TRUE, and also NA where my_subset_criteria is NA subset(my_data,
my_subset_criteria == T)

#END OF EXAMPLE

This behavior is also mentioned here
https://urldefense.proofpoint.com/v2/url?u=https-3A__statisticaloddsand
ends.wordpress.com_2018_10_07_subsetting-2Din-2Dthe-2Dpresence-2Dof-2Dn
as_=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=NoPFkG
0n9RFRaacmiiQ9Hp1cGniz9ED5YGN11-Jh6rD_zkTTE8e5egsKqzQDMSEW=5lgkxT5A_M
SfElILNk1ZM3RGpcBWpMBu713av1DH1mk=

Q. Is this the intended behavior when subsetting with brackets?

Thank you!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailm
an_listinfo_r-2Dhelp=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRz
sn7AkP-g=NoPFkG0n9RFRaacmiiQ9Hp1cGniz9ED5YGN11-Jh6rD_zkTTE8e5egsKqzQD
MSEW=g9IzSC3WrXPLYjys_RdYSmgUoFFjsbwRJZZodqtDRa0=
PLEASE do read the posting guide
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org
_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsR
zsn7AkP-g=NoPFkG0n9RFRaacmiiQ9Hp1cGniz9ED5YGN11-Jh6rD_zkTTE8e5egsKqzQ
DMSEW=uy6rCSNVehGynLn3ZCpLp_r2gHhoGcya4dbRe-tqQRc=
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailm
an_listinfo_r-2Dhelp=DwIFaQ=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRz
sn7AkP-g=QLbQb6DaELgtR0Qo6aQx51ea30OmGIC0oqVB_naWxmKYlQyw_N81MiAKj_5Z
9TXC=G7rw7ZKvhE_HMF4z5cA5Gsr0C018E51Ov9ye3Ui2GX0=
PLEASE do read the posting guide
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org
_posting-2Dguide.html=DwIFaQ=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsR
zsn7AkP-g=QLbQb6DaELgtR0Qo6aQx51ea30OmGIC0oqVB_naWxmKYlQyw_N81MiAKj_5
Z9TXC=PKD9VZ1n0p_NfoQ2OvbmPEVr14lVwLZx09mOIWPRZmk=
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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ggplot2

2022-04-04 Thread David Winsemius



On 4/4/22 04:39, Ebert,Timothy Aaron wrote:

install.packages("ggplot2")



Depending on your OS, there might be a better chance of success with


install.packages("ggplot2", dependencies=TRUE)

The Linux install process doesn't need this but the binary install on MacOS or 
Windows may need this to prevent the sort of error message that was offered.

--
David


library(ggplot2)

An alternative
install.packages("tidyverse")
library(tidyverse)

The first only installs ggplot2. The alternative installs a bunch of other 
stuff as well.

Tim

-Original Message-
From: R-help  On Behalf Of Richard Vickery
Sent: Sunday, April 3, 2022 12:49 PM
To: R-help@r-project.org
Subject: [R] ggplot2

[External Email]

Hi there,

I am finally getting to some material I had problems with in university, where I was 
introduced to R - one of those that because of time constraints, I had challenges 
figuring out, particularly because I decided long ago on using Fedora Linux. The book, 
"Understanding Statistics Using R" by Andy Field et. al., says to install 
ggplot2 into R and the version of R that the dnf command installs will neigher install 
this package nor 'scales'. The result I get is below, and I attempted installing the 
packages via the tar command, and that neither worked, and I attempted
library("ggplot2") and R said the package was unavailable. What can I do to 
move forward?

Thanks,

Richard

 [[alternative HTML version deleted]]

__
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=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=7xEzNpsPEMvdQLIcBNo-VFJErGQIZfwF2ueg-0lesWT4DSOwIMyZ5deX1XUeO2R2=QTw5eQQCMPK5qxhL7YKJYRMJWwmPSDI4bR9Px8VJrvA=
PLEASE do read the posting guide 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=7xEzNpsPEMvdQLIcBNo-VFJErGQIZfwF2ueg-0lesWT4DSOwIMyZ5deX1XUeO2R2=0kmwSZfq16L-GtPuQa5mSO8VGqauae08iBxm57dPnKI=
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] Question About lm()

2022-02-09 Thread David Winsemius
The models are NOT equivalent. Why would you’ll think they were?

— 
David

Sent from my iPhone

> On Feb 9, 2022, at 11:10 PM, Bromaghin, Jeffrey F via R-help 
>  wrote:
> 
> Hello,
> 
> I was constructing a simple linear model with one categorical (3-levels) and 
> one quantitative predictor variable for a colleague. I estimated model 
> parameters with and without an intercept, sometimes called reference cell 
> coding and cell means coding.
> 
> Model 1: yResp ~ -1 + xCat + xCont
> Model 2: yResp ~ xCat + xCont
> 
> These models are equivalent and the estimated coefficients come out fine, but 
> the R-squared and F statistics returned by summary() differ markedly. I spent 
> some time looking at the code for both lm() and summary.lm() but did not find 
> the source of the difference. aov() and anova() results also differ, so I 
> suspect the issue involves how the sums of squares are being computed. I've 
> also spent some time trying to search online for information on this, without 
> success. I haven't used lm() for quite a while, but my memory is that these 
> differences didn't occur in the distant past when I was teaching.
> 
> Thanks in advance for any insights you might have,
> Jeff
> 
> Jeffrey F. Bromaghin
> Research Statistician
> USGS Alaska Science Center
> 907-786-7086
> Jeffrey Bromaghin, Ph.D. | U.S. Geological Survey 
> (usgs.gov)<https://www.usgs.gov/staff-profiles/jeffrey-bromaghin>
> Ecosystems Analytics | U.S. Geological Survey 
> (usgs.gov)<https://www.usgs.gov/centers/alaska-science-center/science/ecosystems-analytics>
> 
> 
>[[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] Row exclude

2022-01-30 Thread David Carlson via R-help
You need to add "-": ` (dat3 <- dat1[-unique(c(BadName, BadAge,
BadWeight)), ])` which makes the command NOT).

David

On Sun, Jan 30, 2022 at 11:00 AM Val  wrote:

> Thank you David. What about if I want to list the excluded rows? I used
> this (dat3 <- dat1[unique(c(BadName, BadAge, BadWeight)), ]) It did not
> work.The desired output  is,   Alex,  20,  13X  John,  3BC, 175  Jack3, 34,
>  140 ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
> ZjQcmQRYFpfptBannerEnd
> Thank you David.
>
> What about if I want to list the excluded rows?
> I used this
> (dat3 <- dat1[unique(c(BadName, BadAge, BadWeight)), ])
>
> It did not work.The desired output  is,
>   Alex,  20,  13X
>  John,  3BC, 175
>  Jack3, 34,  140
>
> Thank you,
>
> On Sat, Jan 29, 2022 at 10:15 PM David Carlson  wrote:
>
>> It is possible that there would be errors on the same row for different
>> columns. This does not happen in your example. If row 4 was "John6, 3BC,
>> 175X" then row 4 would be included 3 times, but we only need to remove it
>> once. Removing the duplicates is not necessary since R would not get
>> confused, but length(unique(c(BadName, BadAge, BadWeight)) indicates how
>> many lines are being removed.
>>
>> David
>>
>> On Sat, Jan 29, 2022 at 8:32 PM Val  wrote:
>>
>>> Thank you David for your help. I just have one question on this. What is
>>> the purpose of  using the "unique" function on this?   (dat2 <-
>>> dat1[-unique(c(BadName, BadAge, BadWeight)), ])   I got the same result
>>> without using it. ZjQcmQRYFpfptBannerStart
>>> This Message Is From an External Sender
>>> This message came from outside your organization.
>>> ZjQcmQRYFpfptBannerEnd
>>> Thank you David for your help.
>>>
>>> I just have one question on this. What is the purpose of  using the
>>> "unique" function on this?
>>>   (dat2 <- dat1[-unique(c(BadName, BadAge, BadWeight)), ])
>>>
>>> I got the same result without using it.
>>>(dat2 <- dat1[-(c(BadName, BadAge, BadWeight)), ])
>>>
>>> My concern is when I am applying this for the large data set the
>>> "unique"  function may consume resources(time  and memory).
>>>
>>> Thank you.
>>>
>>> On Sat, Jan 29, 2022 at 12:30 AM David Carlson 
>>> wrote:
>>>
>>>> Given that you know which columns should be numeric and which should be
>>>> character, finding characters in numeric columns or numbers in character
>>>> columns is not difficult. Your data frame consists of three character
>>>> columns so you can use regular expressions as Bert mentioned. First
>>>> you should strip the whitespace out of your data:
>>>>
>>>> dat1 <-read.table(text="Name, Age, Weight
>>>>   Alex,  20,  13X
>>>>   Bob,  25,  142
>>>>   Carol, 24,  120
>>>>   John,  3BC,  175
>>>>   Katy,  35,  160
>>>>   Jack3, 34,  140",sep=",", header=TRUE, stringsAsFactors=FALSE,
>>>> strip.white=TRUE)
>>>>
>>>> Now check to see if all of the fields are character as expected.
>>>>
>>>> sapply(dat1, typeof)
>>>> #Name Age      Weight
>>>> # "character" "character" "character"
>>>>
>>>> Now identify character variables containing numbers and numeric
>>>> variables containing characters:
>>>>
>>>> BadName <- which(grepl("[[:digit:]]", dat1$Name))
>>>> BadAge <- which(grepl("[[:alpha:]]", dat1$Age))
>>>> BadWeight <- which(grepl("[[:alpha:]]", dat1$Weight))
>>>>
>>>> Next remove those rows:
>>>>
>>>> (dat2 <- dat1[-unique(c(BadName, BadAge, BadWeight)), ])
>>>> #Name Age Weight
>>>> #  2   Bob  25142
>>>> #  3 Carol  24120
>>>> #  5  Katy  35160
>>>>
>>>> You still need to convert Age and Weight to numeric, e.g. dat2$Age <-
>>>> as.numeric(dat2$Age).
>>>>
>>>> David Carlson
>>>>
>>>>
>>>> On Fri, Jan 28, 2022 at 11:59 PM Bert Gunter 
>>>> wrote:
>>>>
>>>>> As character 'polluted' entries will cause a column to be read in (via
>>>>> read.table and rel

Re: [R] Row exclude

2022-01-29 Thread David Carlson via R-help
It is possible that there would be errors on the same row for different
columns. This does not happen in your example. If row 4 was "John6, 3BC,
175X" then row 4 would be included 3 times, but we only need to remove it
once. Removing the duplicates is not necessary since R would not get
confused, but length(unique(c(BadName, BadAge, BadWeight)) indicates how
many lines are being removed.

David

On Sat, Jan 29, 2022 at 8:32 PM Val  wrote:

> Thank you David for your help. I just have one question on this. What is
> the purpose of  using the "unique" function on this?   (dat2 <-
> dat1[-unique(c(BadName, BadAge, BadWeight)), ])   I got the same result
> without using it. ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
> ZjQcmQRYFpfptBannerEnd
> Thank you David for your help.
>
> I just have one question on this. What is the purpose of  using the
> "unique" function on this?
>   (dat2 <- dat1[-unique(c(BadName, BadAge, BadWeight)), ])
>
> I got the same result without using it.
>(dat2 <- dat1[-(c(BadName, BadAge, BadWeight)), ])
>
> My concern is when I am applying this for the large data set the "unique"
> function may consume resources(time  and memory).
>
> Thank you.
>
> On Sat, Jan 29, 2022 at 12:30 AM David Carlson  wrote:
>
>> Given that you know which columns should be numeric and which should be
>> character, finding characters in numeric columns or numbers in character
>> columns is not difficult. Your data frame consists of three character
>> columns so you can use regular expressions as Bert mentioned. First you
>> should strip the whitespace out of your data:
>>
>> dat1 <-read.table(text="Name, Age, Weight
>>   Alex,  20,  13X
>>   Bob,  25,  142
>>   Carol, 24,  120
>>   John,  3BC,  175
>>   Katy,  35,  160
>>   Jack3, 34,  140",sep=",", header=TRUE, stringsAsFactors=FALSE,
>> strip.white=TRUE)
>>
>> Now check to see if all of the fields are character as expected.
>>
>> sapply(dat1, typeof)
>> #Name Age  Weight
>> # "character" "character" "character"
>>
>> Now identify character variables containing numbers and numeric variables
>> containing characters:
>>
>> BadName <- which(grepl("[[:digit:]]", dat1$Name))
>> BadAge <- which(grepl("[[:alpha:]]", dat1$Age))
>> BadWeight <- which(grepl("[[:alpha:]]", dat1$Weight))
>>
>> Next remove those rows:
>>
>> (dat2 <- dat1[-unique(c(BadName, BadAge, BadWeight)), ])
>> #Name Age Weight
>> #  2   Bob  25142
>> #  3 Carol  24120
>> #  5  Katy  35160
>>
>> You still need to convert Age and Weight to numeric, e.g. dat2$Age <-
>> as.numeric(dat2$Age).
>>
>> David Carlson
>>
>>
>> On Fri, Jan 28, 2022 at 11:59 PM Bert Gunter 
>> wrote:
>>
>>> As character 'polluted' entries will cause a column to be read in (via
>>> read.table and relatives) as factor or character data, this sounds like a
>>> job for regular expressions. If you are not familiar with this subject,
>>> time to learn. And, yes, ZjQcmQRYFpfptBannerStart
>>> This Message Is From an External Sender
>>> This message came from outside your organization.
>>> ZjQcmQRYFpfptBannerEnd
>>>
>>> As character 'polluted' entries will cause a column to be read in (via
>>> read.table and relatives) as factor or character data, this sounds like a
>>> job for regular expressions. If you are not familiar with this subject,
>>> time to learn. And, yes, some heavy lifting will be required.
>>> See ?regexp for a start maybe? Or the stringr package?
>>>
>>> Cheers,
>>> Bert
>>>
>>>
>>>
>>>
>>> On Fri, Jan 28, 2022, 7:08 PM Val  wrote:
>>>
>>> > Hi All,
>>> >
>>> > I want to remove rows that contain a character string in an integer
>>> > column or a digit in a character column.
>>> >
>>> > Sample data
>>> >
>>> > dat1 <-read.table(text="Name, Age, Weight
>>> >  Alex,  20,  13X
>>> >  Bob,   25,  142
>>> >  Carol, 24,  120
>>> >  John,  3BC,  175
>>> >  Katy,  35,  160
>>> >  Jack3, 34,  140",sep=",",header=TRUE,stringsAsFactors=F)
>>> >
>>> > If the Age/Weight column contains any character(s) then remove
>>>

Re: [R] Speed up studentized confidence intervals ?

2021-12-29 Thread David Winsemius



On 12/29/21 11:08 AM, varin sacha via R-help wrote:

Dear David,
Dear Rui,

Many thanks for your response. It perfectly works for the mean. Now I have a 
problem with my R code for the median. Because I always get 1 (100%) coverage 
probability that is more than very strange. Indeed, considering that an 
interval whose lower limit is the smallest value in the sample and whose upper 
limit is the largest value has 1/32 + 1/32 = 1/16 probability of non-coverage, 
implying that the confidence of such an interval is 15/16 rather than 1 (100%), 
I suspect that the confidence interval I use for the median is not correctly 
defined for n=5 observations, and likely contains all observations in the 
sample ? What is wrong with my R code ?



Seems to me that doing  a bootstrap within a `replicate` call is not 
needed. (Use one or the other as a mechanism for replication.


Here's what I would consider to be a "bootstrap" operation for 
estimating a 95% CI on the Gamma distributed population you created:


Used a sample size of 1 rather than 10


> quantile( replicate( 1000, {median(sample(s,5))}) , .5+c(-0.475,0.475))
 2.5% 97.5%
0.1343071 0.6848352

This is using boot::boot to calculate medians of samples of size 5

> med <- function( data, indices) {
+ d <- data[indices[1:5]] # allows boot to select sample
+ return( median(d))
+ }
> res <- boot(data=s, med, 1000)

> str(res)
List of 11
 $ t0   : num 0.275
 $ t    : num [1:1000, 1] 0.501 0.152 0.222 0.11 0.444 ...
 $ R    : num 1000
 $ data : num [1:1] 0.7304 0.4062 0.1901 0.0275 0.2748 ...
 $ seed : int [1:626] 10403 431 -118115842 -603122380 -2026881868 
758139796 1148648893 -1161368223 1814605964 -1456558535 ...

 $ statistic:function (data, indices)
  ..- attr(*, "srcref")= 'srcref' int [1:8] 1 8 4 1 8 1 1 4
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' 


 $ sim  : chr "ordinary"
 $ call : language boot(data = s, statistic = med, R = 1000)
 $ stype    : chr "i"
 $ strata   : num [1:1] 1 1 1 1 1 1 1 1 1 1 ...
 $ weights  : num [1:1] 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 
1e-04 1e-04 1e-04 ...

 - attr(*, "class")= chr "boot"
 - attr(*, "boot_type")= chr "boot"

> quantile( res$t , .5+c(-0.475,0.475))
 2.5% 97.5%
0.1283309 0.6821874






library(boot)

s=rgamma(n=10,shape=2,rate=5)
median(s)

N <- 100
out <- replicate(N, {
a<- sample(s,size=5)
median(a)

dat<-data.frame(a)
med<-function(d,i) {
temp<-d[i,]
median(temp)
}

   boot.out <- boot(data = dat, statistic = med, R = 1)
   boot.ci(boot.out, type = "bca")$bca[, 4:5]
})

#coverage probability
median(out[1, ] < median(s) & median(s) < out[2, ])





Le jeudi 23 décembre 2021, 14:10:36 UTC+1, Rui Barradas  
a écrit :





Hello,

The code is running very slowly because you are recreating the function
in the replicate() loop and because you are creating a data.frame also
in the loop.

And because in the bootstrap statistic function med() you are computing
the variance of yet another loop. This is probably statistically wrong
but like David says, without a problem description it's hard to say.

Also, why compute variances if they are never used?

Here is complete code executing in much less than 2:00 hours. Note that
it passes the vector a directly to med(), not a df with just one column.


library(boot)

set.seed(2021)
s <- sample(178:798, 10, replace = TRUE)
mean(s)

med <- function(d, i) {
   temp <- d[i]
   f <- mean(temp)
   g <- var(temp)
   c(Mean = f, Var = g)
}

N <- 1000
out <- replicate(N, {
   a <- sample(s, size = 5)
   boot.out <- boot(data = a, statistic = med, R = 1)
   boot.ci(boot.out, type = "stud")$stud[, 4:5]
})
mean(out[1, ] < mean(s) & mean(s) < out[2, ])
#[1] 0.952



Hope this helps,

Rui Barradas

Às 11:45 de 19/12/21, varin sacha via R-help escreveu:

Dear R-experts,

Here below my R code working but really really slowly ! I need 2 hours with my 
computer to finally get an answer ! Is there a way to improve my R code to 
speed it up ? At least to win 1 hour ;=)

Many thanks


library(boot)

s<- sample(178:798, 10, replace=TRUE)
mean(s)

N <- 1000
out <- replicate(N, {
a<- sample(s,size=5)
mean(a)
dat<-data.frame(a)

med<-function(d,i) {
temp<-d[i,]
f<-mean(temp)
g<-var(replicate(50,mean(sample(temp,replace=T
return(c(f,g))

}

     boot.out <- boot(data = dat, statistic = med, R = 1)
     boot.ci(boot.out, type = "stud")$stud[, 4:5]
})
mean(out[1,] < mean(s) & mean(s) < out[2,])


___

Re: [R] Error Awareness

2021-12-26 Thread David Winsemius



On 12/23/21 3:11 AM, Stephen H. Dawson, DSL via R-help wrote:

Hi,


I am thinking about awareness of errors when an R script runs.

My concern is I have an error-free script. I run it for months on end 
without problems. Then, something changes somewhere causing an error. 
My wonderment is how R will tell me I had an error in the script, but 
the rest of the script ran without impairment.


QUESTIONS
What are some of the more helpful options available to an R developer 
to capture errors in a script run?


What are some of the best processes to implement these more helpful 
options?


See this insight from Spencer Graves from Feb 2011 on Rhelp:

https://stat.ethz.ch/pipermail/r-help/2011-February/268512.html





Thanks,


__
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] Speed up studentized confidence intervals ?

2021-12-22 Thread David Winsemius
I’m wondering if this is an X-Y problem. (A request to do X when the real 
problem should be doing Y. ) You haven’t explained the goals in natural or 
mathematical language which is leaving me to wonder why you are doing either 
sampling or replication (much less doing both within each iteration in the the 
function given to boot. )

— 
David

Sent from my iPhone

> On Dec 19, 2021, at 3:50 AM, varin sacha via R-help  
> wrote:
> 
> Dear R-experts,
> 
> Here below my R code working but really really slowly ! I need 2 hours with 
> my computer to finally get an answer ! Is there a way to improve my R code to 
> speed it up ? At least to win 1 hour ;=)
> 
> Many thanks
> 
> 
> library(boot)
> 
> s<- sample(178:798, 10, replace=TRUE)
> mean(s)
> 
> N <- 1000
> out <- replicate(N, {
> a<- sample(s,size=5)
> mean(a)
> dat<-data.frame(a)
> 
> med<-function(d,i) {
> temp<-d[i,]
> f<-mean(temp)
> g<-var(replicate(50,mean(sample(temp,replace=T
> return(c(f,g))
> 
> }
> 
>   boot.out <- boot(data = dat, statistic = med, R = 1)
>   boot.ci(boot.out, type = "stud")$stud[, 4:5]
> })
> mean(out[1,] < mean(s) & mean(s) < out[2,]) 
> 
> 
> __
> 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   >