[R] random numbers with constraints

2021-01-27 Thread Denis Francisci
Hi, I would like to generate random numbers in R with some constraints: - my vector of numbers must contain 410 values; - min value must be 9.6 and max value must be 11.6; - sum of vector's values must be 4200. Is there a way to do this in R? And is it possible to generate this series in such a way

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Martin Maechler
> Martin Maechler > on Tue, 26 Jan 2021 12:37:58 +0100 writes: > Marcel Baumgartner > on Tue, 26 Jan 2021 08:55:48 +0100 writes: >> Dear all, my colleague posted our issue on stackoverflow: >> Calling R script from Python does not save log file in >> version

Re: [R] How to predict/interpolate new Y given knwon Xs and Ys?

2021-01-27 Thread Luigi Marongiu
Dear Jeff, I am not sure if I understood the procedure properly but it looks like it works: ``` Y <-c(1.301030, 1.602060, 1.903090, 2.204120, 2.505150, 2.806180, 3.107210, 3.408240, 3.709270, 4.010300, 4.311330, 4.612360, 4.913390, 5.214420, 5.515450, 5.816480, 6.117510, 6.418540, 6.

Re: [R] random numbers with constraints

2021-01-27 Thread Ralf Goertz
Am Wed, 27 Jan 2021 09:03:15 +0100 schrieb Denis Francisci : > Hi, > I would like to generate random numbers in R with some constraints: > - my vector of numbers must contain 410 values; > - min value must be 9.6 and max value must be 11.6; > - sum of vector's values must be 4200. > Is there a way

Re: [R] random numbers with constraints

2021-01-27 Thread Abby Spurdle
u <- runif (410) u <- (u - min (u) ) / diff (range (u) ) constrained.sample <- function (rate) { plim <- pexp (c (9.6, 11.6), rate) p <- plim [1] + diff (plim) * u qexp (p, rate) } diff.sum <- function (rate) sum (constrained.sample (rate) ) - 4200 rate <- uniroot (diff.sum, c (1,

Re: [R] How to predict/interpolate new Y given knwon Xs and Ys?

2021-01-27 Thread Abby Spurdle
I got 16.60964. Your curve is not linear up to the 39th point. And as your points appear to be deterministic and nonlinear, splines are likely to be easier to use. Here's a base-only solution (if you don't like my kubik suggestion): g <- splinefun (X, Y) f <- function (x) g (x) - 6 uniroot (f, c

Re: [R] How to predict/interpolate new Y given knwon Xs and Ys?

2021-01-27 Thread Luigi Marongiu
That is right, I removed the points above 39, and also got 16.60964, which looks good to me. Splines is good and I will use it for non-linear interpolation. For now I used linear conversion to keep it simple but looks to me it is getting out of hand. I simply need to do the following interpolation:

Re: [R] How to predict/interpolate new Y given knwon Xs and Ys?

2021-01-27 Thread Jeff Newmiller
Your piecewise-linear function Y(X) is not invertible as a whole so there is no general solution per algebra. You keep saying predict can do this, but as I pointed out and Rui ventured to expand the math on, predict cannot calculate an inverse even if you swap the inputs. And as Abby pointed ou

Re: [R] How to predict/interpolate new Y given knwon Xs and Ys?

2021-01-27 Thread Luigi Marongiu
Thank you for the clarification. On Wed, Jan 27, 2021 at 3:32 PM Jeff Newmiller wrote: > > Your piecewise-linear function Y(X) is not invertible as a whole so there is > no general solution per algebra. > > You keep saying predict can do this, but as I pointed out and Rui ventured to > expand t

Re: [R] problem installing R and RStudio

2021-01-27 Thread Carlos Gonzalez
Thank you @LucyNjoki!!! Everything runs ok now. El mar, 26 de ene. de 2021 a la(s) 16:51, John Kane (jrkrid...@gmail.com) escribió: > A couple of Window solutions > > https://community.rstudio.com/t/problems-with-r-4-0-0-windows-error-package-or-namespace-load-failed-for-stats-in-indl-x-as-logica

Re: [R] random numbers with constraints

2021-01-27 Thread Denis Francisci
Wonderful! This is exactly what I need! Thank you very much!! Denis Il giorno mer 27 gen 2021 alle ore 10:58 Abby Spurdle ha scritto: > u <- runif (410) > u <- (u - min (u) ) / diff (range (u) ) > > constrained.sample <- function (rate) > { plim <- pexp (c (9.6, 11.6), rate) > p <- plim

Re: [R] Is there anyone who uses both R and Python here? How do you debug? Perhaps in RStudio?

2021-01-27 Thread Robert Knight
An iterative process works well. Python to get the data desired and then Rscript script.r from a command line. My process involves building a script in R using, using Rstudio, Pycharm, VS Code, Kate, or some other editor. Then using data input built with Python as input to Rscript. The R scripts

Re: [R] Is there anyone who uses both R and Python here? How do you debug? Perhaps in RStudio?

2021-01-27 Thread Spencer Graves
You can mix R and Python code in the same R Markdown vignette. See: https://bookdown.org/yihui/rmarkdown/language-engines.html ```{r "RcodeChunk"} # R code ``` ```{python "PythonCodeChunk"} # Python code ``` I did this a couple of years ago. I haven't used Python since. However, this i

[R] problem when loading tidyverse

2021-01-27 Thread Carlos Gonzalez
Why when loading tidyverse shows the following: -- Conflicts -- tidyverse_conflicts() -- x dplyr::filter() masks stats::filter() x dplyr::lag()masks stats::lag() -- Saludos / Regards Carlos A. Gonzalez Mobile +598 94 234 653 cag...@gmail.com

