Re: [R] x[0]: Can '0' be made an allowed index in R?

2024-04-23 Thread Jeff Newmiller via R-help
While I certainly think using negative indices to denote element exclusion is a 
cool feature, I think people wanting to use zero-based indexes probably are not 
planning to use that feature. Python uses negative numbers to index from the 
end, which is a completely different use of negative indexes with the exclusion 
feature that R users just happily ignore. It is only the possible surprise that 
exclusion doesn't work consistently that is relevant here.

I would hope that uses of alternate indexing schemes in most packages be 
wrapped inside functions as much as possible so that R users don't have to get 
dragged into this paradigm shift to make use of those algorithms.

On April ,
>> v
>[0,] [1,] [2,] [3,] [4,] [5,] [6,] [7,] [8,] [9,]
>   123456789   10
>
>> dim(v)
>[1] 10
>
>> v[-1]
>[1]  1  3  4  5  6  7  8  9 10
>
>> v[-0]
>[1] 1
>
>Best,
> John
>
>On 2024-04-23 9:03 a.m., Peter Dalgaard via R-help wrote:
>> Caution: External email.
>> 
>> 
>> Doesn't sound like you got the point. x[-1] normally removes the first 
>> element. With 0-based indices, this cannot work.
>> 
>> - pd
>> 
>>> On 22 Apr 2024, at 17:31 , Ebert,Timothy Aaron  wrote:
>>> 
>>> You could have negative indices. There are two ways to do this.
>>> 1) provide a large offset.
>>> Offset <- 30
>>> for (i in -29 to 120) { print(df[i+Offset])}
>>> 
>>> 
>>> 2) use absolute values if all indices are negative.
>>> for (i in -200 to -1) {print(df[abs(i)])}
>>> 
>>> Tim
>>> 
>>> 
>>> 
>>> -Original Message-
>>> From: R-help  On Behalf Of Peter Dalgaard via 
>>> R-help
>>> Sent: Monday, April 22, 2024 10:36 AM
>>> To: Rolf Turner 
>>> Cc: R help project ; Hans W 
>>> Subject: Re: [R] x[0]: Can '0' be made an allowed index in R?
>>> 
>>> [External Email]
>>> 
>>> Heh. Did anyone bring up negative indices yet?
>>> 
>>> -pd
>>> 
 On 22 Apr 2024, at 10:46 , Rolf Turner  wrote:
 
 
 See fortunes::fortune(36).
 
 cheers,
 
 Rolf Turner
 
 --
 Honorary Research Fellow
 Department of Statistics
 University of Auckland
 Stats. Dep't. (secretaries) phone:
 +64-9-373-7599 ext. 89622
 Home phone: +64-9-480-4619
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat/
 .ethz.ch%2Fmailman%2Flistinfo%2Fr-help=05%7C02%7Ctebert%40ufl.edu
 %7C79ca6aadcaee4aa3241308dc62d986f6%7C0d4da0f84a314d76ace60a62331e1b84
 %7C0%7C0%7C638493933686698527%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
 MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=
 wmv9OYcMES0nElT9OAKTdjBk%2BB55bQ7BjxOuaVVkPg4%3D=0
 PLEASE do read the posting guide
 http://www.r/
 -project.org%2Fposting-guide.html=05%7C02%7Ctebert%40ufl.edu%7C79
 ca6aadcaee4aa3241308dc62d986f6%7C0d4da0f84a314d76ace60a62331e1b84%7C0%
 7C0%7C638493933686711061%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL
 CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=AP78X
 nfKrX6B0YVM0N76ty9v%2Fw%2BchHIytw33X7M9umE%3D=0
 and provide commented, minimal, self-contained, reproducible code.
>>> 
>>> --
>>> Peter Dalgaard, Professor,
>>> Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 
>>> Frederiksberg, Denmark
>>> Phone: (+45)38153501
>>> Office: A 4.23
>>> Email: pd@cbs.dk  Priv: pda...@gmail.com
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> --
>> Peter Dalgaard, Professor,
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Office: A 4.23
>> Email: pd@cbs.dk  Priv: pda...@gmail.com
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] passing a modified argument to an S3 method

2024-04-20 Thread Jeff Newmiller via R-help
The parameters in a specific call to a function are stored in a special list 
which is used to move/copy data from the calling environment into the 
environment created for a particular function call.

UseMethod does not act like a normal function call... it does a kind of magic 
substitution of the implementation method `test.default` into the call stack 
where the generic function `test` was. The argument list remains, but the 
environment associated with the generic function `test` is discarded in the 
process. The argument list was never actually modified in `test`... just the 
environment.

You are expected to think of `test` as a placeholder... a kind of abstract 
method that doesn't actually do anything other than map from a generic method 
to an implementation method. Your goal of adding shared behavior this way is 
not possible.

I recommend reading Advanced R in book form or online to help you navigate R 
behavior like this.

On April 20, 2024 8:51:23 AM PDT, Bert Gunter  wrote:
>I do not understand what your goal is here (more context may be helpful,
>perhaps to others rather than me). So I doubt this is what you want, but
>here is a guess -- no need to respond if it is unhelpful:
>
>## test.default returns NULL if object "y" not found in **calling
>environment and enclosures**;
>## otherwise y.
>
>test <- function(x){
>   UseMethod("test")
>}
>test.default <- function(x){
>   tryCatch(y, error = function(e)NULL)
>}
>
>## y not found
>test(x=3)
>NULL
>
>## y found
>> y <- 'abcd'
>> test(x = 3)
>[1] "abcd"
>
>Cheers,
>Bert
>
>
>
>
>On Sat, Apr 20, 2024 at 4:23 AM CRAN.r via R-help 
>wrote:
>
>> Is there a way to pass a modified argument from an S3 generic to a
>> method?  Here's a non-working example that I want to return "abcd".
>>
>>   test <- function(x, y = NULL){
>> y <- "abcd"
>> UseMethod("test")
>>   }
>>   test.default <- function(x, y = NULL) y
>>   test(x = 3)
>>
>> Is that possible? I've looked around a lot, but can't find any examples or
>> discussion.
>>
>> Jay
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

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


Re: [R] [Tagged] Re: Import multiple tif raster

2024-04-18 Thread Jeff Newmiller via R-help
Your original code with relative path would also work if you did not put the 
leading slash.

On April 18, 2024 10:04:04 AM PDT, "SIBYLLE STÖCKLI via R-help" 
 wrote:
>Dear community
>Dear Ivan
>
>Thanks a lot. The code works now. Solution: direct and full path to the .tif 
>files.
>I confused back and forward slash
>
>
>#first import all files in a single folder as a list 
>rastlist <- list.files(path = "C:/Users/Sibylle 
>Stöckli/Desktop/NCCS_Impacts_Lot2_2022/InVEST/Species_Input/valpar_bee_presence",
> pattern='.tif$', all.files= T, full.names= T)
>
>At the end I got a warning
>#to run a function on an individual raster e.g., plot 
>> boxplot(allrasters[[1]])
>> 
>> p<-boxplot(allrasters[[1]])
>Warning message:
>In .local(x, ...) : taking a sample of 1e+05 cells
>> 
>Not all of the characters in C:/Users/Sibylle 
>Stöckli/Desktop/Test_Rasterfile.R could be encoded using ASCII. To save using 
>a different encoding, choose "File | Save with Encoding..." from the main menu.
>>
>
>Kind regards
>Sibylle
>
>-Original Message-
>From: R-help  On Behalf Of SIBYLLE STÖCKLI via 
>R-help
>Sent: Thursday, April 18, 2024 6:48 PM
>To: 'Ivan Krylov' ; 'SIBYLLE STÖCKLI via R-help' 
>
>Subject: Re: [R] Import multiple tif raster
>
>Dear Ivan
>
>Thanks a lot.
>
>I tried now to provide the full path. However probably the "ö" in the path 
>produces the error, would that be possible?
>
>> #first import all files in a single folder as a list rastlist <- 
>> list.files(path = "C:\Users\Sibylle 
>> Stöckli\Desktop\NCCS_Impacts_Lot2_2022\InVEST\Species_Input\valpar_bee
>> _presence", pattern='.tif$', all.files= T, full.names= T)
>Error: '\U' used without hex digits in character string (:1:35)
>
>Kind regards
>Sibylle
>
>-Original Message-
>From: Ivan Krylov 
>Sent: Thursday, April 18, 2024 2:39 PM
>To: SIBYLLE STÖCKLI via R-help 
>Cc: sibylle.stoec...@gmx.ch
>Subject: Re: [R] Import multiple tif raster
>
>В Thu, 18 Apr 2024 11:08:33 +0200
>SIBYLLE STÖCKLI via R-help  пишет:
>
>> > #to check the index numbers of all imported raster list elements 
>> > allrasters
>> list()
>> > 
>> > #call single raster element
>> > allrasters[[1]]
>> Error in allrasters[[1]] : subscript out of bounds
>
>`allrasters` is an empty list, so it doesn't have a first item.
>Therefore, allrasters[[1]] is an error. Why is this so? Probably because 
>list.files(...) above returned an empty vector.
>
>Check rastlist and/or length(rastlist). Make sure that the path you're giving 
>to list.files (the one starting with
>/NCCS_Impacts_Lot2_2022/InVEST/...) exists on your computer. Did you mean to 
>start it with a slash, making it an absolute path starting from the root of 
>the filesystem?
>
>--
>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.

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


Re: [R] missing() fails to detect missing

2024-04-17 Thread Jeff Newmiller via R-help
Fascinating. Or, well, not.

Failing to use a method signature that is compatible with the generic is a 
no-no. So your bug seems to me to be outside the bounds of how R is supposed to 
be used. So don't do that.

On April 17, 2024 4:25:38 PM PDT, "Boylan, Ross via R-help" 
 wrote:
>When a generic (S4) has an argument with a default followed by ..., missing() 
>doesn't seem to work if the method omits the ...
>Sample---
>foo <- function(x, y=0, ...){
>  "you are very generic"
>}
>
># no ... in function arguments
>setMethod("foo", signature="character", function(x, y=0){
>  if (missing(y))
>return("must give y for character")
>  y
>})
>
>setMethod("foo", signature="numeric", function(x, y=0, ...){
>  if (missing(y))
>return("must give y for numeric")
>  y
>})
>
>print(foo("a"))  #[1] 0
>print(foo(0))#[1] "must give y for numeric"
>--
>It's the result for foo("a") I'm puzzled by, since missing(y) does not 
>evaluate to TRUE.
>
>Background
>==
>The methods documentation has 2 points on which the above definitions may fail.
>
>1. The generic has regular arguments and ... arguments.  But dotsMethods docs 
>say
>> either the signature of the generic function is "..." only, or it
>> does not contain "..."
>Since the arguments in ... are not part of the signatures I think I'm OK, but 
>another reading is that
>one just shouldn't mix ... and other arguments.
>
>2. setMethod docs say
>> The definition must be a function with the same formal arguments as the 
> generic; however, setMethod() will handle methods that add arguments, if ... 
> is a formal argument to the generic.
>Since the initial definition has arguments x, y, ... and the first method 
>definition has only x, y, the arguments don't match.  So maybe that's the 
>problem.
>
>I don't know if the fact that y has a default value matters.
>
>The real code has a function f that ordinarily requires an additional piece of 
>information, y, to compute a result.  But for one class, the result doesn't 
>depend on y and so that argument may be omitted.
>
>Context
>==
>R 4.3.3 on MS-Windows under RStudio 2023.12.1 build 402.
>
>Thanks for any insights.
>Ross
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Output of tapply function as data frame: Problem Fixed

2024-03-28 Thread Jeff Newmiller via R-help
I would guess your version of R is earlier than 4.1, when the built-in pipe was 
introduced to the language

On March 28, 2024 6:43:05 PM PDT, Ogbos Okike  wrote:
>Dear Rui,
>Thanks again for resolving this. I have already started using the version
>that works for me.
>
>But to clarify the second part, please let me paste the what I did and the
>error message:
>
>> set.seed(2024)
>> data <- data.frame(
>+Date = sample(seq(Sys.Date() - 5, Sys.Date(), by = "1 days"), 100L,
>+ TRUE),
>+count = sample(10L, 100L, TRUE)
>+ )
>>
>> # coerce tapply's result to class "data.frame"
>> res <- with(data, tapply(count, Date, mean)) |> as.data.frame()
>Error: unexpected '>' in "res <- with(data, tapply(count, Date, mean)) |>"
>> # assign a dates column from the row names
>> res$Date <- row.names(res)
>Error in row.names(res) : object 'res' not found
>> # cosmetics
>> names(res)[2:1] <- names(data)
>Error in names(res)[2:1] <- names(data) : object 'res' not found
>> # note that the row names are still tapply's names vector
>> # and that the columns order is not Date/count. Both are fixed
>> # after the calculations.
>> res
>
>You can see that the error message is on the pipe. Please, let me know
>where I am missing it.
>Thanks.
>
>On Wed, Mar 27, 2024 at 10:45 PM Rui Barradas  wrote:
>
>> Às 08:58 de 27/03/2024, Ogbos Okike escreveu:
>> > Dear Rui,
>> > Nice to hear from you!
>> >
>> > I am sorry for the omission and I have taken note.
>> >
>> > Many thanks for responding. The second solution looks elegant as it
>> quickly
>> > resolved the problem.
>> >
>> > Please, take a second look at the first solution. It refused to run.
>> Looks
>> > as if the pipe is not properly positioned. Efforts to correct it and get
>> it
>> > run failed. If you can look further, it would be great. If time does not
>> > permit, I am fine too.
>> >
>> > But having the too solutions will certainly make the subject more
>> > interesting.
>> > Thank you so much.
>> > With warmest regards from
>> > Ogbos
>> >
>> > On Wed, Mar 27, 2024 at 8:44 AM Rui Barradas 
>> wrote:
>> >
>> >> Às 04:30 de 27/03/2024, Ogbos Okike escreveu:
>> >>> Warm greetings to you all.
>> >>>
>> >>> Using the tapply function below:
>> >>> data<-read.table("FD1month",col.names = c("Dates","count"))
>> >>> x=data$count
>> >>>f<-factor(data$Dates)
>> >>> AB<- tapply(x,f,mean)
>> >>>
>> >>>
>> >>> I made a simple calculation. The result, stored in AB, is of the form
>> >>> below. But an effort to write AB to a file as a data frame fails. When
>> I
>> >>> use the write table, it only produces the count column and strip of the
>> >>> first column (date).
>> >>>
>> >>> 2005-11-01 2005-12-01 2006-01-01 2006-02-01 2006-03-01 2006-04-01
>> >>> 2006-05-01
>> >>>-4.106887  -4.259154  -5.836090  -4.756757  -4.118011  -4.487942
>> >>>-4.430705
>> >>> 2006-06-01 2006-07-01 2006-08-01 2006-09-01 2006-10-01 2006-11-01
>> >>> 2006-12-01
>> >>>-3.856727  -6.067103  -6.418767  -4.383031  -3.985805  -4.768196
>> >>> -10.072579
>> >>> 2007-01-01 2007-02-01 2007-03-01 2007-04-01 2007-05-01 2007-06-01
>> >>> 2007-07-01
>> >>>-5.342338  -4.653128  -4.325094  -4.525373  -4.574783  -3.915600
>> >>>-4.127980
>> >>> 2007-08-01 2007-09-01 2007-10-01 2007-11-01 2007-12-01 2008-01-01
>> >>> 2008-02-01
>> >>>-3.952150  -4.033518  -4.532878  -4.522941  -4.485693  -3.922155
>> >>>-4.183578
>> >>> 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01 2008-08-01
>> >>> 2008-09-01
>> >>>-4.336969  -3.813306  -4.296579  -4.575095  -4.036036  -4.727994
>> >>>-4.347428
>> >>> 2008-10-01 2008-11-01 2008-12-01
>> >>>-4.029918  -4.260326  -4.454224
>> >>>
>> >>> But the normal format I wish to display only appears on the terminal,
>> >>> leading me to copy it and paste into a text file. That is, when I enter
>> >> AB
>> >>> on the terminal, it returns a format in the form:
>> >>>
>> >>> 008-02-01  -4.183578
>> >>> 2008-03-01  -4.336969
>> >>> 2008-04-01  -3.813306
>> >>> 2008-05-01  -4.296579
>> >>> 2008-06-01  -4.575095
>> >>> 2008-07-01  -4.036036
>> >>> 2008-08-01  -4.727994
>> >>> 2008-09-01  -4.347428
>> >>> 2008-10-01  -4.029918
>> >>> 2008-11-01  -4.260326
>> >>> 2008-12-01  -4.454224
>> >>>
>> >>> Now, my question: How do I write out two columns displayed by AB on the
>> >>> terminal to a file?
>> >>>
>> >>> I have tried using AB<-data.frame(AB) but it doesn't work either.
>> >>>
>> >>> Many thanks for your time.
>> >>> Ogbos
>> >>>
>> >>>[[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.
>> >> Hello,
>> >>
>> >> The main trick is to pipe to as.data.frame. But the result will have one
>> >> column only, you must assign 

Re: [R] Printout and saved results

2024-03-25 Thread Jeff Newmiller via R-help
Your desire is not unusual among novices... but it is really not a good idea 
for your function to be making those decisions. Look at how R does things:

The lm function prints nothing... it returns an object containing the result of 
a linear regression. If you happen to call it directly from the R command 
prompt and don't assign it to a variable, then the command interpreter notices 
that return value and prints it. Since the lm object has a dedicated print 
method associated with it, that output looks different than a plain list object 
would... but the fact that it has a special print method (?print.lm) is just 
window dressing unrelated to your request.

The important part is that the lm function doesn't even consider printing 
anything out... it is the code that calls the function that determines whether 
it will get printed. So...

lm( hp ~ disp, data = mtcars )  # printed by command interpreter
z <- lm( hp ~ disp, data = mtcars ) # assignment operator returns the value of 
z to the command processor, but invisibly
( z <- lm( hp ~ disp, data = mtcars ) ) # strips off the invisible marking so 
the value gets printed

Another example:

f <- function() {
  x <- 4
  x  # doesn't print
  invisible( 5 ) # return invisible result
}

f()  # doesn't print 4 because there is no command prompt looking at x alone on 
a line... it is inside f
# command prompt doesn't print 5 because that 5 has been marked as invisible
(f()) # command interpreter prints 5

Leaving it up to the calling code to decide whether to print gives you the 
option of calling your analysis function possibly thousands of times and 
figuring out some slick way to summarize all those runs without thousands of 
printouts that you are not going to wade through anyway and would only slow the 
computer down (printing really does slow the computer down!)


On March 25, 2024 9:00:49 PM PDT, Steven Yen  wrote:
>I just like the subroutine to spit out results (Mean, Std.dev, etc.) and also 
>be able to access the results for further processing, i.e.,
>
>v$Mean
>
>v$Std.dev
>
>On 3/26/2024 11:24 AM, Richard O'Keefe wrote:
>> Not clear what you mean by "saved".
>> If you call a function and the result is printed, the result is
>> remembered for a wee while in
>> the variable .Last.value, so you can do
>>> function.with.interesting.result(...)
>>> retained.interesting.result <- .Last.value
>> or even
>>> .Last.value -> retained.interesting.result
>> If you know before you start writing the expression that you want to
>> save the value,
>> you can wrap the assignment in parentheses, making it an expression:
>> 
>>> (retained.interesting.result <- function.with.interesting.result(..))
>> 
>> On Tue, 26 Mar 2024 at 15:03, Steven Yen  wrote:
>>> How can I have both printout and saved results at the same time.
>>> 
>>> The subroutine first return "out" and the printout gets printed, but not
>>> saved.
>>> 
>>> I then run the "invisible" line. Results got saved and accessible but no
>>> printout.
>>> 
>>> How can I have both printout and also have the results saved? Thank you!
>>> 
>>>   > dstat4 <- function(data,digits=3){
>>> +   Mean<- apply(data,2,mean,na.rm=TRUE)
>>> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
>>> +   Min <- apply(data,2,min,na.rm=TRUE)
>>> +   Max <- apply(data,2,max,na.rm=TRUE)
>>> +   Obs <- dim(data)[1]
>>> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
>>> +   out
>>> + # invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
>>> + }
>>>   > x1<-rnorm(n=5,mean=5, sd=1)
>>>   > x2<-rnorm(n=5,mean=10,sd=2)
>>>   > w<-rnorm(n=5,mean=2,sd=0.3)
>>>   > mydata<-data.frame(cbind(x1,x2))
>>>   > v<-dstat4(mydata); v
>>>Mean Std.dev   MinMax Obs
>>> x1  5.000   0.922 3.900  6.282   5
>>> x2 10.769   1.713 9.209 13.346   5
>>>   > v$Mean
>>> Error in v$Mean : $ operator is invalid for atomic vectors
>>>   > dstat4 <- function(data,digits=3){
>>> +   Mean<- apply(data,2,mean,na.rm=TRUE)
>>> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
>>> +   Min <- apply(data,2,min,na.rm=TRUE)
>>> +   Max <- apply(data,2,max,na.rm=TRUE)
>>> +   Obs <- dim(data)[1]
>>> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
>>> + # out
>>> +   invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
>>> + }
>>> 
>>>   > v<-dstat4(mydata)
>>>   > v$Mean
>>> x1   x2
>>> 4.233051 9.564454
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/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 

Re: [R] as.complex()

2024-03-25 Thread Jeff Newmiller via R-help
?complex

On March 25, 2024 12:23:43 AM PDT, Thomas K  wrote:
>Needing a < , > comparison for imaginary numbers
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Generating mouse click and hold using R

2024-03-13 Thread Jeff Newmiller via R-help
No idea if the package below would work. This package is MSWindows only. Since 
this was readily found using a search engine, you should have mentioned that 
you already found this and why it didn't work for you when you posted.

https://cran.r-project.org/web/packages/KeyboardSimulator/readme/README.html
https://stat.ethz.ch/R-manual/R-devel/library/base/html/Sys.sleep.html


On March 13, 2024 6:31:59 AM PDT, Christofer Bogaso 
 wrote:
>Hi,
>
>I wonder if R can provide any functionality where I need simulate
>mouse click in windows machine at certain coordinate on screen and
>hold the click for certain seconds e.g. for 5 seconds
>
>Really appreciate if I can have someone suggestion how above can be
>simulated with R
>
>Thanks and regards,
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Initializing vector and matrices

2024-03-02 Thread Jeff Newmiller via R-help
To be fair, these replies no longer include the original question, which was 
IMO really quite clear (if misguided), and was actually targeted at 
understanding pre-allocation for better performance. Richard's suggestion to 
store the along-the-way constructed vectors in a list and examine the lengths 
of the elements of that list after it is completely constructed if it is really 
desired to force vectors of varying lengths into a matrix seems appropriate. 
The possibly-misguided part is in the thought that vectors of different lengths 
belong in a matrix at all... leaving them in a list seems more likely to be 
appropriate.

OP: Avoid mis-using NA to "fill out" the end of uniform-length vectors. Each 
index position in a vector should represent some information... if you are 
throwing NAs or zeros in willy-nilly then you are not taking care to assign 
meaning to those positions, and likely wasting memory and time doing so. If you 
were taking such care, then any appropriate NAs would already be present in the 
vectors before you put them into the matrix, and the original question would 
not have crossed OPs mind because the vectors world already be of the same 
length. NA means that information for a specific position is "unknown", not 
"space filler".

Now if OP wants better guidance on restructuring their analysis, then certainly 
sharing those details would help the discussion move away from the original 
misguided question... but that would be another thread to answer the question 
that should have been asked.

On March 2, 2024 9:53:41 AM PST, Bert Gunter  wrote:
>"It would be really really helpful to have a clearer idea of what you
>are trying to do."
>
>Amen!
>
>But in R, "constructing" objects by extending them piece by piece is
>generally very inefficient (e.g.
>https://r-craft.org/growing-objects-and-loop-memory-pre-allocation/),
>although sometimes?/often? unavoidable (hence the relevance of your
>comment above). R generally prefers to take a "whole object" point of
>view ( see R books by Chambers, et. al.) and provides code for basic
>operations like vector/matrix, etc. construction to do so. When this
>is not possible, I suspect "optimal" efficient strategies for
>allocating space to build objects gets you into the weeds of how R
>works.
>
>Cheers,
>Bert
>
>
>
>
>On Sat, Mar 2, 2024 at 1:02 AM Richard O'Keefe  wrote:
>>
>> The matrix equivalent of
>>   x <- ...
>>   v <- ...
>>   x[length(x)+1] <- v
>> is
>>   m <- ...
>>   r <- ...
>>   m <- rbind(m, r)
>> or
>>   m <- ...
>>   k <- ...
>>   m <- cbind(m, c)
>>
>> A vector or matrix so constructed never has "holes" in it.
>> It's better to think of CONSTRUCTING vectors and matrices rather than
>> INITIALISING them,
>> because always being fully defined is important.
>>
>> It would be really really helpful to have a clearer idea of what you
>> are trying to do.
>>
>> On Fri, 1 Mar 2024 at 03:31, Ebert,Timothy Aaron  wrote:
>> >
>> > You could declare a matrix much larger than you intend to use. This works 
>> > with a few megabytes of data. It is not very efficient, so scaling up may 
>> > become a problem.
>> > m22 <- matrix(NA, 1:60, ncol=6)
>> >
>> > It does not work to add a new column to the matrix, as in you get an error 
>> > if you try m22[ , 7] but convert to data frame and add a column
>> >
>> > m23 <- data.frame(m22)
>> > m23$x7 <- 12
>> >
>> > The only penalty that I know of to having unused space in a matrix is the 
>> > amount of memory it takes. One side effect is that your program may have a 
>> > mistake that you would normally catch with a subscript out of bounds error 
>> > but with the extra space it now runs without errors.
>> >
>> > Tim
>> >
>> >
>> >
>> > -Original Message-
>> > From: R-help  On Behalf Of Richard O'Keefe
>> > Sent: Thursday, February 29, 2024 5:29 AM
>> > To: Steven Yen 
>> > Cc: R-help Mailing List 
>> > Subject: Re: [R] Initializing vector and matrices
>> >
>> > [External Email]
>> >
>> > x <- numeric(0)
>> > for (...) {
>> > x[length(x)+1] <- ...
>> > }
>> > works.
>> > You can build a matrix by building a vector one element at a time this 
>> > way, and then reshaping it at the end.  That only works if you don't need 
>> > it to be a matrix at all times.
>> > Another approach is to build a list of rows.  It's not a matrix, but a 
>> > list of rows can be a *ragged* matrix with rows of varying length.
>> >
>> > On Wed, 28 Feb 2024 at 21:57, Steven Yen  wrote:
>> > >
>> > > Is there as way to initialize a vector (matrix) with an unknown length
>> > > (dimension)? NULL does not seem to work. The lines below work with a
>> > > vector of length 4 and a matrix of 4 x 4. What if I do not know
>> > > initially the length/dimension of the vector/matrix?
>> > >
>> > > All I want is to add up (accumulate)  the vector and matrix as I go
>> > > through the loop.
>> > >
>> > > Or, are there other ways to accumulate such vectors and matrices?
>> > >
>> > >  > x<-rep(0,4)  # this works but I like 

Re: [R] installation: while running make, unable to run pdflatex on 'NEWS.tex'

2024-03-01 Thread Jeff Newmiller via R-help
This really is all LaTeX errors, not R errors. Both examples complain that 
pdftexcmds.sty is not installed. Most "sty" files are in LaTeX packages. Each 
LaTeX distribution has its own way to install packages ... but the difficulty 
is usually on the same order of difficulty as installing R packages from 
CRAN... that is, pretty easy. But you need to read about _your_ TeX system for 
details. I use Google to figure out which package has the given file in it... 
it is usually the same as whatever comes before ".sty", but not always.

On March 1, 2024 7:46:53 AM PST, Benjamin Tyner  wrote:
>
>A kind member of R-core suggested this is due to a misconfiguration on my 
>system, and to post it to the mailing list for troubleshooting.
>
>When trying to build R version 4.3.3, in at least two places during the 
>process it gives LaTeX errors of the form:
>
>(example 1)
>
>   you should 'make docs' now ...
>   make[1]: Entering directory '/home/btyner/R-4.3.3/doc'
>   creating doc/NEWS
>   creating doc/NEWS.pdf
>   Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet =
>   quiet, :
>   unable to run pdflatex on 'NEWS.tex'
>   LaTeX errors:
>   ! LaTeX Error: File `pdftexcmds.sty' not found.
>
>   Type X to quit or  to proceed,
>   or enter new name. (Default extension: sty)
>
>   ! Emergency stop.
>   
>
>   l.108 RequirePackage{pdftexcmds}[2018/09/10]
>   ^^M
>   ! ==> Fatal error occurred, no output PDF file produced!
>   Calls:  -> texi2pdf -> texi2dvi
>   Execution halted
>   make[1]: /*/ [Makefile:74: NEWS.pdf] Error 1
>   make[1]: Leaving directory '/home/btyner/R-4.3.3/doc'
>   make: [Makefile:73: docs] Error 2 (ignored)
>
>(example 2)
>
>   make[1]: Entering directory '/home/btyner/R-4.3.3/src/library'
>   building/updating vignettes for package 'grid' ...
>   building/updating vignettes for package 'parallel' ...
>   building/updating vignettes for package 'utils' ...
>   building/updating vignettes for package 'stats' ...
>   processing 'reshape.Rnw'
>   Error: compiling TeX file 'reshape.tex' failed with message:
>   unable to run pdflatex on 'reshape.tex'
>   LaTeX errors:
>   ! LaTeX Error: File `pdftexcmds.sty' not found.
>
>   Type X to quit or  to proceed,
>   or enter new name. (Default extension: sty)
>
>   ! Emergency stop.
>   
>
>   l.108 RequirePackage{pdftexcmds}[2018/09/10]
>   ^^M
>   ! ==> Fatal error occurred, no output PDF file produced!
>   Execution halted
>   make[1]: ** [Makefile:103: vignettes] Error 1
>   make[1]: Leaving directory '/home/btyner/R-4.3.3/src/library'
>   make: ** [Makefile:81: vignettes] Error 2
>
>here is my |pdflatex --version| info:
>
>   pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian)
>   kpathsea version 6.3.4/dev
>   Compiled with libpng 1.6.37; using libpng 1.6.37
>   Compiled with zlib 1.2.11; using zlib 1.2.11
>   Compiled with xpdf version 4.03
>
>my platform info:
>
>   Platform: x86_64-pc-linux-gnu (64-bit)
>   Running under: Ubuntu 22.04.4 LTS
>
>I installed from this file with corresponding md5sum
>
>   R-4.3.3.tar.xz 5602f5996107c346dba12a16e866d2e2
>
>The specific commands I ran which led to the error were:
>
>   wget https://cran.r-project.org/src/base/R-4/R-4.3.3.tar.xz
>   mkdir R433
>   tar xJf R-4.3.3.tar.xz
>   cd R-4.3.3
>   ./configure --prefix=/home/btyner/R433
>   make
>
>Happy to provide any additional information needed.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Trouble reading a UTF-16LE file

2024-02-28 Thread Jeff Newmiller via R-help
When you specify LE you are overriding any useful information that the BOM 
could convey... see 
https://softwareengineering.stackexchange.com/questions/370088/is-the-bom-optional-for-utf-16-and-utf-32.

?Encoding

On February 28, 2024 5:44:49 AM PST, "Ebert,Timothy Aaron"  
wrote:
>Dear R-help,
>I am having trouble reading a UTF-16LE formatted file. The issue appears 
> to be a byte order mark at the beginning of the file. I have tried 
> readLines(file, encoding='utf-16LE') but got me 
>
>[1]"\xff\xfe1" ""  ""  ""  ""  ""
>
>
>
>Regards,
>Tim
>
>
>
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] converting MATLAB -> R | element-wise operation

2024-02-27 Thread Jeff Newmiller via R-help
Why anything but sweep?

The fundamental data type in Matlab is a matrix... they don't have vectors, 
they have Nx1 matrices and 1xM matrices.

Vectors don't have any concept of "row" vs. "column". Straight division is 
always elementwise with recycling as needed, and matrices are really vectors in 
row-major order:

1 2 3
4 5 6

is really

1 4 2 5 3 6

and when you do straight division NN / lambda then lambda is repeated:

1 4 2 5 3 6
2 3 4 2 3 4

to get

0.5 1.3 0.5 2.5 1.0 1.5

but if you transpose first

1 4
2 5
3 6

then that corresponds to an underlying vector:

1 2 3 4 5 6

which lines up with lambda in t(NN)/lambda as:

1 2 3 4 5 6
2 3 4 2 3 4

to obtain:

0.50 0.67 0.75 2.0 1.67 1.50

and inherits the dimensions of t(NN):

0.50 2.00
0.67 1.67
0.75 1.50

which can be transposed back as in t( t( NN ) / lambda ):

0.50 0.67 0.75
2.00 1.67 1.50

but that requires a lot of moving elements around while sweep does not.

Operators are not necessarily "better" than named functions... they just look 
different.


On February 27, 2024 11:54:26 AM PST, Evan Cooch  wrote:
>So, trying to convert a very long, somewhat technical bit of lin alg 
>MATLAB code to R. Most of it working, but raninto a stumbling block that 
>is probaably simple enough for someone to explain.
>
>Basically, trying to 'line up' MATLAB results from an element-wise 
>division of a matrix by a vector with R output.
>
>Here is a simplified version of the MATLAB code I'm translating:
>
>NN = [1, 2, 3; 4, 5, 6];  % Example matrix
>lambda = [2, 3, 4];  % Example vector
>result_matlab = NN ./ lambda;
>
>which yields
>
>  0.5   0.7   0.75000
>  2.0   1.7   1.5
>
>
>So, the only way I have stumbled onto in R to generate the same results 
>is to use 'sweep'. The following 'works', but I'm hoping someone can 
>explain why I need something as convoluted as this seems (to me, at least).
>
>NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
>lambda <- c(2, 3, 4)  # Example vector
>sweep(NN, 2, lambda, "/")
>
>
>  [,1]  [,2] [,3]
>[1,]  0.5 0.667 0.75
>[2,]  2.0 1.667 1.50
>
>First tried the more 'obvious' NN/lambda, but that yields 'the wrong 
>answer' (based solely on what I'm trying to accomplish):
>
>
>    [,1] [,2] [,3]
>[1,] 0.50  0.5  1.0
>[2,] 1.33  2.5  1.5
>
>So, why 'sweep'?
>
>   [[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.


Re: [R] Rtools and things dependent on it

2024-02-23 Thread Jeff Newmiller via R-help
RTools is a set of command-line programs needed for compiling R and its 
packages on Windows. You don't need it if your OS is not Windows.

In theory, users on Windows should not need to worry about compiling packages 
to binary (zip) form, because CRAN compiles the source code for every package 
that supports Windows and just updating in a few days should bring in the 
current binaries. In practice, that task seems to always be lagging for certain 
packages, so you may end up using old versions of packages if you only rely on 
binary packages. Tidyverse packages seem to be among the worst in this 
respect.. there are many many dependencies and getting just one old one can 
make it all but impossible to get a current set of top-level Tidyverse 
packages. I think this is the strongest argument for teaching beginners to use 
Bsse R at first... the most plaintive cries come from beginners tasked with 
preparing their Windows computers to use tidyverse for their "class" at times 
when the binary files are very out of date.

Once installed and an RtoolsXX directory is present, it is still necessary to 
add the Rtools\mingw64\bin directory to your PATH environment variable so R can 
find it. Unfortunately there is no one way to do this because some people use 
multiple versions of R/Rtools and you can't just add all of them to your PATH. 
One of my preferred ways is to put the following in a newly-created .Rprofile 
text file in the Documents directory

Sys.setenv( PATH=paste( "C:\\Rtools43\\mingw64", Sys.getenv( "PATH" ), sep=";" 
) )

after restarting R it should be ready to install source packages when needed.

The problem is that beginners rarely remember doing this and after updating to 
R/Rtools 4.4.0 they will not understand why all their existing packages 
disappear (they must be reinstalled for each x.y version of R) nor why the 
source install doesn't work anymore (the 43 in their .Rprofile file which they 
have long ago forgotten must be updated to 44).

On February 23, 2024 3:39:28 PM PST, "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.
>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.
>
>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.
>
>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?
>
>Avi
>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help=05%7C02%7CJSorkin%40som.umaryland.edu%7C8d5f2c8346f24559a7f908dc34bf9979%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638443244987424663%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C6%7C%7C%7C=BO9wgkrjNmI4j2deiBDxHw%2F9tVjynfQYEHhBZ8BGq%2Fk%3D=0
>PLEASE do read the posting guide 
>https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html=05%7C02%7CJSorkin%40som.umaryland.edu%7C8d5f2c8346f24559a7f908dc34bf9979%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638443244987432863%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C6%7C%7C%7C=kVnTbE6ZEpmJ88Zmu%2FUbUH%2F%2FnjoSHSmDjuIxxxw3uz8%3D=0
>and provide commented, minimal, self-contained, reproducible code.
>
>   [[alternative HTML version deleted]]
>

Re: [R] Help

2024-02-20 Thread Jeff Newmiller via R-help
Regarding 1 and 2, please read the Posting Guide mentioned at the bottom of 
every R-help post. R does not equal statistics... and education about 
statistics is way too ambitious to include in this mailing list that is about a 
tool that happens to be useful for statisticians.

There are forums online that do cater to statistical methods (e.g. Cross 
Validated or many results from a search engine)... but such conversations can 
be extensive so as Rolf suggests this is a good time to learn what resources 
your educational institutions can provide... online forums may be too limiting 
when your questions are so vague.

On February 20, 2024 2:14:58 PM PST, Rolf Turner  wrote:
>
>On Mon, 19 Feb 2024 17:39:23 +0100
>Lisa Hupfer via R-help  wrote:
>
>> I am writing my master thesis in which I compared two cultures . So
>> for my statistics I need to compare Age,Sex,Culture as well as have a
>> look at the tasks scores .
>> 
>> Anyone familiar with this ?
>> I’d love to share my script so you guide me where I did wrong .
>
>(1) This post is far too vague to be appropriate for this list.
>
>(2) You should learn some statistics; probably linear modelling.
>
>(3) You should talk to your thesis advisor.
>
>(4) Please see fortunes::fortune(285).
>
>cheers,
>
>Rolf Turner
>
>

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


Re: [R] Network issue

2024-02-20 Thread Jeff Newmiller via R-help
... and if the problem is networking, then you will likely need help from 
someone who knows your local configuration. Employers often do things that 
limit what R can do, and none of us are likely to know about those things.

On February 20, 2024 11:43:24 AM PST, stephen sefick  wrote:
>Maybe I missed the rest of the post? You are more likely to get help with
>your problems if you create a minimal reproducible example.
>Kindest regards,
>
>Stephen Sefick
>
>On Tue, Feb 20, 2024, 12:24 James Powell  wrote:
>
>>
>
>   [[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.


Re: [R] List of Words in BioWordVec

2024-02-01 Thread Jeff Newmiller via R-help
I thought so too, but Google suggests there is at least one package on CRAN 
with this symbol in it.

OP:

a) You should always mention which contributed package you are using. Most 
references to this term online seem to be related to Python rather than R.

b) This seems like extremely specialized knowledge... even if it is a CRAN 
package this doesn't seem like the kind of R language topic normally discussed 
here. The CRAN package entry online may include a pointer to a more appropriate 
venue for getting help.

c) Also, we can only see the text portion of your email ... it is strongly 
recommended in the Posting Guide (linked in the message footer) to send your 
questions formatted as text rather than HTML to avoid "we don't see what you 
see" mis-communication. Sorry if that seems vague, but there are too many email 
programs out there for us to know how you should configure yours to do this... 
but it is practically always possible.

On February 1, 2024 6:09:04 PM PST, Bert Gunter  wrote:
>I *think* this might be better posted here:
>https://bioconductor.org/help/support/
>
>Cheers,
>Bert
>
>On Thu, Feb 1, 2024 at 4:37 PM TJUN KIAT TEO  wrote:
>
>> Is there a way to extract list of words in  BioWordVec  in R
>>
>> Thank you
>>
>> Tjun Kiat
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

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


Re: [R] Use of geometric mean .. in good data analysis

2024-01-22 Thread Jeff Newmiller via R-help
Still OT... but here is my own (I think previously mentioned here) rant on 
people thrashing about with log transformation and an all-too-common kludge to 
deal with zeros mixed among small numbers... 
https://gist.github.com/jdnewmil/99301a88de702ad2fcbaef33326b08b4

OP perhaps posting a link here to your question posed wherever you end up with 
it will help shorten this thread.

On January 22, 2024 12:23:20 PM PST, Bert Gunter  wrote:
>Ah LOD's, typically LLOD's ("lower limits of detection").
>
>Disclaimer: I am *NOT* in any sense an expert on such matters. What follows
>are just some comments based on my personal experience. Please filter
>accordingly. Also, while I kept it on list as Martin suggested it might be
>useful to do so, most folks probably can safely ignore the rant that
>follows as off topic and not of interest. So you've been warned!!
>
>The rant:
>My experience is: data that contain a "bunch" of values that are, e.g.
>below a LLOD, are frequently reported and/or analyzed by various ad hoc,
>and imho, uniformly bad methods. e.g.:
>
>1) The censored values are recorded and analyzed as at the LLOD;
>2) The censored values are recorded and analyzed at some arbitrary value
>below the LLOD, like LLOD/2;
>3) The censored values are are "imputed" by ad hoc methods, e.g. uniform
>random values between 0 and the LLOD for left censoring.
>
>To repeat, *IMO*, all of this is junk and will produced misleading
>statistical results. Whether they mislead enough to substantively affect
>the science or regulatory decisions depend on the specifics of the
>circumstances. I accept no general claim as to their innocuousness.
>
>Further:
>
>a) When you have a "lot" of values -- 50%? 75%?, 25%? -- face facts: you
>have (practically) no useful information from the values that you do have
>to infer what the distribution of values that you don't have looks like.
>All one can sensibly do is say that x% of the values are below a LOD and
>here's the distribution of what lies above. Presumably, if you have such
>data conditional on covariates with the obvious intent to determine the
>relationship to those covariates, you could analyze the percentages of
>LLOD's and known values separately. There are undoubtedly more
>sophisticated methods out there, so this is where you need to go to the
>literature to see what might suit; though I think it will still have to
>come down to looking at these separately (e.g. with extra parameters to
>account for unmeasurable values). Another way of saying this is: any
>analysis which treats all the data as arising from a single distribution
>will depend more on the assumptions you make than on the data. So good luck
>with that!
>
>b) If you have a "modest" amount of (known) censoring -- 5%?, 20%? 10%? --
>methods for the analysis of censored data should be useful. My
>understanding is that MI (multiple imputation) is regarded as a generally
>useful approach, and there are many R packages that can do various flavors
>of this. Again, you should consult the literature: there are very likely
>nontechnical reviews of this topic, too, as well as online discussions and
>tutorials.
>
>So if you are serious about dealing with this and have a lot of data with
>these issues, my advice would be to stop looking for ad hoc advice and dig
>into the literature: it's one of the many areas of "data science" where
>seemingly simple but pervasive questions require complex answers.
>
>And, again, heed my personal caveats.
>
>Thus endeth my rant.
>
>Cheers to all,
>Bert
>
>
>
>On Mon, Jan 22, 2024 at 9:29 AM Rich Shepard 
>wrote:
>
>> On Mon, 22 Jan 2024, Martin Maechler wrote:
>>
>> > I think it is a good question, not really only about geo-chemistry, but
>> > about statistics in applied sciences (and engineering for that matter).
>>
>> > John W Tukey (and several other of the grands of the time) had the log
>> > transform among the "First aid transformations":
>> >
>> > If the data for a continuous variable must all be positive it is also
>> > typically the case that the distribution is considerably skewed to the
>> > right. In such a case behave as a good human who sees another human in
>> > health distress: apply First Aid -- do the things you learned to do
>> > quickly without too much thought, because things must happen fast ---to
>> > hopefully save the other's life.
>>
>> Martin,
>>
>> Thanks very much. I will look further into this because toxic metals and
>> organic compounds in geochemical collections almost always have censored
>> lab
>> results (below method dection limits) that range from about 15% to 80% or
>> more, and there almost always are very high extreme values.
>>
>> I'll learn to understand what benefits log transforms have over
>> compositional data analyses.
>>
>> Best regards,
>>
>> Rich
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the 

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Jeff Newmiller via R-help
This sounds suspiciously like homework (which is off-topic... see the Posting 
Guide), and you haven't indicated how you plan to encode your poker hands, and 
most core features of other languages are possible in R so if you really 
understand these other techniques and R then you should be able to do this 
already.

