Re: [R] save(), load(), saveRDS(), and readRDS()

2023-09-29 Thread Jorgen Harmse via R-help
Ivan Krylov points out that load(file, e <- new.env()) is cumbersome. I put it into a function. Regards, Jorgen Harmse. #' Save & load lists & environments #' #' \code{\link{save}} has to be told what to save from an environment, and the obvious way #' to save a structure creates an extra

Re: [R] lattice densityplot with weights

2023-09-29 Thread Deepayan Sarkar
Yes, the following should (mostly) work: lattice::densityplot(~ x, mydf, groups = name, weights = wt, auto.key = list(space = "inside"), grid = TRUE) I just realised that the 'subdensity' and 'warnWbw' arguments are not passed through by densityplot(), so there is no way to get rid of the

Re: [R] lattice densityplot with weights

2023-09-29 Thread Bert Gunter
Unless I misunderstand... See ?panel.densityplot Lattice functions do their work through a host of panel functions, typically passing their ... arguments to the panel functions. panel.densityplot has a weights argument. Cheers, Bert On Fri, Sep 29, 2023 at 3:32 AM Naresh Gurbuxani <

Re: [R] replace character by numeric value

2023-09-29 Thread Ebert,Timothy Aaron
You might also try mynewdf <- mydf |> dplyr::mutate(side = ifelse(side == 'BUY', 1,-1)) This may give unexpected results if there are other choices besides "BUY" and "SELL". mynewdf <- mydf |> dplyr::mutate(side = ifelse(side == 'BUY', 1, ifelse(side == 'SELL', -1, NA))) is an option that

Re: [R] replace character by numeric value

2023-09-29 Thread Ben Bolker
The reason you're getting the result as character is that you have 'side' as your alternative result in the second ifelse(). If "BUY" and "SELL" are the only options you might try ifelse(side == 'BUY', 1, ifelse(side == 'SELL', -1, NA)) or c(1,-1)[match(side, c("BUY", "SELL"))] or

Re: [R] replace character by numeric value

2023-09-29 Thread Ebert,Timothy Aaron
Does this work? mynewdf$side <- as.numeric(mynewdf$side) This code would be the next line after your mutate. TIm -Original Message- From: R-help On Behalf Of Enrico Schumann Sent: Thursday, September 28, 2023 3:13 AM To: arnaud gaboury Cc: r-help Subject: Re: [R] replace character by

Re: [R] Odd result

2023-09-29 Thread peter dalgaard
Yes. Also notice that something fishy seems to be going on in columns 2 and 3 (assuming that the date/time is 1 column). They appear to be read as character data, even though the content is numeric? -pd > On 24 Sep 2023, at 11:58 , Michael Dewey wrote: > > Dear David > > To get the first 46

[R] lattice densityplot with weights

2023-09-29 Thread Naresh Gurbuxani
density() function in R accepts weights as an input. Using this function, one can calculate density and plot it. Is it possible to combined these two operations in lattice densityplot()? mydf <- data.frame(name = "A", x = seq(-2.9, 2.9, by = 0.2), wt = diff(pnorm(seq(-3, 3, by = 0.2 mydf

Re: [R] save(), load(), saveRDS(), and readRDS()

2023-09-29 Thread Ivan Krylov
On Thu, 28 Sep 2023 23:46:45 +0800 Shu Fai Cheung wrote: > In my personal work, I prefer using saveRDS() and loadRDS() as I > don't like the risk of overwriting anything in the global > environment. There's the load(file, e <- new.env()) idiom, but that's potentially a lot to type.

Re: [ESS] Have M-x R point at the most recent version of R

2023-09-29 Thread Manuel Teodoro via ESS-help
ESS needs C:/Programme/R/R-4.2.2/bin/R.exe I'm not sure if I'm missing something but it seems to me that you want to define it in your init file, but then you will have to update it each time that you change R versions. Use the following line (setq inferior-ess-r-program