Re: [R] problem when loading tidyverse

2021-01-27 Thread Jeff Newmiller
These are not errors, they are informational, and the Posting Guide points out that details of how to use contributed packages such as tidyverse are off topic (too many of them for one list). If you want to use the versions of the functions that tidyverse is overriding, specify the desired pack

Re: [R] problem when loading tidyverse

2021-01-27 Thread Carlos Gonzalez
Many thanks, Jeff. Very clear El mié, 27 de ene. de 2021 a la(s) 14:29, Jeff Newmiller ( jdnew...@dcn.davis.ca.us) escribió: > These are not errors, they are informational, and the Posting Guide points > out that details of how to use contributed packages such as tidyverse are > off topic (too ma

[R] create

2021-01-27 Thread Val
Hi all, I have a sample of data as shown below, dt <-read.table(text="name Item check A DESK NORF B RANGE GARRA C CLOCKPALM D DESK RR E ALARMDESPRF H DESK RF K DESK CORR K WARF CORR G NONE RF ",header=TRUE, fill=T) I want create another

Re: [R] create

2021-01-27 Thread Bert Gunter
Thanks for the reprex. I think this is one way to do what you want: dt$flag2 <- 0 + with(dt,Item == "DESK" & check %in% code2) > dt$flag2 <- 0 + with(dt,Item == "DESK" & check %in% code2) > dt name Item check flag2 1A DESK NORF 0 2B RANGE GARRA 0 3C CLOCK PALM 0 4

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
Note that in R-3.6.3 commandArgs() does not include the arguments intended to be processed by the shell, "1>", "arguments.txt", etc., but in R-4.0.3 it does include them. It is as though an R shell() command was replaced by a system() command so cmd.exe didn't get a chance to process the command l

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
I mistyped, 3.6.3 omits "1>", "log.txt" (not arguments.txt"), etc. My test was run in C:\tmp and used -e instead of -f and bin/R.exe instead of bin/x64/R.exe, using the following python script: import subprocess cmd363 = " ".join(["C:/R/R-3.6.3/bin/R.exe", "--vanilla", "--quiet", # "-f"

Re: [R] random numbers with constraints

2021-01-27 Thread Abby Spurdle
I note that there's a possibility of floating point errors. If all values have one digit after the decimal point, you could replace: qexp (p, rate) with round (qexp (p, rate), 1). However, sometimes uniroot will fail, due to problems with input. On Thu, Jan 28, 2021 at 5:02 AM Denis Francisci wr

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Duncan Murdoch
On 27/01/2021 3:38 a.m., Martin Maechler wrote: Martin Maechler on Tue, 26 Jan 2021 12:37:58 +0100 writes: Marcel Baumgartner on Tue, 26 Jan 2021 08:55:48 +0100 writes: >> Dear all, my colleague posted our issue on stackoverflow: >> Calling R script from Python does not

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Duncan Murdoch
On 27/01/2021 3:17 p.m., Duncan Murdoch wrote: On 27/01/2021 3:38 a.m., Martin Maechler wrote: Martin Maechler on Tue, 26 Jan 2021 12:37:58 +0100 writes: Marcel Baumgartner on Tue, 26 Jan 2021 08:55:48 +0100 writes: >> Dear all, my colleague posted our issue on stackoverfl

[R] Get 3 values not only 1

2021-01-27 Thread varin sacha via R-help
Dear R-experts, Here below my R code working but I would like to get 3 values not only 1. The value I get is, according to my R code, the variance value. My goal is to get 3 values : the bias value, the variance value and the MSE value. How to solve my problem ? Many thanks. #

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
I believe the problem is from svn 77925 in gnuwin/front-ends/rcmdfn.c, which was committed a few days after 3.6.3 was released. Rterm used to put double quotes around a command line argument only if it contained a space, now it double quotes all arguments. It sees shell constructs like "1>" and t

Re: [R] Get 3 values not only 1

2021-01-27 Thread Jim Lemon
Hi varin, How about this: Mbv<-data.frame(MSE=rep(NA,1000), biais=rep(NA,1000),variance=rep(NA,1000)) for(i in 1 :1000) { n<-dim(Dataset)[1] p<-0.667 sam<-sample(1 :n,floor(p*n),replace=FALSE) Training <-Dataset [sam,] Testing <- Dataset [-sam,] fit2<-lm(PIB.hab~ISQ.2018) ypred<-predict(fit

Re: [R] Get 3 values not only 1

2021-01-27 Thread jim holtman
Is this what you are after? You need to store a vector in the list: > > # Data > PIB.hab<-c(12000,34000,25000,43000,12500,32400,76320,45890,76345,90565,76580,45670,23450,34560,65430,65435,56755,87655,90755,45675) > ISQ.2018<-c(564,587,489,421,478,499,521,510,532,476,421,467,5

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Duncan Murdoch
On 27/01/2021 3:40 p.m., Bill Dunlap wrote: I believe the problem is from svn 77925 in gnuwin/front-ends/rcmdfn.c, which was committed a few days after 3.6.3 was released. Rterm used to put double quotes around a command line argument only if it contained a space, now it double quotes all argume

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
I tried the following change, that adds quotes if the argument does not include ">". Index: front-ends/rcmdfn.c === --- front-ends/rcmdfn.c (revision 79883) +++ front-ends/rcmdfn.c (working copy) @@ -173,9 +173,13 @@ fp