If this is not homework, then please show your work so far instead of showing a 
completely different example.

On December 14, 2023 12:00:12 AM PST, "Martin Møller Skarbiniks Pedersen" 
 wrote:
>Hi,
>
>  I need to sort a data.frame based on a custom sorting function.
>  It is easy in many languages but I can't find a way to do it in R.
>
>  In many cases I could just use an ordered factor but my data.frame
>contains poker hands and
>I need to rank these hands. I already got a function that compares two hands.
>
>Here is a MRE (Minimal, Reproducible Example):
>
>
>df <- data.frame(person = c("Alice", "Bob", "Charlie"), value =
>c("Medium", "Small", "Large"))
>
># 0 means equal, -1 means left before right, 1 means right before left
>custom_sort <- function(left, right) {
>  if (left == right) return(0)
>  if (left == "Small") return(-1)
>  if (left == "Medium" & right == "Large") return(-1)
>  return(1)
>}
>
>#  sort df according to custom_soft
># expect output is a data.frame:
># name   size
># 1 Bob Medium
># 2   Alice  Small
># 3 Charlie  Large
>
>In this simple case I can just use an ordered factor but what about
>the poker hands situation?
>
>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 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.


Re: [R] reshape() not dropping varaibles

2023-12-10 Thread Jeff Newmiller via R-help
It would be nice to see what OP wanted to end up with, but the link contained 
input data to experiment with.

The first problem is that if you are not interested in working with the whole 
set of columns then you need to only give a data frame with the columns you 
want to work with:

dta.wide <- reshape(
  Data[, c( "SURVEYDATE", "COMMON_NAME", "TOTAL_CATCH" ) ]
  , direction = "wide"
  , idvar = "SURVEYDATE"
  , timevar = "COMMON_NAME"
  , v.names = "TOTAL_CATCH"
)

Second, there are multiple rows of TOTAL_CATCH for each combination of 
SURVEYDATE and COMMON_NAME. reshape does not do math on the data... you have to 
resolve that yourself first by choosing how you want to turn a bunch of numbers 
into one... in this case I chose to sum them up:

Data.agg <- aggregate(
  TOTAL_CATCH ~ SURVEYDATE + COMMON_NAME
  , data = Data
  , FUN = sum
)
# the aggregate calculation implicitly leaves out columns you don't specify

dta.wide <- reshape(
  Data.agg
  , direction = "wide"
  , idvar = "SURVEYDATE"
  , timevar = "COMMON_NAME"
  , v.names = "TOTAL_CATCH"
)
Data.wide

On December 10, 2023 7:35:17 AM PST, Bert Gunter  wrote:
>Posting a few rows, say 5, of your data using dput() along with the result
>that you would like to get for those rows would help get you a quicker and
>more accurate response, I believe. This is as suggested by the posting
>guide, linked below, which you should read if you have not already.
>
>-- Bert
>
>
>
>On Sun, Dec 10, 2023 at 2:38 AM Bob O'Hara  wrote:
>
>> Hi all!
>>
>> I1m trying to re-format some data from long to wide format with reshape().
>> Specifically, the data has SURVEYDATE, which I want to be in the rows, and
>> COMMON_NAME which should be the columns. The entries should be TOTAL_CATCH.
>> The data has a bunch of other variables, which can be ignored.
>>
>> When I run reshape(), it includes all of the variables, not just
>> TOTAL_CATCH:
>>
>> Data <- read.csv("
>>
>> https://conservancy.umn.edu/bitstream/handle/11299/227105/fish_data_raw.csv?sequence=6=y
>> ")
>> Data.wide <- reshape(Data, direction = "wide",
>> idvar = "SURVEYDATE", timevar = "COMMON_NAME",
>> v.names = "TOTAL_CATCH")
>> names(Data.wide)
>>
>> I tried with the example on the help page, which works fine:
>>
>> # this works
>> Indometh$thing <- 1:nrow(Indometh)
>> wide <- reshape(Indometh, direction = "wide", idvar = "Subject",
>> timevar = "time", v.names = "conc", sep= "_")
>> names(wide)
>>
>> There are some obvious work-arounds and alternatives, but it would be nice
>> to have this sorted. Can anyone help?
>>
>> Bob
>>
>> Bob
>>
>> --
>> Bob O'Hara
>> Institutt for matematiske fag
>> NTNU
>> 7491 Trondheim
>> Norway
>>
>> Mobile: +47 915 54 416
>> Journal of Negative Results - EEB: www.jnr-eeb.org
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

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


Re: [R] Volume of polygon

2023-12-05 Thread Jeff Newmiller via R-help
A raster is just a matrix of elevations. Each element of that matrix has a 
horizontal area. If you subtract that elevation from a reference elevation and 
zero out all negative values then you are left with a bunch of rectangular 
parallelopipeds of varying height. Add those heights up and multiply by the 
scalar area of the parallelopipeds and you have the volume. Repeat this for 
various elevations and form a set of estimates of volume vs elevation. You can 
use approxfun or splinefun to create a function from those points for more 
general use.

There are some subtleties such as converting between elevation and depth, and 
whether you are concerned about disjoint depressions (they would not drain)... 
but OP really should have read the posting guide and asked this question on 
R-sig-geo mailing list.

On December 5, 2023 9:09:12 PM PST, Bert Gunter  wrote:
>The volume of a polygon  = 0.  Polyhedra  have volumes.
>
>This may be irrelevant, but if the lake is cylindrical == constant cross
>sectional area at all depths, then height doubles when the volume does and
>vice versa.  Otherwise you have to know how area varies with height or use
>more sensible approximations thereto.
>
>Cheers,
>Bert
>
>On Tue, Dec 5, 2023, 20:13 javad bayat  wrote:
>
>>  Dear all;
>> I am trying to calculate the volume of a polygon shapefile according to a
>> DEM raster. I have provided some codes at the end of this email.I dont know
>> if the codes are correct or not. Following this, I have another question
>> too.
>> I want to know if the volume of the reservoir rises or doubles, what would
>> be the elevation?
>> I would be more than happy if anyone could help me.
>> Sincerely
>>
>> "
>> library(raster)
>> library(terra)
>> library(exactextractr)
>> library(dplyr)
>> library(sf)
>> r <- raster("Base.tif")
>> p <- shapefile("p.shp")
>> r <- crop(r, p)
>> r <- mask(r, p)
>> x <- exact_extract(r, p, coverage_area = TRUE)
>>
>> x1 = as.data.frame(x[1])
>> head(x1)
>> x1 = na.omit(x1)
>>
>> x1$Height = max(x1[,1]) - x1[,1]
>>
>> x1$Vol = x1[,2] * x1[,3]
>>
>> sum(x1$Vol)
>>
>> "
>>
>> --
>> Best Regards
>> Javad Bayat
>> M.Sc. Environment Engineering
>> Alternative Mail: bayat...@yahoo.com
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] adding "Page X of XX" to PDFs

2023-12-02 Thread Jeff Newmiller via R-help
He clearly stated he was using the pdf() graphics device.

On December 2, 2023 10:36:44 AM PST, Ben Bolker  wrote:
>  It's still not entirely clear to me what framework you're using to generate 
> the PDF, but if it's rmarkdown/Rnw (Sweave)/Quarto-based, then as far as I 
> know all of those frameworks use LaTeX as the last step in the script-to-PDF 
> pipeline, and allow the inclusion of arbitrary LaTeX code, so the 'lastpage' 
> package would do this for you:
>
>https://stackoverflow.com/questions/70343001/how-to-show-the-total-number-of-pages-in-a-pdf-via-the-rmarkdown-i-e-display
>
>https://tex.stackexchange.com/questions/227/how-can-i-add-page-of-on-my-document
>
>
>
>On 2023-12-02 12:23 p.m., Ebert,Timothy Aaron wrote:
>> Would this work in general? Say I have a document with figures, special 
>> equations, text, and tables. The text and tables are relatively easy. The 
>> figures would need a conversion from pixels to lines, and the equations 
>> maybe printed out, counted as a figure, and then added to the line count. It 
>> would also be tricky if a title line was at 32 point font and the text at 
>> 12, and the more complex the formatting the harder to deal with rows as 
>> related to page size.
>> 
>> Thankfully I do not think I will have to do this, so the question is for 
>> theoretical interest on my part (at least for now).
>> 
>> Tim
>> 
>> -Original Message-
>> From: R-help  On Behalf Of Jeff Newmiller via 
>> R-help
>> Sent: Saturday, December 2, 2023 11:46 AM
>> To: r-help@r-project.org
>> Subject: Re: [R] adding "Page X of XX" to PDFs
>> 
>> [External Email]
>> 
>> One of the most fundamental characteristics of R programming is the use of 
>> data frames of column vectors, and one of the very first challenges I had as 
>> a then-Perl-programmer was coming to grips with the fact that unknown-length 
>> CSV files would be read completely into memory as rows and once the entire 
>> CSV was in memory it would be transposed into column vectors. I was 
>> resistant to this philosophy at first, but the advantages in computation 
>> speed and simplicity eventually won me over.
>> 
>> I would say that if you want to know how many pages you are going to produce 
>> with R, then you are going to have to count them before you create them. 
>> Building a dataframe that describes (in terms of parameters to be passed to 
>> a page-generating function in each row) what you are going to put on each 
>> page before you actually print it can make this pre-counting problem 
>> trivial, and the code that does the printing is likely to be more modular 
>> and testable as well.
>> 
>> On December 1, 2023 12:53:25 PM PST, Dennis Fisher  
>> wrote:
>>> OS X
>>> R 4.3.1
>>> 
>>> Colleagues
>>> 
>>> I often create multipage PDFs [pdf()] in which the text "Page X" appears in 
>>> the margin.  These PDFs are created automatically using a massive R script.
>>> 
>>> One of my clients requested that I change this to:
>>>Page X of XX
>>> where XX is the total number of pages.
>>> 
>>> I don't know the number of expected pages so I can't think of any clever 
>>> way to do this.  I suppose that I could create the PDF, find out the number 
>>> of pages, then have a second pass in which the R script was fed the number 
>>> of pages.  However, there is one disadvantage to this -- the original PDF 
>>> contains a timestamp on each page -- the new version would have a different 
>>> timestamp -- so I would prefer to not use this approach.
>>> 
>>> Has anyone thought of some terribly clever way to solve this problem?
>>> 
>>> Dennis
>>> 
>>> Dennis Fisher MD
>>> P < (The "P Less Than" Company)
>>> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>>> http://www.plessthan.com/
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> --
>> 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://

Re: [R] adding "Page X of XX" to PDFs

2023-12-02 Thread Jeff Newmiller via R-help
One of the most fundamental characteristics of R programming is the use of data 
frames of column vectors, and one of the very first challenges I had as a 
then-Perl-programmer was coming to grips with the fact that unknown-length CSV 
files would be read completely into memory as rows and once the entire CSV was 
in memory it would be transposed into column vectors. I was resistant to this 
philosophy at first, but the advantages in computation speed and simplicity 
eventually won me over.

I would say that if you want to know how many pages you are going to produce 
with R, then you are going to have to count them before you create them. 
Building a dataframe that describes (in terms of parameters to be passed to a 
page-generating function in each row) what you are going to put on each page 
before you actually print it can make this pre-counting problem trivial, and 
the code that does the printing is likely to be more modular and testable as 
well.

On December 1, 2023 12:53:25 PM PST, Dennis Fisher  wrote:
>OS X
>R 4.3.1
>
>Colleagues
>
>I often create multipage PDFs [pdf()] in which the text "Page X" appears in 
>the margin.  These PDFs are created automatically using a massive R script.
>
>One of my clients requested that I change this to:
>   Page X of XX 
>where XX is the total number of pages.  
>
>I don't know the number of expected pages so I can't think of any clever way 
>to do this.  I suppose that I could create the PDF, find out the number of 
>pages, then have a second pass in which the R script was fed the number of 
>pages.  However, there is one disadvantage to this -- the original PDF 
>contains a timestamp on each page -- the new version would have a different 
>timestamp -- so I would prefer to not use this approach.
>
>Has anyone thought of some terribly clever way to solve this problem?
>
>Dennis
>
>Dennis Fisher MD
>P < (The "P Less Than" Company)
>Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>www.PLessThan.com
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Code editor for writing R code

2023-11-29 Thread Jeff Newmiller via R-help
Quarto is built on top of RMarkdown when R is used, so RMarkdown isn't going 
anywhere soon. Don't spread unnecessary FUD.

Quarto is well-supported in VSCode, though.

And reply to the right branch of the thread... Bert is not in the thread below.

On November 29, 2023 10:29:03 AM PST, Eric Berger  wrote:
>Bert,
>Posit (formerly RStudio) has moved from RMarkdown to Quarto. They
>still support RMarkdown but major new features will be in Quarto. For
>new users a better choice would be Quarto.
>See https://quarto.org/docs/faq/rmarkdown.html
>
>Secondly, the OP stated he was using the VS-Code IDE, so there is no
>reason to point him to the Posit/RStudio IDE for this functionality
>which VS-Code supports very well (as I noted in my response.)
>
>Best,
>Eric
>
>On Wed, Nov 29, 2023 at 6:55 PM Christofer Bogaso
> wrote:
>>
>> Hi Sergei,
>>
>> Where can I find TeX Comments extension in VS Code?
>>
>> On Wed, Nov 29, 2023 at 9:34 PM Sergei Ko  wrote:
>> >
>> > TeX Comments extension in VS Code
>> >
>> >
>> >
>> >
>> > Sent from my phone
>> >
>> >
>> >  Original message 
>> > From: Christofer Bogaso 
>> > Date: Wed, 29 Nov 2023, 15:57
>> > To: r-help 
>> > Subject: [R] Code editor for writing R code
>> >
>> > Hi,
>> >
>> > Currently I use VS-Code to write codes in R. While it is very good, it
>> > does not allow me to write Latex expressions in comments, which I am
>> > willing to have to write corresponding mathematical expressions as
>> > comments in my code files.
>> >
>> > Does there exist any Code editor for R, that allows me to write Latex
>> > in comments?
>> >
>> > Any information will be appreciated.
>> >
>> > 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.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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.

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


Re: [R] Why Rprofile.site is not built with manual installation of R devel in linux?

2023-11-09 Thread Jeff Newmiller via R-help
No clue. Tip: R-devel is the mailing list for anything related to development 
versions of R. Off-topic here.

On November 9, 2023 2:59:44 AM PST, "Iago Giné Vázquez"  
wrote:
>Hi all,
>
>I downloaded R-devel as explicited in 
>https://developer.r-project.org/SVNtips.html
>Then, I tried to install it through instructions in 
>https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Installation
>(taking into account also 
>https://stat.ethz.ch/pipermail/r-devel/2016-May/072777.html)
>So:
>export REPOS=https://svn.r-project.org/R
>export RTOP=~ #adjust as necessary
>cd $RTOP
>svn co $REPOS/trunk r-devel/R
>cd r-devel/R
>tools/rsync-recommended
>mkdir ../build-R
> cd ../build-R
> ../R/configure --prefix=/where/you/want/R/to/go
> make
> make check
>make install
>make install-tests
>cd tests
>## followed by one of
>../bin/R CMD make check
>../bin/R CMD make check-devel
>
>And here I get the following error
>checking package 'base'
>Error in file(filename, "r", encoding = encoding) :
>  cannot open the connection
>Calls: source -> file
>In addition: Warning message:
>In file(filename, "r", encoding = encoding) :
>  cannot open file '.../etc/Rprofile.site': No such file or directory
>Execution halted
>
>where the dots ... specify the path to the build-R folder where R-devel was 
>built. And I check the etc folder and indeed there is no the Rprofile.site
>-rw-r--r-- 1 iago iago  209 Nov  9 08:27 javaconf
>-rw-r--r-- 1 iago iago  770 Nov  9 08:35 ldpaths
>-rw-r--r-- 1 iago iago 6672 Nov  9 08:35 Makeconf
>-rw-r--r-- 1 iago iago 3336 Nov  9 08:27 Makefile
>-rw-r--r-- 1 iago iago 1853 Nov  9 08:27 Renviron
>-rw-r--r-- 1 iago iago 1173 Nov  9 08:32 repositories
>
>I note that make install installed R in the path I specified in  
>../R/configure --prefix=/where/you/want/R/to/go
>however
>1. make install-tests installed the tests folder in build-R .
>2.  In the installed R in /where/you/want/R/to/go, there is no even etc 
> folder, there are only the folders bin, lib and share.
>
>Am I  skipping some step? I am on Debain 12.
>
>Thank you!
>
>
>Iago
>
>   [[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.


Re: [R] strptime with +03:00 zone designator

2023-11-05 Thread Jeff Newmiller via R-help
I usually just use a regex to strip the colon.

On November 5, 2023 3:45:01 PM PST, Richard O'Keefe  wrote:
>I have some data that includes timestamps like this:
>2017-02-28T13:35:00+03:00
>The documentation for strptime says that %z expects
>an offset like 0300.  I don't see any way in the documentation
>to get it to accept +hh:mm with a colon separator, and
>everything I tried gave me NA as the answer.
>
>Section 4.2.5.1 of ISO 8601:2004(E) allows both the
>absence of colons in +hh[mm] (basic format) and the
>presence of colons in +hh:mm (extended format).
>Again in section 4.2.5.2 where a zone offset is combined
>with a time of day: if you have hh:mm:ss you are using
>extended format and the offset MUST have a colon; if
>you have hhmmss you are using basic format and the
>offset MUST NOT have a colon.  And again in section
>4.3.2 (complete representations of date and time of day).
>If you use hyphens and colons in the date and time part
>you MUST have a colon in the zone designator.
>
>So I am dealing with timestamps in strict ISO 8601
>complete extended representation, and it is rather
>frustrating that strptime doesn't deal with it simply.
>
>The simplest thing would be for R's own version of
>strptime to allow an optional colon between the hour
>digits and the minute digits of a zone designator.
>
>I'm about to clone the data source and edit it to
>remove the colons, but is there something obvious
>I am missing?
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Sum data according to date in sequence

2023-11-03 Thread Jeff Newmiller via R-help
Cbind is not a very good tool for adding columns to a data frame. Either use 
explicit column referencing like

dt1$x <- new_data_vector

but you do have to make sure the new data vector has the same number of values 
and in the same order as the other data in dt1. The transition from multiple 
records per day to one record per day would make the starting data and ending 
data incompatible.

library(dplyr)

dt1 <- structure(list(StationName = c("PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1"), date = c("1/14/2016", "1/14/2016",
"1/14/2016", "1/15/2016", "1/15/2016", "1/15/2016", "1/15/2016",
"1/16/2016", "1/16/2016", "1/16/2016", "1/16/2016", "1/16/2016",
"1/16/2016", "1/16/2016", "1/17/2016", "1/17/2016", "1/17/2016",
"1/17/2016", "1/17/2016", "1/18/2016"), time = c("12:09", "19:50",
"20:22", "8:25", "14:23", "18:17", "21:46", "10:19", "12:12",
"14:12", "16:22", "19:16", "19:19", "20:24", "9:54", "12:16",
"13:53", "19:03", "22:00", "8:58"), EnergykWh = c(4.680496, 6.272414,
1.032782, 11.004884, 10.096824, 6.658797, 4.808874, 1.469384,
2.996239, 0.303222, 4.988339, 8.131804, 0.117156, 3.285669, 1.175608,
3.677487, 1.068393, 8.820755, 8.138583, 9.0575)), row.names = c(NA,
20L), class = "data.frame")

ans <- (
  dt1
  %>% mutate(
Dt = as.Date( date, format = "%m/%d/%Y" )
  )
  %>% group_by( StationName, Dt )
  %>% summarize( DailyEnergykWh = sum( EnergykWh ) )
)


On November 3, 2023 2:51:20 AM PDT, roslinazairimah zakaria 
 wrote:
>Hi,
>I tried this:
># extract date from the time stamp
>dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh)
>head(dt1)
>colnames(dt1) <- c("date", "EnergykWh")
>and
>my dt1 becomes these, the dates are replace by numbers.
>
>dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh)
>dput(head(dt1))
>colnames(dt1) <- c("date", "EnergykWh")
>dput(head(dt1))
>
>
>> dput(head(dt1))structure(c(16814, 16814, 16814, 16815, 16815, 16815, 
>> 4.680496,
>6.272414, 1.032782, 11.004884, 10.096824, 6.658797), dim = c(6L,
>2L), dimnames = list(NULL, c("date", "EnergykWh")))
>
>Then I tried this:
>library(dplyr)
>dt1 %>%
>  group_by(date) %>%
>  summarise(EnergykWh.sum = sum(EnergykWh))
>and got this errors
>
>dt1 %>%+   group_by(date) %>%+   summarise(EnergykWh.sum =
>sum(EnergykWh))Error in UseMethod("group_by") :
>  no applicable method for 'group_by' applied to an object of class
>"c('matrix', 'array', 'double', 'numeric')"
>
>
>
>On Fri, Nov 3, 2023 at 7:23 AM roslinazairimah zakaria 
>wrote:
>
>> Dear all,
>>
>> I have this set of data. I would like to sum the EnergykWh according date
>> sequences.
>>
>> > head(dt1,20)   StationName  date  time EnergykWh
>> 1  PALO ALTO CA / CAMBRIDGE #1 1/14/2016 12:09  4.680496
>> 2  PALO ALTO CA / CAMBRIDGE #1 1/14/2016 19:50  6.272414
>> 3  PALO ALTO CA / CAMBRIDGE #1 1/14/2016 20:22  1.032782
>> 4  PALO ALTO CA / CAMBRIDGE #1 1/15/2016  8:25 11.004884
>> 5  PALO ALTO CA / CAMBRIDGE #1 1/15/2016 14:23 10.096824
>> 6  PALO ALTO CA / CAMBRIDGE #1 1/15/2016 18:17  6.658797
>> 7  PALO ALTO CA / CAMBRIDGE #1 1/15/2016 21:46  4.808874
>> 8  PALO ALTO CA / CAMBRIDGE #1 1/16/2016 10:19  1.469384
>> 9  PALO ALTO CA / CAMBRIDGE #1 1/16/2016 12:12  2.996239
>> 10 PALO ALTO CA / CAMBRIDGE #1 1/16/2016 14:12  0.303222
>> 11 PALO ALTO CA / CAMBRIDGE #1 1/16/2016 16:22  4.988339
>> 12 PALO ALTO CA / CAMBRIDGE #1 1/16/2016 19:16  8.131804
>> 13 PALO ALTO CA / CAMBRIDGE #1 1/16/2016 19:19  0.117156
>> 14 PALO ALTO CA / CAMBRIDGE #1 1/16/2016 20:24  3.285669
>> 15 PALO ALTO CA / CAMBRIDGE #1 1/17/2016  9:54  1.175608
>> 16 PALO ALTO CA / CAMBRIDGE #1 1/17/2016 12:16  3.677487
>> 17 PALO ALTO CA / CAMBRIDGE #1 1/17/2016 13:53  1.068393
>> 18 PALO ALTO CA / CAMBRIDGE #1 1/17/2016 19:03  8.820755
>> 19 PALO ALTO CA / CAMBRIDGE #1 1/17/2016 22:00  8.138583
>> 20 PALO ALTO CA / CAMBRIDGE #1 1/18/2016  8:58  9.057500
>>
>> I have tried this:
>> library(dplyr)
>> sums <- dt1 %>%
>>   group_by(date) %>%
>>   summarise(EnergykWh = sum(EnergykWh))
>>
>> head(sums,20)
>>
>> The date is not by daily sequence but by year sequence.
>>
>> > head(sums,20)# A tibble: 20 × 2
>>date  EnergykWh
>>  1 1/1/2017 25.3   2 1/1/2018 61.0   3 
>> 1/1/2019  0.627 4 1/1/2020 10.7   5 1/10/201769.4   6 1/10/2018  
>>   54.5   7 1/10/201949.1   8 1/10/202045.9   9 1/11/201773.9  10 
>> 1/11/201853.3  11 1/11/201993.5  12 1/11/2020   

Re: [R] [Tagged] Re: col.names in as.data.frame() ?

2023-10-28 Thread Jeff Newmiller via R-help
as.data.frame is a _converter_, while data.frame is a _constructor_.  Changing 
the object contents is not what a conversion is for.

On October 28, 2023 11:39:22 AM PDT, Boris Steipe  
wrote:
>Thanks Duncan and Avi!
>
>That you could use NULL in a matrix() dimnames = list(...) argument wasn't 
>clear to me. I thought that would be equivalent to a one-element list - and 
>thereby define rownames. So that's good to know.
>
>The documentation could be more explicit - but it is probably more work to do 
>that than just patch the code to honour a col.names argument. (At least I 
>can't see a reason not to.)
>
>Thanks again!
>:-)
>
>
>
>
>> On Oct 28, 2023, at 14:24, avi.e.gr...@gmail.com wrote:
>> 
>> Борис,
>> 
>> Try this where you tell matrix the column names you want:
>> 
>> nouns <- as.data.frame(
>>  matrix(c(
>>"gaggle",
>>"geese",
>> 
>>"dule",
>>"doves",
>> 
>>"wake",
>>"vultures"
>>  ), 
>>  ncol = 2, 
>>  byrow = TRUE, 
>>  dimnames=list(NULL, c("collective", "category"
>> 
>> Result:
>> 
>>> nouns
>>  collective category
>> 1 gagglegeese
>> 2   duledoves
>> 3   wake vultures
>> 
>> 
>> The above simply names the columns earlier when creating the matrix.
>> 
>> There are other ways and the way you tried LOOKS like it should work but
>> fails for me with a message about it weirdly expecting three rows versus two
>> which seems to confuse rows and columns. My version of R is recent and I
>> wonder if there is a bug here.
>> 
>> Consider whether you really need the data.frame created in a single
>> statement or can you change the column names next as in:
>> 
>> 
>>> nouns
>>  V1   V2
>> 1 gagglegeese
>> 2   duledoves
>> 3   wake vultures
>>> colnames(nouns)
>> [1] "V1" "V2"
>>> colnames(nouns) <- c("collective", "category")
>>> nouns
>>  collective category
>> 1 gagglegeese
>> 2   duledoves
>> 3   wake vultures
>> 
>> Is there a known bug here or is the documentation wrong?
>> 
>> -Original Message-
>> From: R-help  On Behalf Of Boris Steipe
>> Sent: Saturday, October 28, 2023 1:54 PM
>> To: R. Mailing List 
>> Subject: [R] col.names in as.data.frame() ?
>> 
>> I have been trying to create a data frame from some structured text in a
>> single expression. Reprex:
>> 
>> nouns <- as.data.frame(
>>  matrix(c(
>>"gaggle",
>>"geese",
>> 
>>"dule",
>>"doves",
>> 
>>"wake",
>>"vultures"
>>  ), ncol = 2, byrow = TRUE),
>>  col.names = c("collective", "category")
>> )
>> 
>> But ... :
>> 
>>> str(nouns)
>> 'data.frame': 3 obs. of  2 variables:
>> $ V1: chr  "gaggle" "dule" "wake"
>> $ V2: chr  "geese" "doves" "vultures"
>> 
>> i.e. the col.names argument does nothing. From my reading of ?as.data.frame,
>> my example should have worked.
>> 
>> I know how to get the required result with colnames(), but I would like to
>> understand why the idiom as written didn't work, and how I could have known
>> that from the help file.
>> 
>> 
>> Thanks!
>> Boris
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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.

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


Re: [R] Yext in parentheses.

2023-10-26 Thread Jeff Newmiller via R-help
I recommend cutting snippets out of your code by stopping the code at the point 
of interest and using dput() to pull out "data as it is" before the troublesome 
section and then using the reprex package to test that the snippet runs.

Either you will notice the problem on your own while taking this time, or you 
will end up with something we can actually try out. Your current approach fails 
to provide everything we might need precisely because you don't know what you 
need to know to solve your problem.

If you have privacy issues with the data then once you have a reprex you can 
make a shareable reprex by replacing the private data with generic data of the 
same type. Also, you should often experiment to reduce the size of your sample 
data to a minimum necessary to reproduce the problem, as this will often remove 
unnecessary confusion as well.

Remember, you are trying to learn how to solve your problems on your own 
anyway, so this is not wasted time even if you do end up solving it on your own.

On October 26, 2023 9:18:10 AM PDT, Steven Yen  wrote:
>Dear All
>
>My program is long and sorry I do not have a replicable set of codes to 
>present. But I present a chunk of codes at the end below. Essentially,
>
>1. I initialize cat.ref as NUL (see line 1)
>
>2. Then, I repeatedly add elements to cat.ref, where each element 
>include parentheses in double quotations (see line 2).
>
>I had expected cat.ref to eventually contain the list
>
>dilemma1(ref),scigrn1(ref),...
>
>Not so, I end up getting the following (see first column; not in 
>parentheses, like (ref.)).
>
>dilemma1.ref.. 22.356 2.619 8.535 0.000 *** scigrn1.ref.. 22.474 2.697 
>8.334 0.000 ***
>
>Any idea how I might revise lines like the following (first line below):
>
>dv.group<-c("dilemma2","dilemma3"); cat.ref<-"dilemma1(ref.)"
>
>etc. Thanks.
>
>   ap0<-zx.ref<-NULL
>
>   dv.group<-c("dilemma2","dilemma3"); cat.ref<-"dilemma1(ref.)"
>   if(any(dv.group%in%jindex)){
>     v<-pred0(dv.group,cat.ref)
>     ap0<-rbind(ap0,v$ap0); zx.ref<-c(zx.ref,v$cat.ref)
>   }
>
>   dv.group<-c("scigrn2","scigrn3"); cat.ref<-"scigrn1(ref.)"
>   if(any(dv.group%in%jindex)){
>     v<-pred0(dv.group,cat.ref)
>     ap0<-rbind(ap0,v$ap0); zx.ref<-c(zx.ref,v$cat.ref)
>   }
>
>
>   [[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.


Re: [R] [Tagged] Re: Fwd: r-stats: Geometric Distribution

2023-10-19 Thread Jeff Newmiller via R-help
What makes sense in a math class is not necessarily the same as what makes 
sense in a floating point analysis environment.

You lose a lot of significant digits when you add 1 to a floating point number 
that is close to zero, and this implementation allows the user to avoid that 
structural deficiency inherent in your preferred formulation.

This is a case where you need to read the documentation and adapt your handling 
of numbers to get the most accurate results.

Or write your own version that destroys significant digits.

There are other functions that allow for similar maintenance of significant 
digits... like log1p and expm1. See i.e. 
https://en.m.wikipedia.org/wiki/Natural_logarithm#lnp1 for discussion.

On October 18, 2023 10:44:21 PM PDT, Sahil Sharma 
 wrote:
>Hi, today I came across the same problem. And, I'm able to explain it with
>an example as well.
>
>Suppose I want to PDF or P(X=5) in Geometric Distribution with P = 0.2.
>
>The theoretical formula is P * (1-P) ^ (x -1). But the R function dgeom(x,
>p) works like P * (1-P) ^ x, it does not reduce 1 from x because in r the x
>starts from 0. In that case, if I am writing x as 5 then in-principle it
>should work like x = 4 because starting from zero, 4 is the 5th place of x.
>E.g., 0,1,2,3,4 there are five digits.
>
>However, the x in dgeom(x,p) is exactly working like 5.
>
>Here are some codes that I used:
>
>> dgeom(5, 0.2)
>[1] 0.065536
>
>If I use the formula manually, i.e., p(1-P)^x-1, I get this.
>
>> 0.2 * (1-0.2)^(5-1)
>[1] 0.08192
>
>Even if x starts from 0 in r, that's why we do not minus 1 from x, it
>should work like 4 when I'm writing 5, but not, it is working exactly 5.
>For example, if I manually put the 5 at the place of X, I get same results
>as dgeom(x,p).
>
>> 0.2 * (1-0.2)^(5)
>[1] 0.065536
>
>
>
>I guess there is a need for solution to this problem otherwise, it may
>result in erroneous calculations. Either the function dgeom(x,p) can
>perform and result as per the theoretical definition of PDF in Geometric
>Distribution, or the user applying this function must be prompted about the
>nature of this function so that the user manually minus one from x and then
>enter it into the function dgeom(x,p).
>
>Thanks, and Regards
>Sahil
>
>
>
>
>
>On Tue, Oct 17, 2023 at 6:39 PM Ivan Krylov  wrote:
>
>> В Tue, 17 Oct 2023 12:12:05 +0530
>> Sahil Sharma  пишет:
>>
>> > The original formula for Geometric Distribution PDF is
>> > *((1-p)^x-1)*P*. However, the current r function *dgeom(x, p)* is
>> > doing this: *((1-p)^x)*P, *it is not reducing 1 from x.
>>
>> Your definition is valid for integer 'x' starting from 1. ('x'th trial
>> is the first success.)
>>
>> The definition in help(dgeom):
>>
>> >> p(x) = p (1-p)^x
>> >> for x = 0, 1, 2, ..., 0 < p <= 1.
>>
>> ...is valid for integer x starting from 0. ('x' failures until the
>> first success.)
>>
>> They are equivalent, but they use the name 'x' for two subtly different
>> things.
>>
>> Thank you for giving attention to this and best of luck in your future
>> research!
>>
>> --
>> Best regards,
>> Ivan
>>
>
>   [[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.


Re: [R] Best way to test for numeric digits?

2023-10-18 Thread Jeff Newmiller via R-help
Use any occurrence of one or more digits as a separator?

s <- c( "CCl3F", "Li4Al4H16", "CCl2CO2AlPO4SiO4Cl" )
strsplit( s, "\\d+" )


On October 18, 2023 7:59:01 AM PDT, Leonard Mada via R-help 
 wrote:
>Dear List members,
>
>What is the best way to test for numeric digits?
>
>suppressWarnings(as.double(c("Li", "Na", "K",  "2", "Rb", "Ca", "3")))
># [1] NA NA NA  2 NA NA  3
>The above requires the use of the suppressWarnings function. Are there any 
>better ways?
>
>I was working to extract chemical elements from a formula, something like this:
>split.symbol.character = function(x, rm.digits = TRUE) {
>    # Perl is partly broken in R 4.3, but this works:
>    regex = "(?<=[A-Z])(?![a-z]|$)|(?<=.)(?=[A-Z])|(?<=[a-z])(?=[^a-z])";
>    # stringi::stri_split(x, regex = regex);
>    s = strsplit(x, regex, perl = TRUE);
>    if(rm.digits) {
>    s = lapply(s, function(s) {
>        isNotD = is.na(suppressWarnings(as.numeric(s)));
>        s = s[isNotD];
>    });
>    }
>    return(s);
>}
>
>split.symbol.character(c("CCl3F", "Li4Al4H16", "CCl2CO2AlPO4SiO4Cl"))
>
>
>Sincerely,
>
>
>Leonard
>
>
>Note:
># works:
>regex = "(?<=[A-Z])(?![a-z]|$)|(?<=.)(?=[A-Z])|(?<=[a-z])(?=[^a-z])";
>strsplit(c("CCl3F", "Li4Al4H16", "CCl2CO2AlPO4SiO4Cl"), regex, perl = T)
>
>
># broken in R 4.3.1
># only slightly "erroneous" with stringi::stri_split
>regex = "(?<=[A-Z])(?![a-z]|$)|(?=[A-Z])|(?<=[a-z])(?=[^a-z])";
>strsplit(c("CCl3F", "Li4Al4H16", "CCl2CO2AlPO4SiO4Cl"), regex, perl = T)
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Ynt: creating a time series

2023-10-16 Thread Jeff Newmiller via R-help
Then your data has extra data points... either duplicates or records with 
timestamps not on 15min intervals.


On October 16, 2023 7:29:25 AM PDT, "ahmet varlı"  
wrote:
>hello,
>
>because ı have data between these times and it has 177647 elements
>
>Gönderen: Marc Girondot via R-help  adına R-help 
>
>Gönderildi: 16 Ekim 2023 Pazartesi 13:43
>Kime: r-help@r-project.org 
>Konu: Re: [R] creating a time series
>
>Why did you expect to have 177647 elements ?
>
>I found that 177642 is the correct number:
>
>Marc
>
>baslangic <- as.POSIXct("2017-11-02 13:30:00", tz = "CET")
>bitis <- as.POSIXct("2022-11-26 23:45:00", tz = "CET")  #
>zaman_seti <- seq.POSIXt(from = baslangic, to = bitis, by = 60 * 15)
>
>y2017_11_02 <- seq(from=as.POSIXct("2017-11-02 13:30:00", tz = "CET"),
>to=as.POSIXct("2017-11-02 23:45:00", tz = "CET"), by = 60 * 15)
># Length 42 - OK
>length(y2017_11_02)
>y2017_11_12 <- seq(from=as.POSIXct("2017-11-03 00:00:00", tz = "CET"),
>to=as.POSIXct("2017-12-31 23:45:00", tz = "CET"), by = 60 * 15)
># ((30-2)+31)*24*4=5664 - OK
>length(y2017_11_12)
>y2018 <- seq(from=as.POSIXct("2018-01-01 00:00:00", tz = "CET"),
>to=as.POSIXct("2018-12-31 23:45:00", tz = "CET"), by = 60 * 15)
># (365)*24*4=35040 - OK
>length(y2018)
>y2019 <- seq(from=as.POSIXct("2019-01-01 00:00:00", tz = "CET"),
>to=as.POSIXct("2019-12-31 23:45:00", tz = "CET"), by = 60 * 15)
># (365)*24*4=35040 - OK
>length(y2019)
>y2020 <- seq(from=as.POSIXct("2020-01-01 00:00:00", tz = "CET"),
>to=as.POSIXct("2020-12-31 23:45:00", tz = "CET"), by = 60 * 15)
># (366)*24*4=35136 - OK
>length(y2020)
>y2021 <- seq(from=as.POSIXct("2021-01-01 00:00:00", tz = "CET"),
>to=as.POSIXct("2021-12-31 23:45:00", tz = "CET"), by = 60 * 15)
># (365)*24*4=35040 - OK
>length(y2021)
>y2022 <- seq(from=as.POSIXct("2022-01-01 00:00:00", tz = "CET"),
>to=as.POSIXct("2022-11-26 23:45:00", tz = "CET"), by = 60 * 15)
># (365-31-4)*24*4=31680 - OK
>length(y2022)
>
>length(y2017_11_02)+length(y2017_11_12)+length(y2018)+length(y2019)+length(y2020)+length(y2021)+length(y2022)
>length(zaman_seti)
>
>
>Le 16/10/2023 à 12:12, ahmet varlı a écrit :
>> Hello everyone,
>>
>> � had 15 minutes of data from 2017-11-02 13:30:00 to  2022-11-26 23:45:00 
>> and number of data is 177647
>>
>> � would like to ask why my time series are less then my expectation.
>>
>>
>> baslangic <- as.POSIXct("2017-11-02 13:30:00", tz = "CET")
>> bitis <- as.POSIXct("2022-11-26 23:45:00", tz = "CET")  #
>> zaman_seti <- seq.POSIXt(from = baslangic, to = bitis, by = 60 * 15)
>>
>>
>> length(zaman_seti)
>> [1] 177642
>>
>> but it has to be  177647
>>
>>
>>
>> and secondly � have times in this format ( 2.11.2017 13:30/DD-MM- 
>> HH:MM:SS)
>>
>> su_seviyeleri_data <- as.POSIXct(su_seviyeleri_data$kayit_zaman, format = 
>> "%Y-%m-%d %H:%M:%S")
>>
>> I am using this code to change the format but it gives result as Na
>>
>> How can � solve this problem?
>>
>> Bests,
>>
>>
>>
>>
>>
>>[[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.

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


Re: [R] Plot to a device and examine the plot?

2023-10-15 Thread Jeff Newmiller via R-help
This question is not clear to me. What is it you hope to retrieve from the 
device?

Note that the type of device in your example is system-dependent. The content 
in a png() would be different than the content in a win.graph() device.

On October 15, 2023 8:04:00 AM PDT, Shu Fai Cheung  
wrote:
>Hi All,
>
>I want to inspect the content of a plot generated by another function.
>
>For example:
>
>plot.new()
>polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
>
>A polygon will be drawn. If I do not know what has been done to generate
>the plot, is it possible to query the content in the active device?
>
>Regards,
>Shu Fai
>
>   [[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.


Re: [R] Create new data frame with conditional sums

2023-10-14 Thread Jeff Newmiller via R-help
Pre-compute the per-interval answers and use findInterval to look up the 
per-row answers...

dat <- read.table( text=
"Tract  Pct Totpop
1  0.054000
2  0.033500
3  0.014500
4  0.124100
5  0.213900
6  0.044250
7  0.075100
8  0.094700
9  0.064950
10 0.034800
", header=TRUE )
dat2 <- aggregate( Totpop ~ Pct, dat, FUN = sum )
dat2$TotpopSum <- rev( cumsum( rev( dat2$Totpop ) ) )
Cutoff <- seq( 0, .15, .01 )
ans <- data.frame(
  Cutoff = Cutoff
  , Pop = dat2$TotpopSum[
findInterval(
  Cutoff
  , c( -Inf, dat2$Pct )
  , left.open = TRUE
)
  ]
)
ans




On October 14, 2023 8:10:56 AM PDT, Bert Gunter  wrote:
>Well, here's one way to do it:
>(dat is your example data frame)
>
>Cutoff <- seq(0, .15, .01)
>Pop <- with(dat, sapply(Cutoff, \(p)sum(Totpop[Pct >= p])))
>
>I think there must be a more efficient way to do it with cumsum(), though.
>
>Cheers,
>Bert
>
>On Sat, Oct 14, 2023 at 12:53 AM Jason Stout, M.D.  
>wrote:
>>
>> This seems like it should be simple but I can't get it to work properly.  
>> I'm starting with a data frame like this:
>>
>> Tract  Pct  Totpop
>> 1  0.054000
>> 2  0.033500
>> 3  0.014500
>> 4  0.124100
>> 5  0.213900
>> 6  0.044250
>> 7  0.075100
>> 8  0.094700
>> 9  0.064950
>> 10   0.034800
>>
>> And I want to end up with a data frame with two columns, a "Cutoff" column 
>> that is a simple sequence of equally spaced cutoffs (let's say in this case 
>> from 0-0.15 by 0.01) and a "Pop" column which equals the sum of "Totpop" in 
>> the prior data frame in which "Pct" is greater than or equal to "cutoff."  
>> So in this toy example, this is what I want for a result:
>>
>>Cutoff   Pop
>> 10.00 43800
>> 20.01 43800
>> 30.02 39300
>> 40.03 39300
>> 50.04 31000
>> 60.05 26750
>> 70.06 22750
>> 80.07 17800
>> 90.08 12700
>> 10   0.09 12700
>> 11   0.10  8000
>> 12   0.11  8000
>> 13   0.12  8000
>> 14   0.13  3900
>> 15   0.14  3900
>> 16   0.15  3900
>>
>> I can do this with a for loop but it seems there should be an easier, 
>> vectorized way that would be more efficient.  Here is a reproducible example:
>>
>> dummydata<-data.frame(Tract=seq(1,10,by=1),Pct=c(0.05,0.03,0.01,0.12,0.21,0.04,0.07,0.09,0.06,0.03),Totpop=c(4000,3500,4500,4100,
>>  
>> 3900,4250,5100,4700,
>>  
>> 4950,4800))
>> dfrm<-data.frame(matrix(ncol=2,nrow=0,dimnames=list(NULL,c("Cutoff","Pop"
>> for (i in seq(0,0.15,by=0.01)) {
>>  temp<-sum(dummydata[dummydata$Pct>=i,"Totpop"])
>> dfrm[nrow(dfrm)+1,]<-c(i,temp)
>> }
>>
>> Jason Stout, MD, MHS
>> Division of Infectious Diseases
>> Dept of Medicine
>> Duke University
>> Box 102359-DUMC
>> Durham, NC 27710
>> FAX 919-681-7494
>>
>>
>> [[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.

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


Re: [R] if-else that returns vector

2023-10-12 Thread Jeff Newmiller via R-help
What a strange question... ifelse returns a vector (all data in R is vectors... 
some have length 1, but length zero is also possible, as are longer vectors) 
that is exactly as long as the logical vector that you give it, filled with 
elements from the respective positions in the vectors supplied in the second 
and third arguments. Because your logical vector is length 1, you only get a 
vector with the first element of the second argument.

If you want to choose between one of two vectors considered wholly, then "if" 
is what you need:

result <- if (TRUE) c(1,2,3) else c(5,6)


On October 12, 2023 1:22:03 PM PDT, Christofer Bogaso 
 wrote:
>Hi,
>
>Following expression returns only the first element
>
>ifelse(T, c(1,2,3), c(5,6))
>
>However I am looking for some one-liner expression like above which
>will return the entire vector.
>
>Is there any way to achieve this?
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Is it possible to get a downward pointing solid triangle plotting symbol in R?

2023-10-08 Thread Jeff Newmiller via R-help
Ah, I accidentally replied only to you. I re-introduced the list here...

Maybe this [1] will help?

[1] 
https://coolbutuseless.github.io/2021/11/04/custom-ggplot2-point-shapes-with-gggrid/

On October 8, 2023 1:04:23 AM PDT, Chris Evans  wrote:
>
>On 07/10/2023 17:45, Jeff Newmiller wrote:
>> No, you seem to be missing the distinction between code points (numbers 
>> representing the semantics of a character) and the visible presentation of a 
>> character. Some graphics devices don't understand Unicode at all (e.g. 
>> pdf()) and not all fonts have glyphs for all code points.
>Thanks, that's helpful.  I think I have no illusions about that distinction 
>but seem to have overvalued what it said in 
>https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Encoding-issues. 
>That doesn't alert to the issue with pdf() and fonts.  I did have a niggly 
>feeling things couldn't be as easy as that seemed to imply.
>> Which is not to say you cannot get away with using this approach... but you 
>> will need to be prepared to deal with "it doesn't work" or "it looks wrong" 
>> complaints so documenting where it doesn't work (as you deal with such 
>> complaints?) may be advisable for your sanity. A solution that hardcoded 
>> three-sided polygons would avoid such concerns though it would be more 
>> tedious.
>
>And certainly beyond my limited programming capacities.  Hm, I suspect PDF 
>output will be important to to some users, probably including myself, so if 
>that won't handle this then I think I probably will go for the clumsy but 
>seemingly usable workaround using ggnewscale at least for now.  I'll check out 
>its output with the main graphic file outputs (probably not the correct term: 
>pdf(), png() etc.) but I assume that as the fillable triangles are in the 
>default R symbols they will come through to those various outputs.
>
>Was there a reason you replied only to me?  This seems the sort of 
>clarification that I learn from watching the list: too trivial?  I would like 
>to post it to the list but won't unless you are OK for me to do that.
>
>Many thanks again ...
>
>Chris
>
>> 
>> On October 7, 2023 8:18:24 AM PDT, Chris Evans via 
>> R-help  wrote:
>>> SO helpful. Thanks to all.  I _think_ the answer to Jeff's question may be 
>>> "It should only be problematical on R earlier than 2.10". At least,
>>> that's how I read this:
>>> 
>>> There is a portable way to have arbitrary text in character strings (only) 
>>> in your R code, which is to supply them in Unicode as ‘\u’
>>> escapes (or, rarely needed except for emojis, ‘\U’ escapes). If 
>>> there are any characters not in the current encoding the parser
>>> will encode the character string as UTF-8 and mark it as such. This applies 
>>> also to character strings in datasets: they can be prepared
>>> using ‘\u’ escapes or encoded in UTF-8 in a UTF-8 locale, or even 
>>> converted to UTF-8 /via/ |iconv()|. If you do this, make sure you have
>>> ‘R (>= 2.10)’ (or later) in the ‘Depends’ field of the DESCRIPTION file.
>>> 
>>> (Quoting 
>>> fromhttps://cran.r-project.org/doc/manuals/r-release/R-exts.html#Encoding-issues.
>>>  Thanks for that pointer Jan.)
>>> 
>>> ### using UTF to solve my issue (for R versions >= 2.10 I think)
>>> library(tidyverse)
>>> tibble(x = 2:9, y = 2:9, c = c(rep("A", 5), rep("B", 3))) %>%
>>>    mutate(y1 = y + 1,
>>>   y2 = y + 2) -> tmpTibPoints
>>> tibble(x = c(1, 5, 5, 1), y = c(1, 1, 5, 5), a = rep("a", 4)) -> tmpTibArea1
>>> tibble(x = c(5, 10, 10, 5), y = c(1, 1, 5, 5), a = rep("b", 4)) -> 
>>> tmpTibArea2
>>> tibble(x = c(1, 5, 5, 1), y = c(5, 5, 10, 10), a = rep("c", 4)) -> 
>>> tmpTibArea3
>>> tibble(x = c(5, 10, 10, 5), y = c(5, 5, 10, 10), a = rep("d", 4)) -> 
>>> tmpTibArea4
>>> bind_rows(tmpTibArea1,
>>>     tmpTibArea2,
>>>     tmpTibArea3,
>>>     tmpTibArea4) -> tmpTibAreas
>>> 
>>> # Unicode characters for black up- and down-pointing characters
>>> pts_shapes <- c("\U25B2", "\U25BC") |> setNames(c("A", "B"))
>>> pts_colors <- c("blue", "red") |> setNames(c("A", "B"))
>>> 
>>> pts_shapes
>>> 
>>> ggplot() +
>>>    ### this was the suggestion from Rui Barradas
>>>    geom_point(data = tmpTibPoints,
>>>  

Re: [R] Confirming MySQL Alive

2023-10-07 Thread Jeff Newmiller via R-help
Not really an R question, but some processes are connected to interactive 
terminals (where someone can type) and some are not (because they were created 
and managed by another process). The system call creates a process and controls 
all interactions with that process. You really should not be messing with sudo 
in the background like that.

On October 7, 2023 8:09:25 AM PDT, "Stephen H. Dawson, DSL via R-help" 
 wrote:
>Hi,
>
>
>Getting some data from an older MySQL box. I had an event recently where the 
>MySQL box went off-line for maintenance without a prior announcement of 
>service disruption.
>
>I decided to add a line on my local version of MySQL as I considered how to 
>handle this condition going forward.
>
>system("sudo systemctl status mysql", input = rstudioapi::askForPassword("sudo 
>password"))
>
>system("sudo systemctl status mysql",input=readline("Enter Password: "))
>
>
>Both fail for the same reason, saying I need a terminal.
>
>
>> system("sudo systemctl status mysql", input = 
>> rstudioapi::askForPassword("sudo password"))
>sudo: a terminal is required to read the password; either use the -S option to 
>read from standard input or configure an askpass helper
>sudo: a password is required
>>
>
>
>
>> system("sudo systemctl status mysql",input=readline("Enter Password: "))
>Enter Password: ***REDACTED***
>sudo: a terminal is required to read the password; either use the -S option to 
>read from standard input or configure an askpass helper
>sudo: a password is required
>>
>
>
>
>I can run the code segments for things like ls and pwd. So, there is something 
>unique about systemctl and R that is beyond my understanding today.
>
>QUESTIONS
>What is so special about systemctl and R in a system syntax statement?
>
>What are some of the best practices to confirm a box I am hitting for data 
>with R , either local or across the network, has MySQL up and running?
>
>
>Thanks,

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


Re: [R] R Gigs

2023-10-06 Thread Jeff Newmiller via R-help
That list is _very_ low volume... most employers who would benefit from the 
skills of an R user don't know that R exists.

On October 6, 2023 1:50:17 PM PDT, Fred Kwebiha  wrote:
>Thanks Bert.
>
>I have Subscribed now to that list.
>
>*Best Regards,*
>
>*FRED KWEBIHA*
>*+256-782-746-154*
>
>
>On Fri, Oct 6, 2023 at 11:36 PM Bert Gunter  wrote:
>
>> May be an age gap here, but I assume "gigs" = freelance jobs. If so,
>> https://stat.ethz.ch/mailman/listinfo/r-sig-jobs
>> might be useful. As well as an online search in all the usual places.
>> Otherwise, please excuse my out-of-date ignorance.
>>
>> Cheers,
>> Bert
>>
>> On Fri, Oct 6, 2023 at 1:23 PM Fred Kwebiha  wrote:
>> >
>> > Dear Community,
>> >
>> > Where Can I get Gigs related to R programming language?
>> >
>> > Thanks in Advance for your help.
>> >
>> > *Best Regards,*
>> >
>> > *FRED KWEBIHA*
>> > *+256-782-746-154*
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[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.


Re: [R] Is it possible to get a downward pointing solid triangle plotting symbol in R?

2023-10-06 Thread Jeff Newmiller via R-help
Doesn't the outcome of this suggestion still depend on which fonts and output 
device you are using? ... and that is to some degree still system dependent...

On October 6, 2023 7:50:00 AM PDT, Rui Barradas  wrote:
>Às 10:09 de 06/10/2023, Chris Evans via R-help escreveu:
>> The reason I am asking is that I would like to mark areas on a plot using 
>> geom_polygon() and aes(fill = variable) to fill various polygons forming the 
>> background of a plot with different colours. Then I would like to overlay 
>> that with points representing direction of change: improved, no reliable 
>> change, deteriorated. The obvious symbols to use for those three directions 
>> are an upward arrow, a circle or square and a downward pointing arrow.  
>> There is a solid upward point triangle symbol in R (ph = 17) and there are 
>> both upward and downward pointing open triangle symbols (pch 21 and 25) but 
>> to fill those with a solid colour so they will be visible over the 
>> background requires that I use a fill aesthetic and that gets me a mess with 
>> the legend as I will have used a different fill mapping to fill the 
>> polygons.  This silly reprex shows the issue I think.
>> 
>> library(tidyverse)
>> tibble(x = 2:9, y = 2:9, c = c(rep("A", 5), rep("B", 3))) -> tmpTibPoints
>> tibble(x = c(1, 5, 5, 1), y = c(1, 1, 5, 5), a = rep("a", 4)) -> tmpTibArea1
>> tibble(x = c(5, 10, 10, 5), y = c(1, 1, 5, 5), a = rep("b", 4)) -> 
>> tmpTibArea2
>> tibble(x = c(1, 5, 5, 1), y = c(5, 5, 10, 10), a = rep("c", 4)) -> 
>> tmpTibArea3
>> tibble(x = c(5, 10, 10, 5), y = c(5, 5, 10, 10), a = rep("d", 4)) -> 
>> tmpTibArea4
>> bind_rows(tmpTibArea1,
>>    tmpTibArea2,
>>    tmpTibArea3,
>>    tmpTibArea4) -> tmpTibAreas
>> ggplot(data = tmpTib,
>>     aes(x = x, y = y)) +
>>    geom_polygon(data = tmpTibAreas,
>>     aes(x = x, y = y, fill = a)) +
>>    geom_point(data = tmpTibPoints,
>>   aes(x = x, y = y, fill = c),
>>   pch = 24,
>>   size = 6)
>> 
>> Does anyone know a way to create a solid downward pointing symbol?  Or 
>> another workaround?
>> 
>> TIA,
>> 
>> Chris
>> 
>Hello,
>
>Maybe you can solve the problem with unicode characters.
>See the two scale_*_manual at the end of the plot.
>
>
>
># Unicode characters for black up- and down-pointing characters
>pts_shapes <- c("\U25B2", "\U25BC") |> setNames(c("A", "B"))
>pts_colors <- c("blue", "red") |> setNames(c("A", "B"))
>
>ggplot(data = tmpTibAreas,
>   aes(x = x, y = y)) +
>  geom_polygon(data = tmpTibAreas,
>   aes(x = x, y = y, fill = a)) +
>  geom_point(data = tmpTibPoints,
> aes(x = x, y = y, color = c, shape = c),
> size = 6) +
>  scale_shape_manual(values = pts_shapes) +
>  scale_color_manual(values = pts_colors)
>
>
>
>

-- 
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] Jim Lemon RIP (was Re: save(), load(), saveRDS(), and readRDS())

2023-10-04 Thread Jeff Newmiller via R-help
Thank you for informing us. Jim was a remarkably patient helper of many lost R 
analysts. His efforts will be missed.

On October 4, 2023 3:36:50 PM PDT, Jim Lemon  wrote:
>Hello,
>I am very sad to let you know that my husband Jim died on 18th September. I
>apologise for not letting you know earlier but I had trouble finding the
>password for his phone.
>Kind regards,
>Juel
>
>On Fri, 29 Sep 2023, 01:48 Shu Fai Cheung 
>> Hi All,
>>
>> There is a thread about the use of save(), load(), saveRDS(), and
>> loadRDS(). It led me to think about a question regarding them.
>>
>> In my personal work, I prefer using saveRDS() and loadRDS() as I don't like
>> the risk of overwriting anything in the global environment. I also like the
>> freedom to name an object when reading it from a file.
>>
>> However, for teaching, I have to teach save() and load() because, in my
>> discipline, it is common for researchers to share their datasets on the
>> internet using the format saved by save(), and so students need to know how
>> to use load() and what will happen when using it. Actually, I can't recall
>> encountering datasets shared by the .rds format. I have been wondering why
>> save() was usually used in that case.
>>
>> That discussion led me to read the help pages again and I noticed the
>> following warning, from the help page of saveRDS():
>>
>> "Files produced by saveRDS (or serialize to a file connection) are not
>> suitable as an interchange format between machines, for example to download
>> from a website. The files produced by save
>>  have a header identifying
>> the file type and so are better protected against erroneous use."
>>
>> When will the problem mentioned in the warning occur? That is, when will a
>> file saved by saveRDS() not be read correctly? Saved in Linux and then read
>> in Windows? Is it possible to create a reproducible error?
>>
>> Regards,
>> Shu Fai
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

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


Re: [R] save() and load()

2023-09-25 Thread Jeff Newmiller via R-help
You never created any object in R called irisdataTest. Objects in the global 
environment have names that are unrelated to the names of files on disk.

The load function modifies an environment to create a variable named as it was 
named in the environment from which it was saved. Thus, you cannot simply load 
an object that was saved with one name into an object named something else. It 
is possible to create a new environment to put the loaded objects into, but I 
wouldn't recommend trying to explain how to do that to a beginner.  Rather, I 
would instead recommend using saveRDS and readRDS instead to save/load exactly 
one object at a time without storing the object name.

saveRDS( mtcars, "my_mtcars.rds" )
new_obj <- readRDS( "my_mtcars.rds" )

I would also guide them to never save their environment when prompted by R... 
the .RData file this creates will remember mistakes made in previous sessions 
making troubleshooting very difficult later. Instead they should focus on 
making a top-to-bottom script that has all their analysis steps so they can 
start from scratch.

On September 25, 2023 6:23:01 PM PDT, AbouEl-Makarim Aboueissa 
 wrote:
>Dear ALL:
>
>I am teaching statistical packages class this semester, in R programing I
>am trying to explain the use of save() and load() with an example using the
>iris data. It seems that the save() function works, BUT when I tried to
>load the data back to R, it seems that there is a problem(s), I could not
>figure out what went wrong.
>
>Any help would be highly appreciated.
>
>
>I saved the iris data in my computer in the text format, "iris.with.head.txt
>".
>
>Here are my R codes:
>
>> irisdata<-read.table("G:/iris.with.head.txt", header=T)
>>
>> head(irisdata)
>  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
>1  5.1 3.5  1.4 0.2  setosa
>2  4.9 3.0  1.4 0.2  setosa
>3  4.7 3.2  1.3 0.2  setosa
>4  4.6 3.1  1.5 0.2  setosa
>5  5.0 3.6  1.4 0.2  setosa
>6  5.4 3.9  1.7 0.4  setosa
>
>
>
>*# saving the data as an .rda*
>
>save(irisdata,file="G:/irisdataTest.rda")
>
>*# load the data back to R*
>
>load(file="G:/irisdataTest.rda")
>
>
>>head(irisdataTest)
>Error in head(irisdataTest) : object 'irisdataTest' not found
>
>> irisdataTest
>Error: object 'irisdataTest' not found
>
>
>
>with many thanks
>abou
>__
>
>
>*AbouEl-Makarim Aboueissa, PhD*
>
>*Professor, Mathematics and Statistics*
>*Graduate Coordinator*
>
>*Department of Mathematics and Statistics*
>*University of Southern Maine*
>
>   [[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.


Re: [R] Mantel Haenszel test

2023-09-23 Thread Jeff Newmiller via R-help
?cor

cor( M, t( M ) )


On September 23, 2023 7:56:29 AM PDT, tgs77m--- via R-help 
 wrote:
>Colleagues,
>
>I am trying to write a script for the Mantel Haenszel test.
>
>For the MH test, the test statistic is chi-square (MH) = (W-1) * r^2 
>Where W = sum of the case weights. This is straight forward.
>
>I'm having difficulty with r^2. The r^2 is the squared Pearson correlation
>between row and column variables.
>
>Can anyone give me an example of the code which calculates the squared
>Pearson correlation
>between row and column variables? 
>
>I am at a loss on how to do this.
>
>All the best,
>
>Thomas Subia
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] graph in R with grouping letters from the turkey test with agricolae package

2023-09-14 Thread Jeff Newmiller via R-help
This request sounds a lot like "do my work for me"... even like it might be 
homework... both scenarios are disallowed here.

Also, you need to read the Posting Guide... not all attachments are allowed on 
this mailing list, so even if you attached an image we did not get it. Go look 
at the mailing list archive to see what we got instead of what you sent.

On September 12, 2023 3:15:17 PM PDT, Loop Vinyl  wrote:
>Yes, the data and the R code used are attached.
>
>I would like to produce the attached graph (graph1) with the R package
>agricolae, could someone give me an example with the attached data
>(vermiwash and Rcode_vermiwash)?
>
>Fig. 7, https://doi.org/10.1007/s42729-023-01295-3
>
>I expect an adapted graph (graphDoubleFactor) with the data (vermiwash and
>Rcode_vermiwash)
>
>
>Best regards
>
>Em ter., 12 de set. de 2023 às 18:54, Rui Barradas 
>escreveu:
>
>> Às 16:24 de 12/09/2023, Loop Vinyl escreveu:
>> > I would like to produce the attached graph (graph1) with the R package
>> > agricolae, could someone give me an example with the attached data
>> (data)?
>> >
>> > I expect an adapted graph (graph2) with the data (data)
>> >
>> > Best regards
>> >
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> Hello,
>>
>> There are no attached graphs, only data.
>> Can you post the code have you tried?
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>>

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


Re: [R] only install.packages with type="source" will install packages

2023-09-14 Thread Jeff Newmiller via R-help
There is/was a discrepancy between versions in source form and in binary form 
for that package on the CRAN server. (The server that compiles binaries for 
MacOS has been stuck recently.) You declined (automatically or explicitly) to 
upgrade from source. This meant you kept an out-of-date binary version in your 
library when you declined. Updating from source brought you fully up-to-date.

This is normal. If you are not dying to stay on the bleeding edge, ignore the 
source-binary discrepancy that leaves you a bit behind... the binary on CRAN 
will eventually get updated.

On September 14, 2023 7:55:46 AM PDT, Marc Girondot via R-help 
 wrote:
>Dear members,
>
>Since #2 weeks I have a problem with install.packages() or update.packages():
>
>It seems to work, I have no error, but when I run again update.packages(), the 
>same package is proposed again.
>
>Example:
>
>> update.packages()
>insight :
> Version 0.19.3 installed in 
>/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
> Version 0.19.5 available at https://cran.irsn.fr
>Update? (Oui/non/annuler) a
>cancelled by user
>> install.packages("insight")
>essai de l'URL 
>'https://cran.irsn.fr/bin/macosx/big-sur-arm64/contrib/4.3/insight_0.19.3.tgz'
>Content type 'application/x-gzip' length 2092645 bytes (2.0 MB)
>==
>downloaded 2.0 MB
>Les packages binaires téléchargés sont dans
>    /tmp/RtmpDC1kqM/downloaded_packages
>> update.packages()
>insight :
> Version 0.19.3 installed in 
>/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
> Version 0.19.5 available at https://cran.irsn.fr
>Update? (Oui/non/annuler) a
>cancelled by user
>
>If I restart R, it gives the same result.
>
>My .libPaths() is "normal":
>[1] "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library"
>
>The solution is to install with type = "source"
>
>> install.packages("insight", type="source")
>essai de l'URL 
>'https://pbil.univ-lyon1.fr/CRAN/src/contrib/insight_0.19.5.tar.gz'
>Content type 'application/x-gzip' length 935072 bytes (913 KB)
>==
>downloaded 913 KB
>
>* installing *source* package ‘insight’ ...
>** package ‘insight’ correctement décompressé et sommes MD5 vérifiées
>** using staged installation
>** R
>** data
>** inst
>** byte-compile and prepare package for lazy loading
>** help
>*** installing help indices
>*** copying figures
>** building package indices
>** installing vignettes
>** testing if installed package can be loaded from temporary location
>** testing if installed package can be loaded from final location
>** testing if installed package keeps a record of temporary installation path
>* DONE (insight)
>
>Les packages source téléchargés sont dans
>    ‘/private/tmp/RtmpA4I8sr/downloaded_packages’
>
>Then update.packages() does not return insight package.
>
>Have you an idea of what's happened ?
>
>Thanks
>
>Marc
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Regarding error in RStudio

2023-09-05 Thread Jeff Newmiller
R is not RStudio. RStudio is not R.

RStudio helps you work with R, but to do so it "types" in some commands behind 
the scenes. I suspect those errors are because you have a pairing of versions 
of RStudio with a version of R that the RStudio team did not test.

Someone here might be able to help, but the most likely way to encounter 
someone who knows what bugs RStudio has is to ask in the RStudio support area 
[1].

[1] https://support.posit.co/hc/en-us

On September 5, 2023 9:59:28 AM PDT, Sukriti Sood  
wrote:
>Hi,
>
>I am Sukriti Sood, a research analyst at Woodstock Institute 
> . I use RStudio extensively for our analysis. I 
>have been facing two issues for a while:
>
>
>  1.  I am unable to copy from RStudio and paste into or vice versa to any 
> other programs.
>  2.  I am facing some kind of a conversion error (screenshot attached).
>
>I tried looking up online however could not find a resolution to these issues. 
>Could I please get some help with this urgently.
>
>Thanks!
>
>Best,
>Sukriti Sood
>
>Sukriti Sood | Research Analyst
>Woodstock Institute
>Pronouns: She/Her/Hers
>67 East Madison, Suite 2108 | Chicago, Illinois 60603
>O (312) 368-0310 x2029 | C (610) 604-6708
>www.woodstockinst.org | 
>ss...@woodstockinst.org
>
>
>

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


Re: [R] [Pkg-Collaboratos] BioShapes Almost-Package

2023-09-03 Thread Jeff Newmiller
Leonard... the reason roxygen exists is to allow markup in source files to be 
used to automatically generate the numerous files required by standard R 
packages as documented in Writing R Extensions.

If your goal is to not use source files this way then the solution is to not 
use roxygen at all. Just create those files yourself by directly editing them 
from scratch.

On September 3, 2023 7:06:09 PM PDT, Leonard Mada via R-help 
 wrote:
>Thank you Bert.
>
>
>Clarification:
>
>Indeed, I am using an add-on package: it is customary for that package - 
>that is what I have seen - to have the entire documentation included as 
>comments in the R src files. (But maybe I am wrong.)
>
>
>I will try to find some time over the next few days to explore in more 
>detail the R documentation. Although, I do not know how this will 
>interact with the add-on package.
>
>
>Sincerely,
>
>
>Leonard
>
>
>On 9/4/2023 4:58 AM, Bert Gunter wrote:
>> 1. R-package-devel is where queries about package protocols should go.
>>
>> 2. But...
>> "Is there a succinct, but sufficiently informative description of
>> documentation tools?"
>> "Writing R Extensions" (shipped with R) is *the* reference for R 
>> documentation. Whether it's sufficiently "succinct" for you, I cannot 
>> say.
>>
>> "I find that including the documentation in the source files is very
>> distracting."
>> ?? R documentation (.Rd) files are separate from source (.R) files. 
>> Inline documentation in source files is an "add-on" capability 
>> provided by optional packages if one prefers to do this. Such packages 
>> parse the source files to extract the documentation into the .Rd 
>> files/ So not sure what you mean here. Apologies if I have misunderstood.
>>
>> " I would prefer to have only basic comments in the source
>> files and an expanded documentation in a separate location."
>> If I understand you correctly, this is exactly what the R package 
>> process specifies. Again, see the "Writing R Extensions" manual for 
>> details.
>>
>> Also, if you wish to have your package on CRAN, it requires that the 
>> package documents all functions in the package as specified by the 
>> "Writing ..." manual.
>>
>> Again, further questions and elaboration should go to the 
>> R-package-devel list, although I think the manual is really the 
>> authoritative resource to follow.
>>
>> Cheers,
>> Bert
>>
>>
>>
>> On Sun, Sep 3, 2023 at 5:06 PM Leonard Mada via R-help 
>>  wrote:
>>
>> Dear R-List Members,
>>
>> I am looking for collaborators to further develop the BioShapes
>> almost-package. I added a brief description below.
>>
>> A.) BioShapes (Almost-) Package
>>
>> The aim of the BioShapes quasi-package is to facilitate the
>> generation
>> of graphical objects resembling biological and chemical entities,
>> enabling the construction of diagrams based on these objects. It
>> currently includes functions to generate diagrams depicting viral
>> particles, liposomes, double helix / DNA strands, various cell types
>> (like neurons, brush-border cells and duct cells), Ig-domains, as
>> well
>> as more basic shapes.
>>
>> It should offer researchers in the field of biological and chemical
>> sciences a tool to easily generate diagrams depicting the studied
>> biological processes.
>>
>> The package lacks a proper documentation and is not yet released on
>> CRAN. However, it is available on GitHub:
>> https://github.com/discoleo/BioShapes
>>
>> Although there are 27 unique cloners on GitHub, I am still looking
>> for
>> contributors and collaborators. I would appreciate any
>> collaborations to
>> develop it further. I can be contacted both by email and on GitHub.
>>
>>
>> B.) Documentation Tools
>>
>> Is there a succinct, but sufficiently informative description of
>> documentation tools?
>> I find that including the documentation in the source files is very
>> distracting. I would prefer to have only basic comments in the source
>> files and an expanded documentation in a separate location.
>>
>> This question may be more appropriate for the R-package-devel list. I
>> can move the 2nd question to that list.
>>
>> ###
>>
>> As the biological sciences are very vast, I would be very happy for
>> collaborators on the development of this package. Examples with
>> existing
>> shapes are available in (but are unfortunately not documented):
>>
>> Man/examples/Examples.Man.R
>> R/Examples.R
>> R/Examples.Cells.R
>> tests/experimental/*
>>
>>
>> Many thanks,
>>
>> Leonard
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> 
>> and provide 

Re: [R] Problems with installing R packages from source and running C++ in R, even on fresh R installation

2023-08-30 Thread Jeff Newmiller
TL:DR there are at least three maybe four ways to address this depending on 
what you plan to do.

I usually adjust PATH to add Rtools using .Rprofile. But if you do that then if 
you want to use the command line to invoke R then you need to set the PATH 
separately when you start the shell. For this reason some people like to set it 
in the User Environment Variables control panel... but some Rtools programs 
conflict with some Cygwin tools so I don't like to set it globally that way 
since I use Cygwin a lot.

Finally, I _think_ RStudio will try to look up your Rtools and adjust settings 
automagically from within RStudio, but only if you have never previously 
configured it in your environment variables. But that is only inferred from 
reports I have read that imply they never manually set anything and it "just 
works"... I have always set it up manually. If this sounds attractive then you 
might try making sure Rtools is NOT in your PATH before RStudio starts up _and_ 
that it isn't configured in your .Rprofile file.

On August 30, 2023 12:10:28 PM PDT, Duncan Murdoch  
wrote:
>On 30/08/2023 2:59 p.m., Ivan Krylov wrote:
>> On Wed, 30 Aug 2023 16:31:20 +
>> Christophe Bousquet  wrote:
>> 
>>>   So, yes, it seems possible for R to localize paths related to
>>> Rtools... But then, I really do not get where things go wrong...
>> 
>> When installing packages containing code to compile, R eventually calls
>> R CMD SHLIB. Same thing happens with inline C++: it gets stored in a
>> temporary file, compiled into a *.dll using R CMD SHLIB and then loaded
>> using dyn.load().
>> 
>> Write the following into a file named hello.c:
>> 
>> #include 
>> #include 
>> SEXP hello(void) {
>>  SEXP ret = PROTECT(allocVector(STRSXP, 1));
>>  SET_STRING_ELT(ret, 0, mkChar("hello"));
>>  UNPROTECT(1);
>>  return ret;
>> }
>> 
>>  From within R, setwd() to the directory containing hello.c and run:
>> 
>> tools::Rcmd('SHLIB -n hello.c')
>> tools::Rcmd('SHLIB hello.c')
>> 
>> What do the commands print? Does the second command fail?
>> 
>> (Let's Cc: R-help@r-project.org in case people with more experience
>> debugging Windows problems have a better idea what's going on.)
>> 
>
>It sounds exactly as though Rtools files aren't on the path that's in effect 
>when R starts.  That's probably the one stored in the registry. In the old 
>days it was set in the System app in the Windows Control Panel under "Edit the 
>system environment variables".  I don't know if that's still true.
>
>Duncan Murdoch
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Questions about R

2023-08-17 Thread Jeff Newmiller
1. R is open source software. You are welcome to review the source code of the 
R interpreter for handling of PII. No warranty is offered by the (volunteer) 
developers of R.

2. R software is a programming interpreter, which by definition allows for a 
wide range of behaviours.  Users of R frequently share useful scripts and 
compilable source code that they have written in the form of packages. There 
are multiple repositories of such packages online... it is up to the consumer 
of any such contributed package to evaluate whether it is fit for the desired 
purpose.

3. See 2. Whether specific packages are out of date or not depends on the rigor 
of the person sharing their package... it is up to the consumer to evaluate 
fitness for purpose.

FWIW I have never encountered an R package that collected PII. But I have only 
used a few hundred out of the tens of thousands available, so YMMV.

On August 17, 2023 4:10:58 AM PDT, Shaun Parr  wrote:
>
>
>Sent from Outlook for Android
>
>
>Hi there,
>
>My name is Shaun and I work in an organisation where one of our users wishes 
>to install the R software and our process is to assess the safety of anyone 
>software prior to authorisation. I can’t seem to locate all the information 
>that we require on the webpage, so could someone kindly advise me of the 
>following information please?
>
>1. Please can you confirm what user information the software collects (E.g. 
>Name, password, e-mail address, any Personally Identifiable Information etc)?
>2. If any is collected, please can you confirm if the information collected by 
>the software stays locally on the device or if it is transferred anywhere. If 
>it is transferred, could you please advise where it is transferred to (E.g. 
>your own servers, or a third party data centre such as Amazon Web Services or 
>Azure)?
>3. Are there any third-party components installed within the software and, if 
>so, are these also kept up-to-date?
>
>If you could kindly advise this information, it would be really appreciated, 
>thank you 
>
>
>Shaun
>
>   [[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.


Re: [R] 'apply' for 0 or 1 element member.

2023-08-10 Thread Jeff Newmiller
Define

mean0na <- function(x) {
  x[ 0 == x ] <- NA
  mean( x, na.rm = TRUE )
}

and then use that instead of mean.

On August 10, 2023 7:25:08 PM PDT, ani jaya  wrote:
>Hello,
>
>I try to calculate the mean of an array with a condition. My array is
>B=c(181,101,420) in dimensions. And I want to find a specific member
>in 3rd dimension (time monthly) based on a condition of another data
>frame, A =c(420). My final array would be C=c(181,101,12) which 12 is
>a monthly mean based on the condition of A.
>
>what I tried is below but doesn't work.
>
>#find the index with a condition larger than 0.5
>index<-which(A>=0.5)
>#convert the index to monthly
>index1<-index%%12
>#change 0 to 12 (Jan=1, Feb=2, and so on..)
>index1[index1==0]<-12
>
>for (i in 1:12){
>dummy<-index[which(index1==i)]
>C[,,i]<-apply(B[,,dummy],c(1,2), mean,na.rm=T)
>}
>
>The problem is when there is a month that doesnt meet the condition,
>it will return 0 element.
>
>apply(B[,,1],c(1,2), mean,na.rm=T) also produce an error.
>
>Any solution and turnaround would be appreciated.
>
>Thank you
>
>Ani Jaya
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Could not read time series data using read.zoo()

2023-08-03 Thread Jeff Newmiller
no commas?

On August 3, 2023 7:53:07 AM PDT, Christofer Bogaso 
 wrote:
>Hi,
>
>I have a CSV which contains data like below (only first few rows),
>
>Date Adj Close lret
>02-01-1997 737.01
>03-01-1997 748.03 1.48416235
>06-01-1997 747.65 -0.050813009
>07-01-1997 753.23 0.743567202
>08-01-1997 748.41 -0.64196699
>09-01-1997 754.85 0.856809786
>10-01-1997 759.5 0.614126802
>
>However when I try to read this data using below code I get error,
>
>read.zoo("1.csv", sep = ',', format = '%d-%m-%Y')
>
>Error reads as,
>
>index has 4500 bad entries at data rows: 1 2 3 4 5 6 7 8 9.
>
>Could you please help to understand why I am getting this error?
>
>> sessionInfo()
>
>R version 4.2.2 (2022-10-31)
>
>Platform: x86_64-apple-darwin17.0 (64-bit)
>
>Running under: macOS Big Sur ... 10.16
>
>
>Matrix products: default
>
>BLAS:   
>/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
>
>LAPACK: 
>/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
>
>
>locale:
>
>[1] C/UTF-8/C/C/C/C
>
>
>attached base packages:
>
>[1] stats graphics  grDevices utils datasets  methods   base
>
>
>other attached packages:
>
>[1] zoo_1.8-12
>
>
>loaded via a namespace (and not attached):
>
>[1] compiler_4.2.2  tools_4.2.2 grid_4.2.2  lattice_0.20-45
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Downloading a directory of text files into R

2023-07-25 Thread Jeff Newmiller
You cannot read files using name patterns. You can use list.files with patterns 
on your local filesystems, and you can use RCurl or httr contributed packages 
to parse out the web listing of files returned by the web server.  See the 
example in ?RCurl. Then you can download the individual files in an lapply or 
for loop.

On July 25, 2023 3:06:07 PM PDT, Bob Green  wrote:
>Hello,
>
>I am seeking advice as to how I can download the 833 files from this 
>site:"http://home.brisnet.org.au/~bgreen/Data/;
>
>I want to be able to download them to perform a textual analysis.
>
>If the 833 files, which are in a Directory with two subfolders were on my 
>computer I could read them through readtext. Using readtext I get the error:
>
>> x = readtext("http://home.brisnet.org.au/~bgreen/Data/*;)
>Error in download_remote(file, ignore_missing, cache, verbosity) :
>  Remote URL does not end in known extension. Please download the file 
> manually.
>
>> x = readtext("http://home.brisnet.org.au/~bgreen/Data/Dir/()")
>Error in download_remote(file, ignore_missing, cache, verbosity) :
>  Remote URL does not end in known extension. Please download the file 
> manually.
>
>Any suggestions are appreciated.
>
>Bob
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] plotly question

2023-07-21 Thread Jeff Newmiller
plotly is _not_ associated with posit. I think you are unlikely to find 
expertise with plotly in their forums. You might find help at stackoverflow.com.

On July 21, 2023 1:40:49 PM PDT, Bert Gunter  wrote:
>As you apparently haven't received any responses yet, I'll try to
>suggest something useful. However, I have absolutely zero experience
>with plotly, so this is just from general principles and reading the
>plot_ly Help file, which says for the "..." arguments:
>
>"Arguments (i.e., attributes) passed along to the trace type. See
>schema() for a list of acceptable attributes for a given trace type
>(by going to traces -> type -> attributes). Note that attributes
>provided at this level may override other arguments (e.g. plot_ly(x =
>1:10, y = 1:10, color = I("red"), marker = list(color = "blue")))."
>
>So I would **guess** that you needs to go to ?schema to see if the
>further attributes of your "gauge" type that you wish to change are
>there.
>
>Alternatively, plotly is a package from posit.co, formerly RStudio;
>they have an extensive support site and community here:
>https://posit.co/support/
>So you may have success there.
>
>Finally, I assume you have tried web searching appropriate search
>queries, but if not, you should do so. It is sometimes surprising how
>much you can find that way.
>
>... and, again, apologies if my ignorance means my suggestions are useless.
>
>Cheers,
>Bert
>
>
>On Fri, Jul 21, 2023 at 6:19 AM Thomas Subia via R-help
> wrote:
>>
>> Colleagues
>>
>> Here is my reproducible code
>>
>> plot_ly(
>>   domain = list(x = c(0, 1), y = c(0, 1)),
>>   value = 2874,
>>   title = list(text = "Generic"),
>>   type = "indicator",
>>   mode = "gauge+number+delta",
>>   delta = list(reference = 4800),
>>   gauge = list(
>> axis =list(range = list(NULL, 5000)),
>> steps = list(
>> list(range = c(0, 4800), color = "white"),
>> list(range = c(4800, 6000), color = "red")),
>> threshold = list(
>> line = list(color = "black", width = 6),
>> thickness = 0.75,
>> value = 4800)))
>>
>> How can I change the indicator color from green to some other color?
>>
>> How can I change the typeface and font size of the speedometer tick mark 
>> font size?
>>
>> Thomas Subia
>>
>> [[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.

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


Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Jeff Newmiller
I really think you should read that help page.  colnames() accesses the second 
element of dimnames() directly.

On July 3, 2023 11:39:37 AM PDT, "Sorkin, John"  
wrote:
>Jeff,
>Thank you for your reply.
>I should have said with dim names not column names. I want the Mateix to have 
>dim names, no row names, dim names j, k, xxx1, xxx2.
>
>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 Jul 3, 2023, at 2:11 PM, Jeff Newmiller  wrote:
>
>?colnames
>
>On July 3, 2023 11:00:32 AM PDT, "Sorkin, John"  
>wrote:
>I am trying to create an array, myvalues, having 2 rows and 4 columns, where 
>the column names are j,k,xxx1,xxx2. The code below fails, with the following 
>error, "Error in dimnames(myvalues) <- list(NULL, zzz) :
>length of 'dimnames' [2] not equal to array extent"
>
>Please help me get the code to work.
>
>Thank you,
>John
>
># create variable names xxx1 and xxx2.
>string=""
>for (j in 1:2){
>name <- paste("xxx",j,sep="")
>string <- paste(string,name)
>print(string)
>}
># Creation of xxx1 and xxx2 works
>string
>
># Create matrix
>myvalues <- matrix(nrow=2,ncol=4)
>head(myvalues,1)
># Add "j" and "k" to the string of column names
>zzz <- paste("j","k",string)
>zzz
># assign column names, j, k, xxx1, xxx2 to the matrix
># create column names, j, k, xxx1, xxx2.
>dimnames(myvalues)<-list(NULL,zzz)
>
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help=05%7C01%7CJSorkin%40som.umaryland.edu%7C4347c6a62c4b4956756708db7bf0ea2b%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638240046889096206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=y8kLruSvrjxQLegbbPNMMl665EEApCgiSOq%2BEmhQfNE%3D=0
>PLEASE do read the posting guide 
>https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html=05%7C01%7CJSorkin%40som.umaryland.edu%7C4347c6a62c4b4956756708db7bf0ea2b%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638240046889096206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=HBUMNAeG1KurerS2DAhKxxZVRs71TSF0YJSGjP%2FCixA%3D=0
>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://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help=05%7C01%7CJSorkin%40som.umaryland.edu%7C4347c6a62c4b4956756708db7bf0ea2b%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638240046889096206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=y8kLruSvrjxQLegbbPNMMl665EEApCgiSOq%2BEmhQfNE%3D=0
>PLEASE do read the posting guide 
>https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html=05%7C01%7CJSorkin%40som.umaryland.edu%7C4347c6a62c4b4956756708db7bf0ea2b%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638240046889096206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=HBUMNAeG1KurerS2DAhKxxZVRs71TSF0YJSGjP%2FCixA%3D=0
>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.


Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Jeff Newmiller
?colnames

On July 3, 2023 11:00:32 AM PDT, "Sorkin, John"  
wrote:
>I am trying to create an array, myvalues, having 2 rows and 4 columns, where 
>the column names are j,k,xxx1,xxx2. The code below fails, with the following 
>error, "Error in dimnames(myvalues) <- list(NULL, zzz) : 
>  length of 'dimnames' [2] not equal to array extent" 
>
>Please help me get the code to work.
>
>Thank you,
>John
>
># create variable names xxx1 and xxx2.
>string=""
>for (j in 1:2){
>  name <- paste("xxx",j,sep="")
>  string <- paste(string,name)
>  print(string)
>}
># Creation of xxx1 and xxx2 works
>string
>
># Create matrix
>myvalues <- matrix(nrow=2,ncol=4)
>head(myvalues,1)
># Add "j" and "k" to the string of column names
>zzz <- paste("j","k",string)
>zzz
># assign column names, j, k, xxx1, xxx2 to the matrix
># create column names, j, k, xxx1, xxx2.
>dimnames(myvalues)<-list(NULL,zzz)
>
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Adding a numeric class to a data.frame

2023-06-04 Thread Jeff Newmiller
Still waiting for you to communicate... 
https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

On June 4, 2023 7:20:56 PM PDT, Jeff Reichman  wrote:
>Yes - I could have done that but I have over 5,000 calculated probabilities.
>So yes a little more detail would have helped. I'm needing to add those
>probability back into the original data.frame from which the model was
>created as I'm going  to be using ggplot2 so I need the probabilities and
>original dataframe to be one.
>
>-Original Message-
>From: avi.e.gr...@gmail.com  
>Sent: Sunday, June 4, 2023 9:00 PM
>To: 'Jeff Reichman' ; r-help@r-project.org
>Subject: RE: [R] Adding a numeric class to a data.frame
>
>Jeff R, it would be helpful if your intent was understood.
>
>For example, did you want output as a column of labels c("A", "B", "C") and
>another adjacent of c(0.0011566127, 0.0009267028, 0.0081623324) then you
>could do:
>
>data.frame(labels=c("A", "B", "C"), data=c(0.0011566127, 0.0009267028,
>0.0081623324))
>  labels data
>1  A 0.0011566127
>2  B 0.0009267028
>3  C 0.0081623324
>
>If you wanted your columns labeled with the data in multiple columns, try
>this:
>
>> result <- data.frame(t(c(0.0011566127, 0.0009267028, 0.0081623324))) 
>> result
>   X1   X2  X3
>1 0.001156613 0.0009267028 0.008162332
>> names(result) <- c("A", "B", "C")
>> result
>AB   C
>1 0.001156613 0.0009267028 0.008162332
>
>But these are not solutions to your specified problem unless you explain
>properly what you want to do and the exact expected output.
>
>
>
>-Original Message-
>From: R-help  On Behalf Of Jeff Reichman
>Sent: Sunday, June 4, 2023 7:11 PM
>To: r-help@r-project.org
>Subject: [R] Adding a numeric class to a data.frame
>
>R-Help Community
>
> 
>
>How do I add a numeric class to a data .frame. 
>
> 
>
>For example, I have calculated the following probabilities
>
> 
>
>   123
>
>0.0011566127 0.0009267028 0.0081623324
>
> 
>
>How would I add them back into my data.frame for example
>
> 
>
>My_df <- data.frame(col_1 = c('A', 'B', 'C')) such that I end up with
>
> 
>
>col_1   col_2
>
>A  0.0011566127
>
> 
>
>Though I could use a cbind.
>
> 
>
>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.

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


Re: [R] Adding a numeric class to a data.frame

2023-06-04 Thread Jeff Newmiller
The obvious answer is

My_df$col_2 <- prob_result

but whether that would work might depend on the structure of prob_result.

What does

dput(prob_result)

return?

On June 4, 2023 4:11:08 PM PDT, Jeff Reichman  wrote:
>R-Help Community
>
> 
>
>How do I add a numeric class to a data .frame. 
>
> 
>
>For example, I have calculated the following probabilities
>
> 
>
>   123
>
>0.0011566127 0.0009267028 0.0081623324
>
> 
>
>How would I add them back into my data.frame for example
>
> 
>
>My_df <- data.frame(col_1 = c('A', 'B', 'C')) such that I end up with
>
> 
>
>col_1   col_2
>
>A  0.0011566127
>
> 
>
>Though I could use a cbind.
>
> 
>
>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.

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


Re: [R] extract parts of a list before symbol

2023-05-25 Thread Jeff Newmiller
What a remarkable set of detours, Avi, all deriving apparently from a few gaps 
in your understanding of R.

As Rolf said, "names(test)" is the answer.

a) Lists are vectors. They are not atomic vectors, but they are vectors, so 
as.vector(test) is a no-op.

test <- list( a = 1, b = 2, c=3 )
attributes(test)
attributes(as.vector(test))

(Were you thinking of the unlist function? If so, there is no reason to convert 
the value of the list to an atomic vector in order to look at the value of an 
attribute of that list.)

b) Data frames are lists, with the additional constraint that all elements have 
the same length, and that a names attribute and a row.names attribute are both 
required. Converting a list to a data frame to get the names is expensive in 
CPU cycles and breaks as soon as the list elements have a variety of lengths.

c) All data in R is stored as vectors. Worrying about whether a data value is a 
vector is pointless.

d) All objects can have attributes, including the name attribute. However, not 
all objects must have a name attribute... including lists. Omitting a name for 
any of the elements of a list in the constructor will lead to having a 
zero-length character values in the name attribute where the names were 
omitted. Omitting all names in the list constructor will cause no names 
attribute to be created for that list.

test2 <- list( 1, 2, 3 )
attributes(test2)

e) The names() function returns the value of the names attribute. If that 
attribute is missing, it returns NULL. For dataframes, the colnames function is 
equivalent to the names function (I rarely use the colnames function). For 
lists, colnames returns NULL... there are no "columns" in a list, because there 
is no constraint on the (lengths of the) contents of a list.

names(test2)

f) The names attribute, if it exists, is just a character vector. It is never 
necessary to convert the output of names() to a character vector. If the names 
attribute doesn't exist, then it is up to the user to write code that creates 
it.

names(test2) <- c( "A", "B", "C" )
attributes(test2)
names(test2)
# or use the argument names in the list function

names(test2) <- 1:3 # integer
names(test2) # character
attributes(test2)$names <- 1:3 # integer
attributes(test2) # character
test2[[ "2" ]] == 2  # TRUE
test2$`2`  == 2 # TRUE



On May 25, 2023 6:17:37 PM PDT, avi.e.gr...@gmail.com wrote:
>Evan,
>
>List names are less easy than data.frame column names so try this:
>
>> test <- list(a=3,b=5,c=11)
>> colnames(test)
>NULL
>> colnames(as.data.frame(test))
>[1] "a" "b" "c"
>
>But note an entry with no name has one made up for it.
>
>
>> test2 <- list(a=3,b=5, 666, c=11)
>> colnames(data.frame(test2))
>[1] "a""b""X666" "c"   
>
>But that may be overkill as simply converting to a vector if ALL parts are
>of the same type will work too:
>
>> names(as.vector(test))
>[1] "a" "b" "c"
>
>To get one at a time:
>
>> names(as.vector(test))[1]
>[1] "a"
>
>You can do it even simple by looking at the attributes of your list:
>
>> attributes(test)
>$names
>[1] "a" "b" "c"
>
>> attributes(test)$names
>[1] "a" "b" "c"
>> attributes(test)$names[3]
>[1] "c"
>
>
>-Original Message-
>From: R-help  On Behalf Of Evan Cooch
>Sent: Thursday, May 25, 2023 1:30 PM
>To: r-help@r-project.org
>Subject: [R] extract parts of a list before symbol
>
>Suppose I have the following list:
>
>test <- list(a=3,b=5,c=11)
>
>I'm trying to figure out how to extract the characters to the left of 
>the equal sign (i.e., I want to extract a list of the variable names, a, 
>b and c.
>
>I've tried the permutations I know of involving sub - things like 
>sub("\\=.*", "", test), but no matter what I try, sub keeps returning 
>(3, 5, 11). In other words, even though I'm trying to extract the 
>'stuff' before the = sign, I seem to be successful only at grabbing the 
>stuff after the equal sign.
>
>Pointers to the obvious fix? 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.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] data.frame with a column containing an array

2023-05-25 Thread Jeff Newmiller
Maybe... if you want it to act like a matrix... then you should... use a 
matrix...

I think making this behaviour work with 2d arrays could be a feature, but 
making it work with higher dimension arrays would be difficult, and 
differentiating between 2d and higher dimension arrays could have just as 
unexpected behaviors as differentiating between matrices and 2d arrays is for 
you now.

Arrays and matrices are supposed to be more compatible now than they used to 
be... specifying a matrix should work just as well as specifying a 2d array 
when it comes to whatever operations are leading you to want an array at all, 
and will close the door on trying to stuff a higher dimension array into the 
dataframe accidentally.

... or don't put it into a data frame?

On May 25, 2023 10:15:00 AM PDT, Bert Gunter  wrote:
>I really don't know. I would call it a request for extended capabilities of
>[.data.frame, rather than a feature or bug. But maybe wiser heads than mine
>who monitor this list can sort it out.
>
>-- Bert
>
>On Wed, May 24, 2023 at 8:52 PM Georg Kindermann 
>wrote:
>
>> So is this an expected behavior or is it a bug which should be reported
>> somewhere else?
>>
>> Thanks!
>> Georg
>>
>>
>>
>> Gesendet: Dienstag, 09. Mai 2023 um 19:28 Uhr
>> Von: "Bert Gunter" 
>> An: "Georg Kindermann" 
>> Cc: "Rui Barradas" , r-help@r-project.org
>> Betreff: Re: [R] data.frame with a column containing an array
>>
>>
>>
>> I think the following may provide a clearer explanation:
>>
>> subs <- c(1,3)
>> DFA <- data.frame(id = 1:3)
>> ar <- array(1:12, c(3,2,2))
>> ## yielding
>> > ar
>> , , 1
>>
>>  [,1] [,2]
>> [1,]14
>> [2,]25
>> [3,]36
>>
>> , , 2
>>
>>  [,1] [,2]
>> [1,]7   10
>> [2,]8   11
>> [3,]9   12
>>
>> ## array subscripting gives
>> > ar[subs,,]
>> , , 1
>>
>>  [,1] [,2]
>> [1,]14
>> [2,]36
>>
>> , , 2
>>
>>  [,1] [,2]
>> [1,]7   10
>> [2,]9   12
>>
>> ## Now with df's
>> > DFA[["ar"]] <- ar
>> >
>> > DFM <- data.frame(id = 1:3)
>> > DFM[["M"]] <- matrix(1:6, nc =2)
>> >
>> > str(DFM)
>> 'data.frame': 3 obs. of  2 variables:
>>  $ id: int  1 2 3
>>  $ M : int [1:3, 1:2] 1 2 3 4 5 6
>> > str(DFA)
>> 'data.frame': 3 obs. of  2 variables:
>>  $ id: int  1 2 3
>>  $ ar: int [1:3, 1:2, 1:2] 1 2 3 4 5 6 7 8 9 10 ...
>> >
>> > ## But the data frame print method for these give
>> > DFM
>>   id M.1 M.2
>> 1  1   1   4
>> 2  2   2   5
>> 3  3   3   6
>> > DFA
>>   id ar.1 ar.2 ar.3 ar.4
>> 1  1147   10
>> 2  2258   11
>> 3  3369   12
>> >
>> > ## [.data.frame subscripting gives
>> > DFA[subs,]
>>   id ar
>> 1  1  1
>> 3  3  3
>> > DFM[subs,]
>>   id M.1 M.2
>> 1  1   1   4
>> 3  3   3   6
>> >
>> > ## but  explicit array subscripting of course works
>> > DFA$ar[match(subs,DFA$id),,]
>> , , 1
>>
>>  [,1] [,2]
>> [1,]14
>> [2,]36
>>
>> , , 2
>>
>>  [,1] [,2]
>> [1,]7   10
>> [2,]9   12
>>
>>
>> Cheers,
>> Bert
>>
>
>   [[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.


Re: [R] mclapply enters into an infinite loop....

2023-05-16 Thread Jeff Newmiller
It does not look to me like you are providing the necessary arguments to arfima.

Try making this work with lapply first... then try mclapply.

On May 16, 2023 3:10:45 PM PDT, akshay kulkarni  wrote:
>Dear members,
> I am using arfima in an mclapply construction (from 
> the parallel package):
>
>Browse[2]> LYG <- mclapply(LYGH, FUN = arfima, mc.cores = detectCores())
>^C
>Browse[2]> LYG <- mclapply(LYGH[1:10], FUN = arfima, mc.cores = detectCores())
>^C
>Browse[2]> LYG <- mclapply(LYGH[1:2], FUN = arfima, mc.cores = detectCores())
>^C
>
>You can see that I am aborting the execution of mclapply. It doesn't finish 
>even if I reduce the elements to be iterated over to 2. Why is it entering an 
>infinite loop?
>
>Please exhort me if this is to be posted in HPC list.
>
>THanking you,
>Yours sincerely,
>ALSHAY 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.

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


Re: [R] Recombining Mon and Year values

2023-05-16 Thread Jeff Newmiller
I don't use lubridate, but that package works with Date and POSIXt types, which 
I do use. Just remember to include a day when converting (1st of month is 
typical), and use an output format to hide the day when you plot.

On May 16, 2023 1:29:27 PM PDT, Jeff Reichman  wrote:
>R Help
>
> 
>
>I have a data.frame where I've broken out the year  and an ordered
>month  values. But I need to recombine them so I can graph mon-year in
>order but when I recombine I lose the month order and the results are
>plotted alphabetical.
>
> 
>
>Yearmonth  mon_year
>
>  
>
>2021 MarMar-2021
>
>2021 Jan Jan-2021
>
>2021 Apr Apr-2021
>
> 
>
>So do I need to convert the months back to an integer then recombine to
>plot.
>
> 
>
>Jeff Reichman
>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] aggregate wind direction data with wind speed required

2023-05-13 Thread Jeff Newmiller
You don't have to bother with the subtracting from pi/2 bit ... just assume the 
cartesian complex values are (y,x) instead of (x,y).

On May 13, 2023 1:38:51 PM PDT, Bill Dunlap  wrote:
>I think that using complex numbers to represent the wind velocity makes
>this simpler.  You would need to write some simple conversion functions
>since wind directions are typically measured clockwise from north and the
>argument of a complex number is measured counterclockwise from east.  E.g.,
>
>windToComplex <-
>function(speed, degreesCW) {
>  complex(mod=speed, arg=(90-degreesCW)/180*pi)
>}
>complexToWind <-
>function(z) {
>  # Convert complex velocity z to speed and direction (degrees clockwise
>  # from north, in range [0,360)).
>  stopifnot(is.complex(z))
>  data.frame(speed = Mod(z), degreesCW = (pi - Arg(z*1i))/(2*pi)*360)
>}
>
>Then use FUN=mean instead of my_fun.
>
>-Bill
>
>On Sat, May 13, 2023 at 7:51 AM Stefano Sofia <
>stefano.so...@regione.marche.it> wrote:
>
>> Dear list users,
>>
>> I have to aggregate wind direction data (wd) using a function that
>> requires also a second input variable, wind speed (ws).
>>
>> This is the function that I need to use:
>>
>>
>> my_fun <- function(wd1, ws1){
>>
>>   u_component <- -ws1*sin(2*pi*wd1/360)
>>   v_component <- -ws1*cos(2*pi*wd1/360)
>>   mean_u <- mean(u_component, na.rm=T)
>>   mean_v <- mean(v_component, na.rm=T)
>>   mean_wd <- (atan2(mean_u, mean_v) * 360/2/pi) + 180
>>   result <- mean_wd
>>   result
>> }
>>
>> Does the aggregate function work only with functions with a single input
>> variable (the one that I want to aggregate), or its use can be extended to
>> functions with two input variables?
>>
>> Here a simple example (which is meaningless, the important think is the
>> concept behind it):
>> df <- data.frame(day=c(1, 1, 1, 2, 2, 2, 3, 3), month=c(1, 1, 2, 2, 2, 2,
>> 2, 2), wd=c(45, 90, 90, 135, 180, 270, 270, 315), ws=c(7, 7, 8, 3, 2, 7,
>> 14, 13))
>>
>> aggregate(wd ~ day + month, data=df, FUN = my_fun)
>>
>> cannot work, because ws is not taken into consideration.
>>
>> I got lost. Any hint, any help?
>> I hope to have been able to explain my problem.
>> Thank you for your attention,
>> Stefano
>>
>>
>>  (oo)
>> --oOO--( )--OOo--
>> Stefano Sofia PhD
>> Civil Protection - Marche Region - Italy
>> Meteo Section
>> Snow Section
>> Via del Colle Ameno 5
>> 60126 Torrette di Ancona, Ancona (AN)
>> Uff: +39 071 806 7743
>> E-mail: stefano.so...@regione.marche.it
>> ---Oo-oO
>>
>> 
>>
>> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere
>> informazioni confidenziali, pertanto è destinato solo a persone autorizzate
>> alla ricezione. I messaggi di posta elettronica per i client di Regione
>> Marche possono contenere informazioni confidenziali e con privilegi legali.
>> Se non si è il destinatario specificato, non leggere, copiare, inoltrare o
>> archiviare questo messaggio. Se si è ricevuto questo messaggio per errore,
>> inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio
>> computer. Ai sensi dell'art. 6 della DGR n. 1394/2008 si segnala che, in
>> caso di necessità ed urgenza, la risposta al presente messaggio di posta
>> elettronica può essere visionata da persone estranee al destinatario.
>> IMPORTANT NOTICE: This e-mail message is intended to be received only by
>> persons entitled to receive the confidential information it may contain.
>> E-mail messages to clients of Regione Marche may contain information that
>> is confidential and legally privileged. Please do not read, copy, forward,
>> or store this message unless you are an intended recipient of it. If you
>> have received this message in error, please forward it to the sender and
>> delete it completely from your computer system.
>>
>> --
>> Questo messaggio  stato analizzato da Libraesva ESG ed  risultato non
>> infetto.
>> This message was scanned by Libraesva ESG and is believed to be clean.
>>
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

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

Re: [R] Error in as.POSIXlt.character(x, tz, ...)

2023-05-11 Thread Jeff Newmiller
I find your claim suspect... a period is not interchangeable with a colon.

On May 11, 2023 1:56:41 AM PDT, Jinsong Zhao  wrote:
>Hi there,
>
>When I run the following code in R 4.3.0 on FreeBSD, I got error.
>
>> as.POSIXct("1970-01-01 00:00.00 UTC")
>Error in as.POSIXlt.character(x, tz, ...) :
>  character string is not in a standard unambiguous format
>
>The same code could give correct answer in R 4.3.0 on Windows, and R 4.1.2 on 
>a old CentOS.
>
>> as.POSIXct("1970-01-01 00:00.00 UTC")
>[1] "1970-01-01 CST"
>
>I confirmed that all the 3 OSes give the same time zone:
>> Sys.timezone()
>[1] "Asia/Shanghai"
>
>What's wrong with the R on FreeBSD? Any hint? Thanks in advance.
>
>Best,
>Jinsong
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] problem installing RUcausal library

2023-04-23 Thread Jeff Newmiller
Perhaps read the Posting Guide, note that there is a special mailing list for 
MacOSX-specific questions, and post there instead?

You don't appear to have installed gfortran. I am aware that there are specific 
instructions for getting that installed in MacOS that you need to find and 
follow [1].

[1] https://cran.r-project.org/bin/macosx/tools/

On April 23, 2023 4:41:59 AM GMT+09:00, varin sacha via R-help 
 wrote:
>Me again ! How to solve this?
>
>At the end of this page there is the installation command :
>https://gitlab.science.ru.nl/gbucur/RUcausal/-/blob/master/README.Rmd
>
>Working with a MAC, I have tried to install the RUcausal library (copy and 
>paste the installation command).
>
>It is written that the package has been built on Linux using the GNU Compiler 
>Collection. To install the package, open an R instance and run:
>install.packages('devtools') # required package
>devtools::install_git('https://gitlab.science.ru.nl/gbucur/RUcausal')
>
>I get this error message :
>
>  ERROR: package installation failed
>Error: Failed to install 'RUcausal' from Git:
>  ! System command 'R' failed
>0d0bz2p4xg64gn/T/RtmpMs1teQ/Rinst6453ee77bb8/RUcausal’
>
>
>
>install.packages('devtools') # required package
>--- Please select a CRAN mirror for use in this session ---
>trying URL 
>'https://stat.ethz.ch/CRAN/bin/macosx/big-sur-arm64/contrib/4.2/devtools_2.4.5.tgz'
>Content type 'application/x-gzip' length 421790 bytes (411 KB)
>==
>downloaded 411 KB
>
>
>The downloaded binary packages are in
>
>/var/folders/t_/myv0vvms11g40d0bz2p4xg64gn/T//Rtmp7SUtUd/downloaded_packages
>> devtools::install_git('https://gitlab.science.ru.nl/gbucur/RUcausal')
>Downloading git repo https://gitlab.science.ru.nl/gbucur/RUcausal
>'/usr/bin/git' clone --depth 1 --no-hardlinks 
>https://gitlab.science.ru.nl/gbucur/RUcausal 
>/var/folders/t_/myv0vvms11g40d0bz2p4xg64gn/T//Rtmp7SUtUd/file61a2a8e336a
>── R CMD build 
>──
>─ installing the package to process help pages
>  ---ges
>─ installing *source* package ‘RUcausal’ ...
>  ** using staged installation
>  ** libs
>  clang++ -arch arm64 -std=gnu++14 
>-I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG 
>-I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include'
> 
>-I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include'
> -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -Wall 
>-pedantic -c RcppExports.cpp -o RcppExports.o
>  clang++ -arch arm64 -std=gnu++14 
>-I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG 
>-I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include'
> 
>-I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include'
> -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -Wall 
>-pedantic -c compute_DAG_probabilities_BGe_fast.cpp -o 
>compute_DAG_probabilities_BGe_fast.o
>  clang++ -arch arm64 -std=gnu++14 -dynamiclib 
>-Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module 
>-multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib 
>-L/opt/R/arm64/lib -o RUcausal.so RcppExports.o 
>compute_DAG_probabilities_BGe_fast.o 
>-L/Library/Frameworks/R.framework/Resources/lib -lRlapack 
>-L/Library/Frameworks/R.framework/Resources/lib -lRblas 
>-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.6.0/12.0.1 
>-L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lquadmath 
>-F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework 
>-Wl,CoreFoundation
>  ld: warning: directory not found for option 
>'-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.6.0/12.0.1'
>  ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib'
>  ld: library not found for -lgfortran
>  clang: error: linker command failed with exit code 1 (use -v to see 
>invocation)
>  make: *** [RUcausal.so] Error 1
>  ERROR: compilation failed for package ‘RUcausal’
>─ removing 
>‘/private/var/folders/t_/myv0vvms11g40d0bz2p4xg64gn/T/RtmpMs1teQ/Rinst6453ee77bb8/RUcausal’
>  ---
>  ERROR: package installation failed
>Error: Failed to install 'RUcausal' from Git:
>  ! System command 'R' failed
>0d0bz2p4xg64gn/T/RtmpMs1teQ/Rinst6453ee77bb8/RUcausal’
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.

__

Re: [R] detect and replace outliers by the averaged

2023-04-21 Thread Jeff Newmiller
 0

On April 21, 2023 4:08:08 AM GMT+09:00, Dr Eberhard W Lisse  
wrote:
>There is at least one outliers package on CRAN.
>
>el
>On 20/04/2023 20:43, AbouEl-Makarim Aboueissa wrote:
>> Dear All:  *please discard my previous email*
>> 
>> 
>> 
>> *Re:* detect and replace outliers by the average
>> 
>> 
>> 
>> The dataset, please see attached, contains a group factoring column “
>> *factor*” and two columns of data “x1” and “x2” with some NA values. I need
>> some help to detect the outliers and replace it and the NAs with the
>> average within each level (0,1,2) for each variable “x1” and “x2”.
>> 
>> 
>> 
>> I tried the below code, but it did not accomplish what I want to do.
>> 
>> 
>> 
>> 
>> 
>> data<-read.csv("G:/20-Spring_2023/Outliers/data.csv", header=TRUE)
>> 
>> data
>> 
>> replace_outlier_with_mean <- function(x) {
>> 
>>   replace(x, x %in% boxplot.stats(x)$out, mean(x, na.rm=TRUE))   ,
>> na.rm=TRUE NOT working
>> 
>> }
>> 
>> data[] <- lapply(data, replace_outlier_with_mean)
>> 
>> 
>> 
>> 
>> 
>> Thank you all very much for your help in advance.
>> 
>> 
>> 
>> 
>> 
>> with many thanks
>> 
>> abou
>> 
>> 
>> __
>> 
>> 
>> *AbouEl-Makarim Aboueissa, PhD*
>> 
>> *Professor, Mathematics and Statistics*
>> *Graduate Coordinator*
>> 
>> *Department of Mathematics and Statistics*
>> *University of Southern Maine*
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] AIc and BIC in caret...

2023-04-19 Thread Jeff Newmiller
This is a statistical question, not actually a question about R, and thus not 
on topic. Using too many variables leads to models that tend to have large 
errors on new data (not from your fitting sample). [1]

[1] https://en.m.wikipedia.org/wiki/Overfitting

On April 19, 2023 6:50:44 AM PDT, akshay kulkarni  wrote:
>Dear members,
> I am doing some modelling with caret package in R. I 
> do suppose that the package doesn't consider AIC and BIC for model selection, 
> right? They penalise the number of prameters, but I am ready to spend a 
> little more time and a little more money to run the model with more number of 
> parameters, but with a very less SSE.
>
>I know that AIC and BIC are not meant for non parametric ML models, but just 
>want to confirm
>
>Thanking you,
>Yours sincerely,
>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.

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


Re: [R] converting a character matrix into numeric....

2023-04-12 Thread Jeff Newmiller
Isn't this like trying to tie up the horse after it has left the barn? Why not 
figure all this out _before_ converting to xts?

On April 12, 2023 12:29:49 PM PDT, akshay kulkarni  
wrote:
>Dear Rui,
> Not working. I have entirely removed the column containing % 
> but am still bootless:
>
>> head(coredata(INFYTX))
> INFY Historical Data INFY Historical Data INFY Historical Data INFY 
> Historical Data
>[1,] "47.26"  "44.28"  "47.56"  "44.28"
>[2,] "46.30"  "44.92"  "46.53"  "44.06"
>[3,] "45.82"  "47.27"  "47.50"  "45.63"
>[4,] "45.62"  "46.06"  "46.16"  "44.73"
>[5,] "45.05"  "46.28"  "46.50"  "44.77"
>[6,] "45.28"  "44.80"  "46.84"  "44.53"
> INFY Historical Data
>[1,] "1805267"
>[2,] "1536300"
>[3,] "887774"
>[4,] "944036"
>[5,] "759898"
>[6,] "1185402"
>> class(coredata(INFYTX)) <- "numeric"
>> head(coredata(INFYTX))
> INFY Historical Data INFY Historical Data INFY Historical Data INFY 
> Historical Data
>[1,] "47.26"  "44.28"  "47.56"  "44.28"
>[2,] "46.3"   "44.92"  "46.53"  "44.06"
>[3,] "45.82"  "47.27"  "47.5"   "45.63"
>[4,] "45.62"  "46.06"  "46.16"  "44.73"
>[5,] "45.05"  "46.28"  "46.5"   "44.77"
>[6,] "45.28"  "44.8"   "46.84"  "44.53"
> INFY Historical Data
>[1,] "1805267"
>[2,] "1536300"
>[3,] "887774"
>[4,] "944036"
>[5,] "759898"
>[6,] "1185402"
>
>THanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>
>From: Rui Barradas 
>Sent: Thursday, April 13, 2023 12:46 AM
>To: akshay kulkarni ; R help Mailing list 
>
>Subject: Re: [R] converting a character matrix into numeric
>
>�s 19:57 de 12/04/2023, akshay kulkarni escreveu:
>> Dear members,
>>  I have an xts object:
>>
>>> head(INFYTX)
>> INFY Historical Data INFY Historical Data.1 INFY Historical 
>> Data.2
>> 2003-04-16 "47.26"  "44.28""47.56"
>> 2003-04-17 "46.30"  "44.92""46.53"
>> 2003-04-21 "45.82"  "47.27""47.50"
>> 2003-04-22 "45.62"  "46.06""46.16"
>> 2003-04-23 "45.05"  "46.28""46.50"
>> 2003-04-24 "45.28"  "44.80""46.84"
>> INFY Historical Data.3 INFY Historical Data.4
>> 2003-04-16 "44.28""1805267"  "5.77%"
>> 2003-04-17 "44.06""1536300"  "-2.03%"
>> 2003-04-21 "45.63""887774"   "-1.04%"
>> 2003-04-22 "44.73""944036"   "-0.44%"
>> 2003-04-23 "44.77""759898"   "-1.25%"
>> 2003-04-24 "44.53""1185402"  "0.51%"
>>
>> But it is populated with character values and I want to convert them to 
>> numeric. THe following code doesn't work:
>>
>>> head(coredata(INFYTX))
>>   INFY Historical Data INFY Historical Data.1 INFY Historical Data.2 
>> INFY Historical Data.3
>> [1,] "47.26"  "44.28""47.56"
>> "44.28"
>> [2,] "46.30"  "44.92""46.53"
>> "44.06"
>> [3,] "45.82"  "47.27""47.50"
>> "45.63"
>> [4,] "45.62"  "46.06""46.16"
>> "44.73"
>> [5,] "45.05"  "46.28""46.50"
>> "44.77"
>> [6,] "45.28"  "44.80""46.84"
>> "44.53"
>>   INFY Historical Data.4
>> [1,] "1805267"  "5.77%"
>> [2,] "1536300"  "-2.03%"
>> [3,] "887774"   "-1.04%"
>> [4,] "944036"   "-0.44%"
>> [5,] "759898"   "-1.25%"
>> [6,] "1185402"  "0.51%"
>>
>>> class(coredata(INFYTX))
>> [1] "matrix" "array"
>>> class(coredata(INFYTX)) <- "numeric"
>> Warning message:
>> In class(coredata(INFYTX)) <- "numeric" : NAs introduced by coercion
>>> class(coredata(INFYTX))
>> [1] "matrix" "array"
>>> head(coredata(INFYTX))
>>   INFY Historical Data INFY Historical Data.1 INFY Historical Data.2 
>> INFY Historical Data.3
>> [1,] "47.26"  "44.28""47.56"
>> "44.28"
>> [2,] "46.3"   "44.92""46.53"
>> "44.06"
>> [3,] "45.82"  "47.27""47.5" 
>> "45.63"
>> [4,] "45.62"  "46.06""46.16"
>> "44.73"
>> [5,] "45.05"  "46.28""46.5" 
>> "44.77"
>> [6,] "45.28"  

Re: [R] extracting pdf tables...

2023-04-09 Thread Jeff Newmiller
I don't know... I have never used tabulizer (which is no longer on CRAN anyway).

In general you would provide an argument to the data import function that would 
tell it to expect a header. I suspect you will have to set the names(IDT[[4]]) 
<- whatever it should be and remove the first row from the data frame.

On April 9, 2023 12:03:36 PM PDT, akshay kulkarni  wrote:
>Dear Jeff,
>  Thanks for your reply.
>
>I have the following:
>
>> colnames(IDT[[4]])
>[1] "X168""TATA.MOTORS.LIMITED" "TATAMOTORS"  "X4"
>
>THe above has to be the first row of IDT[[4]]. The first row is getting parsed 
>as the column name. How do you make that the first row of IDT[[4]]?
>
>Thanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>From: Jeff Newmiller 
>Sent: Monday, April 10, 2023 12:27 AM
>To: akshay kulkarni ; r-help@r-project.org 
>
>Subject: Re: [R] extracting pdf tables...
>
>Your code used cbind. My first answer was appropriate for rbind.
>
>So you still need to figure out how to deal with the different columns in the 
>tables, which requires more knowledge about their contents than we have.
>
>On April 9, 2023 11:43:01 AM PDT, akshay kulkarni  
>wrote:
>>Dear Jeff,
>>      I want to rbind.
>>
>>Thanking you,
>>Yours sincerely,
>>AKSHAY M KULKARNI
>>
>>From: R-help  on behalf of Jeff Newmiller 
>>
>>Sent: Sunday, April 9, 2023 11:57 PM
>>To: r-help@r-project.org 
>>Subject: Re: [R] extracting pdf tables...
>>
>>Sorry, did not read closely enough.
>>
>>Did you want rbind (which has no problem with different numbers of rows) or 
>>merge (which requires that there be key columns that can be aligned by 
>>repeating data)?
>>
>>On April 9, 2023 10:49:09 AM PDT, Jeff Newmiller  
>>wrote:
>>>Clearly the column names are different. You need to decide what to do about 
>>>that. Choose the subset of dataframes where the column names are the same? 
>>>Rename columns? Omit some columns? Add missing columns filled with NA?
>>>
>>>On April 9, 2023 10:22:32 AM PDT, akshay kulkarni  
>>>wrote:
>>>>Dear members,
>>>> I am extracting a pdf table by the following 
>>>> code:
>>>>
>>>>> library(tabulizer)
>>>>> IDT <- 
>>>>> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>>>>>  = "data.frame")
>>>>
>>>>It returns 4 different data frames which I want to combine them and make 
>>>>one data frame. But when I run this:
>>>>
>>>>> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
>>>> Error in match.names(clabs, names(xi)) :
>>>>names do not match previous names
>>>>
>>>>Also:
>>>>
>>>>> class(IDT[[1]])
>>>>[1] "data.frame"
>>>>
>>>>> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
>>>> Error in data.frame(..., check.names = FALSE) :
>>>>arguments imply differing number of rows: 55, 56, 30, 1
>>>>
>>>>Can anyone please help me to combine all these 4 different data frames?
>>>>
>>>>Thanking you,
>>>>Yours sincerely,
>>>>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.
>>>
>>
>>--
>>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.
>
>--
>Sent from my phone. Please excuse my brevity.

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


Re: [R] extracting pdf tables...

2023-04-09 Thread Jeff Newmiller
Your code used cbind. My first answer was appropriate for rbind.

So you still need to figure out how to deal with the different columns in the 
tables, which requires more knowledge about their contents than we have.

On April 9, 2023 11:43:01 AM PDT, akshay kulkarni  wrote:
>Dear Jeff,
>  I want to rbind.
>
>Thanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>From: R-help  on behalf of Jeff Newmiller 
>
>Sent: Sunday, April 9, 2023 11:57 PM
>To: r-help@r-project.org 
>Subject: Re: [R] extracting pdf tables...
>
>Sorry, did not read closely enough.
>
>Did you want rbind (which has no problem with different numbers of rows) or 
>merge (which requires that there be key columns that can be aligned by 
>repeating data)?
>
>On April 9, 2023 10:49:09 AM PDT, Jeff Newmiller  
>wrote:
>>Clearly the column names are different. You need to decide what to do about 
>>that. Choose the subset of dataframes where the column names are the same? 
>>Rename columns? Omit some columns? Add missing columns filled with NA?
>>
>>On April 9, 2023 10:22:32 AM PDT, akshay kulkarni  
>>wrote:
>>>Dear members,
>>> I am extracting a pdf table by the following 
>>> code:
>>>
>>>> library(tabulizer)
>>>> IDT <- 
>>>> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>>>>  = "data.frame")
>>>
>>>It returns 4 different data frames which I want to combine them and make one 
>>>data frame. But when I run this:
>>>
>>>> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
>>> Error in match.names(clabs, names(xi)) :
>>>names do not match previous names
>>>
>>>Also:
>>>
>>>> class(IDT[[1]])
>>>[1] "data.frame"
>>>
>>>> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
>>> Error in data.frame(..., check.names = FALSE) :
>>>arguments imply differing number of rows: 55, 56, 30, 1
>>>
>>>Can anyone please help me to combine all these 4 different data frames?
>>>
>>>Thanking you,
>>>Yours sincerely,
>>>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.
>>
>
>--
>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.

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


Re: [R] extracting pdf tables...

2023-04-09 Thread Jeff Newmiller
Sorry, did not read closely enough.

Did you want rbind (which has no problem with different numbers of rows) or 
merge (which requires that there be key columns that can be aligned by 
repeating data)?

On April 9, 2023 10:49:09 AM PDT, Jeff Newmiller  
wrote:
>Clearly the column names are different. You need to decide what to do about 
>that. Choose the subset of dataframes where the column names are the same? 
>Rename columns? Omit some columns? Add missing columns filled with NA?
>
>On April 9, 2023 10:22:32 AM PDT, akshay kulkarni  
>wrote:
>>Dear members,
>> I am extracting a pdf table by the following 
>> code:
>>
>>> library(tabulizer)
>>> IDT <- 
>>> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>>>  = "data.frame")
>>
>>It returns 4 different data frames which I want to combine them and make one 
>>data frame. But when I run this:
>>
>>> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
>> Error in match.names(clabs, names(xi)) :
>>names do not match previous names
>>
>>Also:
>>
>>> class(IDT[[1]])
>>[1] "data.frame"
>>
>>> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
>> Error in data.frame(..., check.names = FALSE) :
>>arguments imply differing number of rows: 55, 56, 30, 1
>>
>>Can anyone please help me to combine all these 4 different data frames?
>>
>>Thanking you,
>>Yours sincerely,
>>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.
>

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


Re: [R] extracting pdf tables...

2023-04-09 Thread Jeff Newmiller
Clearly the column names are different. You need to decide what to do about 
that. Choose the subset of dataframes where the column names are the same? 
Rename columns? Omit some columns? Add missing columns filled with NA?

On April 9, 2023 10:22:32 AM PDT, akshay kulkarni  wrote:
>Dear members,
> I am extracting a pdf table by the following code:
>
>> library(tabulizer)
>> IDT <- 
>> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>>  = "data.frame")
>
>It returns 4 different data frames which I want to combine them and make one 
>data frame. But when I run this:
>
>> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
> Error in match.names(clabs, names(xi)) :
>names do not match previous names
>
>Also:
>
>> class(IDT[[1]])
>[1] "data.frame"
>
>> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
> Error in data.frame(..., check.names = FALSE) :
>arguments imply differing number of rows: 55, 56, 30, 1
>
>Can anyone please help me to combine all these 4 different data frames?
>
>Thanking you,
>Yours sincerely,
>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.

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


Re: [R] on lexical scoping....

2023-04-04 Thread Jeff Newmiller
Leading off with you can only have two things in an environment definitely 
indicates this should be read with a skeptical eye.

Although the title of "Advanced R" may be more scary than someone writing notes 
on GitHub like a bro, IMHO Adv R is quite readable for anyone interested in 
questions like this with fewer wrong assertions to unlearn later.

On April 4, 2023 4:53:38 PM PDT, Mark Leeds  wrote:
>obviously, everyone has different opinions on what's useful but I always
>found this document quite
>helpful. I think, in the past, someone said that there are some incorrect
>statements in but I'm not sure
>what they are.
>
>https://askming.github.io/study_notes/Stats_Comp/Note-How%20R%20searches%20and%20finds%20stuff.html
>
>
>On Tue, Apr 4, 2023 at 7:06 PM Bert Gunter  wrote:
>
>> The following *might* be of use to you. If you can predict what the various
>> function invocations will do, I think you have a reasonable grasp of how
>> lexical scoping works in R (contrary or supplementary opinions welcome).
>> It is the sort of thing you will find in the references also. If this is
>> all obvious, sorry for wasting your time.
>> ###
>> search()
>> ls()
>> dat <- list(x =2)
>> attach(dat,2)
>> search()
>> f <- function(){
>>g <- function() x
>>x <- 3
>>g}
>> h <- f()
>> g <- function()x
>> ls()
>> h()
>> g()
>> detach(dat)
>> h()
>> g()
>>
>> ##
>> ## Here is what this gives starting with an empty .GlobalEnv.
>> ##
>>
>> > search()
>>  [1] ".GlobalEnv""package:tools" "package:lattice"
>> "tools:rstudio"
>>  [5] "package:stats" "package:graphics"  "package:grDevices"
>> "package:utils"
>>  [9] "package:datasets"  "package:methods"   "Autoloads"
>> "package:base"
>> > ls()
>> character(0)
>> > dat <- list(x =2)
>> > attach(dat,2)
>> > search()
>>  [1] ".GlobalEnv""dat"   "package:tools"
>> "package:lattice"
>>  [5] "tools:rstudio" "package:stats" "package:graphics"
>>  "package:grDevices"
>>  [9] "package:utils" "package:datasets"  "package:methods"
>> "Autoloads"
>> [13] "package:base"
>> > f <- function(){
>> +g <- function() x
>> +x <- 3
>> +g}
>> > h <- f()
>> > g <- function()x
>> > ls()
>> [1] "dat" "f"   "g"   "h"
>> > h()
>> [1] 3
>> > g()
>> [1] 2
>> > detach(dat)
>> > h()
>> [1] 3
>> > g()
>> Error in g() : object 'x' not found
>>
>> -- Bert
>>
>>
>> On Tue, Apr 4, 2023 at 6:56 AM akshay kulkarni 
>> wrote:
>>
>> > Dear Members,
>> >  I have the following code typed at the
>> > console prompt:
>> >
>> > y   <-   x*10
>> >
>> > X has not been defined and the above code throws an object not found
>> > error. That is, the global environment does not contain x. Why doesn't it
>> > look further in the environment stack, like that of packages? There are
>> > thousands of packages that contain the variable named  x. Of course, that
>> > happens if the above code is in a function (or does it?).
>> >
>> > What concept of R is at work in this dichotomy?
>> >
>> > THanking you,
>> > Yours sincerely,
>> > 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.
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

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


Re: [R] on lexical scoping....

2023-04-04 Thread Jeff Newmiller
Namespaces. Packages only export specific object names from their namespaces. 
But few instances of x would be found there.

Also, function argument lists are not added to the search path until the 
functions are running, and then the search path only goes through the 
environments in which the running functions were defined, not through the call 
stack.

Read Advanced R. [1]

[1] https://adv-r.hadley.nz/environments.html

On April 4, 2023 6:56:04 AM PDT, akshay kulkarni  wrote:
>Dear Members,
> I have the following code typed at the console 
> prompt:
>
>y   <-   x*10
>
>X has not been defined and the above code throws an object not found error. 
>That is, the global environment does not contain x. Why doesn't it look 
>further in the environment stack, like that of packages? There are thousands 
>of packages that contain the variable named  x. Of course, that happens if the 
>above code is in a function (or does it?).
>
>What concept of R is at work in this dichotomy?
>
>THanking you,
>Yours sincerely,
>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.

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


Re: [R] Simple Stacking of Two Columns

2023-04-03 Thread Jeff Newmiller
unname(unlist(NamesWide))

On April 3, 2023 8:08:59 AM PDT, "Sparks, John"  wrote:
>Hi R-Helpers,
>
>Sorry to bother you, but I have a simple task that I can't figure out how to 
>do.
>
>For example, I have some names in two columns
>
>NamesWide<-data.frame(Name1=c("Tom","Dick"),Name2=c("Larry","Curly"))
>
>and I simply want to get a single column
>NamesLong<-data.frame(Names=c("Tom","Dick","Larry","Curly"))
>> NamesLong
>  Names
>1   Tom
>2  Dick
>3 Larry
>4 Curly
>
>
>Stack produces an error
>NamesLong<-stack(NamesWide$Name1,NamesWide$Names2)
>Error in if (drop) { : argument is of length zero
>
>So does bind_rows
>> NamesLong<-dplyr::bind_rows(NamesWide$Name1,NamesWide$Name2)
>Error in `dplyr::bind_rows()`:
>! Argument 1 must be a data frame or a named atomic vector.
>Run `rlang::last_error()` to see where the error occurred.
>
>I tried making separate dataframes to get around the error in bind_rows but it 
>puts the data in two different columns
>Name1<-data.frame(c("Tom","Dick"))
>Name2<-data.frame(c("Larry","Curly"))
>NamesLong<-dplyr::bind_rows(Name1,Name2)
>> NamesLong
>  c..TomDick.. c..LarryCurly..
>1  Tom
>2 Dick
>3Larry
>4Curly
>
>gather makes no change to the data
>NamesLong<-gather(NamesWide,Name1,Name2)
>> NamesLong
>  Name1 Name2
>1   Tom Larry
>2  Dick Curly
>
>
>Please help me solve what should be a very simple problem.
>
>Thanks,
>John Sparks
>
>
>
>
>
>   [[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.


Re: [R] printing a data.frame without row numbers

2023-03-27 Thread Jeff Newmiller
Read ?print.data.frame. There is an argument for that.

On March 27, 2023 10:05:10 AM PDT, Dennis Fisher  wrote:
>R 4.2.3
>OS X
>
>Colleagues,
>
>I am printing a large number of tables using the print command.  A simple 
>example is:
>   print(data.frame(COL1=1:5, COL2=10:6))
>
>The result in this case is:
>  COL1 COL2
>11   10
>229
>338
>447
>556
>
>I would like to print the table WITHOUT the row numbers:
> COL1 COL2
>1   10
>29
>38
>47
>56
>
>Is there any simple way to accomplish this, short of writing my own print 
>method or outputting line-by-line using cat?
>
>Dennis
>
>Dennis Fisher MD
>P < (The "P Less Than" Company)
>Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>www.PLessThan.com
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] lexical scoping for scripts......

2023-03-19 Thread Jeff Newmiller
Again, the answer is "interactivity does not matter".

On March 19, 2023 12:54:28 PM PDT, akshay kulkarni  
wrote:
>Dear Jeff,
> I will not be running R command in the shell prompt. So there 
> is no banner, no > prompt. Just running "myscript.R" from the shell prompt. 
> or from crontab in Linux. I think you get the context.
>
>thanking you,
>yours sincerely
>AKSHAY M KULKARNI
>
>____
>From: Jeff Newmiller 
>Sent: Monday, March 20, 2023 1:01 AM
>To: r-help@r-project.org ; akshay kulkarni 
>; Duncan Murdoch ; R help 
>Mailing list 
>Subject: Re: [R] lexical scoping for scripts..
>
>What do _you_ mean when you use the term "interactive"? Because R 
>distinguishes between executing code in a function and executing code from the 
>global environment, but it does not care whether a person is doing the typing 
>or not.
>
>I get the feeling that you think of your R code in terms of "scripts" when you 
>should be thinking of your code in terms of functions. What parameters do you 
>give to them, and what values do they return. Where you put those return 
>values is up to you... how do you save them now? (Depending on auto-saving to 
>.Rdata files is not a good idea in any case, but if you choose to use save() 
>to specific filename.Rdata files works the same whether you type it 
>interactively or use R CMD BATCH.
>
>On March 19, 2023 11:55:37 AM PDT, akshay kulkarni  
>wrote:
>>Dear Duncun,
>> What if there is no interactive "session" running? I 
>> will be running my scripts automatically from crontab in Linux.
>>
>>THanking you,
>>Yours sincerely,
>>AKSHAY M KULKARNI
>>
>>
>>From: Duncan Murdoch 
>>Sent: Monday, March 20, 2023 12:20 AM
>>To: akshay kulkarni ; R help Mailing list 
>>
>>Subject: Re: [R] lexical scoping for scripts..
>>
>>On 19/03/2023 2:33 p.m., akshay kulkarni wrote:
>>> Dear Duncun,
>>>   thanks for the reply
>>>
>>> So when I run a script in the system command line by R CMD BATCH, the
>>> objects created in the script cannot be stored in the workspace ,right?
>>> If yes, how to save them? Moreover, the only way to save the objects
>>> CREATED from the script permanently is to save them to the disk, right?
>>
>>The objects you create *will* appear in the workspace of the session
>>that's running.  They won't be saved to disk automatically so they'll
>>disappear at the end of the BATCH run.   You can use various functions
>>(save(), save.image(), saveRDS(), writeLines(), etc.) to write them to
>>disk if you don't want them to disappear.
>>
>>Duncan Murdoch
>>
>>
>>>
>>> THanking you,
>>> yours sincerely,
>>> AKSHAY M KULKARNI
>>> 
>>> *From:* Duncan Murdoch 
>>> *Sent:* Saturday, March 18, 2023 11:49 PM
>>> *To:* akshay kulkarni ; R help Mailing list
>>> 
>>> *Subject:* Re: [R] lexical scoping for scripts..
>>> On 18/03/2023 1:57 p.m., akshay kulkarni wrote:
>>>> Dear members,
>>>>   The documentation for source() says:
>>>>
>>>> Input is read and parsed from that file until the end of the file is 
>>>> reached, then the parsed expressions are evaluated sequentially in the 
>>>> chosen environment.
>>>>
>>>> What does this mean? I presume that any objects that are CREATED by the 
>>>> script are stored in the Global environment (if local = FALSE), but the 
>>>> rules for lexical scoping are the same as for functions, right?
>>>
>>> No, assignments will happen in the "chosen environment" as well.
>>>
>>> I'm not sure exactly what you mean about the rules for lexical scoping,
>>> but I think the answer is yes.  So if you do the following:
>>>
>>> Put this code in a file named "f.R":
>>>
>>> x <- 123
>>> f <- function() x
>>>
>>> and you run this code in your global environment:
>>>
>>> x <- 456
>>> e <- new.env()
>>> source("f.R", local = e)
>>>
>>> Then you'll find that x retains the value 456, and e$f() returns 123.
>>>
>>>>
>>>> Does the same apply for running the same script from the system command 
>>>> line b

Re: [R] lexical scoping for scripts......

2023-03-19 Thread Jeff Newmiller
What do _you_ mean when you use the term "interactive"? Because R distinguishes 
between executing code in a function and executing code from the global 
environment, but it does not care whether a person is doing the typing or not.

I get the feeling that you think of your R code in terms of "scripts" when you 
should be thinking of your code in terms of functions. What parameters do you 
give to them, and what values do they return. Where you put those return values 
is up to you... how do you save them now? (Depending on auto-saving to .Rdata 
files is not a good idea in any case, but if you choose to use save() to 
specific filename.Rdata files works the same whether you type it interactively 
or use R CMD BATCH. 

On March 19, 2023 11:55:37 AM PDT, akshay kulkarni  
wrote:
>Dear Duncun,
> What if there is no interactive "session" running? I 
> will be running my scripts automatically from crontab in Linux.
>
>THanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>
>From: Duncan Murdoch 
>Sent: Monday, March 20, 2023 12:20 AM
>To: akshay kulkarni ; R help Mailing list 
>
>Subject: Re: [R] lexical scoping for scripts..
>
>On 19/03/2023 2:33 p.m., akshay kulkarni wrote:
>> Dear Duncun,
>>   thanks for the reply
>>
>> So when I run a script in the system command line by R CMD BATCH, the
>> objects created in the script cannot be stored in the workspace ,right?
>> If yes, how to save them? Moreover, the only way to save the objects
>> CREATED from the script permanently is to save them to the disk, right?
>
>The objects you create *will* appear in the workspace of the session
>that's running.  They won't be saved to disk automatically so they'll
>disappear at the end of the BATCH run.   You can use various functions
>(save(), save.image(), saveRDS(), writeLines(), etc.) to write them to
>disk if you don't want them to disappear.
>
>Duncan Murdoch
>
>
>>
>> THanking you,
>> yours sincerely,
>> AKSHAY M KULKARNI
>> 
>> *From:* Duncan Murdoch 
>> *Sent:* Saturday, March 18, 2023 11:49 PM
>> *To:* akshay kulkarni ; R help Mailing list
>> 
>> *Subject:* Re: [R] lexical scoping for scripts..
>> On 18/03/2023 1:57 p.m., akshay kulkarni wrote:
>>> Dear members,
>>>   The documentation for source() says:
>>>
>>> Input is read and parsed from that file until the end of the file is 
>>> reached, then the parsed expressions are evaluated sequentially in the 
>>> chosen environment.
>>>
>>> What does this mean? I presume that any objects that are CREATED by the 
>>> script are stored in the Global environment (if local = FALSE), but the 
>>> rules for lexical scoping are the same as for functions, right?
>>
>> No, assignments will happen in the "chosen environment" as well.
>>
>> I'm not sure exactly what you mean about the rules for lexical scoping,
>> but I think the answer is yes.  So if you do the following:
>>
>> Put this code in a file named "f.R":
>>
>> x <- 123
>> f <- function() x
>>
>> and you run this code in your global environment:
>>
>> x <- 456
>> e <- new.env()
>> source("f.R", local = e)
>>
>> Then you'll find that x retains the value 456, and e$f() returns 123.
>>
>>>
>>> Does the same apply for running the same script from the system command 
>>> line by R CMD BATCH?
>>
>> I don't think R CMD BATCH has any equivalent to the local argument.
>> Everything is evaluated in the global environment.
>>
>> Duncan Murdoch
>
>
>   [[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.


Re: [R] Removing variables from data frame with a wile card

2023-02-12 Thread Jeff Newmiller
Complain, complain...

x[ names( x ) != "V2" ]

or

x[ ! names( x ) %in% c( "V2", "V3" ) ]

or any other character or logical or integer expression that selects columns 
you want...

On February 12, 2023 6:38:00 PM PST, Steven Yen  wrote:
>x[“V2”] would retain columns of x headed by V2. What I need is the opposite——I 
>need a data grime with those columns excluded.
>
>Steven from iPhone
>
>> On Feb 13, 2023, at 9:33 AM, Rolf Turner  wrote:
>> 
>> 
>>> On Sun, 12 Feb 2023 14:57:36 -0800
>>> Jeff Newmiller  wrote:
>>> 
>>> x["V2"]
>>> 
>>> is more efficient than using drop=FALSE, and perfectly normal syntax
>>> (data frames are lists of columns).
>> 
>> 
>> 
>> I never cease to be amazed by the sagacity and perspicacity of the
>> designers of R.  I  would have worried that x["V2"] would turn out to be
>> a *list* (of length 1), but no, it retains the data.frame class, which
>> is clearly the Right Thing To Do.
>> 
>> cheers,
>> 
>> Rolf
>> 
>> -- 
>> Honorary Research Fellow
>> Department of Statistics
>> University of Auckland
>> Stats. Dep't. phone: +64-9-373-7599 ext. 89622
>> Home phone: +64-9-480-4619
>> 

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


Re: [R] Removing variables from data frame with a wile card

2023-02-12 Thread Jeff Newmiller
x["V2"]

is more efficient than using drop=FALSE, and perfectly normal syntax (data 
frames are lists of columns).  I would ignore the naysayers, or put a comment 
in if you want to accelerate their uptake.

As I understand it, one of the main reasons tibbles exist is because of 
drop=TRUE. List-slice (single-dimension) indexing works equally well with both 
standard and tibble types of data frames.

On February 12, 2023 2:30:15 PM PST, Andrew Simmons  wrote:
>drop = FALSE means that should the indexing select exactly one column, then
>return a data frame with one column, instead of the object in the column.
>It's usually not necessary, but I've messed up some data before by assuming
>the indexing always returns a data frame when it doesn't, so drop = FALSE
>let's me that I will always get a data frame.
>
>```
>x <- data.frame(V1 = 1:5, V2 = letters[1:5])
>x[, "V2"]
>x[, "V2", drop = FALSE]
>```
>
>You'll notice that the first returns a character vector, a through e, where
>the second returns a data frame with one column where the object in the
>column is the same character vector.
>
>You could alternatively use
>
>x["V2"]
>
>which should be identical to x[, "V2", drop = FALSE], but some people don't
>like that because it doesn't look like matrix indexing anymore.
>
>
>On Sun, Feb 12, 2023, 17:18 Steven T. Yen  wrote:
>
>> In the line suggested by Andrew Simmons,
>>
>> mydata <- mydata[, !grepl("^yr", colnames(mydata)), drop = FALSE]
>>
>> what does drop=FALSE do? Thanks.
>>
>> On 1/14/2023 8:48 PM, Steven Yen wrote:
>>
>> Thanks to all. Very helpful.
>>
>> Steven from iPhone
>>
>> On Jan 14, 2023, at 3:08 PM, Andrew Simmons 
>>  wrote:
>>
>> You'll want to use grep() or grepl(). By default, grep() uses extended
>> regular expressions to find matches, but you can also use perl regular
>> expressions and globbing (after converting to a regular expression).
>> For example:
>>
>> grepl("^yr", colnames(mydata))
>>
>> will tell you which 'colnames' start with "yr". If you'd rather you
>> use globbing:
>>
>> grepl(glob2rx("yr*"), colnames(mydata))
>>
>> Then you might write something like this to remove the columns starting
>> with yr:
>>
>> mydata <- mydata[, !grepl("^yr", colnames(mydata)), drop = FALSE]
>>
>> On Sat, Jan 14, 2023 at 1:56 AM Steven T. Yen 
>>  wrote:
>>
>>
>> I have a data frame containing variables "yr3",...,"yr28".
>>
>>
>> How do I remove them with a wild cardsomething similar to "del yr*"
>>
>> in Windows/doc? Thank you.
>>
>>
>> colnames(mydata)
>>
>>   [1] "year"   "weight" "confeduc"   "confothr" "college"
>>
>>   [6] ...
>>
>>  [41] "yr3""yr4""yr5""yr6" "yr7"
>>
>>  [46] "yr8""yr9""yr10"   "yr11" "yr12"
>>
>>  [51] "yr13"   "yr14"   "yr15"   "yr16" "yr17"
>>
>>  [56] "yr18"   "yr19"   "yr20"   "yr21" "yr22"
>>
>>  [61] "yr23"   "yr24"   "yr25"   "yr26" "yr27"
>>
>>  [66] "yr28"...
>>
>>
>> __
>>
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>
>> https://stat.ethz.ch/mailman/listinfo/r-help
>>
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

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


Re: [R] Extracting data using subset function

2023-02-05 Thread Jeff Newmiller
I will not (re-)define the basic terms used in describing how R is used... do 
read [1] for that.

[1] 
https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Writing-your-own-functions,
 also via RShowDoc("R-intro"), in particular contrast section 1.5 vs section 10.

On February 5, 2023 12:10:46 PM PST, Upananda Pani  
wrote:
>Hi Jeff,
>
>Thanks for your reply. What do you exactly mean by "interactively"?  Would
>you please give me an example?
>Upananda
>
>On Mon, Feb 6, 2023 at 1:27 AM Jeff Newmiller 
>wrote:
>
>> No, it means what it says: it is best used interactively rather than in
>> functions. That is not saying you cannot use it... merely that you should
>> probably use it interactively.
>>
>> The fact is, though, that integer indexing is much simpler and clearer for
>> your particular example than subset is.
>>
>> q <- p[1:20]
>> q2 <- subset( p, 1:100 <= 20) # 1:100 are positions
>>
>> On February 5, 2023 11:33:16 AM PST, Upananda Pani <
>> upananda.p...@gmail.com> wrote:
>> >Thank you. It means we can not use the subset function here.
>> >
>> >Regards
>> >
>> >On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona, 
>> wrote:
>> >
>> >> From ?subset:
>> >> Warning
>> >>
>> >> This is a convenience function intended for use interactively. For
>> >> programming it is better to use the standard subsetting functions like [
>> >> <http://127.0.0.1:21786/library/base/help/%5B>, and in particular the
>> >> non-standard evaluation of argument subset can have unanticipated
>> >> consequences.
>> >>
>> >> El 05/02/2023 a las 15:07, Upananda Pani escribió:
>> >>
>> >> Dear All,
>> >>
>> >> I want to create a vector p and extract first 20 observations using
>> subset
>> >> function based on logical condition.
>> >>
>> >> My code is below
>> >>
>> >> p <- 0:100
>> >>
>> >> I know i can extract the first 20 observations using the following
>> command.
>> >>
>> >> q <- p[1:20]
>> >>
>> >> But I want to extract the first 20 observations using subset function
>> which
>> >> requires a logical condition. I am not able to frame the logical
>> condition.
>> >>
>> >> The code should be
>> >>
>> >> q <- subset(p, logical condition)
>> >>
>> >> I am not able to do it. Please let me know what you think.
>> >>
>> >> Best regards,
>> >> Upananda
>> >>
>> >>  [[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__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
>> >> PLEASE do read the posting guide
>> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >>
>> >> --
>> >> * Andrés González Carmona *
>> >>
>> >
>> >   [[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.
>>

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


Re: [R] Extracting data using subset function

2023-02-05 Thread Jeff Newmiller
No, it means what it says: it is best used interactively rather than in 
functions. That is not saying you cannot use it... merely that you should 
probably use it interactively.

The fact is, though, that integer indexing is much simpler and clearer for your 
particular example than subset is.

q <- p[1:20]
q2 <- subset( p, 1:100 <= 20) # 1:100 are positions

On February 5, 2023 11:33:16 AM PST, Upananda Pani  
wrote:
>Thank you. It means we can not use the subset function here.
>
>Regards
>
>On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  wrote:
>
>> From ?subset:
>> Warning
>>
>> This is a convenience function intended for use interactively. For
>> programming it is better to use the standard subsetting functions like [
>> , and in particular the
>> non-standard evaluation of argument subset can have unanticipated
>> consequences.
>>
>> El 05/02/2023 a las 15:07, Upananda Pani escribió:
>>
>> Dear All,
>>
>> I want to create a vector p and extract first 20 observations using subset
>> function based on logical condition.
>>
>> My code is below
>>
>> p <- 0:100
>>
>> I know i can extract the first 20 observations using the following command.
>>
>> q <- p[1:20]
>>
>> But I want to extract the first 20 observations using subset function which
>> requires a logical condition. I am not able to frame the logical condition.
>>
>> The code should be
>>
>> q <- subset(p, logical condition)
>>
>> I am not able to do it. Please let me know what you think.
>>
>> Best regards,
>> Upananda
>>
>>  [[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__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
>> PLEASE do read the posting guide 
>> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> --
>> * Andrés González Carmona *
>>
>
>   [[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.


Re: [R] Bug in R-Help Archives?

2023-01-26 Thread Jeff Newmiller
Every email thread (mailing list or not) gets a hidden identifier that is used 
to identify that thread. It is not that Outlook outsmarted John... any email 
program would have done the same.

John... please don't reply to existing posts with a new subject... many mailing 
list users may be using the threaded view in their email program and never see 
your question at all if they were not interested in the original thread.

On January 26, 2023 11:31:39 PM PST, Deepayan Sarkar 
 wrote:
>From looking at the headers in John Sorkin's mail, my guess is that he
>just replied to the other thread rather than starting a fresh email,
>and in his attempts to hide that, was outsmarted by Outlook.
>
>This is based on references to domains such as yahoo.com,
>dcn.davis.ca.us, and precheza.cz in the header, which were all
>involved in the certification thread.
>
>-Deepayan
>
>On Fri, Jan 27, 2023 at 12:26 PM Rui Barradas  wrote:
>>
>> Às 06:39 de 27/01/2023, Rui Barradas escreveu:
>> > Hello,
>> >
>> > When consulting the R-Help Archives today I've noticed that the thread
>> >
>> > Pipe operator
>> >
>> > started by John Sorkin, Tue Jan 3 17:48:30 CET 2023 is under another
>> > thread,
>> >
>> > R Certification
>> >
>> > started by Mukesh Ghanshyamdas Lekhrajani.
>> >
>> > Isn't this a bug in the filing system?
>> >
>> > Thanks to the list maintainer  Martin Maechler and ETH Zurich for
>> > organizing and hosting the list for all of us. It's an invaluable tool
>> > that has served so many R users along the years and that surely gives a
>> > lot of work organizing and eventual headaches. I hope this is not one of
>> > them.
>> >
>> > Rui Barradas
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> Maybe the attached screen capture makes it more clear.
>>
>> Rui Barradas
>>
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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.

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


Re: [R] implicit loop for nested list

2023-01-26 Thread Jeff Newmiller
Elegance is in the eyes of the beholder...

extractor <- function( simlist, sim_name ) {
  do.call(
cbind
  , lapply(
  simlist
, function( r ) r[[ sim_name ]]
)
  )
}
extractor( mysim, "two.mat" )

... but using do.call will be much more memory efficient than successive cbind 
operations.


On January 26, 2023 7:33:25 PM PST, Naresh Gurbuxani 
 wrote:
>> 
>> I am looking for a more elegant way to write below code.
>> 
>> #Simulation results have different dimensions
>> mysim <- lapply(1:10, function(y) {
>>two.mat <- matrix(rnorm(4), nrow = 2)
>>four.mat <- matrix(rnorm(16), nrow = 4)
>>list(two.mat = two.mat, four.mat = four.mat) #results with different 
>> dimensions
>> })
>> 
>> #Collect different components of simulation results
>> #Is it possible to do this with implicit loops?
>> mat2 <- matrix(nrow = 2, ncol = 1)
>> mat4 <- matrix(nrow = 4, ncol = 1)
>> for (mat.list in mysim) {
>>mat2 <- cbind(mat2, mat.list[["two.mat"]])
>>mat4 <- cbind(mat4, mat.list[["four.mat"]])
>> }
>> mat2 <- mat2[,-1]
>> mat4 <- mat4[,-1]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Minimal match to regexp?

2023-01-25 Thread Jeff Newmiller
Perhaps

sub( "^.*(a.*?a).*$", "\\1", x )


On January 25, 2023 4:19:01 PM PST, Duncan Murdoch  
wrote:
>The docs for ?regexp say this:  "By default repetition is greedy, so the 
>maximal possible number of repeats is used. This can be changed to ‘minimal’ 
>by appending ? to the quantifier. (There are further quantifiers that allow 
>approximate matching: see the TRE documentation.)"
>
>I want the minimal match, but I don't seem to be getting it.  For example,
>
>x <- "abaca"
>grep("a.*?a", x, value = TRUE)
>#> [1] "abaca"
>
>Shouldn't I have gotten "aba", which is the first match to "a.*a"?  If not, 
>what would be the regexp that would give me the first match to "a.*a", without 
>greedy expansion of the .*?
>
>Duncan Murdoch
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Shadow Graphics Error in R Studio

2023-01-25 Thread Jeff Newmiller
If the problem goes away in R but persists in RStudio, then most likely you 
will need to ask in a forum where RStudio experts hang out, like the RStudio 
community forum website.

On January 24, 2023 11:35:52 AM PST, Brinkley Norton 
 wrote:
>Good afternoon!
>
>I'm new to R Studio and am encountering a plotting issue. I'm currently using 
>version 4.2.2 on a Mac OSX. RStudio has been deleted and re-downloaded (as per 
>the help pages) yet I am still encountering the same error. The plot works in 
>R but not in R Studio. Here is the code:
>
>Input:
>plot(mtcars)
>
>Output:
>Error in RStudioGD() :   Shadow graphics device error: r error 4 (Error : C 
>stack usage  7969600 is too close to the limit)
>
>Is there a way to correct this issue?
>
>Every good wish,
>
>Brinkley Norton
>
>   [[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.


Re: [R] function doesn't exists but still runs..... (akshay kulkarni)

2023-01-20 Thread Jeff Newmiller
This is not a "problem" ... it is a "feature". Packages often use functions 
from other packages, but that does NOT mean that you as a user can 
automatically use those functions  also.

If Package A uses Package B to implement something, but Package B becomes 
unavailable, the maintainer of Package A would like to fill in the gap. If 
Package A "Depends" on Package B then users of package A automatically get 
access to Package B and they get used to treating Package A like it contains 
all of the functions in Package B directly.

Therefore it is common to have Package A "Import" Package B so that the Package 
A maintainer won't have to re-implement all of Package B to avoid breaking code 
for users of Package A. They can fix things under the hood for their own 
Package A functions using other code.

If a user wants to depend on Package B, it is up to them to use the library 
function to do so explicitly... and when Package B goes away, they are 
responsible for dealing with that mess themselves.

You asked "how", and got answers... but you didn't bother to follow up on those 
answers by reading things like "Writing R Extensions" or Hadley Wickham's "R 
Packages" or "Advanced R". Don't turn that laziness into a value judgement 
about "problems" with R.

On January 20, 2023 9:18:54 AM PST, akshay kulkarni  
wrote:
>Dear Jorgen,
> thanks for the reply.so according to you one can 
> pegion hole the problem as concerning R's lexical scoping rules,am I right? 
> Or some arcane concept regarding environments?
>
>THanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>From: Jorgen Harmse 
>Sent: Friday, January 20, 2023 9:34 PM
>To: r-help@r-project.org ; akshay...@hotmail.com 
>; williamwdun...@gmail.com 
>Subject: Re: function doesn't exists but still runs. (akshay kulkarni)
>
>
>It may help to expand a bit on Bill Dunlap's answer. I think that library does 
>something like this:
>
>
>
>Create a new environment for all the package objects. This environment will 
>not be directly visible from .GlobalEnv, and ancestor environments may not be 
>directly visible either. It may contain functions & other objects that are not 
>exported, and it may use objects in ancestor environments that .GlobalEnv 
>doesn't see directly. On the other hand, functions in the package will still 
>see external functions in the way the package author intended instead of 
>seeing functions with the same name that are visible to .GlobalEnv.
>
>
>
>Run the source code in the private environment (using source(local=private 
>environment, )?). Most package source code just defines functions, but the 
>source code could build other objects that the package needs for some reason, 
>or it could use delayedAssign to build the objects lazily. By default, the 
>environment of any function defined by the source code is the private 
>environment, so the function has access to private objects and to anything in 
>ancestor environments.
>
>
>
>Create a second new environment whose parent is parent.env(.GlobalEnv). For 
>every export, assign the corresponding object from the private environment 
>into the corresponding name in the public environment. Note that the 
>environment of any function is still the private environment in which it was 
>created. (I think that a function is mostly determined by its environment, its 
>formals, and its body. A function call creates a new environment whose parent 
>is the environment of the function. Thus whoever wrote the function can 
>control the search for anything that isn�t passed in or created by the 
>function itself.)
>
>
>
>Reset parent.env(.GlobalEnv) to be the public environment. This makes all the 
>exported objects (usually functions) available at the command line and allows 
>the user to see everything that was available before (usually by name only, 
>but by scope-resolved name if necessary). As noted by Bill Dunlap and in more 
>detail above, package functions can use functions & other objects that are not 
>directly visible to the user. As he also showed, you can (usually) pierce the 
>privacy as long at least one function is exported. 
>environment(package_function) is the private environment, so you can use it to 
>see all the private objects and everything in the ancestor environments. You 
>can repeat the trick to see private environments of packages you didn't 
>directly pull in. I think you can even unlock bindings and do ghastly things 
>to the package's private environment.
>
>
>
>Regards,
>
>Jorgen Harmse.
>
>--
>
>Message: 17
>Date: Thu, 19 Jan 2023 16:02:31 -0800
>From: Bill Dunlap 
>To: akshay kulkarni 
>Cc: R help Mailing list 
>Subject: Re: [R] function doesn't exists but still runs.
>Message-ID:
>
>Content-Type: text/plain; charset="utf-8"
>
>Look into R's scoping rules.  E.g.,
>https://bookdown.org/rdpeng/rprogdatascience/scoping-rules-of-r.html.
>
>* When a function looks up a 

Re: [R] MLE Estimation of Gamma Distribution Parameters for data with 'zeros'

2023-01-19 Thread Jeff Newmiller
Beware of adding a constant... the magnitude of the constant used can have an 
outsized impact on the answer obtained. See e.g. 
https://gist.github.com/jdnewmil/99301a88de702ad2fcbaef33326b08b4

On January 19, 2023 3:49:29 AM PST, peter dalgaard  wrote:
>Not necessarily homework, Bert. There's a generic issue with MLE and rounded 
>data, in that gamma densities may be 0 at the boundary but small numbers are 
>represented as 0, making the log-likelihood -Inf. 
>
>The cleanest way out is to switch to a discretized distribution in the 
>likelihood, so that instead of log(dgamma(0,...)) you use log(pgamma(.005,..) 
>- pgamma(0,...)) == pgamma(.005,..., log=TRUE). (For data rounded to nearest 
>.01, that is). Cruder techniques would be to just add, like, .0025 to all the 
>zeros. 
>
>-pd
>
>> On 10 Jan 2023, at 18:42 , Bert Gunter  wrote:
>> 
>> Is this homework? This list has a no-homework policy.
>> 
>> 
>> -- Bert
>> 
>> On Tue, Jan 10, 2023 at 8:13 AM Nyasha  wrote:
>>> 
>>> Please how can one go about this one? I don't know how to go about it.
>>> 
>>>[[alternative HTML version deleted]]
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Jeff Newmiller
But it is simultaneously an example of why some researchers like black box 
solvers... a system of dozens of nonlinear equations can potentially have many 
or even infinite solutions. If the researcher is weak in math, they may have no 
idea which solutions are possible and having a tool like FindRoot confidently 
return a solution lets them focus on other things. Sort of like ChatGPT.

TL;DR the author may have no idea about how to resolve this without relying on 
the opaque FindRoot.

On January 19, 2023 6:28:53 AM PST, "Ebert,Timothy Aaron"  
wrote:
>This is a poster child for why we like open source software. "I dump numbers 
>into a black box and get numbers out but I cannot verify how the numbers out 
>were calculated so they must be correct" approach to analysis does not really 
>work for me.
>Tim
>
>-Original Message-
>From: R-help  On Behalf Of Troels Ring
>Sent: Thursday, January 19, 2023 9:18 AM
>To: Valentin Petzel ; r-help mailing list 
>
>Subject: Re: [R] R emulation of FindRoot in Mathematica
>
>[External Email]
>
>Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I
>include below the statements from the paper containing the knowledge on the 
>basis of which I would like to know at specified [H] the concentration of each 
>of the many metabolites given the constraints. I have tried to contact the 
>author to get the full code but it seems difficult.
>
>BW Troels
>
>
>hatp <- 10^6.494*H*atp
>hhatp <- 10^3.944*H*hatp
>hhhatp <- 10^1.9*H*hhatp
>atp  <- 10*H*hhhatp
>mgatp <- 10^4.363*atp*mg
>mghatp <- 10^2.299*hatp*mg
>mg2atp <- 10^1-7*mg*mgatp
>katp <- 10^0.959*atp*k
>
>hadp <- 10^6.349*adp*H
>hhadp <- 10^3.819*hadp*H
>hhhadp <- 10*H*hhadp
>mgadp <- 10^3.294*mg*adp
>mghadp <- 10^1.61*mg*hadp
>mg2adp <- 10*mg*mgadp
>kadp <- 10^0.82*k*adp
>
>hpi <- 10^11.616*H*pi
>hhpi <- 10^6.7*h*hpi
>hhhpi <- 10^1.962*h*hhpi
>mgpi <- 10^3.4*mg*pi
>mghpi <- 10^1.946*mg*hpi
>mghhpi <- 10^1.19*mg*hhpi
>kpi <- 10^0.6*k*pi
>khpi <- 10^1.218*k*hpi
>khhpi <- 10^-0.2*k*hhpi
>
>hpcr <- 10^14.3*h*pcr
>hhpcr <- 10^4.5*h*hpcr
>hhhpcr <- 10^2.7*h*hhpcr
>pcr <- 100*h*hhhpcr
>mghpcr <- 10^1.6*mg*hpcr
>kpcr <- 10^0.74*k*pcr
>khpcr <- 10^0.31*k*hpcr
>khhpcr <- 10^-0.13*k*hhpcr
>
>hcr <- 10^14.3*h*cr
>hhcr <- 10^2.512*h*hcr
>
>hlactate <- 10^3.66*h*lactate
>mglactate <- 10^0.93*mg*lactate
>
>tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp
>
>tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp
>
>tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi
>
>tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + khhpcr
>
>tcr <- cr + hcr + hhcr
>
>tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + kghpi + 
>mghhpi +
>   mghpcr + mglactate
>
>tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr
>
>tlactate <- lactate + hlactate + mglactate
>
># conditions
>
>tatp <- 0.008
>tpcr <- 0.042
>tcr <- 0.004
>tadp <- 0.1
>tpi <- 0.003
>tlactate <- 0.005
>
># free K and Mg constrained to be fixed
>#
>mg <- 0.0006
>k <- 0.12
>
>Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:
>>
>> Hello Troels,
>>
>>
>> As fair as I understand you attempt to numerically solve a system of 
>> non linear equations in multiple variables in R. R does not provide 
>> this functionality natively, but have you tried multiroot from the 
>> rootSolve package:
>>
>>
>> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran
>> .r-project.org%2Fweb%2Fpackages%2FrootSolve%2FrootSolve.pdf=05%7C
>> 01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a3
>> 14d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZ
>> sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
>> D%7C3000%7C%7C%7C=D9A3fwJ5x7GbEV4A01wncLUil7szTdSPul5vd0lsSBw%3D
>> =0
>>
>>
>> multiroot is called like
>>
>>
>> multiroot(f, start, ...)
>>
>>
>> where f is a function of one argument which is a vector of n values 
>> (representing the n variables) and returning a vector of d values 
>> (symbolising the d equations) and start is a vector of length n.
>>
>>
>> E.g. if we want so solve
>>
>>
>> x^2 + y^2 + z^2 = 1
>>
>> x^3-y^3 = 0
>>
>> x - z = 0
>>
>>
>> (which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x 
>> = y = z = ±sqrt(1/3) ~ 0.577)
>>
>>
>> we'd enter
>>
>>
>> f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3, 
>> x[1] - x[3])
>>
>>
>> multiroot(f, c(0,0,0))
>>
>>
>> which yields
>>
>>
>> $root
>>
>> [1] 0.5773502 0.5773505 0.5773502
>>
>>
>> $f.root
>>
>> [1] 1.412261e-07 -2.197939e-07  0.00e+00
>>
>>
>> $iter
>>
>> [1] 31
>>
>>
>> $estim.precis
>>
>> [1] 1.2034e-07
>>
>>
>> Best regards,
>>
>> Valentin
>>
>>
>> Am Donnerstag, 19. Jänner 2023, 10:41:22 CET schrieb Troels Ring:
>>
>> > Hi friends - I hope this is not a misplaced question. From the
>>
>> > literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of
>>
>> > Mathematica 

Re: [R] Printing special characters

2023-01-16 Thread Jeff Newmiller
Use the Cairo PDF device?

On January 16, 2023 12:18:48 AM PST, Dennis Fisher  wrote:
>R 4.2.2
>OS X
>
>Colleagues
>
>A file that I have read includes strings like this:
>   "EVENT ≥ 30 sec"
>When I include the string in a graphic using:
>   mtext(STRING, …)
>it appears as:
>   "EVENT ... 30 sec"
>
>Is there a simple work-around (short of reformatting all the strings, then 
>using plotmath)?
>
>Dennis
>
>Dennis Fisher MD
>P < (The "P Less Than" Company)
>Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>www.PLessThan.com
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] return value of {....}

2023-01-09 Thread Jeff Newmiller
I suspect akshay is (or was? Not sure) unclear about what braces do. They are 
not closures... they create an expression that wraps multiple expressions into 
one expression... they are a little more like parentheses than closures. They 
are not intrinsically associated with creation of environments for holding 
variables.

Functions are closures... they run in a call-specific environment that inherits 
from the environment where the function was defined. Blocks (created with 
braces) simply work with the environment in which they are constructed 
directly. If you want a block that creates a new local environment without 
defining a new function then pass your code block to the ?local function.

On January 9, 2023 8:59:12 AM PST, Bert Gunter  wrote:
>Perhaps the following may be of use to you.
>
>Consider:
>
>> f <- function(){ x <- 3; function(y) x+y}
>> x <- 5
>
>##What does this give?
>> f()
>## Why?
>## How about this?
>>f()(10)
>## Why?
>
>## If you remove "x <- 3" from the above, what will you get when you repeat
>the exercise?
>
>-- Bert
>
>On Mon, Jan 9, 2023 at 8:29 AM Bert Gunter  wrote:
>
>> Unless you do something special within a function, only the value(s)
>> returned are available to the caller. That is the essence of
>> functional-type programming languages.
>>
>> You need to read up on (function) environments in R . You can search on
>> this. ?function and its links also contain useful information, but it may
>> too terse to be explicable to you. There are of course many available
>> references on the internet.
>>
>> I believe your mental model for how R works is flawed, and you have some
>> homework to do to correct it. I may be wrong, naturally, but you can judge
>> by looking at some tutorials.
>>
>> -- Bert
>>
>> On Mon, Jan 9, 2023 at 6:47 AM akshay kulkarni 
>> wrote:
>>
>>> Dear members,
>>>  I have the following code:
>>>
>>> > TB <- {x <- 3;y <- 5}
>>> > TB
>>> [1] 5
>>>
>>> It is consistent with the documentation: For {, the result of the last
>>> expression evaluated. This has the visibility of the last evaluation.
>>>
>>> But both x AND y are created, but the "return value" is y. How can this
>>> be advantageous for solving practical problems? Specifically, consider the
>>> following code:
>>>
>>> F <- function(X) {  expr; expr2; { expr5; expr7}; expr8;expr10}
>>>
>>> Both expr5 and expr7 are created, and are accessible by the code outside
>>> of the nested braces right? But the "return value" of the nested braces is
>>> expr7. So doesn't this mean that only expr7 should be accessible? Please
>>> help me entangle this (of course the return value of F is expr10, and all
>>> the other objects created by the preceding expressions are deleted. But
>>> expr5 is not, after the control passes outside of the nested braces!)
>>>
>>> Thanking you,
>>> Yours sincerely,
>>> 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.
>>>
>>
>
>   [[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.


Re: [R] extracting a table from pdf file....

2023-01-08 Thread Jeff Newmiller
Here is a start for two of them... PDF files are actually programs written in 
the Postscript language... there are a lot of ways to write a program to put 
marks on a page, so this mess is actually not as bad a result as you might have 
encountered.

str(IDTpdf)

DF <- IDTpdf[[1]][ -(1:2), ]
names( DF ) <- c( "SNo", "Scrip", "Symbol", "Leverage" )
DF$SNo <- as.integer( DF$SNo )
DF$Leverage <- as.numeric( DF$Leverage )
IDTpdf[[ 1 ]] <- DF

DF <- IDTpdf[[2]]
names( DF ) <- c( "SNo", "Scrip", "Symbol", "Leverage" )
DF <- rbind(
  data.frame(
SNo = 54
  , Symbol = "DIVISLAB"
  , Scrip = "DIVIS LABORATORIES LTD"
  , Leverage = 4.5
  )
, DF
)
IDTpdf[[ 2 ]] <- DF

do.call( rbind, IDTpdf[ 1:2 ] )

On January 8, 2023 12:59:58 AM PST, akshay kulkarni  
wrote:
>dear members,
>I am extracting a pdf table into a data frame from 
> this URL:
>
>https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf
>
>I am using extract_table() from the tabulizer package (it is archived and have 
>installed it from github)
>
>IDTpdf <- 
>extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output="data.frame;)
>
>But IDTpdf consists of four different dfs, and I want to collapse them into 
>one. The dput of IDTpdf:
>
>list(structure(list(SCRIPS.AVAILABLE.FOR.INTRADAY.WITH.LEVERAGES.PROVIDED.ON.THEM
> = c("S.No.",
>"times)", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
>"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
>"22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32",
>"33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43",
>"44", "45", "46", "47", "48", "49", "50", "51", "52", "53"),
>X = c("Scrip Name", "", "ALKEM LABORATORIES LTD.", "ATUL LTD",
>"ABB INDIA LIMITED", "AARTI INDUSTRIES LTD", "ABBOTT INDIA LIMITED",
>"ADITYA BIRLA CAPITAL LTD.", "ADITYA BIRLA FASHION & RT",
>"ACC LIMITED", "ADANI ENTERPRISES LIMITED", "ADANI PORT & SEZ LTD",
>"AMARA RAJA BATTERIES LTD.", "ASTRAL LIMITED", "AMBUJA CEMENTS LTD",
>"ALEMBIC PHARMA LTD", "APOLLO HOSPITALS ENTER. L", "APOLLO TYRES LTD",
>"ASHOK LEYLAND LTD", "ASIAN PAINTS LIMITED", "AU SMALL FINANCE BANK LTD",
>"AUROBINDO PHARMA LTD", "AXIS BANK LIMITED", "BAJAJ AUTO LIMITED",
>"BAJAJ FINSERV LTD.", "BAJAJ FINANCE LIMITED", "BALRAMPUR CHINI MILLS LTD",
>"BANDHAN BANK LIMITED", "BANK OF BARODA", "BATA INDIA LTD",
>"BHARAT ELECTRONICS LTD", "BERGER PAINTS (I) LTD", "BHARTI AIRTEL LIMITED",
>"BHEL", "BIOCON LIMITED.", "BOSCH LIMITED", "BRITANNIA INDUSTRIES LTD",
>"BIRLASOFT LIMITED", "ZYDUS LIFESCIENCES LTD", "CANARA BANK",
>"CAN FIN HOMES LTD", "CHAMBAL FERTILIZERS LTD", "CHOLAMANDALAM IN & FIN 
> CO",
>"CIPLA LTD", "COAL INDIA LTD", "COFORGE LIMITED", "COLGATE PALMOLIVE LTD.",
>"CONTAINER CORP OF IND LTD", "COROMANDEL INTERNTL. LTD",
>"CROMPT GREA CON ELEC LTD", "CITY UNION BANK LTD", "CUMMINS INDIA LTD",
>"DABUR INDIA LTD", "DEEPAK NITRITE LTD", "DELTA CORP LIMITED"
>), X.1 = c("Symbol Series", "", "ALKEM", "ATUL", "ABB", "AARTIIND",
>"ABBOTINDIA", "ABCAPITAL", "ABFRL", "ACC", "ADANIENT", "ADANIPORTS",
>"AMARAJABAT", "ASTRAL", "AMBUJACEM", "APLLTD", "APOLLOHOSP",
>"APOLLOTYRE", "ASHOKLEY", "ASIANPAINT", "AUBANK", "AUROPHARMA",
>"AXISBANK", "BAJAJ-AUTO", "BAJAJFINSV", "BAJFINANCE", "BALRAMCHIN",
>"BANDHANBNK", "BANKBARODA", "BATAINDIA", "BEL", "BERGEPAINT",
>"BHARTIARTL", "BHEL", "BIOCON", "BOSCHLTD", "BRITANNIA",
>"BSOFT", "ZYDUSLIFE", "CANBK", "CANFINHOME", "CHAMBLFERT",
>"CHOLAFIN", "CIPLA", "COALINDIA", "COFORGE", "COLPAL", "CONCOR",
>"COROMANDEL", "CROMPTON", "CUB", "CUMMINSIND", "DABUR", "DEEPAKNTR",
>"DELTACORP"), X.2 = c("Leverage (in", "", "4.5", "4.5", "4.5",
>"4.5", "4.5", "4.5", "4.5", "4.5", "4", "4.5", "4.5", "4.5",
>"4.5", "4.5", "4.5", "4.5", "4.5", "4.5", "4.5", "4.5", "4.5",
>"4.5", "4.5", "4.5", "4", "4", "4.5", "4.5", "4.5", "4.5",
>"4.5", "4", "4.5", "4.5", "4.5", "4", "4.5", "4", "4.5",
>"4", "4", "4.5", "4.5", "4", "4.5", "4.5", "4.5", "4.5",
>"4.5", "4.5", "4.5", "4.5", "4")), class = "data.frame", row.names = c(NA,
>-55L)), structure(list(X54 = 55:110, DIVI.S.LABORATORIES.LTD = c("DIXON TECHNO 
>(INDIA) LTD",
>"DLF LIMITED", "DR. REDDY S LABORATORIES", "ESCORTS INDIA LTD",
>"EXIDE INDUSTRIES LTD", "FEDERAL BANK LTD", "FIRSTSOURCE SOLU. LTD.",
>"GAIL (INDIA) LTD", "GLENMARK PHARMACEUTICALS", "GMR INFRASTRUCTURE LTD.",
>"GUJ NAR VAL FER & CHEM L", "DALMIA BHARAT LIMITED", "GODREJ CONSUMER 
>PRODUCTS",
>"GRANULES INDIA LIMITED", "GRASIM INDUSTRIES LTD", "GUJARAT STATE PETRO LTD",
>"GUJARAT GAS LIMITED", "HINDUSTAN AERONAUTICS LTD", "HAVELLS INDIA LIMITED",
>"HCL TECHNOLOGIES LTD", "HDFC LTD", "HDFC AMC LIMITED", "HDFC BANK LTD",
>"HDFC LIFE INS CO LTD", "HERO MOTOCORP LIMITED", "HINDALCO INDUSTRIES LTD",
>"HINDUSTAN COPPER LTD", "HONEYWELL AUTOMATION IND", "ICICI BANK LTD.",
>"ICICI LOMBARD GIC LIMITED", "ICICI PRU 

Re: [R] Pipe operator

2023-01-03 Thread Jeff Newmiller
> R is a functional language, hence the pipe operator is not needed.

Not factual... just opinion. Please be conscious of your biases and preface 
opinion with a disclaimer.

I heard identical complaints from embedded assembly language programmers when C 
became all the rage... "don't need another way to say the same thing."

>Also it makes the code unreadable as it is less obvious how a call stack looks 
>like and what the arguments to the function calls are.

How can it make the code unreadable if there is a 1:1 mapping between nested 
function calls and a pipe?

If _you_ don't like pipes, that is your opinion, but that statement is 
factually incorrect... both the parser equivalence and the popularity of the 
syntax prove you wrong. Many people find it more readable than nested prefix 
notation.

>It is relevant for a shell for piping text streams.

So you are willing to allow that it makes sense in shell script but not in R 
script? This is not a self-consistent position. The same expressive principles 
can apply in both shell and in R.

On January 3, 2023 2:32:17 PM PST, Uwe Ligges  
wrote:
>R is a functional language, hence the pipe operator is not needed.
>Also it makes the code unreadable as it is less obvious how a call stack looks 
>like and what the arguments to the function calls are.
>
>It is relevant for a shell for piping text streams.
>
>If people cannot live without the pipe operator (and I wonder why you want to 
>add a level of complexity, as it is more obfuscated what the actual function 
>calls are), please use R's internal one, as it is known by the parser and 
>hence debugging etc is better integrated.
>
>Best,
>Uwe Ligges
>
>
>
>On 03.01.2023 17:48, Sorkin, John wrote:
>> I am trying to understand the reason for existence of the pipe operator, 
>> %>%, and when one should use it. It is my understanding that the operator 
>> sends the file to the left of the operator to the function immediately to 
>> the right of the operator:
>> 
>> c(1:10) %>% mean results in a value of 5.5 which is exactly the same as the 
>> result one obtains using the mean function directly, viz. mean(c(1:10)). 
>> What is the reason for having two syntactically different but semantically 
>> identical ways to call a function? Is one more efficient than the other? 
>> Does one use less memory than the other?
>> 
>> P.S. Please forgive what might seem to be a question with an obvious answer. 
>> I am a programmer dinosaur. I have been programming for more than 50 years. 
>> When I started programming in the 1960s the only pipe one spoke about was a 
>> bong.
>> 
>> John
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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.

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


Re: [R] Pipe operator

2023-01-03 Thread Jeff Newmiller
Ick.

Some people like

x |> cos() |> max(pi/4) |> round(3) -> x

but I much prefer

x <- x |> cos() |> max(pi/4) |> round(3)

On January 3, 2023 11:00:46 AM PST, Boris Steipe  
wrote:
>Working off Avi's example - would:
>
>  x |> cos() |> max(pi/4) |> round(3) |> assign("x", value = _)
>
>...be even more intuitive to read? Or are there hidden problems with that?
>
>
>
>Cheers,
>Boris
>
>
>> On 2023-01-03, at 12:40, avi.e.gr...@gmail.com wrote:
>> 
>> John,
>> 
>> The topic has indeed been discussed here endlessly but new people still
>> stumble upon it.
>> 
>> Until recently, the formal R language did not have a built-in pipe
>> functionality. It was widely used through an assortment of packages and
>> there are quite a few variations on the theme including different
>> implementations.
>> 
>> Most existing code does use the operator %>% but there is now a built-in |>
>> operator that is generally faster but is not as easy to use in a few cases.
>> 
>> Please forget the use of the word FILE here. Pipes are a form of syntactic
>> sugar that generally is about the FIRST argument to a function. They are NOT
>> meant to be used just for the trivial case you mention where indeed there is
>> an easy way to do things. Yes, they work in such situations. But consider a
>> deeply nested expression like this:
>> 
>> Result <- round(max(cos(x), 3.14159/4), 3)
>> 
>> There are MANY deeper nested expressions like this commonly used. The above
>> can be written linearly as in
>> 
>> Temp1 <- cos(x)
>> Temp2 <- max(Temp1, 3.14159/4)
>> Result <- round(Temp2, 3)
>> 
>> Translation, for some variable x, calculate the cosine and take the maximum
>> value of it as compared to pi/4 and round the result to three decimal
>> places. Not an uncommon kind of thing to do and sometimes you can nest such
>> things many layers deep and get hopelessly confused if not done somewhat
>> linearly.
>> 
>> What pipes allow is to write this closer to the second way while not seeing
>> or keeping any temporary variables around. The goal is to replace the FIRST
>> argument to a function with whatever resulted as the value of the previous
>> expression. That is often a vector or data.frame or list or any kind of
>> object but can also be fairly complex as in a list of lists of matrices.
>> 
>> So you can still start with cos(x) OR you can write this where the x is
>> removed from within and leaves cos() empty:
>> 
>> x %>% cos
>> or
>> x |> cos()
>> 
>> In the previous version of pipes the parentheses after cos() are optional if
>> there are no additional arguments but the new pipe requires them.
>> 
>> So continuing the above, using multiple lines, the pipe looks like:
>> 
>> Result <-
>>  x %>%
>>  cos() %>%
>>  max(3.14159/4) %>%
>>  round(3)
>> 
>> This gives the same result but is arguably easier for some to read and
>> follow. Nobody forces you to use it and for simple cases, most people don't.
>> 
>> There is a grouping of packages called the tidyverse that makes heavy use of
>> pipes routine as they made most or all their functions such that the first
>> argument is the one normally piped to and it can be very handy to write code
>> that says, read in your data into a variable (a data.frame or tibble often)
>> and PIPE IT to a function that renames some columns and PIPE the resulting
>> modified object to a function that retains only selected rows and pipe that
>> to a function that drops some of the columns and pipe that to a function
>> that groups the items or sorts them and pipe that to a function that does a
>> join with another object or generates a report or so many other things.
>> 
>> So the real answer is that piping is another WAY of doing things from a
>> programmers perspective. Underneath it all, it is mostly syntactic sugar and
>> the interpreter rearranges your code and performs the steps in what seems
>> like a different order at times. Generally, you do not need to care.
>> 
>> 
>> 
>> -Original Message-
>> From: R-help  On Behalf Of Sorkin, John
>> Sent: Tuesday, January 3, 2023 11:49 AM
>> To: 'R-help Mailing List' 
>> Subject: [R] Pipe operator
>> 
>> I am trying to understand the reason for existence of the pipe operator,
>> %>%, and when one should use it. It is my understanding that the operator
>> sends the file to the left of the operator to the function immediately to
>> the right of the operator:
>> 
>> c(1:10) %>% mean results in a value of 5.5 which is exactly the same as the
>> result one obtains using the mean function directly, viz. mean(c(1:10)).
>> What is the reason for having two syntactically different but semantically
>> identical ways to call a function? Is one more efficient than the other?
>> Does one use less memory than the other? 
>> 
>> P.S. Please forgive what might seem to be a question with an obvious answer.
>> I am a programmer dinosaur. I have been programming for more than 50 years.
>> When I started programming in the 1960s the only pipe one spoke about was a
>> bong.  
>> 

Re: [R] Pipe operator

2023-01-03 Thread Jeff Newmiller
The other responses here have been very good, but I felt it necessary to point 
out that the concept of a pipe originated around when you started programming 
[1] (text based). It did take awhile for it to migrate into programming 
languages such as OCaml, but Powershell makes extensive use of (object-based) 
pipes.

Re memory use: not so much. Variables are small... it is the data they point to 
that is large, and it is not possible to analyze data without storing it 
somewhere. But when the variables are numerous they can interfere with our 
ability to understand the program... using pipes lets us focus on results 
obtained after several steps so fewer intermediate values clutter the variable 
space.

Re speed: the magrittr pipe (%>%) is much slower than the built-in pipe at 
coordinating the transfer of data from left to right, but that is not usually 
significant compared to the computation speed on the actual data in the 
functions.

 [1] 
https://en.m.wikipedia.org/wiki/Pipeline_(Unix)#:~:text=The%20concept%20of%20pipelines%20was,Ritchie%20%26%20Thompson%2C%201974).

On January 3, 2023 9:13:22 AM PST, "Sorkin, John"  
wrote:
>Tim,
>
>Thank you for your reply. I did not know about the |> operator. Do both %>% 
>and |> work in base R?
>
>You suggested that the pipe operator can produce code with fewer variables. 
>May I ask you to send a short example in which the pipe operator saves 
>variables. Does said saving of variables speed up processing or result in less 
>memory usage?
>
>Thank you,
>John
>
>
>From: Ebert,Timothy Aaron 
>Sent: Tuesday, January 3, 2023 12:07 PM
>To: Sorkin, John; 'R-help Mailing List'
>Subject: RE: Pipe operator
>
>The pipe shortens code and results in fewer variables because you do not have 
>to save intermediate steps. Once you get used to the idea it is useful. Note 
>that there is also the |> pipe that is part of base R. As far as I know it 
>does the same thing as %>%, or at my level of programing I have not 
>encountered a difference.
>
>Tim
>
>-Original Message-
>From: R-help  On Behalf Of Sorkin, John
>Sent: Tuesday, January 3, 2023 11:49 AM
>To: 'R-help Mailing List' 
>Subject: [R] Pipe operator
>
>[External Email]
>
>I am trying to understand the reason for existence of the pipe operator, %>%, 
>and when one should use it. It is my understanding that the operator sends the 
>file to the left of the operator to the function immediately to the right of 
>the operator:
>
>c(1:10) %>% mean results in a value of 5.5 which is exactly the same as the 
>result one obtains using the mean function directly, viz. mean(c(1:10)). What 
>is the reason for having two syntactically different but semantically 
>identical ways to call a function? Is one more efficient than the other? Does 
>one use less memory than the other?
>
>P.S. Please forgive what might seem to be a question with an obvious answer. I 
>am a programmer dinosaur. I have been programming for more than 50 years. When 
>I started programming in the 1960s the only pipe one spoke about was a bong.
>
>John
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help=05%7C01%7Cjsorkin%40som.umaryland.edu%7Cdc0d677272114cf6ba2808daedad0ec5%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638083624783034240%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=7dDMSg%2FmPQ5xXP6zu6MWLmARdtdlrYWb3mXPZQj0La0%3D=0
>PLEASE do read the posting guide 
>https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html=05%7C01%7Cjsorkin%40som.umaryland.edu%7Cdc0d677272114cf6ba2808daedad0ec5%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638083624783034240%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=l5BZyjup%2Bho%2FijE1zQMxb5JE3F5VfKBZpUKHYW4k4Fg%3D=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.

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


Re: [R] R Certification

2023-01-02 Thread Jeff Newmiller
I think this request is like saying "I want a unicorn." There are many 
organizations that will enter your name into a certificate form for a fee, 
possibly with some credibility... but if they put "r-project.org" down as the 
name of the organization granting this "certificate" then you are probably 
getting fooled.

On December 30, 2022 8:33:09 AM PST, Mukesh Ghanshyamdas Lekhrajani via R-help 
 wrote:
>Hello R Support Team,
>
> 
>
>I want to do R certification, could you help me with the list of
>certificates with their prices so it helps me to register.
>
> 
>
>I want to do the certification directly from the governing body
>"r-project.org" and not from any 3rd party.
>
> 
>
>Please help.
>
> 
>
> 
>
> 
>
>Mukesh
>
>+91 9819285174
>
>
>   [[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.


Re: [R] Integer division

2022-12-19 Thread Jeff Newmiller
See https://en.m.wikipedia.org/wiki/Modulo_operation, Variants of the 
definition, esp the point that Knuth recommended the floor definition. The 
behavior of %/% follows from the definition of %% given the documented relation 
in ?Arithmetic.

R is not obligated to repeat the mistakes of C or Fortran.

On December 19, 2022 7:15:01 AM PST, "Göran Broström"  wrote:
>
>
>Den 2022-12-19 kl. 15:41, skrev Martin Maechler:
>>> Göran Broström
>>>  on Mon, 19 Dec 2022 14:22:00 +0100 writes:
>> 
>>  > I have a long vector x with five-digit codes where the
>>  > first digit of each is of special interest, so I extracted
>>  > them through
>> 
>>  >> y <- x %/% 1
>> 
>>  > but to my surprise y contained the value -1 in some
>>  > places. It turned out that x contains -1 as a symbol for
>>  > 'missing value' so in effect I found that
>> 
>>  >> -1 %/% 1 == -1
>> 
>>  > Had to check the help page for "%/%", and the first
>>  > relevant comment I found was:
>> 
>>  > "Users are sometimes surprised by the value returned".
>> 
>>  > No surprise there. Further down:
>> 
>>  > ‘%%’ indicates ‘x mod y’ (“x modulo y”) and ‘%/%’
>>  > indicates integer division.  It is guaranteed that
>> 
>>  >   ‘ x == (x %% y) + y * (x %/% y) ’ (up to rounding
>>  > error)
>> 
>>  > I did expect (a %/% b) to return round(a / b), like
>>  > gfortran and gcc,
>> 
>> What???  I cannot believe you.
>
>Well, you shouldn't, I generalized too far.
>> 
>> No time for checking now, but I bet that
>> 8 / 3  gives 2 and not 3  in C and Fortran
>> (and hence gcc, etc)
>
>But compare -8 %/% 3 in R and -8 / 3 in C/Fortran.
>
>G,
>
>> 
>> 
>>  > but instead I get floor(a / b) in
>>  > R. What is the reason for these different definitions? And
>>  > shouldn't R's definition be documented?
>> 
>> 
>> 
>>  > Thanks, Göran
>> 
>>  > __
>>  > R-help@r-project.org mailing list -- To UNSUBSCRIBE and
>>  > more, see https://stat.ethz.ch/mailman/listinfo/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.

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


Re: [R] Error 3221226505

2022-12-18 Thread Jeff Newmiller
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*
>

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


Re: [R] Adding comment in C++ code for debugging purpose

2022-12-16 Thread Jeff Newmiller
a) This is not the Rcpp help list.

b) Writing to stdout without going through R is not supported in packages. Do 
read the Writing R Extensions manual.

On December 16, 2022 3:32:33 PM PST, Christofer Bogaso 
 wrote:
>Hi,
>
>I am using an R package where there are some C++ code.
>
>To check some intermediate values generated by that C++ code, I added
>a line like
>
>std::cout << "My values";
>
>Now with this modification, I next build a modified package (source) using
>
>R CMD build
>
>Next I install this modified package using install.packages() function
>
>However during the run-time of the C++ code with above modification, I
>dont get any print with "My values"
>
>Can you please help to understand why am not getting that printed?
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] is.na()<- on a character vector

2022-12-16 Thread Jeff Newmiller
I don't find _either_ of these acceptable.

On the other hand,

x[ is.na( x ) ] <- 1

should have no effect on x.

On December 16, 2022 10:28:52 AM PST, "Göran Broström"  
wrote:
>I'm confused:
>
>> x <- 1:2
>> is.na(x) <- 1
>> x
>[1] NA  2
>
>OK, but
>
>> x <- c("A", "B")
>> is.na(x) <- "A"
>> x
>   A 
>"A" "B"  NA  
>
>What happens?
>
>G_ran
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] library(tseries) - spellng error in output

2022-12-14 Thread Jeff Newmiller
Contact the package maintainer. See maintainer().

On December 14, 2022 7:04:28 PM PST, roslinazairimah zakaria 
 wrote:
>Hi R-users,
>
>Just to inform that there is one spelling error in the output for *Jarque-Bera
>test in R.*
>
>*library(tseries)*
>
>
>
>
>
>
>
>
>
>
>
>*> #Jarque-Bera normality test> normalTest(dt_i, method='jb')Title: Jarque
>- Bera Normalality TestTest Results:  STATISTIC:X-squared: 16.8853  P
>VALUE:Asymptotic p Value: 0.0002155 *
>

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


Re: [R] Plot a line using ggplot2

2022-12-08 Thread Jeff Newmiller
Please run your code before you send it. Your example is not reproducible.

library(ggplot2)

linedata<- data.frame(
  PointEstx = c( 1, 2 )
, PointEsty = c( 1, 1.5 )
)
# make sure we have a data frame
str(linedata)

#plot the data
ggplot(
  linedata
, aes( x = PointEstx
 , y = PointEsty
 )
) + geom_line()

On December 8, 2022 5:05:47 PM PST, "Sorkin, John"  
wrote:
>Colleagues,
>
>I am trying to plot a simple line using ggplot2. I get the axes, but I don't 
>get the line. Please let me know what my error I am making.
>Thank you,
>John
>
># Define x and y values
>PointEstx <- Estx+1.96*SE
>PointEsty  <- 1
>
>row2 <- cbind(PointEstx,PointEsty)
>linedata<- data_frame(rbind(row1,row2))
>linedata
># make sure we have a data frame
>class(linedata)
>
>#plot the data
>ggplot(linedata,aes(x=PointEstx, y=PointEsty), geom_line())
>
>
>
>
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] setting timezone variable permanently...

2022-12-07 Thread Jeff Newmiller
As I said, the tz is linked to your data, not where you OR your compute server 
are, so setting TZ in your R code or specifying it as the tz argument when you 
convert it are the best options.

If you choose to use your OS to set it that is up to you... but your code 
should not depend on that setting either way.

On December 7, 2022 9:19:40 AM PST, akshay kulkarni  
wrote:
>dear Jeff,
> THanks for your reply. Would you not recommend this  solution 
> too : 
> https://stackoverflow.com/questions/49738564/r-set-environment-variable-permanently
>  ?
>
>THanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>________
>From: Jeff Newmiller 
>Sent: Wednesday, December 7, 2022 10:44 PM
>To: r-help@r-project.org ; akshay kulkarni 
>; R help Mailing list 
>Subject: Re: [R] setting timezone variable permanently...
>
>Technically this is a question regarding your operating system, since 
>environment variables are propagated by the OS creation of processes and 
>different OSes include different mechanisms for configuring them.
>
>However, for practical purposes in R you can just put that statement into your 
>.Rprofile file.
>
>I would not recommend it though... rather you should include this statement in 
>every script that depends on this assumption. Otherwise your script will have 
>a hidden configuration dependency. In fact the timezone you set should be 
>linked with the data files you are using... if you work with time data from 
>different places then you should set it appropriately for that data at the 
>point in your script where you do the import.
>
>On December 7, 2022 8:47:20 AM PST, akshay kulkarni  
>wrote:
>>Dear members,
>> I am setting the Time zone environment variable 
>> by this code:
>>
>>> Sys.setenv(TZ = "Asia/Kolkata")
>>
>>But I have to run it every time I open a new R session. How do I set it 
>>permanently?
>>
>>Thanking you,
>>Yours sincerely,
>>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.
>
>--
>Sent from my phone. Please excuse my brevity.

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


  1   2   3   4   5   6   7   8   9   10   >