From deep@y@n@@@rk@r @end|ng |rom gm@||@com Thu Jun 1 06:04:48 2023 From: deep@y@n@@@rk@r @end|ng |rom gm@||@com (Deepayan Sarkar) Date: Thu, 1 Jun 2023 09:34:48 +0530 Subject: [R] plot level, velocity, acceleration with one x axis In-Reply-To: <39decd19-d963-8324-bb2e-7d44a33eaf9c@effectivedefense.org> References: <96cad904-56fb-8db5-d909-96ddb037a31a@effectivedefense.org> <88be9a8e-86bd-cd5f-0d4b-c871d4987bf3@effectivedefense.org> <6c729593-7aeb-030d-c595-e1241d6169d3@effectivedefense.org> <39decd19-d963-8324-bb2e-7d44a33eaf9c@effectivedefense.org> Message-ID: I think your proposal of modifying plot.ts() to allow 'log' to be vectorized would be the most natural solution here. For what it's worth, the details of the implementation and the fact that you can supply a panel function allows an ugly hack: pfun <- function(...) { e <- parent.frame() e$log <- "" lines(...) } plot(DAX., log = "y", panel = pfun) This would need to be modified to include a counter in more complicated cases; we can do without because only the first panel has a log scale in this example. -Deepayan On Thu, Jun 1, 2023 at 12:53?AM Spencer Graves wrote: > > > > On 5/31/23 2:12 PM, Viechtbauer, Wolfgang (NP) wrote: > > How about using the same 'mar' for all plots, but adding an outer margin? > > > > DAX <- EuStockMarkets[, 'DAX'] > > DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX)))) > > colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)') > > head(DAX.) > > > > par(mfrow=c(3,1), mar=c(1,4.5,0,2), oma=c(3,0,1,0)) > > > > plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE) > > axis(2) > > box(col='grey') > > > > plot(DAX.[, 2], ylab='vel (%)', axes=FALSE) > > axis(2) > > box(col='grey') > > > > plot(DAX.[, 3], ylab='accel (%)', axes=FALSE) > > axis(2) > > box(col='grey') > > axis(1) > > > > Best, > > Wolfgang > > > That's exactly what I needed. > > > Thanks, Spencer > > > > >> -----Original Message----- > >> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Spencer Graves > >> Sent: Wednesday, 31 May, 2023 17:45 > >> To: Eric Berger > >> Cc: r-help > >> Subject: Re: [R] plot level, velocity, acceleration with one x axis > >> > >> On 5/31/23 9:20 AM, Eric Berger wrote: > >>> I sent you an updated response to deal with the redundant copies of the x-axis. > >>> Re-sending. > >>> > >> par(mfrow=c(3,1)) > >> plot(DAX.[, 1], log='y', ylab='DAX', xaxt="n") > >> plot(DAX.[, 2], ylab='vel (%)', xaxt="n") > >> plot(DAX.[, 3], ylab='accel (%)') > >> > >> I got that. The primary problem with that is that most of the > >> vertical space is reserved for axis labels, whether they are printed or > >> not. If I squeeze the vertical dimension of the plot, I get, "figure > >> margins too large". To control that, I need to set "mar" separately for > >> each panel, and then the plot regions for each are not the same size. > >> Using the "layout" function instead of "mfrow" is better, but I don't > >> see now to make that work consistently without fixing the aspect ratio. > >> There may be a way in the tidyverse, but I haven't found it yet. The > >> only solution I've found so far that makes sense to me is to modify the > >> code for plot.ts to accept a vector for the log argument, with the > >> constraint that length(lot) = either 1 or ncol(x) and returning > >> invisibly an object that would make it feasible for a user to call > >> axis(2, ...) once for each vertical axis to handle cases where someone > >> wanted to a vertical scale different from linear and log. I'd want to > >> make sure that lines.ts also works with this, because I want to add fits > >> and predictions. > >> > >> Comments? > >> Thanks, > >> Spencer Graves > >> > >> ** With either of the following plots, if I adjust the aspect ratio by > >> enlarging or reducing the vertical dimension of the plot, the relative > >> sizes of the plot regions change. > >> > >> DAX <- EuStockMarkets[, 'DAX'] > >> DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX)))) > >> colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)') > >> head(DAX.) > >> > >> plot(DAX., log='xy') > >> > >> op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1)) > >> plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE) > >> axis(2) > >> box(col='grey') > >> par(mar=c(0, 4.1, 0, 2.1)) > >> plot(DAX.[, 2], ylab='vel (%)', axes=FALSE) > >> axis(2) > >> box(col='grey') > >> par(mar=c(5.1, 4.1, 0, 2.1)) > >> plot(DAX.[, 3], ylab='accel (%)', axes=FALSE) > >> axis(2) > >> box(col='grey') > >> axis(1) > >> par(op) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch Thu Jun 1 09:58:32 2023 From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler) Date: Thu, 1 Jun 2023 09:58:32 +0200 Subject: [R] error in arfima... In-Reply-To: References: Message-ID: <25720.20392.521283.415199@stat.math.ethz.ch> >>>>> akshay kulkarni >>>>> on Wed, 31 May 2023 20:55:33 +0000 writes: > dear members, > I am using arfima() from forecast package to model a time > series. The following is the code: >> LYGH[[202]] > [1] 45.40 3.25 6.50 2.15 >> arfima(LYGH[[202]]) > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : > NA/NaN/Inf in foreign function call (arg 5) > I tried viewing .fdcov() with the following code: > View(environment(fracdiff)$.fdcov) > but I see no stop() with the above mentioned error message. > Can you please help? Well, as I am the maintainer of the *fracdiff* package, I'm trying. OTOH, as we will see below, you did not give us enough information to really help you... > THanking you, > Yours sincerely, > AKSHAY M KULKARNI Your problem is not (yet) reproducible (*) I've done the following in an "empty" (i.e. freshly started) R session, R 4.3.0: ----begin_R_transcript___save_as__arfima-ex.Rout__------------------------------ > > lN <- loadedNamespaces() > library(forecast) Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo > options(width=75) > setdiff(loadedNamespaces(), lN) # -- see all the *!^@...! forecast loads: [1] "gtable" "dplyr" "tidyselect" "Rcpp" "parallel" [6] "scales" "lattice" "ggplot2" "R6" "generics" [11] "curl" "lmtest" "tibble" "munsell" "nnet" [16] "forecast" "timeDate" "pillar" "rlang" "quantmod" [21] "utf8" "urca" "quadprog" "cli" "magrittr" [26] "xts" "grid" "nlme" "lifecycle" "fracdiff" [31] "vctrs" "glue" "tseries" "zoo" "fansi" [36] "colorspace" "TTR" "pkgconfig" > arfima(c(45.40, 3.25, 6.50, 2.15)) Call: arfima(y = c(45.4, 3.25, 6.5, 2.15)) Coefficients: d 4.583013e-05 sigma[eps] = 18.01252 a list with components: [1] "log.likelihood" "n" "msg" [4] "d" "ar" "ma" [7] "covariance.dpq" "fnormMin" "sigma" [10] "stderror.dpq" "correlation.dpq" "h" [13] "d.tol" "M" "hessian.dpq" [16] "length.w" "residuals" "fitted" [19] "call" "x" "series" > > sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Fedora Linux 36 (Thirty Six) Matrix products: default BLAS: /usr/local64.sfs/app/R/R-4.3.0-inst/lib/libRblas.so LAPACK: /usr/lib64/liblapack.so.3.10.1 locale: [1] LC_CTYPE=de_CH.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=de_CH.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=de_CH.UTF-8 [7] LC_PAPER=de_CH.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C time zone: Europe/Zurich tzcode source: system (glibc) attached base packages: [1] graphics grDevices datasets stats utils methods base other attached packages: [1] forecast_8.21 fortunes_1.5-4 sfsmisc_1.1-15 loaded via a namespace (and not attached): [1] gtable_0.3.3 dplyr_1.1.2 compiler_4.3.0 [4] tidyselect_1.2.0 Rcpp_1.0.10 parallel_4.3.0 [7] scales_1.2.1 lattice_0.21-8 ggplot2_3.4.2 [10] R6_2.5.1 generics_0.1.3 curl_5.0.0 [13] lmtest_0.9-40 tibble_3.2.1 munsell_0.5.0 [16] nnet_7.3-19 timeDate_4022.108 pillar_1.9.0 [19] rlang_1.1.1 quantmod_0.4.22 utf8_1.2.3 [22] urca_1.3-3 quadprog_1.5-8 cli_3.6.1 [25] magrittr_2.0.3 xts_0.13.1 grid_4.3.0 [28] nlme_3.1-162 lifecycle_1.0.3 fracdiff_1.5-2 [31] vctrs_0.6.2 glue_1.6.2 tseries_0.10-54 [34] zoo_1.8-12 fansi_1.0.4 colorspace_2.1-0 [37] TTR_0.24.3 tools_4.3.0 pkgconfig_2.0.3 > ##---end__R_transcript--------------------------------------------------------------- Note that your error message pointed me to my (old, but still fine) package {fracdiff} with its principal function fracdiff() around which arfima() is a user-friendly and generalization wrapper. In other words arfima() calls fracdiff::fracdiff() and the error happens there --- for you, but not for me, if I try to use the same data as you. I see that you must have found that too, because you mentioned View(environment(fracdiff)$.fdcov) Maybe you need to update.packages() {which should re-install R packages you have installed but which have become outdated in the mean time} If the error persists, please send us the output of 1) dput(LYGH[[202]]) so we get your exact data 2) sessionInfo() so we get much info about your R "setup" .... last but not least: If you are really calling arfima() with a time series of length 4 (which your LYGH[[202]] above seems to suggest) then you really need to learn a bit about the tools you are using: It really does not make any sense to fit a somewhat sophisticated time-series model (or *any* time-series model, I'd say) to a "series" with 4 values. Best regards, Martin -- Martin Maechler ETH Zurich and R Core team From v@r|n@@ch@ @end|ng |rom y@hoo@|r Thu Jun 1 21:42:21 2023 From: v@r|n@@ch@ @end|ng |rom y@hoo@|r (varin sacha) Date: Thu, 1 Jun 2023 19:42:21 +0000 (UTC) Subject: [R] Exact 95% CIs weibull distribution References: <1210843777.5136267.1685648541248.ref@mail.yahoo.com> Message-ID: <1210843777.5136267.1685648541248@mail.yahoo.com> R-experts, I am trying to find the exact 95% confidence intervals of the mean (and the median) for the weibull distribution. Here below I have the exact 95% CIs of the meanlog and the median for a lognormal using EnvStats library (ready-to-run function in library) but I don't find how to get the exact 95% CIs of the mean and median for the weibull. Indeed, the ready-to-run function in EnvStats library is not available for weibull. Any help would be appreciated. #Exact 95% CIs for the meanlog lognormal distribution library(EnvStats) x=rlnorm(100000,0,1) elnorm(x,method="mvue",ci=TRUE,ci.type="two-sided",ci.method="exact",conf.level=0.95) ? #Exact 95% CIs for the median lognormal distribution library(EnvStats) x=rlnorm(100000,0,1) eqlnorm(x, p=0.5, method="mvue",ci=TRUE,ci.type="two-sided",ci.method="exact",conf.level=0.95) ? #Exact 95% CIs for the mean weibull distribution library(EnvStats) x=rweibull(100000,shape=2, scale=2) eqweibull(x, p = 0.925) eqweibull(x, p = 0.975) #Exact 95% CIs for the median weibull distribution library(EnvStats) x=rweibull(100000,shape=2, scale=2) eqweibull(x, p = 0.5, method = "mle", digits = 0) From ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de Fri Jun 2 11:17:42 2023 From: ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de (Uwe Ligges) Date: Fri, 2 Jun 2023 11:17:42 +0200 Subject: [R] Help sourcing datasets (.csv) In-Reply-To: References: Message-ID: <74c477a0-9a10-2c94-e874-bb101281347d@statistik.tu-dortmund.de> See ?data On 28.05.2023 10:53, james carrigan wrote: > Dear Sir or Madam > I?m trying to compile a collection of datasets that require use of the following hypothesis tests. > Are there datasets within the R library that I can get access to? > Kind regards > James Carrigan > > Hypothesis Testing > t.test(X,Y) > ? performs a two sample t-test between X and Y > t.test(X,Y,paired=TRUE) > ? performs a paired t-test between X and Y > prop.test(x = c(a, b), n = c(n1, n2)) > ? performs a 2-sample test for equality of proportions with continuity correction > > Sent from my iPad Sent from my iPhone > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From tebert @end|ng |rom u||@edu Fri Jun 2 17:55:08 2023 From: tebert @end|ng |rom u||@edu (Ebert,Timothy Aaron) Date: Fri, 2 Jun 2023 15:55:08 +0000 Subject: [R] Help sourcing datasets (.csv) In-Reply-To: <74c477a0-9a10-2c94-e874-bb101281347d@statistik.tu-dortmund.de> References: <74c477a0-9a10-2c94-e874-bb101281347d@statistik.tu-dortmund.de> Message-ID: Another suggestion: The statistics does not care where the numbers come from. The values 1, 2, 3 have a mean of 2 no matter if these are weights of a bird, plant heights, or concrete tensile strength. Your interpretation might change, but the mean is still 2. Try synthetic data. X<-rnorm(1000, mean=4, sd=2) Y<-14+12*X cor(X,Y) That is too simple, but it is the start. Y<- rnorm(1000, mean=14, sd=2) + 12*X cor(X,Y) look at the result in something like ggplot2 Dataf <- data.frame(X,Y) ggplot(Dataf, aes(X, Y)) + geom.point() + stat_smooth(method=lm, se=FALSE) This approach has a few advantages: 1) I know that X and Y are samples from the Gaussian (Normal) distribution. 2) I know that the data are homoscedastic. 3) I can change 1 and 2 in whatever way I want. Possibly useful if you want to understand how violations in model assumptions influence outcomes. 4) I can look closely at the influence of sample size when assumptions are met and when they are not. Note that ANOVA and regression do not assume that the independent or dependent variables are normally distributed. The assumption of Normality is for the error term in the model. However, if both dependent and independent variables are normally distributed then it is likely that the error term will also be normally distributed. What should I get here? Y<- rnorm(1000, mean=14, sd=2) + X*rnorm(1000, mean=12, sd=27) Tim -----Original Message----- From: R-help On Behalf Of Uwe Ligges Sent: Friday, June 2, 2023 5:18 AM To: james carrigan ; r-help at r-project.org Subject: Re: [R] Help sourcing datasets (.csv) [External Email] See ?data On 28.05.2023 10:53, james carrigan wrote: > Dear Sir or Madam > I'm trying to compile a collection of datasets that require use of the following hypothesis tests. > Are there datasets within the R library that I can get access to? > Kind regards > James Carrigan > > Hypothesis Testing > t.test(X,Y) > - performs a two sample t-test between X and Y > t.test(X,Y,paired=TRUE) > - performs a paired t-test between X and Y prop.test(x = c(a, b), n = > c(n1, n2)) - performs a 2-sample test for equality of proportions with > continuity correction > > Sent from my iPad Sent from my iPhone > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat/ > .ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu > %7C5f3292c3315b446b8b9008db634a37cb%7C0d4da0f84a314d76ace60a62331e1b84 > %7C0%7C0%7C638212942641271785%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw > MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sda > ta=s5NqLzxYTlnA1BHldzka%2F2i%2FoefvsLmU%2FDuLJav5mMc%3D&reserved=0 > PLEASE do read the posting guide > http://www.r/ > -project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C5f > 3292c3315b446b8b9008db634a37cb%7C0d4da0f84a314d76ace60a62331e1b84%7C0% > 7C0%7C638212942641271785%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL > CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=xG > MQDNZksGydmnYDLAFjZ%2BEZp4ne%2Bf5JK%2BO9qrH7zeU%3D&reserved=0 > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From @k@h@y_e4 @end|ng |rom hotm@||@com Sun Jun 4 13:24:41 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sun, 4 Jun 2023 11:24:41 +0000 Subject: [R] error in arfima... In-Reply-To: <25720.20392.521283.415199@stat.math.ethz.ch> References: <25720.20392.521283.415199@stat.math.ethz.ch> Message-ID: Dear Martin, REgrets to reply this late.... I am staring at a conundrum never before encountered in my experience with R: LYGH[[201]] [1] 45.40 3.25 6.50 2.15 > arfima(LYGH[[201]]) Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : NA/NaN/Inf in foreign function call (arg 5) > arfima(c(45.40,3.25,6.50,2.15)) Call: arfima(y = c(45.4, 3.25, 6.5, 2.15)) Coefficients: d 4.583013e-05 sigma[eps] = 18.01252 a list with components: [1] "log.likelihood" "n" "msg" "d" "ar" [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" [16] "length.w" "residuals" "fitted" "call" "x" [21] "series" Please note that the index of LYGH has changed from 202 to 201 due to some randomness in one of my function. PLEASE HELP. Output of dput LYGH[[201]]: > dput(LYGH[[201]]) c(45.4, 3.25, 6.5, 2.14999999999998) output of session info() sessionInfo() R version 4.1.2 (2021-11-01) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows Server x64 (build 14393) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] parallel stats graphics grDevices utils datasets methods base other attached packages: [1] pbmcapply_1.5.1 imputeTS_3.3 forecast_8.17.0 loaded via a namespace (and not attached): [1] Rcpp_1.0.7 urca_1.3-3 pillar_1.9.0 compiler_4.1.2 tseries_0.10-51 [6] tools_4.1.2 xts_0.12.1 nlme_3.1-153 lifecycle_1.0.3 tibble_3.2.1 [11] gtable_0.3.3 lattice_0.20-45 pkgconfig_2.0.3 rlang_1.1.0 cli_3.6.1 [16] rstudioapi_0.14 curl_4.3.2 xml2_1.3.3 dplyr_1.1.1 generics_0.1.3 [21] vctrs_0.6.1 gridtext_0.1.5 ggtext_0.1.2 lmtest_0.9-40 grid_4.1.2 [26] nnet_7.3-16 tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 fansi_1.0.4 [31] ggplot2_3.4.2 TTR_0.24.3 magrittr_2.0.3 scales_1.2.1 quantmod_0.4.20 [36] timeDate_4021.106 colorspace_2.1-0 fracdiff_1.5-1 quadprog_1.5-8 utf8_1.2.3 [41] stinepack_1.4 munsell_0.5.0 zoo_1.8-10 PLease Also note: arfima(c(45.4, 3.25, 6.5, 2.14999999999998)) Call: arfima(y = c(45.4, 3.25, 6.5, 2.14999999999998)) Coefficients: d 4.583013e-05 sigma[eps] = 18.01252 a list with components: [1] "log.likelihood" "n" "msg" "d" "ar" [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" [16] "length.w" "residuals" "fitted" "call" "x" [21] "series" Many thanks in advance.... Thanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Martin Maechler Sent: Thursday, June 1, 2023 1:28 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] error in arfima... >>>>> akshay kulkarni >>>>> on Wed, 31 May 2023 20:55:33 +0000 writes: > dear members, > I am using arfima() from forecast package to model a time > series. The following is the code: >> LYGH[[202]] > [1] 45.40 3.25 6.50 2.15 >> arfima(LYGH[[202]]) > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : > NA/NaN/Inf in foreign function call (arg 5) > I tried viewing .fdcov() with the following code: > View(environment(fracdiff)$.fdcov) > but I see no stop() with the above mentioned error message. > Can you please help? Well, as I am the maintainer of the *fracdiff* package, I'm trying. OTOH, as we will see below, you did not give us enough information to really help you... > THanking you, > Yours sincerely, > AKSHAY M KULKARNI Your problem is not (yet) reproducible (*) I've done the following in an "empty" (i.e. freshly started) R session, R 4.3.0: ----begin_R_transcript___save_as__arfima-ex.Rout__------------------------------ > > lN <- loadedNamespaces() > library(forecast) Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo > options(width=75) > setdiff(loadedNamespaces(), lN) # -- see all the *!^@...! forecast loads: [1] "gtable" "dplyr" "tidyselect" "Rcpp" "parallel" [6] "scales" "lattice" "ggplot2" "R6" "generics" [11] "curl" "lmtest" "tibble" "munsell" "nnet" [16] "forecast" "timeDate" "pillar" "rlang" "quantmod" [21] "utf8" "urca" "quadprog" "cli" "magrittr" [26] "xts" "grid" "nlme" "lifecycle" "fracdiff" [31] "vctrs" "glue" "tseries" "zoo" "fansi" [36] "colorspace" "TTR" "pkgconfig" > arfima(c(45.40, 3.25, 6.50, 2.15)) Call: arfima(y = c(45.4, 3.25, 6.5, 2.15)) Coefficients: d 4.583013e-05 sigma[eps] = 18.01252 a list with components: [1] "log.likelihood" "n" "msg" [4] "d" "ar" "ma" [7] "covariance.dpq" "fnormMin" "sigma" [10] "stderror.dpq" "correlation.dpq" "h" [13] "d.tol" "M" "hessian.dpq" [16] "length.w" "residuals" "fitted" [19] "call" "x" "series" > > sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Fedora Linux 36 (Thirty Six) Matrix products: default BLAS: /usr/local64.sfs/app/R/R-4.3.0-inst/lib/libRblas.so LAPACK: /usr/lib64/liblapack.so.3.10.1 locale: [1] LC_CTYPE=de_CH.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=de_CH.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=de_CH.UTF-8 [7] LC_PAPER=de_CH.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C time zone: Europe/Zurich tzcode source: system (glibc) attached base packages: [1] graphics grDevices datasets stats utils methods base other attached packages: [1] forecast_8.21 fortunes_1.5-4 sfsmisc_1.1-15 loaded via a namespace (and not attached): [1] gtable_0.3.3 dplyr_1.1.2 compiler_4.3.0 [4] tidyselect_1.2.0 Rcpp_1.0.10 parallel_4.3.0 [7] scales_1.2.1 lattice_0.21-8 ggplot2_3.4.2 [10] R6_2.5.1 generics_0.1.3 curl_5.0.0 [13] lmtest_0.9-40 tibble_3.2.1 munsell_0.5.0 [16] nnet_7.3-19 timeDate_4022.108 pillar_1.9.0 [19] rlang_1.1.1 quantmod_0.4.22 utf8_1.2.3 [22] urca_1.3-3 quadprog_1.5-8 cli_3.6.1 [25] magrittr_2.0.3 xts_0.13.1 grid_4.3.0 [28] nlme_3.1-162 lifecycle_1.0.3 fracdiff_1.5-2 [31] vctrs_0.6.2 glue_1.6.2 tseries_0.10-54 [34] zoo_1.8-12 fansi_1.0.4 colorspace_2.1-0 [37] TTR_0.24.3 tools_4.3.0 pkgconfig_2.0.3 > ##---end__R_transcript--------------------------------------------------------------- Note that your error message pointed me to my (old, but still fine) package {fracdiff} with its principal function fracdiff() around which arfima() is a user-friendly and generalization wrapper. In other words arfima() calls fracdiff::fracdiff() and the error happens there --- for you, but not for me, if I try to use the same data as you. I see that you must have found that too, because you mentioned View(environment(fracdiff)$.fdcov) Maybe you need to update.packages() {which should re-install R packages you have installed but which have become outdated in the mean time} If the error persists, please send us the output of 1) dput(LYGH[[202]]) so we get your exact data 2) sessionInfo() so we get much info about your R "setup" .... last but not least: If you are really calling arfima() with a time series of length 4 (which your LYGH[[202]] above seems to suggest) then you really need to learn a bit about the tools you are using: It really does not make any sense to fit a somewhat sophisticated time-series model (or *any* time-series model, I'd say) to a "series" with 4 values. Best regards, Martin -- Martin Maechler ETH Zurich and R Core team [[alternative HTML version deleted]] From re|chm@nj @end|ng |rom @bcg|ob@|@net Mon Jun 5 01:11:08 2023 From: re|chm@nj @end|ng |rom @bcg|ob@|@net (Jeff Reichman) Date: Sun, 4 Jun 2023 18:11:08 -0500 Subject: [R] Adding a numeric class to a data.frame References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> Message-ID: <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> R-Help Community How do I add a numeric class to a data .frame. For example, I have calculated the following probabilities 1 2 3 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]] From jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@ Mon Jun 5 01:37:23 2023 From: jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@ (Jeff Newmiller) Date: Sun, 04 Jun 2023 16:37:23 -0700 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> Message-ID: <86F1D370-63B3-4655-AF83-ACBE724F19D4@dcn.davis.ca.us> 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 > > > > 1 2 3 > >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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/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. From @vi@e@gross m@iii@g oii gm@ii@com Mon Jun 5 03:59:47 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Sun, 4 Jun 2023 21:59:47 -0400 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> Message-ID: <009201d99751$68622d30$39268790$@gmail.com> 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 A B 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 at 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 1 2 3 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From re|chm@nj @end|ng |rom @bcg|ob@|@net Mon Jun 5 04:20:56 2023 From: re|chm@nj @end|ng |rom @bcg|ob@|@net (Jeff Reichman) Date: Sun, 4 Jun 2023 21:20:56 -0500 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <009201d99751$68622d30$39268790$@gmail.com> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> <009201d99751$68622d30$39268790$@gmail.com> Message-ID: <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> 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.gross at gmail.com Sent: Sunday, June 4, 2023 9:00 PM To: 'Jeff Reichman' ; r-help at 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 A B 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 at 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 1 2 3 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@ Mon Jun 5 04:38:24 2023 From: jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@ (Jeff Newmiller) Date: Sun, 04 Jun 2023 19:38:24 -0700 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> <009201d99751$68622d30$39268790$@gmail.com> <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> Message-ID: <37DEDB3D-8F8A-4FBE-8EB8-7566E3E7B34E@dcn.davis.ca.us> 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.gross at gmail.com >Sent: Sunday, June 4, 2023 9:00 PM >To: 'Jeff Reichman' ; r-help at 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 > A B 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 at 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 > > > > 1 2 3 > >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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/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. From @vi@e@gross m@iii@g oii gm@ii@com Mon Jun 5 04:57:35 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Sun, 4 Jun 2023 22:57:35 -0400 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> <009201d99751$68622d30$39268790$@gmail.com> <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> Message-ID: <009401d99759$7b74b570$725e2050$@gmail.com> Jeff, The number of items is not relevant except insofar as your vector of probabilities is in the same order as the other vector and the same length. If for example you had a vector of test scores for 10,000 tests and you calculated the probability in the data of having a 100, then the probability of a 99 and so on, then you could make another vector of 10,000 giving the probability of the corresponding entries. So before calling ggplot, assuming you have two vectors called orig and prob, you make a data.frame like Df <- data.frame(orig=orig, prob=prob) You use that in ggplot. You can of course add additional columns. Or if your data is in another format, do things like long to wide conversion and many other things. If you already have a data.frame with one or more columns including orig, you can attache the probabilities with something as simple as: Df$prob = prob If you are using ggplot, you may as well be using elements of the tidyverse that provide a different take on how to do some things compared to base R but that is not something easily discussed here. -----Original Message----- From: Jeff Reichman Sent: Sunday, June 4, 2023 10:21 PM To: avi.e.gross at gmail.com; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame 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.gross at gmail.com Sent: Sunday, June 4, 2023 9:00 PM To: 'Jeff Reichman' ; r-help at 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 A B 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 at 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 1 2 3 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch Mon Jun 5 11:49:20 2023 From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler) Date: Mon, 5 Jun 2023 11:49:20 +0200 Subject: [R] error in arfima... In-Reply-To: References: <25720.20392.521283.415199@stat.math.ethz.ch> Message-ID: <25725.44960.478222.430645@stat.math.ethz.ch> > Dear Martin, > REgrets to reply this late.... > I am staring at a conundrum never before encountered in my experience with R: > LYGH[[201]] > [1] 45.40 3.25 6.50 2.15 > > arfima(LYGH[[201]]) > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : > NA/NaN/Inf in foreign function call (arg 5) > > arfima(c(45.40,3.25,6.50,2.15)) > Call: > arfima(y = c(45.4, 3.25, 6.5, 2.15)) > Coefficients: > d > 4.583013e-05 > sigma[eps] = 18.01252 > a list with components: > [1] "log.likelihood" "n" "msg" "d" "ar" > [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" > [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" > [16] "length.w" "residuals" "fitted" "call" "x" > [21] "series" > Please note that the index of LYGH has changed from 202 to 201 due to some randomness in one of my function. > PLEASE HELP. > Output of dput LYGH[[201]]: > > dput(LYGH[[201]]) > c(45.4, 3.25, 6.5, 2.14999999999998) > output of session info() > sessionInfo() > R version 4.1.2 (2021-11-01) > Platform: x86_64-w64-mingw32/x64 (64-bit) > Running under: Windows Server x64 (build 14393) > Matrix products: default > locale: > [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > attached base packages: > [1] parallel stats graphics grDevices utils datasets methods base > other attached packages: > [1] pbmcapply_1.5.1 imputeTS_3.3 forecast_8.17.0 > loaded via a namespace (and not attached): > [1] Rcpp_1.0.7 urca_1.3-3 pillar_1.9.0 compiler_4.1.2 tseries_0.10-51 > [6] tools_4.1.2 xts_0.12.1 nlme_3.1-153 lifecycle_1.0.3 tibble_3.2.1 > [11] gtable_0.3.3 lattice_0.20-45 pkgconfig_2.0.3 rlang_1.1.0 cli_3.6.1 > [16] rstudioapi_0.14 curl_4.3.2 xml2_1.3.3 dplyr_1.1.1 generics_0.1.3 > [21] vctrs_0.6.1 gridtext_0.1.5 ggtext_0.1.2 lmtest_0.9-40 grid_4.1.2 > [26] nnet_7.3-16 tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 fansi_1.0.4 > [31] ggplot2_3.4.2 TTR_0.24.3 magrittr_2.0.3 scales_1.2.1 quantmod_0.4.20 > [36] timeDate_4021.106 colorspace_2.1-0 fracdiff_1.5-1 quadprog_1.5-8 utf8_1.2.3 > [41] stinepack_1.4 munsell_0.5.0 zoo_1.8-10 > PLease Also note: > arfima(c(45.4, 3.25, 6.5, 2.14999999999998)) > Call: > arfima(y = c(45.4, 3.25, 6.5, 2.14999999999998)) > Coefficients: > d > 4.583013e-05 > sigma[eps] = 18.01252 > a list with components: > [1] "log.likelihood" "n" "msg" "d" "ar" > [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" > [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" > [16] "length.w" "residuals" "fitted" "call" "x" > [21] "series" > Many thanks in advance.... > Thanking you, > Yours sincerely, > AKSHAY M KULKARNI Hmm... indeed, "conundrum" may be a euphemism for the situation..... which clearly points to a bug *somewhere*. As your dput() shows, the argument *is* a simple vector .. and even if the default dput() may loose a few bits in precison... you did show that with (possibly only almost) identical argument, the error did not happen. I really have no idea what's going on, .... Some musing/ideas: the NA/NaN/Inf warning may come from a memory corruption problem somewhere because some of the involved packages using compiled code or the old version of R/lapack/??? or ??? cause it. Does the error only happen occasionally? If you "randomly" do a few calls of either arfima(c(45.4, 3.25, 6.5, 2.14999999999998)) or arfima(LYGH[[201]]) do you see "random" behavior? [if yes; this confirms typically memory protection/allocation/... bugs] fracdiff itself has also been updated (to 1.5-2) but that was really only a compiler warning, not a bug fix, and I cannot imagine that that makes the difference. I think you should consider let your 'Windows Server' provider update R on that server. Notably the Windows version of R has had problems fixed in the mean time .. and at least there's a hope the problem disappears. Lastly (but probably not helping more), you could use dput() with control="digits" and even .Internal(inspect( * )) magic on your LYGH[[201]] When I use simple numeric vectors "like" your LYGH[..], I get > dput(c(45.4, 3.25, 6.5, 2.15), control="digits") c(45.399999999999999, 3.25, 6.5, 2.1499999999999999) > .Internal(inspect(c(45.4, 3.25, 6.5, 2.15)) + ) @9874728 14 REALSXP g0c3 [] (len=4, tl=0) 45.4,3.25,6.5,2.15 > Martin > ________________________________ > From: Martin Maechler > Sent: Thursday, June 1, 2023 1:28 PM > To: akshay kulkarni > Cc: R help Mailing list > Subject: Re: [R] error in arfima... > >>>>> akshay kulkarni > >>>>> on Wed, 31 May 2023 20:55:33 +0000 writes: > > dear members, > > I am using arfima() from forecast package to model a time > > series. The following is the code: > >> LYGH[[202]] > > [1] 45.40 3.25 6.50 2.15 > >> arfima(LYGH[[202]]) > > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : > > NA/NaN/Inf in foreign function call (arg 5) > > I tried viewing .fdcov() with the following code: > > View(environment(fracdiff)$.fdcov) > > but I see no stop() with the above mentioned error message. > > Can you please help? > Well, as I am the maintainer of the *fracdiff* package, > I'm trying. OTOH, as we will see below, you did not give us enough > information to really help you... > > THanking you, > > Yours sincerely, > > AKSHAY M KULKARNI > Your problem is not (yet) reproducible (*) > I've done the following in an "empty" (i.e. freshly started) R > session, R 4.3.0: > ----begin_R_transcript___save_as__arfima-ex.Rout__------------------------------ > > > > lN <- loadedNamespaces() > > library(forecast) > Registered S3 method overwritten by 'quantmod': > method from > as.zoo.data.frame zoo > > options(width=75) > > setdiff(loadedNamespaces(), lN) # -- see all the *!^@...! forecast loads: > [1] "gtable" "dplyr" "tidyselect" "Rcpp" "parallel" > [6] "scales" "lattice" "ggplot2" "R6" "generics" > [11] "curl" "lmtest" "tibble" "munsell" "nnet" > [16] "forecast" "timeDate" "pillar" "rlang" "quantmod" > [21] "utf8" "urca" "quadprog" "cli" "magrittr" > [26] "xts" "grid" "nlme" "lifecycle" "fracdiff" > [31] "vctrs" "glue" "tseries" "zoo" "fansi" > [36] "colorspace" "TTR" "pkgconfig" > > arfima(c(45.40, 3.25, 6.50, 2.15)) > Call: > arfima(y = c(45.4, 3.25, 6.5, 2.15)) > Coefficients: > d > 4.583013e-05 > sigma[eps] = 18.01252 > a list with components: > [1] "log.likelihood" "n" "msg" > [4] "d" "ar" "ma" > [7] "covariance.dpq" "fnormMin" "sigma" > [10] "stderror.dpq" "correlation.dpq" "h" > [13] "d.tol" "M" "hessian.dpq" > [16] "length.w" "residuals" "fitted" > [19] "call" "x" "series" > > > > sessionInfo() > R version 4.3.0 (2023-04-21) > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Fedora Linux 36 (Thirty Six) > Matrix products: default > BLAS: /usr/local64.sfs/app/R/R-4.3.0-inst/lib/libRblas.so > LAPACK: /usr/lib64/liblapack.so.3.10.1 > locale: > [1] LC_CTYPE=de_CH.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=de_CH.UTF-8 > [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=de_CH.UTF-8 > [7] LC_PAPER=de_CH.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C > time zone: Europe/Zurich > tzcode source: system (glibc) > attached base packages: > [1] graphics grDevices datasets stats utils methods base > other attached packages: > [1] forecast_8.21 fortunes_1.5-4 sfsmisc_1.1-15 > loaded via a namespace (and not attached): > [1] gtable_0.3.3 dplyr_1.1.2 compiler_4.3.0 > [4] tidyselect_1.2.0 Rcpp_1.0.10 parallel_4.3.0 > [7] scales_1.2.1 lattice_0.21-8 ggplot2_3.4.2 > [10] R6_2.5.1 generics_0.1.3 curl_5.0.0 > [13] lmtest_0.9-40 tibble_3.2.1 munsell_0.5.0 > [16] nnet_7.3-19 timeDate_4022.108 pillar_1.9.0 > [19] rlang_1.1.1 quantmod_0.4.22 utf8_1.2.3 > [22] urca_1.3-3 quadprog_1.5-8 cli_3.6.1 > [25] magrittr_2.0.3 xts_0.13.1 grid_4.3.0 > [28] nlme_3.1-162 lifecycle_1.0.3 fracdiff_1.5-2 > [31] vctrs_0.6.2 glue_1.6.2 tseries_0.10-54 > [34] zoo_1.8-12 fansi_1.0.4 colorspace_2.1-0 > [37] TTR_0.24.3 tools_4.3.0 pkgconfig_2.0.3 > > > ##---end__R_transcript--------------------------------------------------------------- > Note that your error message pointed me to my (old, but still > fine) package {fracdiff} with its principal function fracdiff() > around which arfima() is a user-friendly and > generalization wrapper. > In other words arfima() calls fracdiff::fracdiff() and the error > happens there --- for you, but not for me, if I try to use the > same data as you. > I see that you must have found that too, because you mentioned > View(environment(fracdiff)$.fdcov) > Maybe you need to > update.packages() > {which should re-install R packages you have installed but which > have become outdated in the mean time} > If the error persists, please send us the output of > 1) > dput(LYGH[[202]]) > so we get your exact data > 2) > sessionInfo() > so we get much info about your R "setup" > .... last but not least: If you are really calling arfima() > with a time series of length 4 (which your LYGH[[202]] above > seems to suggest) > then you really need to learn a bit about the tools you are > using: It really does not make any sense to fit a somewhat > sophisticated time-series model (or *any* time-series model, I'd say) > to a "series" with 4 values. > Best regards, > Martin > -- > Martin Maechler > ETH Zurich and R Core team From re|chm@nj @end|ng |rom @bcg|ob@|@net Mon Jun 5 13:29:27 2023 From: re|chm@nj @end|ng |rom @bcg|ob@|@net (Jeff Reichman) Date: Mon, 5 Jun 2023 06:29:27 -0500 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <009401d99759$7b74b570$725e2050$@gmail.com> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> <009201d99751$68622d30$39268790$@gmail.com> <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> <009401d99759$7b74b570$725e2050$@gmail.com> Message-ID: <001e01d997a0$fd9cbf10$f8d63d30$@sbcglobal.net> Avi But I don't have a column header to call. Do I simply use column position > pred_probability 1 2 3 5 8 0.001156612672 0.000926702837 0.008162332353 0.001544764162 0.000919503109 .......... > str(pred_probability ) Named num [1:6964] 0.001157 0.000927 0.008162 0.001545 0.00092 ... - attr(*, "names")= chr [1:6964] "1" "2" "3" "5" ... > Jeff -----Original Message----- From: avi.e.gross at gmail.com Sent: Sunday, June 4, 2023 9:58 PM To: 'Jeff Reichman' ; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame Jeff, The number of items is not relevant except insofar as your vector of probabilities is in the same order as the other vector and the same length. If for example you had a vector of test scores for 10,000 tests and you calculated the probability in the data of having a 100, then the probability of a 99 and so on, then you could make another vector of 10,000 giving the probability of the corresponding entries. So before calling ggplot, assuming you have two vectors called orig and prob, you make a data.frame like Df <- data.frame(orig=orig, prob=prob) You use that in ggplot. You can of course add additional columns. Or if your data is in another format, do things like long to wide conversion and many other things. If you already have a data.frame with one or more columns including orig, you can attache the probabilities with something as simple as: Df$prob = prob If you are using ggplot, you may as well be using elements of the tidyverse that provide a different take on how to do some things compared to base R but that is not something easily discussed here. -----Original Message----- From: Jeff Reichman Sent: Sunday, June 4, 2023 10:21 PM To: avi.e.gross at gmail.com; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame 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.gross at gmail.com Sent: Sunday, June 4, 2023 9:00 PM To: 'Jeff Reichman' ; r-help at 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 A B 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 at 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 1 2 3 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From @k@h@y_e4 @end|ng |rom hotm@||@com Mon Jun 5 16:11:12 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Mon, 5 Jun 2023 14:11:12 +0000 Subject: [R] error in arfima... In-Reply-To: <25725.44960.478222.430645@stat.math.ethz.ch> References: <25720.20392.521283.415199@stat.math.ethz.ch> <25725.44960.478222.430645@stat.math.ethz.ch> Message-ID: Dear Martin, Sad that the bug is beyond your ken... Fortunately, the error happens only rarely...The length of LYGH was 719 and there were only two such errors..I will just replace them with NA and make do. By the by, what if I send LYGH as an attachment to your actual mail ( not the r-help mail)? Will it help? Can you then pinpoint the cause? Or should I raise a bug report? If yes, how( I never raised one)? THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Martin Maechler Sent: Monday, June 5, 2023 3:19 PM To: akshay kulkarni Cc: Martin Maechler ; R help Mailing list Subject: Re: [R] error in arfima... > Dear Martin, > REgrets to reply this late.... > I am staring at a conundrum never before encountered in my experience with R: > LYGH[[201]] > [1] 45.40 3.25 6.50 2.15 > > arfima(LYGH[[201]]) > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : > NA/NaN/Inf in foreign function call (arg 5) > > arfima(c(45.40,3.25,6.50,2.15)) > Call: > arfima(y = c(45.4, 3.25, 6.5, 2.15)) > Coefficients: > d > 4.583013e-05 > sigma[eps] = 18.01252 > a list with components: > [1] "log.likelihood" "n" "msg" "d" "ar" > [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" > [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" > [16] "length.w" "residuals" "fitted" "call" "x" > [21] "series" > Please note that the index of LYGH has changed from 202 to 201 due to some randomness in one of my function. > PLEASE HELP. > Output of dput LYGH[[201]]: > > dput(LYGH[[201]]) > c(45.4, 3.25, 6.5, 2.14999999999998) > output of session info() > sessionInfo() > R version 4.1.2 (2021-11-01) > Platform: x86_64-w64-mingw32/x64 (64-bit) > Matrix products: default > locale: > [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > attached base packages: > [1] parallel stats graphics grDevices utils datasets methods base > other attached packages: > [1] pbmcapply_1.5.1 imputeTS_3.3 forecast_8.17.0 > loaded via a namespace (and not attached): > [1] Rcpp_1.0.7 urca_1.3-3 pillar_1.9.0 compiler_4.1.2 tseries_0.10-51 > [6] tools_4.1.2 xts_0.12.1 nlme_3.1-153 lifecycle_1.0.3 tibble_3.2.1 > [11] gtable_0.3.3 lattice_0.20-45 pkgconfig_2.0.3 rlang_1.1.0 cli_3.6.1 > [16] rstudioapi_0.14 curl_4.3.2 xml2_1.3.3 dplyr_1.1.1 generics_0.1.3 > [21] vctrs_0.6.1 gridtext_0.1.5 ggtext_0.1.2 lmtest_0.9-40 grid_4.1.2 > [26] nnet_7.3-16 tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 fansi_1.0.4 > [31] ggplot2_3.4.2 TTR_0.24.3 magrittr_2.0.3 scales_1.2.1 quantmod_0.4.20 > [36] timeDate_4021.106 colorspace_2.1-0 fracdiff_1.5-1 quadprog_1.5-8 utf8_1.2.3 > [41] stinepack_1.4 munsell_0.5.0 zoo_1.8-10 > PLease Also note: > arfima(c(45.4, 3.25, 6.5, 2.14999999999998)) > Call: > arfima(y = c(45.4, 3.25, 6.5, 2.14999999999998)) > Coefficients: > d > 4.583013e-05 > sigma[eps] = 18.01252 > a list with components: > [1] "log.likelihood" "n" "msg" "d" "ar" > [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" > [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" > [16] "length.w" "residuals" "fitted" "call" "x" > [21] "series" > Many thanks in advance.... > Thanking you, > Yours sincerely, > AKSHAY M KULKARNI Hmm... indeed, "conundrum" may be a euphemism for the situation..... which clearly points to a bug *somewhere*. As your dput() shows, the argument *is* a simple vector .. and even if the default dput() may loose a few bits in precison... you did show that with (possibly only almost) identical argument, the error did not happen. I really have no idea what's going on, .... Some musing/ideas: the NA/NaN/Inf warning may come from a memory corruption problem somewhere because some of the involved packages using compiled code or the old version of R/lapack/??? or ??? cause it. Does the error only happen occasionally? If you "randomly" do a few calls of either arfima(c(45.4, 3.25, 6.5, 2.14999999999998)) or arfima(LYGH[[201]]) do you see "random" behavior? [if yes; this confirms typically memory protection/allocation/... bugs] fracdiff itself has also been updated (to 1.5-2) but that was really only a compiler warning, not a bug fix, and I cannot imagine that that makes the difference. had problems fixed in the mean time .. and at least there's a hope the problem disappears. Lastly (but probably not helping more), you could use dput() with control="digits" and even .Internal(inspect( * )) magic on your LYGH[[201]] When I use simple numeric vectors "like" your LYGH[..], I get > dput(c(45.4, 3.25, 6.5, 2.15), control="digits") c(45.399999999999999, 3.25, 6.5, 2.1499999999999999) > .Internal(inspect(c(45.4, 3.25, 6.5, 2.15)) + ) @9874728 14 REALSXP g0c3 [] (len=4, tl=0) 45.4,3.25,6.5,2.15 > Martin > ________________________________ > From: Martin Maechler > Sent: Thursday, June 1, 2023 1:28 PM > To: akshay kulkarni > Cc: R help Mailing list > Subject: Re: [R] error in arfima... > >>>>> akshay kulkarni > >>>>> on Wed, 31 May 2023 20:55:33 +0000 writes: > > dear members, > > I am using arfima() from forecast package to model a time > > series. The following is the code: > >> LYGH[[202]] > > [1] 45.40 3.25 6.50 2.15 > >> arfima(LYGH[[202]]) > > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : > > NA/NaN/Inf in foreign function call (arg 5) > > I tried viewing .fdcov() with the following code: > > View(environment(fracdiff)$.fdcov) > > but I see no stop() with the above mentioned error message. > > Can you please help? > Well, as I am the maintainer of the *fracdiff* package, > I'm trying. OTOH, as we will see below, you did not give us enough > information to really help you... > > THanking you, > > Yours sincerely, > > AKSHAY M KULKARNI > Your problem is not (yet) reproducible (*) > I've done the following in an "empty" (i.e. freshly started) R > session, R 4.3.0: > ----begin_R_transcript___save_as__arfima-ex.Rout__------------------------------ > > > > lN <- loadedNamespaces() > > library(forecast) > Registered S3 method overwritten by 'quantmod': > method from > as.zoo.data.frame zoo > > options(width=75) > > setdiff(loadedNamespaces(), lN) # -- see all the *!^@...! forecast loads: > [1] "gtable" "dplyr" "tidyselect" "Rcpp" "parallel" > [6] "scales" "lattice" "ggplot2" "R6" "generics" > [11] "curl" "lmtest" "tibble" "munsell" "nnet" > [16] "forecast" "timeDate" "pillar" "rlang" "quantmod" > [21] "utf8" "urca" "quadprog" "cli" "magrittr" > [26] "xts" "grid" "nlme" "lifecycle" "fracdiff" > [31] "vctrs" "glue" "tseries" "zoo" "fansi" > [36] "colorspace" "TTR" "pkgconfig" > > arfima(c(45.40, 3.25, 6.50, 2.15)) > Call: > arfima(y = c(45.4, 3.25, 6.5, 2.15)) > Coefficients: > d > 4.583013e-05 > sigma[eps] = 18.01252 > a list with components: > [1] "log.likelihood" "n" "msg" > [4] "d" "ar" "ma" > [7] "covariance.dpq" "fnormMin" "sigma" > [10] "stderror.dpq" "correlation.dpq" "h" > [13] "d.tol" "M" "hessian.dpq" > [16] "length.w" "residuals" "fitted" > [19] "call" "x" "series" > > > > sessionInfo() > R version 4.3.0 (2023-04-21) > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Fedora Linux 36 (Thirty Six) > Matrix products: default > BLAS: /usr/local64.sfs/app/R/R-4.3.0-inst/lib/libRblas.so > LAPACK: /usr/lib64/liblapack.so.3.10.1 > locale: > [1] LC_CTYPE=de_CH.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=de_CH.UTF-8 > [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=de_CH.UTF-8 > [7] LC_PAPER=de_CH.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C > time zone: Europe/Zurich > tzcode source: system (glibc) > attached base packages: > [1] graphics grDevices datasets stats utils methods base > other attached packages: > [1] forecast_8.21 fortunes_1.5-4 sfsmisc_1.1-15 > loaded via a namespace (and not attached): > [1] gtable_0.3.3 dplyr_1.1.2 compiler_4.3.0 > [4] tidyselect_1.2.0 Rcpp_1.0.10 parallel_4.3.0 > [7] scales_1.2.1 lattice_0.21-8 ggplot2_3.4.2 > [10] R6_2.5.1 generics_0.1.3 curl_5.0.0 > [13] lmtest_0.9-40 tibble_3.2.1 munsell_0.5.0 > [16] nnet_7.3-19 timeDate_4022.108 pillar_1.9.0 > [19] rlang_1.1.1 quantmod_0.4.22 utf8_1.2.3 > [22] urca_1.3-3 quadprog_1.5-8 cli_3.6.1 > [25] magrittr_2.0.3 xts_0.13.1 grid_4.3.0 > [28] nlme_3.1-162 lifecycle_1.0.3 fracdiff_1.5-2 > [31] vctrs_0.6.2 glue_1.6.2 tseries_0.10-54 > [34] zoo_1.8-12 fansi_1.0.4 colorspace_2.1-0 > [37] TTR_0.24.3 tools_4.3.0 pkgconfig_2.0.3 > > > ##---end__R_transcript--------------------------------------------------------------- > Note that your error message pointed me to my (old, but still > fine) package {fracdiff} with its principal function fracdiff() > around which arfima() is a user-friendly and > generalization wrapper. > In other words arfima() calls fracdiff::fracdiff() and the error > happens there --- for you, but not for me, if I try to use the > same data as you. > I see that you must have found that too, because you mentioned > View(environment(fracdiff)$.fdcov) > Maybe you need to > update.packages() > {which should re-install R packages you have installed but which > have become outdated in the mean time} > If the error persists, please send us the output of > 1) > dput(LYGH[[202]]) > so we get your exact data > 2) > sessionInfo() > so we get much info about your R "setup" > .... last but not least: If you are really calling arfima() > with a time series of length 4 (which your LYGH[[202]] above > seems to suggest) > then you really need to learn a bit about the tools you are > using: It really does not make any sense to fit a somewhat > sophisticated time-series model (or *any* time-series model, I'd say) > to a "series" with 4 values. > Best regards, > Martin > -- > Martin Maechler > ETH Zurich and R Core team [[alternative HTML version deleted]] From @vi@e@gross m@iii@g oii gm@ii@com Tue Jun 6 02:55:07 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Mon, 5 Jun 2023 20:55:07 -0400 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <001e01d997a0$fd9cbf10$f8d63d30$@sbcglobal.net> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> <009201d99751$68622d30$39268790$@gmail.com> <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> <009401d99759$7b74b570$725e2050$@gmail.com> <001e01d997a0$fd9cbf10$f8d63d30$@sbcglobal.net> Message-ID: <01ca01d99811$89ced5c0$9d6c8140$@gmail.com> Jeff, I wish I could give you an answer to a very specific question. You have lots of numbers in a vector representing whatever "probabilities" mean something to you. There are currently no names associated with them. And you want to make some kind of graph using ggplot. So, to be quite clear, ggplot tends to like a data.frame or one of several other such tabular constructs when making graphs, or have some data coerced into such a format. BUT I am aghast at the concept of giving it a data.frame with one row and thousands of un-named columns. First, the columns will have semi-numerical names by default and second, they cannot be used by ggplot unless you specify a name. What you normally need is not lots of columns but lots of rows. One column suffices for some purposes and multiple columns are often present for many purposes. But what are you graphing as in probability versus what? Is that item correlated with each result in some way? You eventually need to probably make a data.frame with two or more such columns with names for the columns. You need to tell ggplot something like ggplot(mydata, aes(x=whatever, y=whatever, ...)) + geom_line(or whatever) ... But as you release info this slowly, I think I will now drop out of this conversation. Good luck. -----Original Message----- From: Jeff Reichman Sent: Monday, June 5, 2023 7:29 AM To: avi.e.gross at gmail.com; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame Avi But I don't have a column header to call. Do I simply use column position > pred_probability 1 2 3 5 8 0.001156612672 0.000926702837 0.008162332353 0.001544764162 0.000919503109 .......... > str(pred_probability ) Named num [1:6964] 0.001157 0.000927 0.008162 0.001545 0.00092 ... - attr(*, "names")= chr [1:6964] "1" "2" "3" "5" ... > Jeff -----Original Message----- From: avi.e.gross at gmail.com Sent: Sunday, June 4, 2023 9:58 PM To: 'Jeff Reichman' ; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame Jeff, The number of items is not relevant except insofar as your vector of probabilities is in the same order as the other vector and the same length. If for example you had a vector of test scores for 10,000 tests and you calculated the probability in the data of having a 100, then the probability of a 99 and so on, then you could make another vector of 10,000 giving the probability of the corresponding entries. So before calling ggplot, assuming you have two vectors called orig and prob, you make a data.frame like Df <- data.frame(orig=orig, prob=prob) You use that in ggplot. You can of course add additional columns. Or if your data is in another format, do things like long to wide conversion and many other things. If you already have a data.frame with one or more columns including orig, you can attache the probabilities with something as simple as: Df$prob = prob If you are using ggplot, you may as well be using elements of the tidyverse that provide a different take on how to do some things compared to base R but that is not something easily discussed here. -----Original Message----- From: Jeff Reichman Sent: Sunday, June 4, 2023 10:21 PM To: avi.e.gross at gmail.com; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame 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.gross at gmail.com Sent: Sunday, June 4, 2023 9:00 PM To: 'Jeff Reichman' ; r-help at 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 A B 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 at 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 1 2 3 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From re|chm@nj @end|ng |rom @bcg|ob@|@net Tue Jun 6 03:26:57 2023 From: re|chm@nj @end|ng |rom @bcg|ob@|@net (Jeff Reichman) Date: Mon, 5 Jun 2023 20:26:57 -0500 Subject: [R] Adding a numeric class to a data.frame In-Reply-To: <01ca01d99811$89ced5c0$9d6c8140$@gmail.com> References: <00d301d99739$d9000ed0$8b002c70$.ref@sbcglobal.net> <00d301d99739$d9000ed0$8b002c70$@sbcglobal.net> <009201d99751$68622d30$39268790$@gmail.com> <012601d99754$5ce4dd10$16ae9730$@sbcglobal.net> <009401d99759$7b74b570$725e2050$@gmail.com> <001e01d997a0$fd9cbf10$f8d63d30$@sbcglobal.net> <01ca01d99811$89ced5c0$9d6c8140$@gmail.com> Message-ID: <010401d99815$fd1e5920$f75b0b60$@sbcglobal.net> Avi I'm not sure why but neither the "cbind" nor "with" functions seemed to work with the numeric object so I ended up converting the object to a numeric vector prob <- as.numeric(pred_probability) then used the cbind function df <- cbind(train, prob); which seemed to work???? I do appreciate your time and assistance. Jeff -----Original Message----- From: avi.e.gross at gmail.com Sent: Monday, June 5, 2023 7:55 PM To: 'Jeff Reichman' ; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame Jeff, I wish I could give you an answer to a very specific question. You have lots of numbers in a vector representing whatever "probabilities" mean something to you. There are currently no names associated with them. And you want to make some kind of graph using ggplot. So, to be quite clear, ggplot tends to like a data.frame or one of several other such tabular constructs when making graphs, or have some data coerced into such a format. BUT I am aghast at the concept of giving it a data.frame with one row and thousands of un-named columns. First, the columns will have semi-numerical names by default and second, they cannot be used by ggplot unless you specify a name. What you normally need is not lots of columns but lots of rows. One column suffices for some purposes and multiple columns are often present for many purposes. But what are you graphing as in probability versus what? Is that item correlated with each result in some way? You eventually need to probably make a data.frame with two or more such columns with names for the columns. You need to tell ggplot something like ggplot(mydata, aes(x=whatever, y=whatever, ...)) + geom_line(or whatever) ... But as you release info this slowly, I think I will now drop out of this conversation. Good luck. -----Original Message----- From: Jeff Reichman Sent: Monday, June 5, 2023 7:29 AM To: avi.e.gross at gmail.com; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame Avi But I don't have a column header to call. Do I simply use column position > pred_probability 1 2 3 5 8 0.001156612672 0.000926702837 0.008162332353 0.001544764162 0.000919503109 .......... > str(pred_probability ) Named num [1:6964] 0.001157 0.000927 0.008162 0.001545 0.00092 ... - attr(*, "names")= chr [1:6964] "1" "2" "3" "5" ... > Jeff -----Original Message----- From: avi.e.gross at gmail.com Sent: Sunday, June 4, 2023 9:58 PM To: 'Jeff Reichman' ; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame Jeff, The number of items is not relevant except insofar as your vector of probabilities is in the same order as the other vector and the same length. If for example you had a vector of test scores for 10,000 tests and you calculated the probability in the data of having a 100, then the probability of a 99 and so on, then you could make another vector of 10,000 giving the probability of the corresponding entries. So before calling ggplot, assuming you have two vectors called orig and prob, you make a data.frame like Df <- data.frame(orig=orig, prob=prob) You use that in ggplot. You can of course add additional columns. Or if your data is in another format, do things like long to wide conversion and many other things. If you already have a data.frame with one or more columns including orig, you can attache the probabilities with something as simple as: Df$prob = prob If you are using ggplot, you may as well be using elements of the tidyverse that provide a different take on how to do some things compared to base R but that is not something easily discussed here. -----Original Message----- From: Jeff Reichman Sent: Sunday, June 4, 2023 10:21 PM To: avi.e.gross at gmail.com; r-help at r-project.org Subject: RE: [R] Adding a numeric class to a data.frame 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.gross at gmail.com Sent: Sunday, June 4, 2023 9:00 PM To: 'Jeff Reichman' ; r-help at 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 A B 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 at 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 1 2 3 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From tg@77m @end|ng |rom y@hoo@com Tue Jun 6 05:34:03 2023 From: tg@77m @end|ng |rom y@hoo@com (Thomas Subia) Date: Tue, 6 Jun 2023 03:34:03 +0000 (UTC) Subject: [R] latticeExtra References: <1791465946.209568.1686022443270.ref@mail.yahoo.com> Message-ID: <1791465946.209568.1686022443270@mail.yahoo.com> Colleagues, I am trying to create a 3D barplot using the following script d <- read.table(text=' x?? y???? z t1?? 5?? high t1?? 2?? low t1?? 4?? med t2?? 8?? high t2?? 1?? low t2?? 3?? med t3? 50?? high t3? 12?? med t3? 35?? low', header=TRUE) library(latticeExtra) cloud(y~x+z, d, panel.3d.cloud=panel.3dbars, col.facet='grey', ????? xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1), ????? par.settings = list(axis.line = list(col = "transparent"))) Executing this results in this error message Error using packet 1 non-numeric argument to binary operator I suspect that this error stems from read.table. This graph is easily done with Excel but I'd rather use R Any help would be appreciated. Thanks Thomas Subia [[alternative HTML version deleted]] From rmh @end|ng |rom temp|e@edu Tue Jun 6 05:45:34 2023 From: rmh @end|ng |rom temp|e@edu (Richard M. Heiberger) Date: Tue, 6 Jun 2023 03:45:34 +0000 Subject: [R] [External] latticeExtra In-Reply-To: <1791465946.209568.1686022443270@mail.yahoo.com> References: <1791465946.209568.1686022443270.ref@mail.yahoo.com> <1791465946.209568.1686022443270@mail.yahoo.com> Message-ID: <60EE2E67-74E8-4777-AD6A-EFE88AE5D9E6@temple.edu> This works. > d$zz <- factor(d$z, levels=c("low","med","high")) > d$xx <- as.factor(d$x) > cloud(y~xx+zz, d, panel.3d.cloud=panel.3dbars, col.facet='grey', + xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1), + par.settings = list(axis.line = list(col = "transparent"))) > the default levels for factor are alphabetic. That is ok for d$x. From tg@77m @end|ng |rom y@hoo@com Tue Jun 6 06:19:55 2023 From: tg@77m @end|ng |rom y@hoo@com (Thomas Subia) Date: Tue, 6 Jun 2023 04:19:55 +0000 (UTC) Subject: [R] [External] latticeExtra In-Reply-To: <60EE2E67-74E8-4777-AD6A-EFE88AE5D9E6@temple.edu> References: <1791465946.209568.1686022443270.ref@mail.yahoo.com> <1791465946.209568.1686022443270@mail.yahoo.com> <60EE2E67-74E8-4777-AD6A-EFE88AE5D9E6@temple.edu> Message-ID: <23449470.221905.1686025195890@mail.yahoo.com> Colleagues, Thanks for the help! Root cause of the problem was not to define z and x as factors!Now I know better. All the best, Thomas Subia On Monday, June 5, 2023 at 08:45:39 PM PDT, Richard M. Heiberger wrote: This works. > d$zz <- factor(d$z, levels=c("low","med","high")) > d$xx <- as.factor(d$x) > cloud(y~xx+zz, d, panel.3d.cloud=panel.3dbars, col.facet='grey', +? ? ? xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1), +? ? ? par.settings = list(axis.line = list(col = "transparent"))) > the default levels for factor are alphabetic.? That is ok for d$x. [[alternative HTML version deleted]] From kev|n @end|ng |rom zembower@org Tue Jun 6 20:37:45 2023 From: kev|n @end|ng |rom zembower@org (=?UTF-8?Q?Kevin_Zembower?=) Date: Tue, 6 Jun 2023 18:37:45 +0000 Subject: [R] Recommended ways to draw US Census map on Open Street Map base map? References: Message-ID: <0100018892002da7-a934c35c-a4cd-4b10-add7-79eedc3beeab-000000@email.amazonses.com> Hello, all, I asked a version of this question on the R-sig-geo list, but didn't get any response. I'm asking here in the hopes of a wider audience. I'm trying to draw US Census map data, fetched with tigris, on top of a base map fetched by the package OpenStreetMap. I'm hoping for the most straight-forward solution. I made significant progress with leaflet(), but didn't need the interactivity of the map. I just need a 2D, static map that I can print and include in a document. Here's some of what I've tried so far: ========================================== library(tidyverse) library(tigris) options(tigris_use_cache = TRUE) library(OpenStreetMap) library(ggplot2) ## Get an Open Street Map: rw_map <- openmap(nw, se, type = "osm", mergeTiles = TRUE) %>% openproj(projection = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") ## Get an example census map: rw_tract <- tracts(state = "MD", county = "Baltimore city", year = "2020") %>% filter(NAME == "2711.01") ## This works: autoplot.OpenStreetMap(rw_map) ## So does this: plot(rw_tract$geometry) ## These don't: autoplot.OpenStreetMap(rw_map) + geom_sf(rw_tract$geometry) ggplot(map_data(rw_map), aes(long, lat)) ggplot(aes(x="long", y="lat")) + geom_sf(rw_map$geometry) ===================================================== I think my problem in part is failing to fully understand the formats of the rw_map and rw_tract containers. rw_tract says it's a simple feature collection, but rw_map just gives me lists of the data. Can anyone help nudge me along in getting my rw_tract to be drawn on my rw_map? Any advice or guidance on putting together map data from different sources? And an over-arching question: Is moving in this direction, with ggplot2, the way you would recommend accomplishing this task? Is there a simpler, more straight-forward way of doing this? Thanks in advance for your help and efforts. -Kevin From bgunter@4567 @end|ng |rom gm@||@com Tue Jun 6 21:17:58 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Tue, 6 Jun 2023 12:17:58 -0700 Subject: [R] Recommended ways to draw US Census map on Open Street Map base map? In-Reply-To: <0100018892002da7-a934c35c-a4cd-4b10-add7-79eedc3beeab-000000@email.amazonses.com> References: <0100018892002da7-a934c35c-a4cd-4b10-add7-79eedc3beeab-000000@email.amazonses.com> Message-ID: As you are using Rstudio stuff(ggplot, tidyverse,etc.), you might try the RStudio support site here (note that they have rebranded under the banner "posit.co"). However, I would have also thought the R-sig-geo list was the best place to look for such help. Cheers, Bert On Tue, Jun 6, 2023 at 11:38?AM Kevin Zembower via R-help < r-help at r-project.org> wrote: > Hello, all, > > I asked a version of this question on the R-sig-geo list, but didn't get > any response. I'm asking here in the hopes of a wider audience. > > I'm trying to draw US Census map data, fetched with tigris, on top of a > base map fetched by the package OpenStreetMap. I'm hoping for the most > straight-forward solution. I made significant progress with leaflet(), > but didn't need the interactivity of the map. I just need a 2D, static > map that I can print and include in a document. > > Here's some of what I've tried so far: > ========================================== > library(tidyverse) > library(tigris) > options(tigris_use_cache = TRUE) > library(OpenStreetMap) > library(ggplot2) > > ## Get an Open Street Map: > rw_map <- openmap(nw, se, > type = "osm", > mergeTiles = TRUE) %>% > openproj(projection = "+proj=longlat +ellps=WGS84 +datum=WGS84 > +no_defs") > > ## Get an example census map: > rw_tract <- tracts(state = "MD", > county = "Baltimore city", > year = "2020") %>% > filter(NAME == "2711.01") > > ## This works: > autoplot.OpenStreetMap(rw_map) > > ## So does this: > plot(rw_tract$geometry) > > ## These don't: > autoplot.OpenStreetMap(rw_map) + > geom_sf(rw_tract$geometry) > > ggplot(map_data(rw_map), aes(long, lat)) > > > ggplot(aes(x="long", y="lat")) + > geom_sf(rw_map$geometry) > ===================================================== > > I think my problem in part is failing to fully understand the formats of > the rw_map and rw_tract containers. rw_tract says it's a simple feature > collection, but rw_map just gives me lists of the data. > > Can anyone help nudge me along in getting my rw_tract to be drawn on my > rw_map? Any advice or guidance on putting together map data from > different sources? > > And an over-arching question: Is moving in this direction, with ggplot2, > the way you would recommend accomplishing this task? Is there a simpler, > more straight-forward way of doing this? > > Thanks in advance for your help and efforts. > > -Kevin > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From drj|m|emon @end|ng |rom gm@||@com Wed Jun 7 06:27:23 2023 From: drj|m|emon @end|ng |rom gm@||@com (Jim Lemon) Date: Wed, 7 Jun 2023 14:27:23 +1000 Subject: [R] Plotrix pyramid plot: request for a little help In-Reply-To: References: Message-ID: Hi Mohsin, As I don't have your data, I had to fake it, so there are probably some mistakes in the example below: # my suggestion x<-c(143,108,95,72,70,85,125,123,64,67,144,55,60,200,70,100,65,140,49,45,77,58,66,50,77) y<-c(41,32,28,13,15,29,72,71,17,180,9,13,145,29,56,22,97,13,9,42,20,7,30,10,41) labels<-c("sector","increase","period","foreign","compared","exchange","rate", "expected","impact","mpc","oil","sbp","growth","credit","economic","private", "year","government","improvement","months","average","cpi","real","net", "developments") top25_df<-data.frame(x=x,y=y,labels=labels) pyramid.plot(top25_df$x,top25_df$y, labels=top25_df$labels, main="Words Common in MPS statements", gap=40, unit="Count", top.labels=c("2016-20","Words","2021-23"), laxlab=seq(0,200,by=25),raxlab=seq(0,200,by=25)) To answer your question, I used the "laxlab" and "raxlab" arguments. I also extended them to 0-200 to cover the range of the largest counts. You can use 0-150 for both, but it is not a good idea to req I added the unit="Count", which you can delete if you don't want it. I think it's a good idea to let the viewer know what the units are. Apart from On Tue, Jun 6, 2023 at 3:39?PM Mohsin Waheed wrote: > > Hi, > > > > I am working on a research study wherein I have employed a variety of textual analysis methods including plotrix pyramid plot. However, with the pyramid plot, I am unable to set the x-axis limits; for example, how can I manually define the frequency range as 0, 50, 100, 150? > > > > Would really appreciate your reply. Plot and codes files are attached for your perusal. > > > > Regards, > > > > Mohsin > > > > > > Sent from Mail for Windows > > From drj|m|emon @end|ng |rom gm@||@com Wed Jun 7 06:31:38 2023 From: drj|m|emon @end|ng |rom gm@||@com (Jim Lemon) Date: Wed, 7 Jun 2023 14:31:38 +1000 Subject: [R] Plotrix pyramid plot: request for a little help In-Reply-To: References: Message-ID: Hi Mohsin, I must have hit the wrong key and sent the last email. The last paragraph should read: To answer your question, I used the "laxlab" and "raxlab" arguments. I also extended them to 0-200 to cover the range of the largest counts. You can use 0-150 for both, but it is not a good idea to request different labels, as the plot won't be correct. I added the unit="Count", which you can delete if you don't want it. I think it's a good idea to let the viewer know what the units are. I have also attached an image which didn't get into the last email. Jim -------------- next part -------------- A non-text attachment was scrubbed... Name: ms_07_06.png Type: image/png Size: 34420 bytes Desc: not available URL: From @jord@ng@rz@2009 @end|ng |rom my@||t@edu Wed Jun 7 23:11:50 2023 From: @jord@ng@rz@2009 @end|ng |rom my@||t@edu (=?UTF-8?Q?Ad=C3=A1n_Guillermo_Jordan=2DGarza?=) Date: Wed, 7 Jun 2023 15:11:50 -0600 Subject: [R] side scan data In-Reply-To: References: Message-ID: > > Dear R users, is there a package that will allow us to read and visualize > sonar data from .xtf files? > Thank you, Libre de virus.www.avg.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> [[alternative HTML version deleted]] From bgunter@4567 @end|ng |rom gm@||@com Wed Jun 7 23:37:41 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Wed, 7 Jun 2023 14:37:41 -0700 Subject: [R] side scan data In-Reply-To: References: Message-ID: I found none, e.g. searching here . There is a python module, however, that you might be able to use instead: https://pypi.org/project/pyxtf/ Cheers, Bert On Wed, Jun 7, 2023 at 2:12?PM Ad?n Guillermo Jordan-Garza < ajordangarza2009 at my.fit.edu> wrote: > > > > Dear R users, is there a package that will allow us to read and visualize > > sonar data from .xtf files? > > > Thank you, > > < > http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail > > > Libre > de virus.www.avg.com > < > http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail > > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From @@h|mk@poor @end|ng |rom gm@||@com Thu Jun 8 07:41:08 2023 From: @@h|mk@poor @end|ng |rom gm@||@com (Ashim Kapoor) Date: Thu, 8 Jun 2023 11:11:08 +0530 Subject: [R] Cryptic error from stargazer Message-ID: Dear All, Here is my reproducible example: > library(stargazer) Please cite as: Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables. R package version 5.2.2. https://CRAN.R-project.org/package=stargazer > x1=1:1000 ; y = 2 * x1+ rnorm(1000) > stargazer(lm(y~x1)) Error in (.format.s.statistics.list != "p25") && (.format.s.statistics.list != : 'length = 7' in coercion to 'logical(1)' The error returned is cryptic and I am not able to google and find the solution. Here is my sessionInfo: > sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux 10 (buster) Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so; LAPACK version 3.8.0 locale: [1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN [4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN [7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C time zone: Asia/Kolkata tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] stargazer_5.2.2 loaded via a namespace (and not attached): [1] compiler_4.3.0 Any help will be appreciated. Thank you, Ashim From @@h|mk@poor @end|ng |rom gm@||@com Thu Jun 8 07:51:40 2023 From: @@h|mk@poor @end|ng |rom gm@||@com (Ashim Kapoor) Date: Thu, 8 Jun 2023 11:21:40 +0530 Subject: [R] Cryptic error from stargazer In-Reply-To: References: Message-ID: Dear All, I had done an automatic upgrade of my Debian 10 system which had also upgraded R. I reinstalled the stargazer package and the error went away. Query : Do I need to reinstall all packages with each upgrade of R ? Best, Ashim On Thu, Jun 8, 2023 at 11:11?AM Ashim Kapoor wrote: > > Dear All, > > Here is my reproducible example: > > > library(stargazer) > > Please cite as: > > Hlavac, Marek (2018). stargazer: Well-Formatted Regression and > Summary Statistics Tables. > R package version 5.2.2. https://CRAN.R-project.org/package=stargazer > > > x1=1:1000 ; y = 2 * x1+ rnorm(1000) > > stargazer(lm(y~x1)) > Error in (.format.s.statistics.list != "p25") && > (.format.s.statistics.list != : > 'length = 7' in coercion to 'logical(1)' > > The error returned is cryptic and I am not able to google and find the solution. > > Here is my sessionInfo: > > > sessionInfo() > R version 4.3.0 (2023-04-21) > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Debian GNU/Linux 10 (buster) > > Matrix products: default > BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 > LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so; LAPACK version 3.8.0 > > locale: > [1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN > [4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN > [7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C > [10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C > > time zone: Asia/Kolkata > tzcode source: system (glibc) > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] stargazer_5.2.2 > > loaded via a namespace (and not attached): > [1] compiler_4.3.0 > > Any help will be appreciated. > > Thank you, > Ashim From e@ @end|ng |rom enr|co@chum@nn@net Thu Jun 8 09:43:52 2023 From: e@ @end|ng |rom enr|co@chum@nn@net (Enrico Schumann) Date: Thu, 08 Jun 2023 09:43:52 +0200 Subject: [R] Cryptic error from stargazer In-Reply-To: (Ashim Kapoor's message of "Thu, 8 Jun 2023 11:21:40 +0530") References: Message-ID: <87legueb2v.fsf@enricoschumann.net> On Thu, 08 Jun 2023, Ashim Kapoor writes: > Dear All, > > I had done an automatic upgrade of my Debian 10 system which had also > upgraded R. > > I reinstalled the stargazer package and the error went away. > > Query : Do I need to reinstall all packages with each upgrade of R ? > > Best, > Ashim Your session info says "stargazer 5.2.2". What version do you have now? CRAN has 5.2.3. It seems likely to me that i) with R 4.3-0, certain warnings in the package have become errors (the NEWS file for R 4.3-0, https://cloud.r-project.org/doc/manuals/r-release/NEWS.html , has a prominent first item about using && and errors.) and ii) the package maintainer fixed those warnings/errors in 5.2.3. kind regards Enrico > On Thu, Jun 8, 2023 at 11:11?AM Ashim Kapoor wrote: >> >> Dear All, >> >> Here is my reproducible example: >> >> > library(stargazer) >> >> Please cite as: >> >> Hlavac, Marek (2018). stargazer: Well-Formatted Regression and >> Summary Statistics Tables. >> R package version 5.2.2. https://CRAN.R-project.org/package=stargazer >> >> > x1=1:1000 ; y = 2 * x1+ rnorm(1000) >> > stargazer(lm(y~x1)) >> Error in (.format.s.statistics.list != "p25") && >> (.format.s.statistics.list != : >> 'length = 7' in coercion to 'logical(1)' >> >> The error returned is cryptic and I am not able to google and find the solution. >> >> Here is my sessionInfo: >> >> > sessionInfo() >> R version 4.3.0 (2023-04-21) >> Platform: x86_64-pc-linux-gnu (64-bit) >> Running under: Debian GNU/Linux 10 (buster) >> >> Matrix products: default >> BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 >> LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so; LAPACK version 3.8.0 >> >> locale: >> [1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN >> [4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN >> [7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C >> [10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C >> >> time zone: Asia/Kolkata >> tzcode source: system (glibc) >> >> attached base packages: >> [1] stats graphics grDevices utils datasets methods base >> >> other attached packages: >> [1] stargazer_5.2.2 >> >> loaded via a namespace (and not attached): >> [1] compiler_4.3.0 >> >> Any help will be appreciated. >> >> Thank you, >> Ashim > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net From @@h|mk@poor @end|ng |rom gm@||@com Thu Jun 8 10:12:34 2023 From: @@h|mk@poor @end|ng |rom gm@||@com (Ashim Kapoor) Date: Thu, 8 Jun 2023 13:42:34 +0530 Subject: [R] Cryptic error from stargazer In-Reply-To: <87legueb2v.fsf@enricoschumann.net> References: <87legueb2v.fsf@enricoschumann.net> Message-ID: Dear Enrico, --- snip ------------------------------ > library(stargazer) Please cite as: Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables. R package version 5.2.3. https://CRAN.R-project.org/package=stargazer > --- snip-------------------------- Yes I do think I now have 5.2.3 Many thanks, Ashim On Thu, Jun 8, 2023 at 1:13?PM Enrico Schumann wrote: > > On Thu, 08 Jun 2023, Ashim Kapoor writes: > > > Dear All, > > > > I had done an automatic upgrade of my Debian 10 system which had also > > upgraded R. > > > > I reinstalled the stargazer package and the error went away. > > > > Query : Do I need to reinstall all packages with each upgrade of R ? > > > > Best, > > Ashim > > Your session info says "stargazer 5.2.2". What version do > you have now? CRAN has 5.2.3. It seems likely to me that > > i) with R 4.3-0, certain warnings in the package have > become errors (the NEWS file for R 4.3-0, > https://cloud.r-project.org/doc/manuals/r-release/NEWS.html , > has a prominent first item about using && and errors.) > > and > > ii) the package maintainer fixed those warnings/errors in 5.2.3. > > kind regards > Enrico > > > > On Thu, Jun 8, 2023 at 11:11?AM Ashim Kapoor wrote: > >> > >> Dear All, > >> > >> Here is my reproducible example: > >> > >> > library(stargazer) > >> > >> Please cite as: > >> > >> Hlavac, Marek (2018). stargazer: Well-Formatted Regression and > >> Summary Statistics Tables. > >> R package version 5.2.2. https://CRAN.R-project.org/package=stargazer > >> > >> > x1=1:1000 ; y = 2 * x1+ rnorm(1000) > >> > stargazer(lm(y~x1)) > >> Error in (.format.s.statistics.list != "p25") && > >> (.format.s.statistics.list != : > >> 'length = 7' in coercion to 'logical(1)' > >> > >> The error returned is cryptic and I am not able to google and find the solution. > >> > >> Here is my sessionInfo: > >> > >> > sessionInfo() > >> R version 4.3.0 (2023-04-21) > >> Platform: x86_64-pc-linux-gnu (64-bit) > >> Running under: Debian GNU/Linux 10 (buster) > >> > >> Matrix products: default > >> BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 > >> LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so; LAPACK version 3.8.0 > >> > >> locale: > >> [1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN > >> [4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN > >> [7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C > >> [10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C > >> > >> time zone: Asia/Kolkata > >> tzcode source: system (glibc) > >> > >> attached base packages: > >> [1] stats graphics grDevices utils datasets methods base > >> > >> other attached packages: > >> [1] stargazer_5.2.2 > >> > >> loaded via a namespace (and not attached): > >> [1] compiler_4.3.0 > >> > >> Any help will be appreciated. > >> > >> Thank you, > >> Ashim > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > -- > Enrico Schumann > Lucerne, Switzerland > http://enricoschumann.net From ||@her @end|ng |rom p|e@@th@n@com Thu Jun 8 04:14:58 2023 From: ||@her @end|ng |rom p|e@@th@n@com (Dennis Fisher) Date: Wed, 7 Jun 2023 19:14:58 -0700 Subject: [R] need help with plotmath and/or plotting unicode characters Message-ID: <80B29117-3F79-4B55-9A13-B6EF1BFFFA52@plessthan.com> R 4.2.3 OS X Colleagues This should be easy -- but not for me. I want to plot text similar to this: N ? XX: YY where XX can be either 1 or 50 and YY is an integer I envision that there would be two solutions: UNICODE: If I can generate "?" via unicode, the problem is solved: mtext(side=3, paste0("N ", UNICODE, " ", XX, ": ", YY)) PLOTMATH: mtext(side=3, bquote(N <= .(XX) ~":" ~ .(YY))) This comes close: N ? 2 : 13 but I want to remove the space between the 2 and ":" Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com From kry|ov@r00t @end|ng |rom gm@||@com Thu Jun 8 11:04:45 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Thu, 8 Jun 2023 12:04:45 +0300 Subject: [R] need help with plotmath and/or plotting unicode characters In-Reply-To: <80B29117-3F79-4B55-9A13-B6EF1BFFFA52@plessthan.com> References: <80B29117-3F79-4B55-9A13-B6EF1BFFFA52@plessthan.com> Message-ID: <20230608120445.348c3204@Tarkus> On Wed, 7 Jun 2023 19:14:58 -0700 Dennis Fisher wrote: > UNICODE: If I can generate "?" via unicode, the problem is solved: > mtext(side=3, paste0("N ", UNICODE, " ", XX, ": ", YY)) It should be possible to just copy & paste "?" in the R source code nowadays. If for some reason the script has to stay ASCII-encoded, use '\u2265'. > PLOTMATH: > mtext(side=3, bquote(N <= .(XX) ~":" ~ .(YY))) > This comes close: > N ? 2 : 13 > but I want to remove the space between the 2 and ":" Use paste(.(XX), ":") or even just .(XX) * ":" to output them close together. -- Best regards, Ivan From rmh @end|ng |rom temp|e@edu Thu Jun 8 19:39:32 2023 From: rmh @end|ng |rom temp|e@edu (Richard M. Heiberger) Date: Thu, 8 Jun 2023 17:39:32 +0000 Subject: [R] [External] need help with plotmath and/or plotting unicode characters In-Reply-To: <80B29117-3F79-4B55-9A13-B6EF1BFFFA52@plessthan.com> References: <80B29117-3F79-4B55-9A13-B6EF1BFFFA52@plessthan.com> Message-ID: <02838857-8037-408E-808E-832C55DDA517@temple.edu> Use * instead of ~ XX <- 5 YY <- 10 plot(1:10) mtext(side=3, bquote(N <= .(XX) ~":" ~ .(YY))) mtext(side=1, bquote(N <= .(XX) *":" * .(YY))) > On Jun 7, 2023, at 22:14, Dennis Fisher wrote: > > R 4.2.3 > OS X > > Colleagues > > This should be easy -- but not for me. > > I want to plot text similar to this: > N ? XX: YY > > where XX can be either 1 or 50 and YY is an integer > > I envision that there would be two solutions: > > UNICODE: If I can generate "?" via unicode, the problem is solved: > mtext(side=3, paste0("N ", UNICODE, " ", XX, ": ", YY)) > > PLOTMATH: > mtext(side=3, bquote(N <= .(XX) ~":" ~ .(YY))) > This comes close: > N ? 2 : 13 > but I want to remove the space between the 2 and ":" > > 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.r-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch Fri Jun 9 12:06:39 2023 From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler) Date: Fri, 9 Jun 2023 12:06:39 +0200 Subject: [R] error in arfima... In-Reply-To: References: <25720.20392.521283.415199@stat.math.ethz.ch> <25725.44960.478222.430645@stat.math.ethz.ch> Message-ID: <25730.63919.349424.768518@stat.math.ethz.ch> >>>>> akshay kulkarni >>>>> on Mon, 5 Jun 2023 14:11:12 +0000 writes: > Dear Martin, > Sad that the bug is beyond your ken... well, that's not exactly what I tried to say (and I did ask you for more output from your R session and also asked about what happens if you try things several time in a row, etc). At the moment, it looks to me that nobody can reproduce the problem with what you've given, and my personal guess is that something is "bad" only on your computer, i.e., your combination of hardware, software, your R installation, your installation of the forecast package and its many dependencies (other R packages), etc. .. > Fortunately, the error happens only rarely...The length of LYGH was 719 and there were only two such errors..I will just replace them with NA and make do. > By the by, what if I send LYGH as an attachment to your actual mail ( not the r-help mail)? Will it help? Can you then pinpoint the cause? Yes, please do that. Make the file "LYGH.rds" available (on the web or send to me) which you get after saveRDS(LYGH, file="LYGH.rds") > Or should I raise a bug report? If yes, how( I never raised one)? We don't know yet if there is any bug, see above. Martin > THanking you, > Yours sincerely, > AKSHAY M KULKARNI > ________________________________ > From: Martin Maechler > Sent: Monday, June 5, 2023 3:19 PM > To: akshay kulkarni > Cc: Martin Maechler ; R help Mailing list > Subject: Re: [R] error in arfima... >> Dear Martin, >> REgrets to reply this late.... >> I am staring at a conundrum never before encountered in my experience with R: >> LYGH[[201]] >> [1] 45.40 3.25 6.50 2.15 >> > arfima(LYGH[[201]]) >> Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : >> NA/NaN/Inf in foreign function call (arg 5) >> > arfima(c(45.40,3.25,6.50,2.15)) >> Call: >> arfima(y = c(45.4, 3.25, 6.5, 2.15)) >> Coefficients: >> d >> 4.583013e-05 >> sigma[eps] = 18.01252 >> a list with components: >> [1] "log.likelihood" "n" "msg" "d" "ar" >> [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" >> [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" >> [16] "length.w" "residuals" "fitted" "call" "x" >> [21] "series" >> Please note that the index of LYGH has changed from 202 to 201 due to some randomness in one of my function. >> PLEASE HELP. >> Output of dput LYGH[[201]]: >> > dput(LYGH[[201]]) >> c(45.4, 3.25, 6.5, 2.14999999999998) >> output of session info() >> sessionInfo() >> R version 4.1.2 (2021-11-01) >> Platform: x86_64-w64-mingw32/x64 (64-bit) >> Running under: Windows Server x64 (build 14393) >> Matrix products: default >> locale: >> [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 >> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C >> [5] LC_TIME=English_United States.1252 >> attached base packages: >> [1] parallel stats graphics grDevices utils datasets methods base >> other attached packages: >> [1] pbmcapply_1.5.1 imputeTS_3.3 forecast_8.17.0 >> loaded via a namespace (and not attached): >> [1] Rcpp_1.0.7 urca_1.3-3 pillar_1.9.0 compiler_4.1.2 tseries_0.10-51 >> [6] tools_4.1.2 xts_0.12.1 nlme_3.1-153 lifecycle_1.0.3 tibble_3.2.1 >> [11] gtable_0.3.3 lattice_0.20-45 pkgconfig_2.0.3 rlang_1.1.0 cli_3.6.1 >> [16] rstudioapi_0.14 curl_4.3.2 xml2_1.3.3 dplyr_1.1.1 generics_0.1.3 >> [21] vctrs_0.6.1 gridtext_0.1.5 ggtext_0.1.2 lmtest_0.9-40 grid_4.1.2 >> [26] nnet_7.3-16 tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 fansi_1.0.4 >> [31] ggplot2_3.4.2 TTR_0.24.3 magrittr_2.0.3 scales_1.2.1 quantmod_0.4.20 >> [36] timeDate_4021.106 colorspace_2.1-0 fracdiff_1.5-1 quadprog_1.5-8 utf8_1.2.3 >> [41] stinepack_1.4 munsell_0.5.0 zoo_1.8-10 >> PLease Also note: >> arfima(c(45.4, 3.25, 6.5, 2.14999999999998)) >> Call: >> arfima(y = c(45.4, 3.25, 6.5, 2.14999999999998)) >> Coefficients: >> d >> 4.583013e-05 >> sigma[eps] = 18.01252 >> a list with components: >> [1] "log.likelihood" "n" "msg" "d" "ar" >> [6] "ma" "covariance.dpq" "fnormMin" "sigma" "stderror.dpq" >> [11] "correlation.dpq" "h" "d.tol" "M" "hessian.dpq" >> [16] "length.w" "residuals" "fitted" "call" "x" >> [21] "series" >> Many thanks in advance.... >> Thanking you, >> Yours sincerely, >> AKSHAY M KULKARNI > Hmm... indeed, "conundrum" may be a euphemism for the > situation..... which clearly points to a bug *somewhere*. > As your dput() shows, the argument *is* a simple vector .. and > even if the default dput() may loose a few bits in > precison... you did show that with (possibly only almost) > identical argument, the error did not happen. > I really have no idea what's going on, .... > Some musing/ideas: the NA/NaN/Inf warning > may come from a memory corruption problem somewhere because some > of the involved packages using compiled code or the old version of R/lapack/??? > or ??? cause it. > Does the error only happen occasionally? > If you "randomly" do a few calls of either > arfima(c(45.4, 3.25, 6.5, 2.14999999999998)) > or > arfima(LYGH[[201]]) > do you see "random" behavior? [if yes; this confirms typically > memory protection/allocation/... bugs] > fracdiff itself has also been updated (to 1.5-2) but that was really only > a compiler warning, not a bug fix, and I cannot imagine that > that makes the difference. > I think you should consider let your 'Windows Server' provider > update R on that server. Notably the Windows version of R has > had problems fixed in the mean time .. > and at least there's a hope the problem disappears. > Lastly (but probably not helping more), you could use > dput() with control="digits" and even > .Internal(inspect( * )) magic on your LYGH[[201]] > When I use simple numeric vectors "like" your LYGH[..], I get >> dput(c(45.4, 3.25, 6.5, 2.15), control="digits") > c(45.399999999999999, 3.25, 6.5, 2.1499999999999999) >> .Internal(inspect(c(45.4, 3.25, 6.5, 2.15)) + ) > @9874728 14 REALSXP g0c3 [] (len=4, tl=0) 45.4,3.25,6.5,2.15 >> > Martin >> ________________________________ >> From: Martin Maechler >> Sent: Thursday, June 1, 2023 1:28 PM >> To: akshay kulkarni >> Cc: R help Mailing list >> Subject: Re: [R] error in arfima... >> >>>>> akshay kulkarni >> >>>>> on Wed, 31 May 2023 20:55:33 +0000 writes: >> > dear members, >> > I am using arfima() from forecast package to model a time >> > series. The following is the code: >> >> LYGH[[202]] >> > [1] 45.40 3.25 6.50 2.15 >> >> arfima(LYGH[[202]]) >> > Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = fdf$w) : >> > NA/NaN/Inf in foreign function call (arg 5) >> > I tried viewing .fdcov() with the following code: >> > View(environment(fracdiff)$.fdcov) >> > but I see no stop() with the above mentioned error message. >> > Can you please help? >> Well, as I am the maintainer of the *fracdiff* package, >> I'm trying. OTOH, as we will see below, you did not give us enough >> information to really help you... >> > THanking you, >> > Yours sincerely, >> > AKSHAY M KULKARNI >> Your problem is not (yet) reproducible (*) >> I've done the following in an "empty" (i.e. freshly started) R >> session, R 4.3.0: >> ----begin_R_transcript___save_as__arfima-ex.Rout__------------------------------ >> > >> > lN <- loadedNamespaces() >> > library(forecast) >> Registered S3 method overwritten by 'quantmod': >> method from >> as.zoo.data.frame zoo >> > options(width=75) >> > setdiff(loadedNamespaces(), lN) # -- see all the *!^@...! forecast loads: >> [1] "gtable" "dplyr" "tidyselect" "Rcpp" "parallel" >> [6] "scales" "lattice" "ggplot2" "R6" "generics" >> [11] "curl" "lmtest" "tibble" "munsell" "nnet" >> [16] "forecast" "timeDate" "pillar" "rlang" "quantmod" >> [21] "utf8" "urca" "quadprog" "cli" "magrittr" >> [26] "xts" "grid" "nlme" "lifecycle" "fracdiff" >> [31] "vctrs" "glue" "tseries" "zoo" "fansi" >> [36] "colorspace" "TTR" "pkgconfig" >> > arfima(c(45.40, 3.25, 6.50, 2.15)) >> Call: >> arfima(y = c(45.4, 3.25, 6.5, 2.15)) >> Coefficients: >> d >> 4.583013e-05 >> sigma[eps] = 18.01252 >> a list with components: >> [1] "log.likelihood" "n" "msg" >> [4] "d" "ar" "ma" >> [7] "covariance.dpq" "fnormMin" "sigma" >> [10] "stderror.dpq" "correlation.dpq" "h" >> [13] "d.tol" "M" "hessian.dpq" >> [16] "length.w" "residuals" "fitted" >> [19] "call" "x" "series" >> > >> > sessionInfo() >> R version 4.3.0 (2023-04-21) >> Platform: x86_64-pc-linux-gnu (64-bit) >> Running under: Fedora Linux 36 (Thirty Six) >> Matrix products: default >> BLAS: /usr/local64.sfs/app/R/R-4.3.0-inst/lib/libRblas.so >> LAPACK: /usr/lib64/liblapack.so.3.10.1 >> locale: >> [1] LC_CTYPE=de_CH.UTF-8 LC_NUMERIC=C >> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=de_CH.UTF-8 >> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=de_CH.UTF-8 >> [7] LC_PAPER=de_CH.UTF-8 LC_NAME=C >> [9] LC_ADDRESS=C LC_TELEPHONE=C >> [11] LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C >> time zone: Europe/Zurich >> tzcode source: system (glibc) >> attached base packages: >> [1] graphics grDevices datasets stats utils methods base >> other attached packages: >> [1] forecast_8.21 fortunes_1.5-4 sfsmisc_1.1-15 >> loaded via a namespace (and not attached): >> [1] gtable_0.3.3 dplyr_1.1.2 compiler_4.3.0 >> [4] tidyselect_1.2.0 Rcpp_1.0.10 parallel_4.3.0 >> [7] scales_1.2.1 lattice_0.21-8 ggplot2_3.4.2 >> [10] R6_2.5.1 generics_0.1.3 curl_5.0.0 >> [13] lmtest_0.9-40 tibble_3.2.1 munsell_0.5.0 >> [16] nnet_7.3-19 timeDate_4022.108 pillar_1.9.0 >> [19] rlang_1.1.1 quantmod_0.4.22 utf8_1.2.3 >> [22] urca_1.3-3 quadprog_1.5-8 cli_3.6.1 >> [25] magrittr_2.0.3 xts_0.13.1 grid_4.3.0 >> [28] nlme_3.1-162 lifecycle_1.0.3 fracdiff_1.5-2 >> [31] vctrs_0.6.2 glue_1.6.2 tseries_0.10-54 >> [34] zoo_1.8-12 fansi_1.0.4 colorspace_2.1-0 >> [37] TTR_0.24.3 tools_4.3.0 pkgconfig_2.0.3 >> > >> ##---end__R_transcript--------------------------------------------------------------- >> Note that your error message pointed me to my (old, but still >> fine) package {fracdiff} with its principal function fracdiff() >> around which arfima() is a user-friendly and >> generalization wrapper. >> In other words arfima() calls fracdiff::fracdiff() and the error >> happens there --- for you, but not for me, if I try to use the >> same data as you. >> I see that you must have found that too, because you mentioned >> View(environment(fracdiff)$.fdcov) >> Maybe you need to >> update.packages() >> {which should re-install R packages you have installed but which >> have become outdated in the mean time} >> If the error persists, please send us the output of >> 1) >> dput(LYGH[[202]]) >> so we get your exact data >> 2) >> sessionInfo() >> so we get much info about your R "setup" >> .... last but not least: If you are really calling arfima() >> with a time series of length 4 (which your LYGH[[202]] above >> seems to suggest) >> then you really need to learn a bit about the tools you are >> using: It really does not make any sense to fit a somewhat >> sophisticated time-series model (or *any* time-series model, I'd say) >> to a "series" with 4 values. >> Best regards, >> Martin >> -- >> Martin Maechler >> ETH Zurich and R Core team > [[alternative HTML version deleted]] From @@h|mk@poor @end|ng |rom gm@||@com Fri Jun 9 13:46:21 2023 From: @@h|mk@poor @end|ng |rom gm@||@com (Ashim Kapoor) Date: Fri, 9 Jun 2023 17:16:21 +0530 Subject: [R] leaps for plm - looking for variable selection software for panel data Message-ID: Dear all, I have a small query. Just like we have package leaps which can do variable selection for a linear model, do we have any technique/software for variable selection for panel data? Here are the links to the mentioned packages: https://cran.r-project.org/web/packages/leaps/leaps.pdf https://cran.r-project.org/web/packages/plm/plm.pdf Many thanks, Ashim From @k@h@y_e4 @end|ng |rom hotm@||@com Fri Jun 9 20:01:44 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Fri, 9 Jun 2023 18:01:44 +0000 Subject: [R] inconsistency in mclapply..... Message-ID: Dear members, I am using pbmcapply to parellise my code. But the following code doesn't work: > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE) | | 0%, ETA NA^ It just hangs. But the following works: > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2) |==============================================================================================================================================| 100%, Elapsed 00:32 > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE) |==============================================================================================================================================| 100%, Elapsed 00:52 Any idea on why mc.preschedule = FALSE works after the one without it? Many thanks ... THanking you, Yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]] From @k@h@y_e4 @end|ng |rom hotm@||@com Fri Jun 9 20:26:38 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Fri, 9 Jun 2023 18:26:38 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: Message-ID: Dear members, I think I have a hint: The doc says: mc.cleanup if set to TRUE then all children that have been forked by this function will be killed (by sending SIGTERM) before this function returns. Under normal circumstances mclapply waits for the children to deliver results, so this option usually has only effect when mclapply is interrupted. If set to FALSE then child processes are collected, but not forcefully terminated. As a special case this argument can be set to the number of the signal that should be used to kill the children instead of SIGTERM. mc.allow.recursive Unless true, calling mclapply in a child process will use the child and not fork again. I think the child processes are not killed. I think I have to use one or both of the above arguments. Can you please shed some light on which one? ANd what goes on under the hood? THanking you,Yours sincerely,AKSHAY M KULKARNI ________________________________ From: R-help on behalf of akshay kulkarni Sent: Friday, June 9, 2023 11:31 PM To: R help Mailing list Subject: [R] inconsistency in mclapply..... Dear members, I am using pbmcapply to parellise my code. But the following code doesn't work: > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE) | | 0%, ETA NA^ It just hangs. But the following works: > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2) |==============================================================================================================================================| 100%, Elapsed 00:32 > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE) |==============================================================================================================================================| 100%, Elapsed 00:52 Any idea on why mc.preschedule = FALSE works after the one without it? Many thanks ... THanking you, Yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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]] From kry|ov@r00t @end|ng |rom gm@||@com Fri Jun 9 22:13:00 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Fri, 9 Jun 2023 23:13:00 +0300 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: Message-ID: <20230609231300.6a937f88@Tarkus> On Fri, 9 Jun 2023 18:01:44 +0000 akshay kulkarni wrote: > > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = > > FALSE) > | > | > 0%, ETA NA^ > > It just hangs. My questions from the last time still stand: 0) What is your sessionInfo()? Maybe you're running a parallel BLAS which doesn't always handle fork() or something. It may be worth disabling BLAS-level parallelism as long as you're already trying to use 100% of your processor by other means. 1) What does traceback() show after you interrupt pbmclapply? Most likely, you would be interrupting selectChildren(), but if not, the problem may lie in a very different place from what I'm expecting. 2) While pbmclapply is hung, without interrupting it, take a look at the state of the system and the processes on it (are you still on RHEL? use `top` or whatever task manager you're comfortable with). a) Is 100% of the CPU being used? 100% of one core? Is system mostly idle? b) Can you find the child processes launched by pbmclapply? c) Write down the PID of the child process and attach a debugger to it (If you're on RHEL, try following this guide: . If GDB asks you to install additional debug symbols by running debuginfo-install, follow its guidance and then restart GDB.) and obtain a backtrace. (In GDB, the command to obtain a backtrace is "backtrace".) Which function is the child process stuck in? -- Best regards, Ivan From @k@h@y_e4 @end|ng |rom hotm@||@com Fri Jun 9 23:19:11 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Fri, 9 Jun 2023 21:19:11 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: <20230609231300.6a937f88@Tarkus> References: <20230609231300.6a937f88@Tarkus> Message-ID: Dear Ivan, Thanks for the reply. I am pressurised by a fast approaching deadline and your reply calmed me... Take a look at the following code: debug at #26: LYG <- mclapply(LYGH, FUN = arfima, mc.cores = 2, mc.preschedule = FALSE) Browse[2]> length(LYGH) [1] 357 Browse[2]> ^C Browse[2]> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE) | | 0%, ETA NA I am debuuging a function FUN wherein the above expressions appear. The pbmclapply code works well if called inside FUN: > FUN(arg) Result.. But as you may note, it doesn't work while in debug mode.... Also, if I replace pbmclapply by maclapply inside FUN, it hangs.... You might be interested in this: [ec2-user at ip-172-31-15-116 ~]$ exit logout There are stopped jobs. THis occurs when I close R and try to exit the shell prompt( I am on an AWS EC2 RHEL 8 Instance). Can this lead you somewhere? As of now I have quit R in my machine, so I can't get session info..but please let me know if you need it necessarily... by the by, how do you run top when running R? I think at least in my machine, you have to quit R to get to the shell prompt... I request you TO PLEASE reply to this mail as early as possible. I am facing an imminent deadline...please excuse my blatant violation of protocol, but deadlines are deadlines, right? THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Ivan Krylov Sent: Saturday, June 10, 2023 1:43 AM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] inconsistency in mclapply..... On Fri, 9 Jun 2023 18:01:44 +0000 akshay kulkarni wrote: > > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = > > FALSE) > | > | > 0%, ETA NA^ > > It just hangs. My questions from the last time still stand: 0) What is your sessionInfo()? Maybe you're running a parallel BLAS which doesn't always handle fork() or something. It may be worth disabling BLAS-level parallelism as long as you're already trying to use 100% of your processor by other means. 1) What does traceback() show after you interrupt pbmclapply? Most likely, you would be interrupting selectChildren(), but if not, the problem may lie in a very different place from what I'm expecting. 2) While pbmclapply is hung, without interrupting it, take a look at the state of the system and the processes on it (are you still on RHEL? use `top` or whatever task manager you're comfortable with). a) Is 100% of the CPU being used? 100% of one core? Is system mostly idle? b) Can you find the child processes launched by pbmclapply? c) Write down the PID of the child process and attach a debugger to it (If you're on RHEL, try following this guide: . If GDB asks you to install additional debug symbols by running debuginfo-install, follow its guidance and then restart GDB.) and obtain a backtrace. (In GDB, the command to obtain a backtrace is "backtrace".) Which function is the child process stuck in? -- Best regards, Ivan [[alternative HTML version deleted]] From er|cjberger @end|ng |rom gm@||@com Sat Jun 10 06:16:24 2023 From: er|cjberger @end|ng |rom gm@||@com (Eric Berger) Date: Sat, 10 Jun 2023 07:16:24 +0300 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: <20230609231300.6a937f88@Tarkus> Message-ID: Hi Akshay, You do not have to quit R to run 'top'. You can have, for example, 2 windows, with R running in one and top running in the oher. Eric On Sat, Jun 10, 2023 at 12:19?AM akshay kulkarni wrote: > Dear Ivan, > Thanks for the reply. I am pressurised by a fast > approaching deadline and your reply calmed me... > > Take a look at the following code: > > > debug at #26: LYG <- mclapply(LYGH, FUN = arfima, mc.cores = 2, > mc.preschedule = FALSE) > Browse[2]> length(LYGH) > [1] 357 > Browse[2]> > ^C > > Browse[2]> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule > = FALSE) > | > > | 0%, ETA NA > > I am debuuging a function FUN wherein the above expressions appear. The > pbmclapply code works well if called inside FUN: > > FUN(arg) > Result.. > > But as you may note, it doesn't work while in debug mode.... > > Also, if I replace pbmclapply by maclapply inside FUN, it hangs.... > > You might be interested in this: > > [ec2-user at ip-172-31-15-116 ~]$ exit > logout > There are stopped jobs. > > THis occurs when I close R and try to exit the shell prompt( I am on an > AWS EC2 RHEL 8 Instance). Can this lead you somewhere? As of now I have > quit R in my machine, so I can't get session info..but please let me know > if you need it necessarily... > > by the by, how do you run top when running R? I think at least in my > machine, you have to quit R to get to the shell prompt... > > I request you TO PLEASE reply to this mail as early as possible. I am > facing an imminent deadline...please excuse my blatant violation of > protocol, but deadlines are deadlines, right? > > THanking you, > Yours sincerely, > AKSHAY M KULKARNI > > > ________________________________ > From: Ivan Krylov > Sent: Saturday, June 10, 2023 1:43 AM > To: akshay kulkarni > Cc: R help Mailing list > Subject: Re: [R] inconsistency in mclapply..... > > On Fri, 9 Jun 2023 18:01:44 +0000 > akshay kulkarni wrote: > > > > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = > > > FALSE) > > | > > > | > > 0%, ETA NA^ > > > > It just hangs. > > My questions from the last time still stand: > > 0) What is your sessionInfo()? Maybe you're running a parallel BLAS > which doesn't always handle fork() or something. It may be worth > disabling BLAS-level parallelism as long as you're already trying to > use 100% of your processor by other means. > > 1) What does traceback() show after you interrupt pbmclapply? Most > likely, you would be interrupting selectChildren(), but if not, the > problem may lie in a very different place from what I'm expecting. > > 2) While pbmclapply is hung, without interrupting it, take a look at > the state of the system and the processes on it (are you still on RHEL? > use `top` or whatever task manager you're comfortable with). > > a) Is 100% of the CPU being used? 100% of one core? Is system mostly > idle? > > b) Can you find the child processes launched by pbmclapply? > > c) Write down the PID of the child process and attach a debugger to > it (If you're on RHEL, try following this guide: > . If GDB asks you to install > additional debug symbols by running debuginfo-install, follow its > guidance and then restart GDB.) and obtain a backtrace. (In GDB, the > command to obtain a backtrace is "backtrace".) Which function is the > child process stuck in? > > -- > Best regards, > Ivan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From kry|ov@r00t @end|ng |rom gm@||@com Sat Jun 10 09:24:50 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Sat, 10 Jun 2023 10:24:50 +0300 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: <20230609231300.6a937f88@Tarkus> Message-ID: <20230610102450.7acdbef1@Tarkus> On Fri, 9 Jun 2023 21:19:11 +0000 akshay kulkarni wrote: > debug at #26: LYG <- mclapply(LYGH, FUN = arfima, mc.cores = 2, > mc.preschedule = FALSE) > Browse[2]> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = > 2,mc.preschedule = FALSE) > | | 0%, ETA NA So if you interrupt the code _after_ it hangs at 0%, ETA NA, what's the traceback? (We're doing this to confirm that the parent process hangs in either selectChildren() or readChild().) > You might be interested in this: > > [ec2-user at ip-172-31-15-116 ~]$ exit > logout > There are stopped jobs. > > THis occurs when I close R and try to exit the shell prompt( I am on > an AWS EC2 RHEL 8 Instance). Can this lead you somewhere? I guess this proves the existence of child processes, probably spawned by mclapply, but why would they be _stopped_, I don't know. What's the output of jobs -l at this point? (This suggests trying to send them a SIGCONT and seeing what happens. Does mclapply() get unstuck if you run the command killall -SIGCONT R from a separate ssh connection? Would be strange if it worked, but worth a try.) > As of now I have quit R in my machine, so I can't get session > info.. Knowing the output of sessionInfo() could still be useful for solving the problem. It's best to show the output after loading all the packages, ideally just before you reproduce the problem. > by the by, how do you run top when running R? I think at least in my > machine, you have to quit R to get to the shell prompt... I can think of 3 options: 1) Type Ctrl+Z at the R prompt. R (and the rest of the process group, I think) becomes suspended, you return to the command line prompt where you can run other commands. At the system command line prompt, type "fg" and press Enter in order to continue running R. (Press Enter a second time so that R prints its command line prompt again.) This is quick, doesn't require preparation, but messes up the state of the processes you're interested in. (They become suspended instead of running, which may complicate debugging.) 2) Open a second ssh connection to the same machine the same way you had opened the first one. You won't be able to (easily) interact with the R session running in the first connection, but you'll get a second system command line where you'll be able to run top, gdb, and other commands, which should let you inspect the state of the system. 3) Before starting R, install a "terminal multiplexer", that is, GNU Screen or tmux. If you're still on RHEL, use sudo dnf install screen or sudo dnf install tmux. One of these commands needs to be run once per computer. Type the name of the program ("screen" or "tmux") to start it. Inside screen/tmux, start R. In Screen, use Ctrl+A then C in order to create a new virtual terminal; Ctrl+A then type the number in order to switch between terminals. In tmux, use Ctrl+B then C in order to create a new virtual terminal; Ctrl+B then type the number in order to switch between them. Terminals are numbered from 0 upwards, so the second one will be numbered 1, and so on. -- Best regards, Ivan From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 10 10:42:37 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 10 Jun 2023 08:42:37 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: <20230610102450.7acdbef1@Tarkus> References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> Message-ID: Dear Ivan, here is the comprehensive info you requested: THis is the output of top when I run a function LOWn() with mclapply in it. It executes succesfully. (the number of cores in my machine is 2) > LOWn(OHLCDataEP[[63]]) Tasks: 127 total, 3 running, 124 sleeping, 0 stopped, 0 zombie %Cpu0 : 82.3 us, 16.7 sy, 0.0 ni, 0.0 id, 0.0 wa, 1.0 hi, 0.0 si, 0.0 st %Cpu1 : 74.1 us, 24.9 sy, 0.0 ni, 0.0 id, 0.0 wa, 1.0 hi, 0.0 si, 0.0 st MiB Mem : 15531.8 total, 11019.4 free, 3521.8 used, 990.6 buff/cache MiB Swap: 0.0 total, 0.0 free, 0.0 used. 11723.8 avail Mem This is the output of top when I run function LOWp() with mclapply also in it. it hangs: top - 07:48:08 up 54 min, 2 users, load average: 0.02, 0.36, 0.34 Tasks: 127 total, 1 running, 126 sleeping, 0 stopped, 0 zombie %Cpu0 : 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu1 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 15531.8 total, 10976.8 free, 3564.4 used, 990.7 buff/cache MiB Swap: 0.0 total, 0.0 free, 0.0 used. 11681.2 avail Mem The mcalpply call only works the first time when I call it after starting an R session TRaceback of after interrupting LOWp: > LOWp(OHLCDataEP[[63]]) ^C There were 50 or more warnings (use warnings() to see the first 50) > traceback() 3: selectChildren(jobs[!is.na(jobsp)], -1) 2: mclapply(LYGH, FUN = arfima, mc.cores = 2, mc.preschedule = FALSE) at #26 1: LOWp(OHLCDataEP[[63]]) I think child processes spawned by maclapply in FUN2 doesn't get killed...THis is from the top command AFTER interrupting FUN2 (sometimes there is only one R process) 38615 ec2-user 20 0 1016432 400020 13392 S 0.0 2.5 0:02.05 R 38696 ec2-user 20 0 1016436 400416 13676 S 0.0 2.5 0:02.03 R THis is the output when FUN2 is running: 1526 ec2-user 20 0 1525784 651628 23040 S 0.0 4.1 0:11.90 R 2616 ec2-user 20 0 1525784 634688 6092 S 0.0 4.0 0:00.03 R 2617 ec2-user 20 0 1525784 634884 6288 S 0.0 4.0 0:00.02 R THis is AFTER succesful completion of FUN1: 38615 ec2-user 20 0 1016432 400020 13392 S 0.0 2.5 0:02.05 R 38696 ec2-user 20 0 1016436 400416 13676 S 0.0 2.5 0:02.03 R Please note that PIDs are same between FUN1 and FUN2, and also that when I am not parallelising there is only one R process: 1526 ec2-user 20 0 1227788 491248 21368 S 0.0 3.1 0:02.95 R > sessionInfo() R version 4.2.1 (2022-06-23) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux 8.6 (Ootpa) Matrix products: default BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] parallel stats graphics grDevices utils datasets methods [8] base other attached packages: [1] imputeTS_3.3 pbmcapply_1.5.1 attempt_0.3.1 forecast_8.21 loaded via a namespace (and not attached): [1] Rcpp_1.0.10 urca_1.3-3 pillar_1.9.0 compiler_4.2.1 [5] tseries_0.10-54 xts_0.13.1 lifecycle_1.0.3 tibble_3.2.1 [9] gtable_0.3.3 nlme_3.1-157 lattice_0.20-45 pkgconfig_2.0.3 [13] rlang_1.1.1 cli_3.6.1 curl_5.0.0 xml2_1.3.4 [17] generics_0.1.3 vctrs_0.6.2 lmtest_0.9-40 grid_4.2.1 [21] nnet_7.3-17 ggtext_0.1.2 gridtext_0.1.5 glue_1.6.2 [25] R6_2.5.1 fansi_1.0.4 ggplot2_3.4.2 TTR_0.24.3 [29] magrittr_2.0.3 scales_1.2.1 quantmod_0.4.22 timeDate_4022.108 [33] colorspace_2.1-0 fracdiff_1.5-2 quadprog_1.5-8 utf8_1.2.3 [37] stinepack_1.4 munsell_0.5.0 zoo_1.8-12 THis is the output of jobs -l: (it doesn't do anything) [ec2-user at ip-172-31-15-116 ~]$ jobs -l [ec2-user at ip-172-31-15-116 ~]$ killall - SIGCONT R has no effect You had asked me to attach a debugger to the child processes. How do you get the child processes spawned by mclapply? For example, how do i identify, among the listed R processes above, the child processes? Many thanks in advance.... Thanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Ivan Krylov Sent: Saturday, June 10, 2023 12:54 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] inconsistency in mclapply..... On Fri, 9 Jun 2023 21:19:11 +0000 akshay kulkarni wrote: > debug at #26: LYG <- mclapply(LYGH, FUN = arfima, mc.cores = 2, > mc.preschedule = FALSE) > Browse[2]> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = > 2,mc.preschedule = FALSE) > | | 0%, ETA NA So if you interrupt the code _after_ it hangs at 0%, ETA NA, what's the traceback? (We're doing this to confirm that the parent process hangs in either selectChildren() or readChild().) > You might be interested in this: > > [ec2-user at ip-172-31-15-116 ~]$ exit > logout > There are stopped jobs. > > THis occurs when I close R and try to exit the shell prompt( I am on > an AWS EC2 RHEL 8 Instance). Can this lead you somewhere? I guess this proves the existence of child processes, probably spawned by mclapply, but why would they be _stopped_, I don't know. What's the output of jobs -l at this point? (This suggests trying to send them a SIGCONT and seeing what happens. Does mclapply() get unstuck if you run the command killall -SIGCONT R from a separate ssh connection? Would be strange if it worked, but worth a try.) > As of now I have quit R in my machine, so I can't get session > info.. Knowing the output of sessionInfo() could still be useful for solving the problem. It's best to show the output after loading all the packages, ideally just before you reproduce the problem. > by the by, how do you run top when running R? I think at least in my > machine, you have to quit R to get to the shell prompt... I can think of 3 options: 1) Type Ctrl+Z at the R prompt. R (and the rest of the process group, I think) becomes suspended, you return to the command line prompt where you can run other commands. At the system command line prompt, type "fg" and press Enter in order to continue running R. (Press Enter a second time so that R prints its command line prompt again.) This is quick, doesn't require preparation, but messes up the state of the processes you're interested in. (They become suspended instead of running, which may complicate debugging.) 2) Open a second ssh connection to the same machine the same way you had opened the first one. You won't be able to (easily) interact with the R session running in the first connection, but you'll get a second system command line where you'll be able to run top, gdb, and other commands, which should let you inspect the state of the system. 3) Before starting R, install a "terminal multiplexer", that is, GNU Screen or tmux. If you're still on RHEL, use sudo dnf install screen or sudo dnf install tmux. One of these commands needs to be run once per computer. Type the name of the program ("screen" or "tmux") to start it. Inside screen/tmux, start R. In Screen, use Ctrl+A then C in order to create a new virtual terminal; Ctrl+A then type the number in order to switch between terminals. In tmux, use Ctrl+B then C in order to create a new virtual terminal; Ctrl+B then type the number in order to switch between them. Terminals are numbered from 0 upwards, so the second one will be numbered 1, and so on. -- Best regards, Ivan [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Sat Jun 10 11:16:24 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Sat, 10 Jun 2023 12:16:24 +0300 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> Message-ID: <20230610121624.042f3d0a@Tarkus> On Sat, 10 Jun 2023 08:42:37 +0000 akshay kulkarni wrote: > This is the output of top when I run function LOWp() with mclapply > also in it. it hangs: > %Cpu0 : 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 > si, 0.0 st > %Cpu1 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 > si, 0.0 st I see. The system is idle. > TRaceback of after interrupting LOWp: > > > > LOWp(OHLCDataEP[[63]]) > ^C > There were 50 or more warnings (use warnings() to see the first 50) What are the warnings()? > > traceback() > 3: selectChildren(jobs[!is.na(jobsp)], -1) > 2: mclapply(LYGH, FUN = arfima, mc.cores = 2, mc.preschedule = FALSE) > at #26 > 1: LOWp(OHLCDataEP[[63]]) ...and the parent is stuck waiting for at least some of the children. The problem must be inside the child processes. > BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so If you start R like this: OPENBLAS_NUM_THREADS=1 R ...and confirm that Sys.getenv('OPENBLAS_NUM_THREADS') returns 1, then try running your analysis, does it still get stuck? There are reports complaining about OpenBLAS failing fork() tests when built with OpenMP support, and this 'o' at the end of the shared library name looks suspicious. > You had asked me to attach a debugger to the child processes. How do > you get the child processes spawned by mclapply? For example, how do > i identify, among the listed R processes above, the child processes? Make sure that there's only one R session running. Stray R processes can be cleaned up by running killall R or rebooting the AWS virtual machine. Start R and run Sys.getpid(). This is the PID of the parent process. Start your analysis and get it stuck. Do not interrupt the function, let it keep waiting for the child process. In a separate ssh connection or virtual terminal, run top. It should be possible to type lowercase v to display a process tree, then navigate it using arrow keys. Confirm that there is a parent R process with the PID you saw above and a number of child processes branching from it with different PIDs. If there's more than one child, try them both and see if the results are different (hopefully not). Run gdb and enter the following commands (substitute the value of the PID for PID_OF_THE_CHILD_PROCESS): attach PID_OF_THE_CHILD_PROCESS thread apply all backtrace If there's too much text and you can't copy it out of the terminal, use the commands "set logging file gdb.log" and "set logging on", then get the text output from the file "gdb.log" that will be created in the current directory. -- Best regards, Ivan From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 10 13:49:10 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 10 Jun 2023 11:49:10 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: <20230610121624.042f3d0a@Tarkus> References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> Message-ID: Dear Ivan, I opened R with OPENBLAS_NUM_THREADS=1 but am bootless.... The parent process id: 2745 Child processes: 3857 and 3858 FOR 3857: (gdb) backtrace #0 0x00007f94b6454053 in gomp_team_barrier_wait_end () from /lib64/libgomp.so.1 #1 0x00007f94b6452a7d in gomp_team_end () from /lib64/libgomp.so.1 #2 0x00007f94b3c280cf in exec_blas () from /lib64/libopenblaso.so.0 #3 0x00007f94b3c263e4 in gemm_thread_n () from /lib64/libopenblaso.so.0 #4 0x00007f94b3c39077 in dgetrs_N_parallel () from /lib64/libopenblaso.so.0 #5 0x00007f94b39f7f65 in dgesv_ () from /lib64/libopenblaso.so.0 #6 0x00007f948556aebe in La_solve () from /usr/lib64/R/modules//lapack.so #7 0x00007f948556e555 in mod_do_lapack () from /usr/lib64/R/modules//lapack.so #8 0x00007f94b67a9c93 in bcEval () from /usr/lib64/R/lib/libR.so #9 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #10 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #11 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #12 0x00007f94b68045d3 in dispatchMethod.isra.4 () from /usr/lib64/R/lib/libR.so #13 0x00007f94b6804a1c in Rf_usemethod () from /usr/lib64/R/lib/libR.so #14 0x00007f94b6804db9 in do_usemethod () from /usr/lib64/R/lib/libR.so #15 0x00007f94b67ad9b2 in bcEval () from /usr/lib64/R/lib/libR.so #16 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #17 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #18 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #19 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #20 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #21 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #22 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #23 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #24 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #25 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #26 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #27 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #28 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #29 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #30 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #31 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #32 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #33 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #34 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #35 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #36 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #37 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #38 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #39 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #40 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #41 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #42 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so --Type for more, q to quit, c to continue without paging--c #43 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #44 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #45 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #46 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #47 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #48 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #49 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #50 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #51 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #52 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #53 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #54 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #55 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #56 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #57 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #58 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #59 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #60 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #61 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #62 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #63 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #64 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #65 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #66 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #67 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #68 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #69 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #70 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #71 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #72 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #73 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #74 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #75 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #76 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #77 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #78 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #79 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #80 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #81 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #82 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #83 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #84 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #85 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #86 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #87 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #88 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #89 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #90 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #91 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #92 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #93 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #94 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #95 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #96 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #97 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #98 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #99 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #100 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #101 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #102 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #103 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #104 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #105 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #106 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #107 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #108 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #109 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #110 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #111 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #112 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #113 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #114 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #115 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #116 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #117 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #118 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #119 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #120 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #121 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #122 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #123 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #124 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #125 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #126 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #127 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #128 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #129 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #130 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #131 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #132 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #133 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #134 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #135 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #136 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #137 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #138 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #139 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #140 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #141 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #142 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #143 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #144 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #145 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #146 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #147 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #148 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #149 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #150 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #151 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #152 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #153 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #154 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #155 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #156 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #157 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #158 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #159 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #160 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #161 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #162 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #163 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #164 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #165 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #166 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #167 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #168 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #169 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #170 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #171 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #172 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #173 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #174 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #175 0x00007f94b67c2255 in R_forceAndCall () from /usr/lib64/R/lib/libR.so #176 0x00007f94b66f429f in do_lapply () from /usr/lib64/R/lib/libR.so #177 0x00007f94b680232a in do_internal () from /usr/lib64/R/lib/libR.so #178 0x00007f94b67ad9b2 in bcEval () from /usr/lib64/R/lib/libR.so #179 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #180 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #181 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #182 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #183 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #184 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #185 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #186 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #187 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #188 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #189 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #190 0x00007f94b67bcc20 in Rf_eval () from /usr/lib64/R/lib/libR.so #191 0x00007f94b67f192a in Rf_ReplIteration () from /usr/lib64/R/lib/libR.so #192 0x00007f94b67f1c71 in R_ReplConsole () from /usr/lib64/R/lib/libR.so #193 0x00007f94b67f1d30 in run_Rmainloop () from /usr/lib64/R/lib/libR.so #194 0x000055f0700ed8ff in main () FOR 3858 (gdb) backtrace #0 0x00007f94b6454053 in gomp_team_barrier_wait_end () from /lib64/libgomp.so.1 #1 0x00007f94b6452a7d in gomp_team_end () from /lib64/libgomp.so.1 #2 0x00007f94b3c280cf in exec_blas () from /lib64/libopenblaso.so.0 #3 0x00007f94b3c263e4 in gemm_thread_n () from /lib64/libopenblaso.so.0 #4 0x00007f94b3c39077 in dgetrs_N_parallel () from /lib64/libopenblaso.so.0 #5 0x00007f94b39f7f65 in dgesv_ () from /lib64/libopenblaso.so.0 #6 0x00007f948556aebe in La_solve () from /usr/lib64/R/modules//lapack.so #7 0x00007f948556e555 in mod_do_lapack () from /usr/lib64/R/modules//lapack.so #8 0x00007f94b67a9c93 in bcEval () from /usr/lib64/R/lib/libR.so #9 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #10 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #11 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #12 0x00007f94b68045d3 in dispatchMethod.isra.4 () from /usr/lib64/R/lib/libR.so #13 0x00007f94b6804a1c in Rf_usemethod () from /usr/lib64/R/lib/libR.so #14 0x00007f94b6804db9 in do_usemethod () from /usr/lib64/R/lib/libR.so #15 0x00007f94b67ad9b2 in bcEval () from /usr/lib64/R/lib/libR.so #16 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #17 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #18 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #19 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #20 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #21 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #22 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #23 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #24 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #25 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #26 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #27 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #28 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #29 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #30 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #31 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #32 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #33 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #34 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #35 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #36 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #37 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #38 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #39 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #40 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #41 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #42 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so --Type for more, q to quit, c to continue without paging--c #43 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #44 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #45 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #46 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #47 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #48 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #49 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #50 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #51 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #52 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #53 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #54 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #55 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #56 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #57 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #58 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #59 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #60 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #61 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #62 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #63 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #64 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #65 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #66 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #67 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #68 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #69 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #70 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #71 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #72 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #73 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #74 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #75 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #76 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #77 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #78 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #79 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #80 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #81 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #82 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #83 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #84 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #85 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #86 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #87 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #88 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #89 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #90 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #91 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #92 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #93 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #94 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #95 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #96 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #97 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #98 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #99 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #100 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #101 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #102 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #103 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #104 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #105 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #106 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #107 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #108 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #109 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #110 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #111 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #112 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #113 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #114 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #115 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #116 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #117 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #118 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #119 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #120 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #121 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #122 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #123 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #124 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #125 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #126 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #127 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #128 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #129 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #130 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #131 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #132 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #133 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #134 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #135 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #136 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #137 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #138 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #139 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #140 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #141 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #142 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #143 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #144 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #145 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #146 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #147 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #148 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #149 0x00007f94b67bd44c in forcePromise () from /usr/lib64/R/lib/libR.so #150 0x00007f94b67bd8d8 in getvar () from /usr/lib64/R/lib/libR.so #151 0x00007f94b67b1325 in bcEval () from /usr/lib64/R/lib/libR.so #152 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #153 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #154 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #155 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #156 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #157 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #158 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #159 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #160 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #161 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #162 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #163 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #164 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #165 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #166 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #167 0x00007f94b67c2255 in R_forceAndCall () from /usr/lib64/R/lib/libR.so #168 0x00007f94b66f429f in do_lapply () from /usr/lib64/R/lib/libR.so #169 0x00007f94b680232a in do_internal () from /usr/lib64/R/lib/libR.so #170 0x00007f94b67ad9b2 in bcEval () from /usr/lib64/R/lib/libR.so #171 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #172 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #173 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #174 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #175 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #176 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #177 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #178 0x00007f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so #179 0x00007f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so #180 0x00007f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so #181 0x00007f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so #182 0x00007f94b67bcc20 in Rf_eval () from /usr/lib64/R/lib/libR.so #183 0x00007f94b67f192a in Rf_ReplIteration () from /usr/lib64/R/lib/libR.so #184 0x00007f94b67f1c71 in R_ReplConsole () from /usr/lib64/R/lib/libR.so #185 0x00007f94b67f1d30 in run_Rmainloop () from /usr/lib64/R/lib/libR.so #186 0x000055f0700ed8ff in main () I hope this is enough for you to pinpoint the cause of the inconsistency...... WAITING EAGERLY FOR A POSITIVE REPLY.... THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Ivan Krylov Sent: Saturday, June 10, 2023 2:46 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] inconsistency in mclapply..... On Sat, 10 Jun 2023 08:42:37 +0000 akshay kulkarni wrote: > This is the output of top when I run function LOWp() with mclapply > also in it. it hangs: > %Cpu0 : 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 > si, 0.0 st > %Cpu1 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 > si, 0.0 st I see. The system is idle. > TRaceback of after interrupting LOWp: > > > > LOWp(OHLCDataEP[[63]]) > ^C > There were 50 or more warnings (use warnings() to see the first 50) What are the warnings()? > > traceback() > 3: selectChildren(jobs[!is.na(jobsp)], -1) > 2: mclapply(LYGH, FUN = arfima, mc.cores = 2, mc.preschedule = FALSE) > at #26 > 1: LOWp(OHLCDataEP[[63]]) ...and the parent is stuck waiting for at least some of the children. The problem must be inside the child processes. > BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so If you start R like this: OPENBLAS_NUM_THREADS=1 R ...and confirm that Sys.getenv('OPENBLAS_NUM_THREADS') returns 1, then try running your analysis, does it still get stuck? There are reports complaining about OpenBLAS failing fork() tests when built with OpenMP support, and this 'o' at the end of the shared library name looks suspicious. > You had asked me to attach a debugger to the child processes. How do > you get the child processes spawned by mclapply? For example, how do > i identify, among the listed R processes above, the child processes? Make sure that there's only one R session running. Stray R processes can be cleaned up by running killall R or rebooting the AWS virtual machine. Start R and run Sys.getpid(). This is the PID of the parent process. Start your analysis and get it stuck. Do not interrupt the function, let it keep waiting for the child process. In a separate ssh connection or virtual terminal, run top. It should be possible to type lowercase v to display a process tree, then navigate it using arrow keys. Confirm that there is a parent R process with the PID you saw above and a number of child processes branching from it with different PIDs. If there's more than one child, try them both and see if the results are different (hopefully not). Run gdb and enter the following commands (substitute the value of the PID for PID_OF_THE_CHILD_PROCESS): attach PID_OF_THE_CHILD_PROCESS thread apply all backtrace If there's too much text and you can't copy it out of the terminal, use the commands "set logging file gdb.log" and "set logging on", then get the text output from the file "gdb.log" that will be created in the current directory. -- Best regards, Ivan [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Sat Jun 10 14:12:42 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Sat, 10 Jun 2023 15:12:42 +0300 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> Message-ID: <20230610151242.38cd3980@Tarkus> On Sat, 10 Jun 2023 11:49:10 +0000 akshay kulkarni wrote: > (gdb) backtrace > #0 0x00007f94b6454053 in gomp_team_barrier_wait_end () from /lib64/libgomp.so.1 > #1 0x00007f94b6452a7d in gomp_team_end () from /lib64/libgomp.so.1 > #2 0x00007f94b3c280cf in exec_blas () from /lib64/libopenblaso.so.0 > #3 0x00007f94b3c263e4 in gemm_thread_n () from /lib64/libopenblaso.so.0 > #4 0x00007f94b3c39077 in dgetrs_N_parallel () from /lib64/libopenblaso.so.0 > #5 0x00007f94b39f7f65 in dgesv_ () from /lib64/libopenblaso.so.0 > #6 0x00007f948556aebe in La_solve () from /usr/lib64/R/modules//lapack.so > #7 0x00007f948556e555 in mod_do_lapack () from /usr/lib64/R/modules//lapack.so > #8 0x00007f94b67a9c93 in bcEval () from /usr/lib64/R/lib/libR.so I'm afraid this is exactly OpenBLAS trying to use OpenMP and failing because it currently breaks in programs that fork(). Related links are and . I was hoping that setting OPENBLAS_NUM_THREADS=1 would prevent OpenBLAS from trying to use OpenMP, but that doesn't seem to work. If you replace OPENBLAS_NUM_THREADS with OMP_NUM_THREADS (in order to limit the number on OpenMP side), does it also not work? How did you install OpenBLAS on this machine? If my environment variable adjustments don't work, you'll need to either replace OpenBLAS with a different build (for example, one that uses pthreads instead of OpenMP, or a pure single-thread build, since you're already using mclapply), or even remove OpenBLAS altogether and replace it with a different BLAS that is fork()-safe. -- Best regards, Ivan From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 10 15:46:12 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 10 Jun 2023 13:46:12 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: <20230610151242.38cd3980@Tarkus> References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> <20230610151242.38cd3980@Tarkus> Message-ID: Dear Ivan, What if I switch to Ubuntu? I had a similar ( but not exactly the same) problem way back in 2018 and switching to Ubuntu solved it. Thanking you, Yours sincerely, Akshay M Kulkarni ________________________________ From: Ivan Krylov Sent: Saturday, June 10, 2023 5:42 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] inconsistency in mclapply..... On Sat, 10 Jun 2023 11:49:10 +0000 akshay kulkarni wrote: > (gdb) backtrace > #0 0x00007f94b6454053 in gomp_team_barrier_wait_end () from /lib64/libgomp.so.1 > #1 0x00007f94b6452a7d in gomp_team_end () from /lib64/libgomp.so.1 > #2 0x00007f94b3c280cf in exec_blas () from /lib64/libopenblaso.so.0 > #3 0x00007f94b3c263e4 in gemm_thread_n () from /lib64/libopenblaso.so.0 > #4 0x00007f94b3c39077 in dgetrs_N_parallel () from /lib64/libopenblaso.so.0 > #5 0x00007f94b39f7f65 in dgesv_ () from /lib64/libopenblaso.so.0 > #6 0x00007f948556aebe in La_solve () from /usr/lib64/R/modules//lapack.so > #7 0x00007f948556e555 in mod_do_lapack () from /usr/lib64/R/modules//lapack.so > #8 0x00007f94b67a9c93 in bcEval () from /usr/lib64/R/lib/libR.so I'm afraid this is exactly OpenBLAS trying to use OpenMP and failing because it currently breaks in programs that fork(). Related links are and . I was hoping that setting OPENBLAS_NUM_THREADS=1 would prevent OpenBLAS from trying to use OpenMP, but that doesn't seem to work. If you replace OPENBLAS_NUM_THREADS with OMP_NUM_THREADS (in order to limit the number on OpenMP side), does it also not work? How did you install OpenBLAS on this machine? If my environment variable adjustments don't work, you'll need to either replace OpenBLAS with a different build (for example, one that uses pthreads instead of OpenMP, or a pure single-thread build, since you're already using mclapply), or even remove OpenBLAS altogether and replace it with a different BLAS that is fork()-safe. -- Best regards, Ivan [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Sat Jun 10 16:20:16 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Sat, 10 Jun 2023 17:20:16 +0300 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> <20230610151242.38cd3980@Tarkus> Message-ID: <20230610172016.0fe28e0a@Tarkus> On Sat, 10 Jun 2023 13:46:12 +0000 akshay kulkarni wrote: > What if I switch to Ubuntu? > I had a similar ( but not exactly the same) problem way back in 2018 > and switching to Ubuntu solved it. You shouldn't have to switch distros for problems like this one. What you need to switch is your OpenBLAS build: instead of using OpenBLAS built with OpenMP support (which isn't even the default when compiling OpenBLAS), use OpenBLAS built with pthreads support. It's also likely, but not 100% guaranteed, that setting OMP_NUM_THREADS=1 will avoid the issue by never starting any additional threads for OpenBLAS purposes. At least some documentation says that OPENBLAS_NUM_THREADS is ignored on OpenMP builds of OpenBLAS, you actually have to set OMP_NUM_THREADS=1 for it to take any effect. I know very little about RHEL, but it seems that you already have a pthreads build of OpenBLAS installed in /usr/lib64/libopenblasp-r0.3.15.so; you just need to adjust the path to the BLAS implementation used by R. If not, install the openblas-threads package. Can you use flexiblas to switch the BLAS implementation to OPENBLAS-THREADS? This should be possible by using the flexiblas R package or by setting environment variables . That said, I know for sure that on Debian and Ubuntu you get a choice between libopenblas0-openmp / libopenblas0-pthread / libopenblas0-serial, and installing any one of these packages except libopenblas0-openmp should avoid the problem. (And the thread limit should be set to 1 if you're running your tasks in parallel by other means.) -- Best regards, Ivan From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 10 16:44:12 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 10 Jun 2023 14:44:12 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: <20230610172016.0fe28e0a@Tarkus> References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> <20230610151242.38cd3980@Tarkus> <20230610172016.0fe28e0a@Tarkus> Message-ID: Dear Ivan, A million thanks for your precious time.... Thanking you Yours sincerely, AkshayMKulkarni ________________________________ From: Ivan Krylov Sent: Saturday, June 10, 2023 7:50 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] inconsistency in mclapply..... On Sat, 10 Jun 2023 13:46:12 +0000 akshay kulkarni wrote: > What if I switch to Ubuntu? > I had a similar ( but not exactly the same) problem way back in 2018 > and switching to Ubuntu solved it. You shouldn't have to switch distros for problems like this one. What you need to switch is your OpenBLAS build: instead of using OpenBLAS built with OpenMP support (which isn't even the default when compiling OpenBLAS), use OpenBLAS built with pthreads support. It's also likely, but not 100% guaranteed, that setting OMP_NUM_THREADS=1 will avoid the issue by never starting any additional threads for OpenBLAS purposes. At least some documentation says that OPENBLAS_NUM_THREADS is ignored on OpenMP builds of OpenBLAS, you actually have to set OMP_NUM_THREADS=1 for it to take any effect. I know very little about RHEL, but it seems that you already have a pthreads build of OpenBLAS installed in /usr/lib64/libopenblasp-r0.3.15.so; you just need to adjust the path to the BLAS implementation used by R. If not, install the openblas-threads package. Can you use flexiblas to switch the BLAS implementation to OPENBLAS-THREADS? This should be possible by using the flexiblas R package or by setting environment variables . That said, I know for sure that on Debian and Ubuntu you get a choice between libopenblas0-openmp / libopenblas0-pthread / libopenblas0-serial, and installing any one of these packages except libopenblas0-openmp should avoid the problem. (And the thread limit should be set to 1 if you're running your tasks in parallel by other means.) -- Best regards, Ivan [[alternative HTML version deleted]] From @te|@no@@o||@ @end|ng |rom reg|one@m@rche@|t Sat Jun 10 17:48:17 2023 From: @te|@no@@o||@ @end|ng |rom reg|one@m@rche@|t (Stefano Sofia) Date: Sat, 10 Jun 2023 15:48:17 +0000 Subject: [R] aggregate wind direction data with wind speed required In-Reply-To: References: <879769e2d65d41e89bf0ca6593a78e04@regione.marche.it>, Message-ID: Sorry for the big delay of my report, but prolonged severe weather conditions often absorb a large amount of time and energies to my studies. Thanks to all of you for your suggestions. I have not been able to implement Bert Gunter's hint, his code gave me an error I have not been able to fix. Bill Dunlap's hint is smart and has been resolutive. Thank you again to all of you 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.sofia at regione.marche.it ---Oo---------oO---------------------------------------- ________________________________ Da: Bill Dunlap Inviato: sabato 13 maggio 2023 22:38 A: Stefano Sofia Cc: r-help at R-project.org Oggetto: Re: [R] aggregate wind direction data with wind speed required 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 > 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.sofia at 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Questo messaggio ? stato analizzato con Libraesva ESG ed ? risultato non infetto ________________________________ 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]] From j@b@y@t194 @end|ng |rom gm@||@com Sun Jun 11 22:05:05 2023 From: j@b@y@t194 @end|ng |rom gm@||@com (javad bayat) Date: Sun, 11 Jun 2023 23:35:05 +0330 Subject: [R] Problem with filling dataframe's column Message-ID: Dear R users; I am trying to fill a column based on a specific value in another column of a dataframe, but it seems there is a problem with the codes! The "Layer" and the "LU" are two different columns of the dataframe. How can I fix this? Sincerely for (i in 1:nrow(data2$Layer)){ if (data2$Layer == "Level 12") { data2$LU == "Park" } } -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat194 at yahoo.com [[alternative HTML version deleted]] From ru|pb@rr@d@@ @end|ng |rom @@po@pt Sun Jun 11 12:13:28 2023 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Sun, 11 Jun 2023 11:13:28 +0100 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: Message-ID: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> ?s 21:05 de 11/06/2023, javad bayat escreveu: > Dear R users; > I am trying to fill a column based on a specific value in another column of > a dataframe, but it seems there is a problem with the codes! > The "Layer" and the "LU" are two different columns of the dataframe. > How can I fix this? > Sincerely > > > for (i in 1:nrow(data2$Layer)){ > if (data2$Layer == "Level 12") { > data2$LU == "Park" > } > } > > > > Hello, There are two bugs in your code, 1) the index i is not used in the loop 2) the assignment operator is `<-`, not `==` Here is the loop corrected. for (i in 1:nrow(data2$Layer)){ if (data2$Layer[i] == "Level 12") { data2$LU[i] <- "Park" } } But R is a vectorized language, the following two ways are the idiomac ways of doing what you want to do. i <- data2$Layer == "Level 12" data2$LU[i] <- "Park" # equivalent one-liner data2$LU[data2$Layer == "Level 12"] <- "Park" If there are NA's in data2$Layer it's probably safer to use ?which() in the logical index, to have a numeric one. i <- which(data2$Layer == "Level 12") data2$LU[i] <- "Park" # equivalent one-liner data2$LU[which(data2$Layer == "Level 12")] <- "Park" Hope this helps, Rui Barradas From j@b@y@t194 @end|ng |rom gm@||@com Sun Jun 11 23:54:52 2023 From: j@b@y@t194 @end|ng |rom gm@||@com (javad bayat) Date: Mon, 12 Jun 2023 01:24:52 +0330 Subject: [R] Problem with filling dataframe's column In-Reply-To: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> Message-ID: Dear Rui; Many thanks for your email. I used one of your codes, "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works correctly for me. Actually I need to expand the codes so as to consider all "Levels" in the "Layer" column. There are more than hundred levels in the Layer column. If I use your provided code, I have to write it hundred of time as below: data2$LU[which(data2$Layer == "Level 1")] <- "Park"; data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; ... ... ... . Is there any other way to expand the code in order to consider all of the levels simultaneously? Like the below code: data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] <- c("Park", "Agri", "GS", ...) Sincerely On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas wrote: > ?s 21:05 de 11/06/2023, javad bayat escreveu: > > Dear R users; > > I am trying to fill a column based on a specific value in another column > of > > a dataframe, but it seems there is a problem with the codes! > > The "Layer" and the "LU" are two different columns of the dataframe. > > How can I fix this? > > Sincerely > > > > > > for (i in 1:nrow(data2$Layer)){ > > if (data2$Layer == "Level 12") { > > data2$LU == "Park" > > } > > } > > > > > > > > > Hello, > > There are two bugs in your code, > > 1) the index i is not used in the loop > 2) the assignment operator is `<-`, not `==` > > > Here is the loop corrected. > > for (i in 1:nrow(data2$Layer)){ > if (data2$Layer[i] == "Level 12") { > data2$LU[i] <- "Park" > } > } > > > > But R is a vectorized language, the following two ways are the idiomac > ways of doing what you want to do. > > > > i <- data2$Layer == "Level 12" > data2$LU[i] <- "Park" > > # equivalent one-liner > data2$LU[data2$Layer == "Level 12"] <- "Park" > > > > If there are NA's in data2$Layer it's probably safer to use ?which() in > the logical index, to have a numeric one. > > > > i <- which(data2$Layer == "Level 12") > data2$LU[i] <- "Park" > > # equivalent one-liner > data2$LU[which(data2$Layer == "Level 12")] <- "Park" > > > Hope this helps, > > Rui Barradas > -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat194 at yahoo.com [[alternative HTML version deleted]] From ru|pb@rr@d@@ @end|ng |rom @@po@pt Sun Jun 11 14:18:25 2023 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Sun, 11 Jun 2023 13:18:25 +0100 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> Message-ID: <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> ?s 22:54 de 11/06/2023, javad bayat escreveu: > Dear Rui; > Many thanks for your email. I used one of your codes, > "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works > correctly for me. > Actually I need to expand the codes so as to consider all "Levels" in the > "Layer" column. There are more than hundred levels in the Layer column. > If I use your provided code, I have to write it hundred of time as below: > data2$LU[which(data2$Layer == "Level 1")] <- "Park"; > data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; > ... > ... > ... > . > Is there any other way to expand the code in order to consider all of the > levels simultaneously? Like the below code: > data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] <- > c("Park", "Agri", "GS", ...) > > > Sincerely > > > > > On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas wrote: > >> ?s 21:05 de 11/06/2023, javad bayat escreveu: >>> Dear R users; >>> I am trying to fill a column based on a specific value in another column >> of >>> a dataframe, but it seems there is a problem with the codes! >>> The "Layer" and the "LU" are two different columns of the dataframe. >>> How can I fix this? >>> Sincerely >>> >>> >>> for (i in 1:nrow(data2$Layer)){ >>> if (data2$Layer == "Level 12") { >>> data2$LU == "Park" >>> } >>> } >>> >>> >>> >>> >> Hello, >> >> There are two bugs in your code, >> >> 1) the index i is not used in the loop >> 2) the assignment operator is `<-`, not `==` >> >> >> Here is the loop corrected. >> >> for (i in 1:nrow(data2$Layer)){ >> if (data2$Layer[i] == "Level 12") { >> data2$LU[i] <- "Park" >> } >> } >> >> >> >> But R is a vectorized language, the following two ways are the idiomac >> ways of doing what you want to do. >> >> >> >> i <- data2$Layer == "Level 12" >> data2$LU[i] <- "Park" >> >> # equivalent one-liner >> data2$LU[data2$Layer == "Level 12"] <- "Park" >> >> >> >> If there are NA's in data2$Layer it's probably safer to use ?which() in >> the logical index, to have a numeric one. >> >> >> >> i <- which(data2$Layer == "Level 12") >> data2$LU[i] <- "Park" >> >> # equivalent one-liner >> data2$LU[which(data2$Layer == "Level 12")] <- "Park" >> >> >> Hope this helps, >> >> Rui Barradas >> > > Hello, You don't need to repeat the same instruction 100+ times, there is a way of assigning all new LU values at the same time with match(). This assumes that you have the new values in a vector. Values <- sort(unique(data2$Layer)) Names <- c("Park", "Agri", "GS") i <- match(data2$Layer, Values) data2$LU <- Names[i] Hope this helps, Rui Barradas From ru|pb@rr@d@@ @end|ng |rom @@po@pt Sun Jun 11 15:33:54 2023 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Sun, 11 Jun 2023 14:33:54 +0100 Subject: [R] Problem with filling dataframe's column In-Reply-To: <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> Message-ID: <9b68cd98-2bda-50d8-a43f-4fc01e5e97a6@sapo.pt> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: > ?s 22:54 de 11/06/2023, javad bayat escreveu: >> Dear Rui; >> Many thanks for your email. I used one of your codes, >> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works >> correctly for me. >> Actually I need to expand the codes so as to consider all "Levels" in the >> "Layer" column. There are more than hundred levels in the Layer column. >> If I use your provided code, I have to write it hundred of time as below: >> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; >> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; >> ... >> ... >> ... >> . >> Is there any other way to expand the code in order to consider all of the >> levels simultaneously? Like the below code: >> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] <- >> c("Park", "Agri", "GS", ...) >> >> >> Sincerely >> >> >> >> >> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas >> wrote: >> >>> ?s 21:05 de 11/06/2023, javad bayat escreveu: >>>> Dear R users; >>>> I am trying to fill a column based on a specific value in another >>>> column >>> of >>>> a dataframe, but it seems there is a problem with the codes! >>>> The "Layer" and the "LU" are two different columns of the dataframe. >>>> How can I fix this? >>>> Sincerely >>>> >>>> >>>> for (i in 1:nrow(data2$Layer)){ >>>> ??????????? if (data2$Layer == "Level 12") { >>>> ??????????????? data2$LU == "Park" >>>> ??????????????? } >>>> ??????????? } >>>> >>>> >>>> >>>> >>> Hello, >>> >>> There are two bugs in your code, >>> >>> 1) the index i is not used in the loop >>> 2) the assignment operator is `<-`, not `==` >>> >>> >>> Here is the loop corrected. >>> >>> for (i in 1:nrow(data2$Layer)){ >>> ??? if (data2$Layer[i] == "Level 12") { >>> ????? data2$LU[i] <- "Park" >>> ??? } >>> } >>> >>> >>> >>> But R is a vectorized language, the following two ways are the idiomac >>> ways of doing what you want to do. >>> >>> >>> >>> i <- data2$Layer == "Level 12" >>> data2$LU[i] <- "Park" >>> >>> # equivalent one-liner >>> data2$LU[data2$Layer == "Level 12"] <- "Park" >>> >>> >>> >>> If there are NA's in data2$Layer it's probably safer to use ?which() in >>> the logical index, to have a numeric one. >>> >>> >>> >>> i <- which(data2$Layer == "Level 12") >>> data2$LU[i] <- "Park" >>> >>> # equivalent one-liner >>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" >>> >>> >>> Hope this helps, >>> >>> Rui Barradas >>> >> >> > Hello, > > You don't need to repeat the same instruction 100+ times, there is a way > of assigning all new LU values at the same time with match(). > This assumes that you have the new values in a vector. Sorry, this is not clear. I mean This assumes that you have the new values in a vector, the vector Names below. The vector of values to be matched is created from the data. Rui Barradas > > > Values <- sort(unique(data2$Layer)) > Names <- c("Park", "Agri", "GS") > > i <- match(data2$Layer, Values) > data2$LU <- Names[i] > > > Hope this helps, > > Rui Barradas > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From @vi@e@gross m@iii@g oii gm@ii@com Sun Jun 11 16:58:30 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Sun, 11 Jun 2023 10:58:30 -0400 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: Message-ID: <002601d99c75$2f6560a0$8e3021e0$@gmail.com> The problem being discussed is really a common operation that R handles quite easily in many ways. The code shown has way too many things that do not fit to make much sense and is not written the way many R programmers would write it. Loops like the one used are legal but not needed. As has been noted, use of "==" for assignment is the wrong choice. Not using some method to refer to a specific cell would still result in odd behavior. One accepted and common method s to do this vectorized as you are dealing with two vectors of the same size. Code like: Matches <- Data2$Layer == "Level 12" Will result in a Boolean vector containing TRUE where it found a match, FALSE otherwise. Now you can use the above as a sort of indexing as in: data2$LU[Matches] <- "Park" Only the indexes marked TRUE will be selected and set to the new value. Of course, the two lines can be combined as: data2$LU[Data2$Layer == "Level 12"] <- "Park" There are also alternatives where people use functions like ifelse() also in base R. And, of course, some people like alternate packages such as in the Tidyverse where you might have used a mutate() or other methods. -----Original Message----- From: R-help On Behalf Of javad bayat Sent: Sunday, June 11, 2023 4:05 PM To: R-help at r-project.org Subject: [R] Problem with filling dataframe's column Dear R users; I am trying to fill a column based on a specific value in another column of a dataframe, but it seems there is a problem with the codes! The "Layer" and the "LU" are two different columns of the dataframe. How can I fix this? Sincerely for (i in 1:nrow(data2$Layer)){ if (data2$Layer == "Level 12") { data2$LU == "Park" } } -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat194 at yahoo.com [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From ru|pb@rr@d@@ @end|ng |rom @@po@pt Mon Jun 12 15:46:21 2023 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Mon, 12 Jun 2023 14:46:21 +0100 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> <9b68cd98-2bda-50d8-a43f-4fc01e5e97a6@sapo.pt> Message-ID: <6ef99052-964d-b462-5613-509563d15fc5@sapo.pt> ?s 23:13 de 12/06/2023, javad bayat escreveu: > Dear Rui; > Many thanks for the email. I tried your codes and found that the length of > the "Values" and "Names" vectors must be equal, otherwise the results will > not be useful. > For some of the characters in the Layer column that I do not need to be > filled in the LU column, I used "NA". > But I need to delete some of the rows from the table as they are useless > for me. I tried this code to delete entire rows of the dataframe which > contained these three value in the Layer column: It gave me the following > error. > >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] > Warning message: > In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : > argument 'pattern' has length > 1 and only the first element will be > used > >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] > Warning message: > In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : > argument 'pattern' has length > 1 and only the first element will be > used > > How can I do this? > Sincerely > > > > > > > > > > > On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas wrote: > >> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: >>> ?s 22:54 de 11/06/2023, javad bayat escreveu: >>>> Dear Rui; >>>> Many thanks for your email. I used one of your codes, >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works >>>> correctly for me. >>>> Actually I need to expand the codes so as to consider all "Levels" in >> the >>>> "Layer" column. There are more than hundred levels in the Layer column. >>>> If I use your provided code, I have to write it hundred of time as >> below: >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; >>>> ... >>>> ... >>>> ... >>>> . >>>> Is there any other way to expand the code in order to consider all of >> the >>>> levels simultaneously? Like the below code: >>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] >> <- >>>> c("Park", "Agri", "GS", ...) >>>> >>>> >>>> Sincerely >>>> >>>> >>>> >>>> >>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas >>>> wrote: >>>> >>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: >>>>>> Dear R users; >>>>>> I am trying to fill a column based on a specific value in another >>>>>> column >>>>> of >>>>>> a dataframe, but it seems there is a problem with the codes! >>>>>> The "Layer" and the "LU" are two different columns of the dataframe. >>>>>> How can I fix this? >>>>>> Sincerely >>>>>> >>>>>> >>>>>> for (i in 1:nrow(data2$Layer)){ >>>>>> if (data2$Layer == "Level 12") { >>>>>> data2$LU == "Park" >>>>>> } >>>>>> } >>>>>> >>>>>> >>>>>> >>>>>> >>>>> Hello, >>>>> >>>>> There are two bugs in your code, >>>>> >>>>> 1) the index i is not used in the loop >>>>> 2) the assignment operator is `<-`, not `==` >>>>> >>>>> >>>>> Here is the loop corrected. >>>>> >>>>> for (i in 1:nrow(data2$Layer)){ >>>>> if (data2$Layer[i] == "Level 12") { >>>>> data2$LU[i] <- "Park" >>>>> } >>>>> } >>>>> >>>>> >>>>> >>>>> But R is a vectorized language, the following two ways are the idiomac >>>>> ways of doing what you want to do. >>>>> >>>>> >>>>> >>>>> i <- data2$Layer == "Level 12" >>>>> data2$LU[i] <- "Park" >>>>> >>>>> # equivalent one-liner >>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" >>>>> >>>>> >>>>> >>>>> If there are NA's in data2$Layer it's probably safer to use ?which() in >>>>> the logical index, to have a numeric one. >>>>> >>>>> >>>>> >>>>> i <- which(data2$Layer == "Level 12") >>>>> data2$LU[i] <- "Park" >>>>> >>>>> # equivalent one-liner >>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" >>>>> >>>>> >>>>> Hope this helps, >>>>> >>>>> Rui Barradas >>>>> >>>> >>>> >>> Hello, >>> >>> You don't need to repeat the same instruction 100+ times, there is a way >>> of assigning all new LU values at the same time with match(). >>> This assumes that you have the new values in a vector. >> >> Sorry, this is not clear. I mean >> >> >> This assumes that you have the new values in a vector, the vector Names >> below. The vector of values to be matched is created from the data. >> >> >> Rui Barradas >> >>> >>> >>> Values <- sort(unique(data2$Layer)) >>> Names <- c("Park", "Agri", "GS") >>> >>> i <- match(data2$Layer, Values) >>> data2$LU <- Names[i] >>> >>> >>> Hope this helps, >>> >>> Rui Barradas >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/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, Please cc the r-help list, R-Help is threaded and this can in the future be helpful to others. You can combine several patters like this: pat <- c("_esmdes|_Des Section|0") grep(pat, data2$Layer) or, programatically, pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") Hope this helps, Rui Barradas From j@b@y@t194 @end|ng |rom gm@||@com Tue Jun 13 18:18:17 2023 From: j@b@y@t194 @end|ng |rom gm@||@com (javad bayat) Date: Tue, 13 Jun 2023 19:48:17 +0330 Subject: [R] Problem with filling dataframe's column In-Reply-To: <6ef99052-964d-b462-5613-509563d15fc5@sapo.pt> References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> <9b68cd98-2bda-50d8-a43f-4fc01e5e97a6@sapo.pt> <6ef99052-964d-b462-5613-509563d15fc5@sapo.pt> Message-ID: Dear Rui; Hi. I used your codes, but it seems it didn't work for me. > pat <- c("_esmdes|_Des Section|0") > dim(data2) [1] 281549 9 > grep(pat, data2$Layer) > dim(data2) [1] 281549 9 What does grep function do? I expected the function to remove 3 rows of the dataframe. I do not know the reason. On Mon, Jun 12, 2023 at 5:16?PM Rui Barradas wrote: > ?s 23:13 de 12/06/2023, javad bayat escreveu: > > Dear Rui; > > Many thanks for the email. I tried your codes and found that the length > of > > the "Values" and "Names" vectors must be equal, otherwise the results > will > > not be useful. > > For some of the characters in the Layer column that I do not need to be > > filled in the LU column, I used "NA". > > But I need to delete some of the rows from the table as they are useless > > for me. I tried this code to delete entire rows of the dataframe which > > contained these three value in the Layer column: It gave me the following > > error. > > > >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] > > Warning message: > > In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > argument 'pattern' has length > 1 and only the first element will > be > > used > > > >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] > > Warning message: > > In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > argument 'pattern' has length > 1 and only the first element will be > > used > > > > How can I do this? > > Sincerely > > > > > > > > > > > > > > > > > > > > > > On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas > wrote: > > > >> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: > >>> ?s 22:54 de 11/06/2023, javad bayat escreveu: > >>>> Dear Rui; > >>>> Many thanks for your email. I used one of your codes, > >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works > >>>> correctly for me. > >>>> Actually I need to expand the codes so as to consider all "Levels" in > >> the > >>>> "Layer" column. There are more than hundred levels in the Layer > column. > >>>> If I use your provided code, I have to write it hundred of time as > >> below: > >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; > >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; > >>>> ... > >>>> ... > >>>> ... > >>>> . > >>>> Is there any other way to expand the code in order to consider all of > >> the > >>>> levels simultaneously? Like the below code: > >>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] > >> <- > >>>> c("Park", "Agri", "GS", ...) > >>>> > >>>> > >>>> Sincerely > >>>> > >>>> > >>>> > >>>> > >>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas > >>>> wrote: > >>>> > >>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: > >>>>>> Dear R users; > >>>>>> I am trying to fill a column based on a specific value in another > >>>>>> column > >>>>> of > >>>>>> a dataframe, but it seems there is a problem with the codes! > >>>>>> The "Layer" and the "LU" are two different columns of the dataframe. > >>>>>> How can I fix this? > >>>>>> Sincerely > >>>>>> > >>>>>> > >>>>>> for (i in 1:nrow(data2$Layer)){ > >>>>>> if (data2$Layer == "Level 12") { > >>>>>> data2$LU == "Park" > >>>>>> } > >>>>>> } > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>> Hello, > >>>>> > >>>>> There are two bugs in your code, > >>>>> > >>>>> 1) the index i is not used in the loop > >>>>> 2) the assignment operator is `<-`, not `==` > >>>>> > >>>>> > >>>>> Here is the loop corrected. > >>>>> > >>>>> for (i in 1:nrow(data2$Layer)){ > >>>>> if (data2$Layer[i] == "Level 12") { > >>>>> data2$LU[i] <- "Park" > >>>>> } > >>>>> } > >>>>> > >>>>> > >>>>> > >>>>> But R is a vectorized language, the following two ways are the > idiomac > >>>>> ways of doing what you want to do. > >>>>> > >>>>> > >>>>> > >>>>> i <- data2$Layer == "Level 12" > >>>>> data2$LU[i] <- "Park" > >>>>> > >>>>> # equivalent one-liner > >>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" > >>>>> > >>>>> > >>>>> > >>>>> If there are NA's in data2$Layer it's probably safer to use ?which() > in > >>>>> the logical index, to have a numeric one. > >>>>> > >>>>> > >>>>> > >>>>> i <- which(data2$Layer == "Level 12") > >>>>> data2$LU[i] <- "Park" > >>>>> > >>>>> # equivalent one-liner > >>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" > >>>>> > >>>>> > >>>>> Hope this helps, > >>>>> > >>>>> Rui Barradas > >>>>> > >>>> > >>>> > >>> Hello, > >>> > >>> You don't need to repeat the same instruction 100+ times, there is a > way > >>> of assigning all new LU values at the same time with match(). > >>> This assumes that you have the new values in a vector. > >> > >> Sorry, this is not clear. I mean > >> > >> > >> This assumes that you have the new values in a vector, the vector Names > >> below. The vector of values to be matched is created from the data. > >> > >> > >> Rui Barradas > >> > >>> > >>> > >>> Values <- sort(unique(data2$Layer)) > >>> Names <- c("Park", "Agri", "GS") > >>> > >>> i <- match(data2$Layer, Values) > >>> data2$LU <- Names[i] > >>> > >>> > >>> Hope this helps, > >>> > >>> Rui Barradas > >>> > >>> ______________________________________________ > >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >>> https://stat.ethz.ch/mailman/listinfo/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, > > Please cc the r-help list, R-Help is threaded and this can in the future > be helpful to others. > > You can combine several patters like this: > > > pat <- c("_esmdes|_Des Section|0") > grep(pat, data2$Layer) > > or, programatically, > > > pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") > > > Hope this helps, > > Rui Barradas > > -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat194 at yahoo.com [[alternative HTML version deleted]] From er|cjberger @end|ng |rom gm@||@com Tue Jun 13 10:05:49 2023 From: er|cjberger @end|ng |rom gm@||@com (Eric Berger) Date: Tue, 13 Jun 2023 11:05:49 +0300 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> <9b68cd98-2bda-50d8-a43f-4fc01e5e97a6@sapo.pt> <6ef99052-964d-b462-5613-509563d15fc5@sapo.pt> Message-ID: Hi Javed, grep returns the positions of the matches. See an example below. > v <- c("abc", "bcd", "def") > v [1] "abc" "bcd" "def" > grep("cd",v) [1] 2 > w <- v[-grep("cd",v)] > w [1] "abc" "def" > On Tue, Jun 13, 2023 at 8:50?AM javad bayat wrote: > > Dear Rui; > Hi. I used your codes, but it seems it didn't work for me. > > > pat <- c("_esmdes|_Des Section|0") > > dim(data2) > [1] 281549 9 > > grep(pat, data2$Layer) > > dim(data2) > [1] 281549 9 > > What does grep function do? I expected the function to remove 3 rows of the > dataframe. > I do not know the reason. > > > > > > > On Mon, Jun 12, 2023 at 5:16?PM Rui Barradas wrote: > > > ?s 23:13 de 12/06/2023, javad bayat escreveu: > > > Dear Rui; > > > Many thanks for the email. I tried your codes and found that the length > > of > > > the "Values" and "Names" vectors must be equal, otherwise the results > > will > > > not be useful. > > > For some of the characters in the Layer column that I do not need to be > > > filled in the LU column, I used "NA". > > > But I need to delete some of the rows from the table as they are useless > > > for me. I tried this code to delete entire rows of the dataframe which > > > contained these three value in the Layer column: It gave me the following > > > error. > > > > > >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] > > > Warning message: > > > In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > argument 'pattern' has length > 1 and only the first element will > > be > > > used > > > > > >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] > > > Warning message: > > > In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > argument 'pattern' has length > 1 and only the first element will be > > > used > > > > > > How can I do this? > > > Sincerely > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas > > wrote: > > > > > >> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: > > >>> ?s 22:54 de 11/06/2023, javad bayat escreveu: > > >>>> Dear Rui; > > >>>> Many thanks for your email. I used one of your codes, > > >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works > > >>>> correctly for me. > > >>>> Actually I need to expand the codes so as to consider all "Levels" in > > >> the > > >>>> "Layer" column. There are more than hundred levels in the Layer > > column. > > >>>> If I use your provided code, I have to write it hundred of time as > > >> below: > > >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; > > >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; > > >>>> ... > > >>>> ... > > >>>> ... > > >>>> . > > >>>> Is there any other way to expand the code in order to consider all of > > >> the > > >>>> levels simultaneously? Like the below code: > > >>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] > > >> <- > > >>>> c("Park", "Agri", "GS", ...) > > >>>> > > >>>> > > >>>> Sincerely > > >>>> > > >>>> > > >>>> > > >>>> > > >>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas > > >>>> wrote: > > >>>> > > >>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: > > >>>>>> Dear R users; > > >>>>>> I am trying to fill a column based on a specific value in another > > >>>>>> column > > >>>>> of > > >>>>>> a dataframe, but it seems there is a problem with the codes! > > >>>>>> The "Layer" and the "LU" are two different columns of the dataframe. > > >>>>>> How can I fix this? > > >>>>>> Sincerely > > >>>>>> > > >>>>>> > > >>>>>> for (i in 1:nrow(data2$Layer)){ > > >>>>>> if (data2$Layer == "Level 12") { > > >>>>>> data2$LU == "Park" > > >>>>>> } > > >>>>>> } > > >>>>>> > > >>>>>> > > >>>>>> > > >>>>>> > > >>>>> Hello, > > >>>>> > > >>>>> There are two bugs in your code, > > >>>>> > > >>>>> 1) the index i is not used in the loop > > >>>>> 2) the assignment operator is `<-`, not `==` > > >>>>> > > >>>>> > > >>>>> Here is the loop corrected. > > >>>>> > > >>>>> for (i in 1:nrow(data2$Layer)){ > > >>>>> if (data2$Layer[i] == "Level 12") { > > >>>>> data2$LU[i] <- "Park" > > >>>>> } > > >>>>> } > > >>>>> > > >>>>> > > >>>>> > > >>>>> But R is a vectorized language, the following two ways are the > > idiomac > > >>>>> ways of doing what you want to do. > > >>>>> > > >>>>> > > >>>>> > > >>>>> i <- data2$Layer == "Level 12" > > >>>>> data2$LU[i] <- "Park" > > >>>>> > > >>>>> # equivalent one-liner > > >>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" > > >>>>> > > >>>>> > > >>>>> > > >>>>> If there are NA's in data2$Layer it's probably safer to use ?which() > > in > > >>>>> the logical index, to have a numeric one. > > >>>>> > > >>>>> > > >>>>> > > >>>>> i <- which(data2$Layer == "Level 12") > > >>>>> data2$LU[i] <- "Park" > > >>>>> > > >>>>> # equivalent one-liner > > >>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" > > >>>>> > > >>>>> > > >>>>> Hope this helps, > > >>>>> > > >>>>> Rui Barradas > > >>>>> > > >>>> > > >>>> > > >>> Hello, > > >>> > > >>> You don't need to repeat the same instruction 100+ times, there is a > > way > > >>> of assigning all new LU values at the same time with match(). > > >>> This assumes that you have the new values in a vector. > > >> > > >> Sorry, this is not clear. I mean > > >> > > >> > > >> This assumes that you have the new values in a vector, the vector Names > > >> below. The vector of values to be matched is created from the data. > > >> > > >> > > >> Rui Barradas > > >> > > >>> > > >>> > > >>> Values <- sort(unique(data2$Layer)) > > >>> Names <- c("Park", "Agri", "GS") > > >>> > > >>> i <- match(data2$Layer, Values) > > >>> data2$LU <- Names[i] > > >>> > > >>> > > >>> Hope this helps, > > >>> > > >>> Rui Barradas > > >>> > > >>> ______________________________________________ > > >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > >>> https://stat.ethz.ch/mailman/listinfo/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, > > > > Please cc the r-help list, R-Help is threaded and this can in the future > > be helpful to others. > > > > You can combine several patters like this: > > > > > > pat <- c("_esmdes|_Des Section|0") > > grep(pat, data2$Layer) > > > > or, programatically, > > > > > > pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") > > > > > > Hope this helps, > > > > Rui Barradas > > > > > > -- > Best Regards > Javad Bayat > M.Sc. Environment Engineering > Alternative Mail: bayat194 at yahoo.com > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From j@b@y@t194 @end|ng |rom gm@||@com Tue Jun 13 21:46:51 2023 From: j@b@y@t194 @end|ng |rom gm@||@com (javad bayat) Date: Tue, 13 Jun 2023 23:16:51 +0330 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> <9b68cd98-2bda-50d8-a43f-4fc01e5e97a6@sapo.pt> <6ef99052-964d-b462-5613-509563d15fc5@sapo.pt> Message-ID: Dear all; I used these codes and I get what I wanted. Sincerely pat = c("Level 12","Level 22","0") data3 = data2[-which(data2$Layer == pat),] dim(data2) [1] 281549 9 dim(data3) [1] 244075 9 On Tue, Jun 13, 2023 at 11:36?AM Eric Berger wrote: > Hi Javed, > grep returns the positions of the matches. See an example below. > > > v <- c("abc", "bcd", "def") > > v > [1] "abc" "bcd" "def" > > grep("cd",v) > [1] 2 > > w <- v[-grep("cd",v)] > > w > [1] "abc" "def" > > > > > On Tue, Jun 13, 2023 at 8:50?AM javad bayat wrote: > > > > Dear Rui; > > Hi. I used your codes, but it seems it didn't work for me. > > > > > pat <- c("_esmdes|_Des Section|0") > > > dim(data2) > > [1] 281549 9 > > > grep(pat, data2$Layer) > > > dim(data2) > > [1] 281549 9 > > > > What does grep function do? I expected the function to remove 3 rows of > the > > dataframe. > > I do not know the reason. > > > > > > > > > > > > > > On Mon, Jun 12, 2023 at 5:16?PM Rui Barradas > wrote: > > > > > ?s 23:13 de 12/06/2023, javad bayat escreveu: > > > > Dear Rui; > > > > Many thanks for the email. I tried your codes and found that the > length > > > of > > > > the "Values" and "Names" vectors must be equal, otherwise the results > > > will > > > > not be useful. > > > > For some of the characters in the Layer column that I do not need to > be > > > > filled in the LU column, I used "NA". > > > > But I need to delete some of the rows from the table as they are > useless > > > > for me. I tried this code to delete entire rows of the dataframe > which > > > > contained these three value in the Layer column: It gave me the > following > > > > error. > > > > > > > >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] > > > > Warning message: > > > > In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > > argument 'pattern' has length > 1 and only the first element > will > > > be > > > > used > > > > > > > >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] > > > > Warning message: > > > > In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > > argument 'pattern' has length > 1 and only the first element > will be > > > > used > > > > > > > > How can I do this? > > > > Sincerely > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas > > > wrote: > > > > > > > >> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: > > > >>> ?s 22:54 de 11/06/2023, javad bayat escreveu: > > > >>>> Dear Rui; > > > >>>> Many thanks for your email. I used one of your codes, > > > >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it > works > > > >>>> correctly for me. > > > >>>> Actually I need to expand the codes so as to consider all > "Levels" in > > > >> the > > > >>>> "Layer" column. There are more than hundred levels in the Layer > > > column. > > > >>>> If I use your provided code, I have to write it hundred of time as > > > >> below: > > > >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; > > > >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; > > > >>>> ... > > > >>>> ... > > > >>>> ... > > > >>>> . > > > >>>> Is there any other way to expand the code in order to consider > all of > > > >> the > > > >>>> levels simultaneously? Like the below code: > > > >>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", > ...))] > > > >> <- > > > >>>> c("Park", "Agri", "GS", ...) > > > >>>> > > > >>>> > > > >>>> Sincerely > > > >>>> > > > >>>> > > > >>>> > > > >>>> > > > >>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas < > ruipbarradas at sapo.pt> > > > >>>> wrote: > > > >>>> > > > >>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: > > > >>>>>> Dear R users; > > > >>>>>> I am trying to fill a column based on a specific value in > another > > > >>>>>> column > > > >>>>> of > > > >>>>>> a dataframe, but it seems there is a problem with the codes! > > > >>>>>> The "Layer" and the "LU" are two different columns of the > dataframe. > > > >>>>>> How can I fix this? > > > >>>>>> Sincerely > > > >>>>>> > > > >>>>>> > > > >>>>>> for (i in 1:nrow(data2$Layer)){ > > > >>>>>> if (data2$Layer == "Level 12") { > > > >>>>>> data2$LU == "Park" > > > >>>>>> } > > > >>>>>> } > > > >>>>>> > > > >>>>>> > > > >>>>>> > > > >>>>>> > > > >>>>> Hello, > > > >>>>> > > > >>>>> There are two bugs in your code, > > > >>>>> > > > >>>>> 1) the index i is not used in the loop > > > >>>>> 2) the assignment operator is `<-`, not `==` > > > >>>>> > > > >>>>> > > > >>>>> Here is the loop corrected. > > > >>>>> > > > >>>>> for (i in 1:nrow(data2$Layer)){ > > > >>>>> if (data2$Layer[i] == "Level 12") { > > > >>>>> data2$LU[i] <- "Park" > > > >>>>> } > > > >>>>> } > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> But R is a vectorized language, the following two ways are the > > > idiomac > > > >>>>> ways of doing what you want to do. > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> i <- data2$Layer == "Level 12" > > > >>>>> data2$LU[i] <- "Park" > > > >>>>> > > > >>>>> # equivalent one-liner > > > >>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> If there are NA's in data2$Layer it's probably safer to use > ?which() > > > in > > > >>>>> the logical index, to have a numeric one. > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> i <- which(data2$Layer == "Level 12") > > > >>>>> data2$LU[i] <- "Park" > > > >>>>> > > > >>>>> # equivalent one-liner > > > >>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" > > > >>>>> > > > >>>>> > > > >>>>> Hope this helps, > > > >>>>> > > > >>>>> Rui Barradas > > > >>>>> > > > >>>> > > > >>>> > > > >>> Hello, > > > >>> > > > >>> You don't need to repeat the same instruction 100+ times, there is > a > > > way > > > >>> of assigning all new LU values at the same time with match(). > > > >>> This assumes that you have the new values in a vector. > > > >> > > > >> Sorry, this is not clear. I mean > > > >> > > > >> > > > >> This assumes that you have the new values in a vector, the vector > Names > > > >> below. The vector of values to be matched is created from the data. > > > >> > > > >> > > > >> Rui Barradas > > > >> > > > >>> > > > >>> > > > >>> Values <- sort(unique(data2$Layer)) > > > >>> Names <- c("Park", "Agri", "GS") > > > >>> > > > >>> i <- match(data2$Layer, Values) > > > >>> data2$LU <- Names[i] > > > >>> > > > >>> > > > >>> Hope this helps, > > > >>> > > > >>> Rui Barradas > > > >>> > > > >>> ______________________________________________ > > > >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > >>> https://stat.ethz.ch/mailman/listinfo/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, > > > > > > Please cc the r-help list, R-Help is threaded and this can in the > future > > > be helpful to others. > > > > > > You can combine several patters like this: > > > > > > > > > pat <- c("_esmdes|_Des Section|0") > > > grep(pat, data2$Layer) > > > > > > or, programatically, > > > > > > > > > pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") > > > > > > > > > Hope this helps, > > > > > > Rui Barradas > > > > > > > > > > -- > > Best Regards > > Javad Bayat > > M.Sc. Environment Engineering > > Alternative Mail: bayat194 at yahoo.com > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat194 at yahoo.com [[alternative HTML version deleted]] From ru|pb@rr@d@@ @end|ng |rom @@po@pt Tue Jun 13 15:18:32 2023 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Tue, 13 Jun 2023 14:18:32 +0100 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> <9b68cd98-2bda-50d8-a43f-4fc01e5e97a6@sapo.pt> <6ef99052-964d-b462-5613-509563d15fc5@sapo.pt> Message-ID: <67c5637e-af15-0801-a0d6-bcb172e5529c@sapo.pt> ?s 17:18 de 13/06/2023, javad bayat escreveu: > Dear Rui; > Hi. I used your codes, but it seems it didn't work for me. > >> pat <- c("_esmdes|_Des Section|0") >> dim(data2) > [1] 281549 9 >> grep(pat, data2$Layer) >> dim(data2) > [1] 281549 9 > > What does grep function do? I expected the function to remove 3 rows of the > dataframe. > I do not know the reason. > > > > > > > On Mon, Jun 12, 2023 at 5:16?PM Rui Barradas wrote: > >> ?s 23:13 de 12/06/2023, javad bayat escreveu: >>> Dear Rui; >>> Many thanks for the email. I tried your codes and found that the length >> of >>> the "Values" and "Names" vectors must be equal, otherwise the results >> will >>> not be useful. >>> For some of the characters in the Layer column that I do not need to be >>> filled in the LU column, I used "NA". >>> But I need to delete some of the rows from the table as they are useless >>> for me. I tried this code to delete entire rows of the dataframe which >>> contained these three value in the Layer column: It gave me the following >>> error. >>> >>>> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] >>> Warning message: >>> In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : >>> argument 'pattern' has length > 1 and only the first element will >> be >>> used >>> >>>> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] >>> Warning message: >>> In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : >>> argument 'pattern' has length > 1 and only the first element will be >>> used >>> >>> How can I do this? >>> Sincerely >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas >> wrote: >>> >>>> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: >>>>> ?s 22:54 de 11/06/2023, javad bayat escreveu: >>>>>> Dear Rui; >>>>>> Many thanks for your email. I used one of your codes, >>>>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works >>>>>> correctly for me. >>>>>> Actually I need to expand the codes so as to consider all "Levels" in >>>> the >>>>>> "Layer" column. There are more than hundred levels in the Layer >> column. >>>>>> If I use your provided code, I have to write it hundred of time as >>>> below: >>>>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; >>>>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; >>>>>> ... >>>>>> ... >>>>>> ... >>>>>> . >>>>>> Is there any other way to expand the code in order to consider all of >>>> the >>>>>> levels simultaneously? Like the below code: >>>>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", ...))] >>>> <- >>>>>> c("Park", "Agri", "GS", ...) >>>>>> >>>>>> >>>>>> Sincerely >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas >>>>>> wrote: >>>>>> >>>>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: >>>>>>>> Dear R users; >>>>>>>> I am trying to fill a column based on a specific value in another >>>>>>>> column >>>>>>> of >>>>>>>> a dataframe, but it seems there is a problem with the codes! >>>>>>>> The "Layer" and the "LU" are two different columns of the dataframe. >>>>>>>> How can I fix this? >>>>>>>> Sincerely >>>>>>>> >>>>>>>> >>>>>>>> for (i in 1:nrow(data2$Layer)){ >>>>>>>> if (data2$Layer == "Level 12") { >>>>>>>> data2$LU == "Park" >>>>>>>> } >>>>>>>> } >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> There are two bugs in your code, >>>>>>> >>>>>>> 1) the index i is not used in the loop >>>>>>> 2) the assignment operator is `<-`, not `==` >>>>>>> >>>>>>> >>>>>>> Here is the loop corrected. >>>>>>> >>>>>>> for (i in 1:nrow(data2$Layer)){ >>>>>>> if (data2$Layer[i] == "Level 12") { >>>>>>> data2$LU[i] <- "Park" >>>>>>> } >>>>>>> } >>>>>>> >>>>>>> >>>>>>> >>>>>>> But R is a vectorized language, the following two ways are the >> idiomac >>>>>>> ways of doing what you want to do. >>>>>>> >>>>>>> >>>>>>> >>>>>>> i <- data2$Layer == "Level 12" >>>>>>> data2$LU[i] <- "Park" >>>>>>> >>>>>>> # equivalent one-liner >>>>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" >>>>>>> >>>>>>> >>>>>>> >>>>>>> If there are NA's in data2$Layer it's probably safer to use ?which() >> in >>>>>>> the logical index, to have a numeric one. >>>>>>> >>>>>>> >>>>>>> >>>>>>> i <- which(data2$Layer == "Level 12") >>>>>>> data2$LU[i] <- "Park" >>>>>>> >>>>>>> # equivalent one-liner >>>>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" >>>>>>> >>>>>>> >>>>>>> Hope this helps, >>>>>>> >>>>>>> Rui Barradas >>>>>>> >>>>>> >>>>>> >>>>> Hello, >>>>> >>>>> You don't need to repeat the same instruction 100+ times, there is a >> way >>>>> of assigning all new LU values at the same time with match(). >>>>> This assumes that you have the new values in a vector. >>>> >>>> Sorry, this is not clear. I mean >>>> >>>> >>>> This assumes that you have the new values in a vector, the vector Names >>>> below. The vector of values to be matched is created from the data. >>>> >>>> >>>> Rui Barradas >>>> >>>>> >>>>> >>>>> Values <- sort(unique(data2$Layer)) >>>>> Names <- c("Park", "Agri", "GS") >>>>> >>>>> i <- match(data2$Layer, Values) >>>>> data2$LU <- Names[i] >>>>> >>>>> >>>>> Hope this helps, >>>>> >>>>> Rui Barradas >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>> https://stat.ethz.ch/mailman/listinfo/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, >> >> Please cc the r-help list, R-Help is threaded and this can in the future >> be helpful to others. >> >> You can combine several patters like this: >> >> >> pat <- c("_esmdes|_Des Section|0") >> grep(pat, data2$Layer) >> >> or, programatically, >> >> >> pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") >> >> >> Hope this helps, >> >> Rui Barradas >> >> > Hello, I only posted a corrected grep statement, the complete code should be pat <- c("_esmdes|_Des Section|0") data3 <- data2[-grep(pat, data2$Layer),] Sorry for the confusion. Hope this helps, Rui Barradas From kev|n @end|ng |rom zembower@org Tue Jun 13 18:29:57 2023 From: kev|n @end|ng |rom zembower@org (=?UTF-8?Q?Kevin_Zembower?=) Date: Tue, 13 Jun 2023 16:29:57 +0000 Subject: [R] Rmarkdown code rendering as LaTeX, not executing? References: <1c2bfaef-c32a-8516-2064-0c2b9c1e01c9@zembower.org> Message-ID: <01000188b597b2b9-2bdf07cd-c0af-40d9-beef-4c580dd2aac5-000000@email.amazonses.com> Hi, all, I'm trying to compose an Rmarkdown document and render it as a PDF file. My first block of R code seems to work okay, but the second on seems to be interpreted as LaTeX code, and not executed as R code. In the output, the three back-ticks that mark the R code block are interpreted as an opening double-quote, followed by an opening single quote. Here's my test file: ================================ --- title: "An analysis of US 2020 Census Data for the Radnor-Winston neighborhood" author: "E. Kevin Zembower" date: "29 May 2023" output: pdf_document: extra_dependencies: ["array", "booktabs", "dcolumn"] --- ```{r setup, include = FALSE} ``` \section{Abstract} In this document, ... \section{Boundaries of the Radnor-Winston neighborhood} ... For the purposes of this report, the boundaries of RW are as shown in figure \ref{RWneigh}. ... ```{r rw_map, fig.width = 6, fig.height = 4, out.width = "80%", dev = "pdf", fig.cap = "Map of RW neighborhood\label{RWneigh}"} ## Creating a polygon for RW neighborhood, based on CRS 6487 (NAD83 ## (2011) / Maryland ) map in meters: base_x <- 433000 base_y <- 186000 rw_neigh_pg_m <- data.frame( matrix( c(540, 1140, 540, 1070, 480, 1060, 490, 1000, 570, 1000, 570, 940, 550, 930, 550, 890, 580, 890, 590, 820, 640, 820, 650, 590, 520, 580, 470, 580, 350, 660, 350, 710, 180, 725, 190, 900, 220, 900, 220, 1030, 240, 1030, 240, 1110 ), ncol = 2, byrow = TRUE) ) %>% + matrix(c(rep(base_x, nrow(.)), rep(base_y, nrow(.))), nrow = nrow(.)) %>% sf::st_as_sf(coords = c(1,2), dim = "XY") %>% summarize(geometry = st_combine(geometry)) %>% st_cast("POLYGON") %>% st_set_crs(6487) ## Map it: rw_base_blocks <- read_osm(bb(rw_neigh_pg_m, ext = 1.3)) ## Line below gives map in meters (RW_block_map <- tm_shape(rw_base_blocks, projection = 6487) + ## Line below gives map in degrees ## (RW_block_map <- tm_shape(rw_base_blocks, projection = 6487) + tm_rgb() + tm_shape(rw_neigh_pg_m) + tm_fill(col = "green", alpha = 0.2) + tm_borders(lwd = 2, alpha = 1) + tm_scale_bar() + ## tm_grid() + tm_xlab("Long") + tm_ylab("Lat") + tm_grid() + tm_layout(title = "Radnor-Winston Neighborhood") ) ## tmap_save(RW_block_map, "rw_map.png") ``` ==================================================== This code block can also be obtained from https://gist.github.com/kzembower/f9ad52abf82975102cbf715bcfbc0f51. I'm using Emacs and ESS to create this document. This seems to produce its own weirdness, as the text style and font color and sizes change in the R code block as I edit it and add spaces and lines. If the block above is saved as "RW_test.Rmd", I use these lines to create the PDF: =============================== library(rmarkdown) render("RW_test.Rmd") ================================ No errors are generated. Can anyone help me understand what I'm doing wrong? A much shorter test file I created seems to work okay. Thanks in advance for any advice. -Kevin > sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.2 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8 [10] LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8 time zone: America/New_York tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] kableExtra_1.3.4 tidycensus_1.4 lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2 [7] purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0 [13] rmarkdown_2.22 loaded via a namespace (and not attached): [1] gtable_0.3.3 xfun_0.39 raster_3.6-20 tigris_2.0.3 rJava_1.0-6 [6] lattice_0.21-8 tzdb_0.4.0 vctrs_0.6.2 tools_4.3.0 generics_0.1.3 [11] curl_5.0.0 proxy_0.4-27 fansi_1.0.4 pkgconfig_2.0.3 KernSmooth_2.23-21 [16] webshot_0.5.4 uuid_1.1-0 lifecycle_1.0.3 compiler_4.3.0 munsell_0.5.0 [21] tinytex_0.45 terra_1.7-29 codetools_0.2-19 htmltools_0.5.5 class_7.3-22 [26] yaml_2.3.7 crayon_1.5.2 pillar_1.9.0 classInt_0.4-9 tidyselect_1.2.0 [31] rvest_1.0.3 digest_0.6.31 stringi_1.7.12 sf_1.0-13 fastmap_1.1.1 [36] grid_4.3.0 colorspace_2.1-0 cli_3.6.1 magrittr_2.0.3 utf8_1.2.3 [41] e1071_1.7-13 withr_2.5.0 scales_1.2.1 rappdirs_0.3.3 sp_1.6-1 [46] timechange_0.2.0 httr_1.4.6 hms_1.1.3 OpenStreetMap_0.3.4 evaluate_0.21 [51] knitr_1.43 rgdal_1.6-7 viridisLite_0.4.2 rlang_1.1.1 Rcpp_1.0.10 [56] glue_1.6.2 DBI_1.1.3 xml2_1.3.4 svglite_2.1.1 rstudioapi_0.14 [61] jsonlite_1.8.4 R6_2.5.1 systemfonts_1.0.4 units_0.8-2 > From o||v|er@crouzet @end|ng |rom un|v-n@nte@@|r Tue Jun 13 19:31:04 2023 From: o||v|er@crouzet @end|ng |rom un|v-n@nte@@|r (Olivier Crouzet) Date: Tue, 13 Jun 2023 19:31:04 +0200 Subject: [R] Rmarkdown code rendering as LaTeX, not executing? In-Reply-To: <01000188b597b2b9-2bdf07cd-c0af-40d9-beef-4c580dd2aac5-000000@email.amazonses.com> References: <1c2bfaef-c32a-8516-2064-0c2b9c1e01c9@zembower.org> <01000188b597b2b9-2bdf07cd-c0af-40d9-beef-4c580dd2aac5-000000@email.amazonses.com> Message-ID: <20230613193104.1de98ffb04feab04b678a2cb@univ-nantes.fr> Dear Kevin, actually you're mixing markdown and LaTeX syntax, which is the reason why you see LaTeX code in the PDF. You have to choose... 1) Either you wish to produce an RMarkdown document and your sections, subsections... should read: # Abstract In this document, ... ## Boundaries of the Radnor-Winston neighborhood ```{r rw_map, fig.width = 6, fig.height = 4, out.width = "80%", dev = "pdf", fig.cap = "Map of RW neighborhood\label{RWneigh}"} ## Creating a polygon for RW neighborhood, based on CRS 6487 (NAD83 ## (2011) / Maryland ) map in meters: base_x <- 433000 base_y <- 186000 [etc]... ``` But you may not use all the power of LaTeX (easily at least). 2) Or you wish to produce a .Rnw (knitr / Sweave file using LaTeX) and you should use another R code delimitation convention (and change the heading part of the document to LaTeX usage, that is \documentclass{}... \usepackage{}...): < ## Creating a polygon for RW neighborhood, based on CRS 6487 (NAD83 ## (2011) / Maryland ) map in meters: base_x <- 433000 base_y <- 186000 [etc] @ Depending on your choice, compiling the document goes through a different process but both are possible and relatively simple (either from within RStudio or using any other editor). Hope this helps for a first approach. Olivier. On Tue, 13 Jun 2023 16:29:57 +0000 Kevin Zembower via R-help wrote: > Hi, all, > > I'm trying to compose an Rmarkdown document and render it as a PDF > file. My first block of R code seems to work okay, but the second on > seems to be interpreted as LaTeX code, and not executed as R code. In > the output, the three back-ticks that mark the R code block are > interpreted as an opening double-quote, followed by an opening single > quote. > > Here's my test file: > ================================ > --- > title: "An analysis of US 2020 Census Data for the Radnor-Winston > neighborhood" > author: "E. Kevin Zembower" > date: "29 May 2023" > output: > pdf_document: > extra_dependencies: ["array", "booktabs", "dcolumn"] > > --- > > ```{r setup, include = FALSE} > > ``` > > \section{Abstract} > In this document, ... > > \section{Boundaries of the Radnor-Winston neighborhood} > > ... > > For the purposes of this report, the > boundaries of RW are as shown in figure \ref{RWneigh}. ... > > ```{r rw_map, fig.width = 6, fig.height = 4, out.width = "80%", dev > = "pdf", > fig.cap = "Map of RW neighborhood\label{RWneigh}"} > > ## Creating a polygon for RW neighborhood, based on CRS 6487 (NAD83 > ## (2011) / Maryland ) map in meters: > base_x <- 433000 > base_y <- 186000 > rw_neigh_pg_m <- data.frame( > matrix( > c(540, 1140, > 540, 1070, > 480, 1060, > 490, 1000, > 570, 1000, > 570, 940, > 550, 930, > 550, 890, > 580, 890, > 590, 820, > 640, 820, > 650, 590, > 520, 580, > 470, 580, > 350, 660, > 350, 710, > 180, 725, > 190, 900, > 220, 900, > 220, 1030, > 240, 1030, > 240, 1110 > ), > ncol = 2, byrow = TRUE) > ) %>% + matrix(c(rep(base_x, nrow(.)), rep(base_y, nrow(.))), > nrow = nrow(.)) %>% > sf::st_as_sf(coords = c(1,2), dim = "XY") %>% > summarize(geometry = st_combine(geometry)) %>% > st_cast("POLYGON") %>% > st_set_crs(6487) > > ## Map it: > rw_base_blocks <- read_osm(bb(rw_neigh_pg_m, ext = 1.3)) > > ## Line below gives map in meters > (RW_block_map <- tm_shape(rw_base_blocks, projection = 6487) + > ## Line below gives map in degrees > ## (RW_block_map <- tm_shape(rw_base_blocks, projection = 6487) + > tm_rgb() + > tm_shape(rw_neigh_pg_m) + > tm_fill(col = "green", alpha = 0.2) + > tm_borders(lwd = 2, alpha = 1) + > tm_scale_bar() + > ## tm_grid() + tm_xlab("Long") + tm_ylab("Lat") + > tm_grid() + > tm_layout(title = "Radnor-Winston Neighborhood") > ) > > ## tmap_save(RW_block_map, "rw_map.png") > > ``` > ==================================================== > > This code block can also be obtained from > https://gist.github.com/kzembower/f9ad52abf82975102cbf715bcfbc0f51. > > I'm using Emacs and ESS to create this document. This seems to > produce its own weirdness, as the text style and font color and sizes > change in the R code block as I edit it and add spaces and lines. > > If the block above is saved as "RW_test.Rmd", I use these lines to > create the PDF: > =============================== > library(rmarkdown) > render("RW_test.Rmd") > ================================ > > No errors are generated. > > Can anyone help me understand what I'm doing wrong? A much shorter > test file I created seems to work okay. > > Thanks in advance for any advice. > > -Kevin > > > sessionInfo() > R version 4.3.0 (2023-04-21) > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Ubuntu 22.04.2 LTS > > Matrix products: default > BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 > LAPACK: > /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; > LAPACK version 3.10.0 > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > LC_TIME=en_US.UTF-8 > [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 > LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 > LC_ADDRESS=en_US.UTF-8 > [10] LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 > LC_IDENTIFICATION=en_US.UTF-8 > > time zone: America/New_York > tzcode source: system (glibc) > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] kableExtra_1.3.4 tidycensus_1.4 lubridate_1.9.2 > forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2 > [7] purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 > ggplot2_3.4.2 tidyverse_2.0.0 > [13] rmarkdown_2.22 > > loaded via a namespace (and not attached): > [1] gtable_0.3.3 xfun_0.39 raster_3.6-20 > tigris_2.0.3 rJava_1.0-6 > [6] lattice_0.21-8 tzdb_0.4.0 vctrs_0.6.2 > tools_4.3.0 generics_0.1.3 > [11] curl_5.0.0 proxy_0.4-27 fansi_1.0.4 > pkgconfig_2.0.3 KernSmooth_2.23-21 > [16] webshot_0.5.4 uuid_1.1-0 lifecycle_1.0.3 > compiler_4.3.0 munsell_0.5.0 > [21] tinytex_0.45 terra_1.7-29 codetools_0.2-19 > htmltools_0.5.5 class_7.3-22 > [26] yaml_2.3.7 crayon_1.5.2 pillar_1.9.0 > classInt_0.4-9 tidyselect_1.2.0 > [31] rvest_1.0.3 digest_0.6.31 stringi_1.7.12 > sf_1.0-13 fastmap_1.1.1 > [36] grid_4.3.0 colorspace_2.1-0 cli_3.6.1 > magrittr_2.0.3 utf8_1.2.3 > [41] e1071_1.7-13 withr_2.5.0 scales_1.2.1 > rappdirs_0.3.3 sp_1.6-1 > [46] timechange_0.2.0 httr_1.4.6 hms_1.1.3 > OpenStreetMap_0.3.4 evaluate_0.21 > [51] knitr_1.43 rgdal_1.6-7 viridisLite_0.4.2 > rlang_1.1.1 Rcpp_1.0.10 > [56] glue_1.6.2 DBI_1.1.3 xml2_1.3.4 > svglite_2.1.1 rstudioapi_0.14 > [61] jsonlite_1.8.4 R6_2.5.1 systemfonts_1.0.4 > units_0.8-2 > > > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code. -- Olivier Crouzet, PhD http://olivier.ghostinthemachine.space /Ma?tre de Conf?rences/ @LLING - Laboratoire de Linguistique de Nantes UMR6310 CNRS / Universit? de Nantes From w||||@mwdun|@p @end|ng |rom gm@||@com Tue Jun 13 20:00:33 2023 From: w||||@mwdun|@p @end|ng |rom gm@||@com (Bill Dunlap) Date: Tue, 13 Jun 2023 11:00:33 -0700 Subject: [R] Problem with filling dataframe's column In-Reply-To: <67c5637e-af15-0801-a0d6-bcb172e5529c@sapo.pt> References: <468775d9-d4b3-9a71-c291-5149e2b6c463@sapo.pt> <6d5c2714-2e21-f024-1cef-b65e30df89d2@sapo.pt> <9b68cd98-2bda-50d8-a43f-4fc01e5e97a6@sapo.pt> <6ef99052-964d-b462-5613-509563d15fc5@sapo.pt> <67c5637e-af15-0801-a0d6-bcb172e5529c@sapo.pt> Message-ID: It is safer to use !grepl(...) instead of -grep(...) here. If there are no matches, the latter will give you a zero-row data.frame while the former gives you the entire data.frame. E.g., > d <- data.frame(a=c("one","two","three"), b=c(10,20,30)) > d[-grep("Q", d$a),] [1] a b <0 rows> (or 0-length row.names) > d[!grepl("Q", d$a),] a b 1 one 10 2 two 20 3 three 30 -Bill On Tue, Jun 13, 2023 at 6:19?AM Rui Barradas wrote: > ?s 17:18 de 13/06/2023, javad bayat escreveu: > > Dear Rui; > > Hi. I used your codes, but it seems it didn't work for me. > > > >> pat <- c("_esmdes|_Des Section|0") > >> dim(data2) > > [1] 281549 9 > >> grep(pat, data2$Layer) > >> dim(data2) > > [1] 281549 9 > > > > What does grep function do? I expected the function to remove 3 rows of > the > > dataframe. > > I do not know the reason. > > > > > > > > > > > > > > On Mon, Jun 12, 2023 at 5:16?PM Rui Barradas > wrote: > > > >> ?s 23:13 de 12/06/2023, javad bayat escreveu: > >>> Dear Rui; > >>> Many thanks for the email. I tried your codes and found that the length > >> of > >>> the "Values" and "Names" vectors must be equal, otherwise the results > >> will > >>> not be useful. > >>> For some of the characters in the Layer column that I do not need to be > >>> filled in the LU column, I used "NA". > >>> But I need to delete some of the rows from the table as they are > useless > >>> for me. I tried this code to delete entire rows of the dataframe which > >>> contained these three value in the Layer column: It gave me the > following > >>> error. > >>> > >>>> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] > >>> Warning message: > >>> In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : > >>> argument 'pattern' has length > 1 and only the first element > will > >> be > >>> used > >>> > >>>> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] > >>> Warning message: > >>> In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : > >>> argument 'pattern' has length > 1 and only the first element > will be > >>> used > >>> > >>> How can I do this? > >>> Sincerely > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas > >> wrote: > >>> > >>>> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: > >>>>> ?s 22:54 de 11/06/2023, javad bayat escreveu: > >>>>>> Dear Rui; > >>>>>> Many thanks for your email. I used one of your codes, > >>>>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works > >>>>>> correctly for me. > >>>>>> Actually I need to expand the codes so as to consider all "Levels" > in > >>>> the > >>>>>> "Layer" column. There are more than hundred levels in the Layer > >> column. > >>>>>> If I use your provided code, I have to write it hundred of time as > >>>> below: > >>>>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; > >>>>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; > >>>>>> ... > >>>>>> ... > >>>>>> ... > >>>>>> . > >>>>>> Is there any other way to expand the code in order to consider all > of > >>>> the > >>>>>> levels simultaneously? Like the below code: > >>>>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", > ...))] > >>>> <- > >>>>>> c("Park", "Agri", "GS", ...) > >>>>>> > >>>>>> > >>>>>> Sincerely > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas > >>>>>> wrote: > >>>>>> > >>>>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: > >>>>>>>> Dear R users; > >>>>>>>> I am trying to fill a column based on a specific value in another > >>>>>>>> column > >>>>>>> of > >>>>>>>> a dataframe, but it seems there is a problem with the codes! > >>>>>>>> The "Layer" and the "LU" are two different columns of the > dataframe. > >>>>>>>> How can I fix this? > >>>>>>>> Sincerely > >>>>>>>> > >>>>>>>> > >>>>>>>> for (i in 1:nrow(data2$Layer)){ > >>>>>>>> if (data2$Layer == "Level 12") { > >>>>>>>> data2$LU == "Park" > >>>>>>>> } > >>>>>>>> } > >>>>>>>> > >>>>>>>> > >>>>>>>> > >>>>>>>> > >>>>>>> Hello, > >>>>>>> > >>>>>>> There are two bugs in your code, > >>>>>>> > >>>>>>> 1) the index i is not used in the loop > >>>>>>> 2) the assignment operator is `<-`, not `==` > >>>>>>> > >>>>>>> > >>>>>>> Here is the loop corrected. > >>>>>>> > >>>>>>> for (i in 1:nrow(data2$Layer)){ > >>>>>>> if (data2$Layer[i] == "Level 12") { > >>>>>>> data2$LU[i] <- "Park" > >>>>>>> } > >>>>>>> } > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> But R is a vectorized language, the following two ways are the > >> idiomac > >>>>>>> ways of doing what you want to do. > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> i <- data2$Layer == "Level 12" > >>>>>>> data2$LU[i] <- "Park" > >>>>>>> > >>>>>>> # equivalent one-liner > >>>>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> If there are NA's in data2$Layer it's probably safer to use > ?which() > >> in > >>>>>>> the logical index, to have a numeric one. > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> i <- which(data2$Layer == "Level 12") > >>>>>>> data2$LU[i] <- "Park" > >>>>>>> > >>>>>>> # equivalent one-liner > >>>>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" > >>>>>>> > >>>>>>> > >>>>>>> Hope this helps, > >>>>>>> > >>>>>>> Rui Barradas > >>>>>>> > >>>>>> > >>>>>> > >>>>> Hello, > >>>>> > >>>>> You don't need to repeat the same instruction 100+ times, there is a > >> way > >>>>> of assigning all new LU values at the same time with match(). > >>>>> This assumes that you have the new values in a vector. > >>>> > >>>> Sorry, this is not clear. I mean > >>>> > >>>> > >>>> This assumes that you have the new values in a vector, the vector > Names > >>>> below. The vector of values to be matched is created from the data. > >>>> > >>>> > >>>> Rui Barradas > >>>> > >>>>> > >>>>> > >>>>> Values <- sort(unique(data2$Layer)) > >>>>> Names <- c("Park", "Agri", "GS") > >>>>> > >>>>> i <- match(data2$Layer, Values) > >>>>> data2$LU <- Names[i] > >>>>> > >>>>> > >>>>> Hope this helps, > >>>>> > >>>>> Rui Barradas > >>>>> > >>>>> ______________________________________________ > >>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >>>>> https://stat.ethz.ch/mailman/listinfo/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, > >> > >> Please cc the r-help list, R-Help is threaded and this can in the future > >> be helpful to others. > >> > >> You can combine several patters like this: > >> > >> > >> pat <- c("_esmdes|_Des Section|0") > >> grep(pat, data2$Layer) > >> > >> or, programatically, > >> > >> > >> pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") > >> > >> > >> Hope this helps, > >> > >> Rui Barradas > >> > >> > > > Hello, > > I only posted a corrected grep statement, the complete code should be > > > pat <- c("_esmdes|_Des Section|0") > data3 <- data2[-grep(pat, data2$Layer),] > > > Sorry for the confusion. > > Hope this helps, > > Rui Barradas > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com Tue Jun 13 23:07:46 2023 From: @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com (Ana Marija) Date: Tue, 13 Jun 2023 16:07:46 -0500 Subject: [R] log transform a data frame Message-ID: Hello, I have a data frame like this: d11=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv", stringsAsFactors=FALSE, header=TRUE)) > d11 X Domain.decomp. DD.com..load Neighbor.search Launch.PP.GPU.ops. Comm..coord. 1 SYCL 2. 1 0 3.7 0. 1 1 .6 2 CUDA 2 0 3. 1 0 1 .0 Force Wait...Comm..F PIE.mesh Wait.Bonded.GPU wait.GPU.NB.nonloc. 1 1 . 5 1 .3 65.6 0 0 2 1 .2 1 .7 70.9 0 0 Wait.GPU.NB.local NB.X.F.buffer.ops. Write.traje Update Constraints Comm..energies 1 0 7.3 0.3 6.3 8.9 0.9 2 0 4.4 0.3 4.3 9.7 0.9 PIE.redist..X.F PIE.spread PIE.gather PIE.3D.FFT PIE.3D.FFT.comm. PIE.solve.Elec 1 8. 1 29.7 19.9 6.0 1 .2 0.7 2 8.7 30.6 21 .3 8.6 1 .0 0.5 I am trying to log transform the whole data frame, but I get this error: > d1=log(d11) Error in Math.data.frame(d11) : non-numeric variable(s) in data frame: X, Domain.decomp., Neighbor.search, Launch.PP.GPU.ops., Comm..coord., Force, Wait...Comm..F, PIE.redist..X.F, PIE.gather, PIE.3D.FFT.comm My goal is to make a stacked barplot like this: d2=as.matrix(sapply(d1, as.numeric)) b<-barplot(d2, legend= rownames(data2), beside= TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", "#6a51a3")) If I don't log transform my code runs. Please advise, Ana [[alternative HTML version deleted]] From @vi@e@gross m@iii@g oii gm@ii@com Tue Jun 13 23:18:41 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Tue, 13 Jun 2023 17:18:41 -0400 Subject: [R] Problem with filling dataframe's column Message-ID: <00d901d99e3c$a0fc83b0$e2f58b10$@gmail.com> Javad, There may be nothing wrong with the methods people are showing you and if it satisfied you, great. But I note you have lots of data in over a quarter million rows. If much of the text data is redundant, and you want to simplify some operations such as changing some of the values to others I multiple ways, have you done any learning about an R feature very useful for dealing with categorical data called "factors"? If you have a vector or a column in a data.frame that contains text, then it can be replaced by a factor that often takes way less space as it stores a sort of dictionary of all the unique values and just records numbers like 1,2,3 to tell which one each item is. You can access the values using levels(whatever) and also change them. There are packages that make this straightforward such as forcats which is one of the tidyverse packages that also includes many other tools some find useful but are beyond the usual scope of this mailing list. As an example, if you have a vector in mydata$col1 then code like: mydata$col1 <- factor(mydata$col1) No matter which way you do it, you can now access the levels and make whatever changes, and save the changes. One example could be to apply some variant of grep to make the substitution. There is a family of functions build in such as sub() that matches a Regular Expression and replaces it with what you want. This has a similar result to changing all entries without doing all the work. I mean if item 5 used to be "OLD" and is now "NEW" then any of you quarter million entries that have a 5 will now be seen as having a value of "NEW". I will stop here and suggest you may want to read some book that explains R as a unified set of features with some emphasis on using it for the features it is intended to have that can make life easier, rather than using just features it shares with most languages. Some of your questions indicate you have less grounding and are mainly following recipes you stumble across. Otherwise, you will have a collection of what you call "codes" and others like me call programming and that don't necessarily fit well together. -----Original Message----- From: R-help r-help-bounces at r-project.org On Behalf Of javad bayat Sent: Tuesday, June 13, 2023 3:47 PM To: Eric Berger ericjberger at gmail.com Cc: R-help at r-project.org Subject: Re: [R] Problem with filling dataframe's column Dear all; I used these codes and I get what I wanted. Sincerely pat = c("Level 12","Level 22","0") data3 = data2[-which(data2$Layer == pat),] dim(data2) [1] 281549 9 dim(data3) [1] 244075 9 On Tue, Jun 13, 2023 at 11:36?AM Eric Berger < ericjberger at gmail.com> wrote: > Hi Javed, > grep returns the positions of the matches. See an example below. > > > v <- c("abc", "bcd", "def") > > v > [1] "abc" "bcd" "def" > > grep("cd",v) > [1] 2 > > w <- v[-grep("cd",v)] > > w > [1] "abc" "def" > > > > > On Tue, Jun 13, 2023 at 8:50?AM javad bayat < j.bayat194 at gmail.com> wrote: > > > > Dear Rui; > > Hi. I used your codes, but it seems it didn't work for me. > > > > > pat <- c("_esmdes|_Des Section|0") > > > dim(data2) > > [1] 281549 9 > > > grep(pat, data2$Layer) > > > dim(data2) > > [1] 281549 9 > > > > What does grep function do? I expected the function to remove 3 rows of > the > > dataframe. > > I do not know the reason. > > > > > > > > > > > > > > On Mon, Jun 12, 2023 at 5:16?PM Rui Barradas < ruipbarradas at sapo.pt> > wrote: > > > > > ?s 23:13 de 12/06/2023, javad bayat escreveu: > > > > Dear Rui; > > > > Many thanks for the email. I tried your codes and found that the > length > > > of > > > > the "Values" and "Names" vectors must be equal, otherwise the results > > > will > > > > not be useful. > > > > For some of the characters in the Layer column that I do not need to > be > > > > filled in the LU column, I used "NA". > > > > But I need to delete some of the rows from the table as they are > useless > > > > for me. I tried this code to delete entire rows of the dataframe > which > > > > contained these three value in the Layer column: It gave me the > following > > > > error. > > > > > > > >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] > > > > Warning message: > > > > In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > > argument 'pattern' has length > 1 and only the first element > will > > > be > > > > used > > > > > > > >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] > > > > Warning message: > > > > In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > > argument 'pattern' has length > 1 and only the first element > will be > > > > used > > > > > > > > How can I do this? > > > > Sincerely > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas < ruipbarradas at sapo.pt> > > > wrote: > > > > > > > >> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: > > > >>> ?s 22:54 de 11/06/2023, javad bayat escreveu: > > > >>>> Dear Rui; > > > >>>> Many thanks for your email. I used one of your codes, > > > >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it > works > > > >>>> correctly for me. > > > >>>> Actually I need to expand the codes so as to consider all > "Levels" in > > > >> the > > > >>>> "Layer" column. There are more than hundred levels in the Layer > > > column. > > > >>>> If I use your provided code, I have to write it hundred of time as > > > >> below: > > > >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; > > > >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; > > > >>>> ... > > > >>>> ... > > > >>>> ... > > > >>>> . > > > >>>> Is there any other way to expand the code in order to consider > all of > > > >> the > > > >>>> levels simultaneously? Like the below code: > > > >>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", > ...))] > > > >> <- > > > >>>> c("Park", "Agri", "GS", ...) > > > >>>> > > > >>>> > > > >>>> Sincerely > > > >>>> > > > >>>> > > > >>>> > > > >>>> > > > >>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas < > ruipbarradas at sapo.pt> > > > >>>> wrote: > > > >>>> > > > >>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: > > > >>>>>> Dear R users; > > > >>>>>> I am trying to fill a column based on a specific value in > another > > > >>>>>> column > > > >>>>> of > > > >>>>>> a dataframe, but it seems there is a problem with the codes! > > > >>>>>> The "Layer" and the "LU" are two different columns of the > dataframe. > > > >>>>>> How can I fix this? > > > >>>>>> Sincerely > > > >>>>>> > > > >>>>>> > > > >>>>>> for (i in 1:nrow(data2$Layer)){ > > > >>>>>> if (data2$Layer == "Level 12") { > > > >>>>>> data2$LU == "Park" > > > >>>>>> } > > > >>>>>> } > > > >>>>>> > > > >>>>>> > > > >>>>>> > > > >>>>>> > > > >>>>> Hello, > > > >>>>> > > > >>>>> There are two bugs in your code, > > > >>>>> > > > >>>>> 1) the index i is not used in the loop > > > >>>>> 2) the assignment operator is `<-`, not `==` > > > >>>>> > > > >>>>> > > > >>>>> Here is the loop corrected. > > > >>>>> > > > >>>>> for (i in 1:nrow(data2$Layer)){ > > > >>>>> if (data2$Layer[i] == "Level 12") { > > > >>>>> data2$LU[i] <- "Park" > > > >>>>> } > > > >>>>> } > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> But R is a vectorized language, the following two ways are the > > > idiomac > > > >>>>> ways of doing what you want to do. > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> i <- data2$Layer == "Level 12" > > > >>>>> data2$LU[i] <- "Park" > > > >>>>> > > > >>>>> # equivalent one-liner > > > >>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> If there are NA's in data2$Layer it's probably safer to use > ?which() > > > in > > > >>>>> the logical index, to have a numeric one. > > > >>>>> > > > >>>>> > > > >>>>> > > > >>>>> i <- which(data2$Layer == "Level 12") > > > >>>>> data2$LU[i] <- "Park" > > > >>>>> > > > >>>>> # equivalent one-liner > > > >>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" > > > >>>>> > > > >>>>> > > > >>>>> Hope this helps, > > > >>>>> > > > >>>>> Rui Barradas > > > >>>>> > > > >>>> > > > >>>> > > > >>> Hello, > > > >>> > > > >>> You don't need to repeat the same instruction 100+ times, there is > a > > > way > > > >>> of assigning all new LU values at the same time with match(). > > > >>> This assumes that you have the new values in a vector. > > > >> > > > >> Sorry, this is not clear. I mean > > > >> > > > >> > > > >> This assumes that you have the new values in a vector, the vector > Names > > > >> below. The vector of values to be matched is created from the data. > > > >> > > > >> > > > >> Rui Barradas > > > >> > > > >>> > > > >>> > > > >>> Values <- sort(unique(data2$Layer)) > > > >>> Names <- c("Park", "Agri", "GS") > > > >>> > > > >>> i <- match(data2$Layer, Values) > > > >>> data2$LU <- Names[i] > > > >>> > > > >>> > > > >>> Hope this helps, > > > >>> > > > >>> Rui Barradas > > > >>> > > > >>> ______________________________________________ > > > >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > >>> https://stat.ethz.ch/mailman/listinfo/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, > > > > > > Please cc the r-help list, R-Help is threaded and this can in the > future > > > be helpful to others. > > > > > > You can combine several patters like this: > > > > > > > > > pat <- c("_esmdes|_Des Section|0") > > > grep(pat, data2$Layer) > > > > > > or, programatically, > > > > > > > > > pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") > > > > > > > > > Hope this helps, > > > > > > Rui Barradas > > > > > > > > > > -- > > Best Regards > > Javad Bayat > > M.Sc. Environment Engineering > > Alternative Mail: bayat194 at yahoo.com > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat194 at yahoo.com [[alternative HTML version deleted]] From dc@r|@on @end|ng |rom t@mu@edu Wed Jun 14 00:14:25 2023 From: dc@r|@on @end|ng |rom t@mu@edu (David Carlson) Date: Tue, 13 Jun 2023 17:14:25 -0500 Subject: [R] log transform a data frame In-Reply-To: References: Message-ID: Your first data column appears to contain character data (e.g. SYCL) which cannot be converted to numeric. You also appear to have 0's in the numeric columns which will cause problems since log(0) is -Inf. Barplots are useful for categorical data, but not continuous, numeric data which are better handled with box plots or strip charts. Do not use printouts of your data since it hides important information. Use str(a11) and dput(a11) or dput(head(a11)) to provide useful information about your data. David L Carlson Texas A&M University On Tue, Jun 13, 2023 at 4:08?PM Ana Marija wrote: > Hello, I have a data frame like this: d11=suppressWarnings(read. > csv("/Users/anamaria/Downloads/B1. csv", stringsAsFactors=FALSE, > header=TRUE)) > d11 X Domain. decomp. DD. com. . load Neighbor. search > Launch. PP. GPU. ops. Comm. . coord. 1 SYCL 2. 1 > ZjQcmQRYFpfptBannerStart > This Message Is From an External Sender > This message came from outside your organization. > > ZjQcmQRYFpfptBannerEnd > > Hello, > > I have a data frame like this: > > d11=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv", > stringsAsFactors=FALSE, header=TRUE)) > > > d11 > X Domain.decomp. DD.com..load Neighbor.search Launch.PP.GPU.ops. > Comm..coord. > 1 SYCL 2. 1 0 3.7 0. 1 > 1 .6 > 2 CUDA 2 0 3. 1 0 > 1 .0 > Force Wait...Comm..F PIE.mesh Wait.Bonded.GPU wait.GPU.NB.nonloc. > 1 1 . 5 1 .3 65.6 0 0 > 2 1 .2 1 .7 70.9 0 0 > Wait.GPU.NB.local NB.X.F.buffer.ops. Write.traje Update Constraints > Comm..energies > 1 0 7.3 0.3 6.3 8.9 > 0.9 > 2 0 4.4 0.3 4.3 9.7 > 0.9 > PIE.redist..X.F PIE.spread PIE.gather PIE.3D.FFT PIE.3D.FFT.comm. > PIE.solve.Elec > 1 8. 1 29.7 19.9 6.0 1 .2 > 0.7 > 2 8.7 30.6 21 .3 8.6 1 .0 > 0.5 > > I am trying to log transform the whole data frame, but I get this error: > > > d1=log(d11) > Error in Math.data.frame(d11) : > non-numeric variable(s) in data frame: X, Domain.decomp., > Neighbor.search, Launch.PP.GPU.ops., Comm..coord., Force, Wait...Comm..F, > PIE.redist..X.F, PIE.gather, PIE.3D.FFT.comm > > > My goal is to make a stacked barplot like this: > d2=as.matrix(sapply(d1, as.numeric)) > b<-barplot(d2, legend= rownames(data2), beside= > TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", > "#6a51a3")) > > If I don't log transform my code runs. > > Please advise, > Ana > > [[alternative HTML version deleted]] > > ______________________________________________R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czR4zGIstg$ > PLEASE do read the posting guide https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czRLvLqcYM$ > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] From bgunter@4567 @end|ng |rom gm@||@com Wed Jun 14 00:14:40 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Tue, 13 Jun 2023 15:14:40 -0700 Subject: [R] Problem with filling dataframe's column In-Reply-To: <00d901d99e3c$a0fc83b0$e2f58b10$@gmail.com> References: <00d901d99e3c$a0fc83b0$e2f58b10$@gmail.com> Message-ID: Below. On Tue, Jun 13, 2023 at 2:18?PM wrote: > > > Javad, > > There may be nothing wrong with the methods people are showing you and if it satisfied you, great. > > But I note you have lots of data in over a quarter million rows. If much of the text data is redundant, and you want to simplify some operations such as changing some of the values to others I multiple ways, have you done any learning about an R feature very useful for dealing with categorical data called "factors"? > > If you have a vector or a column in a data.frame that contains text, then it can be replaced by a factor that often takes way less space as it stores a sort of dictionary of all the unique values and just records numbers like 1,2,3 to tell which one each item is. -- This is false. It used to be true a **long time ago**, but R has for quite a while used hashing/global string tables to avoid this problem. See here for details/references. As a result, I think many would argue that working with strings *as strings,* not factors, if often a better default, though of course there are still situations where factors are useful (e.g. in ordering results by factor levels where the desired level order is not alphabetical). **I would appreciate correction/ clarification if my claims are wrong or misleading! ** In any case, please do check such claims before making them on this list. Cheers, Bert > > You can access the values using levels(whatever) and also change them. There are packages that make this straightforward such as forcats which is one of the tidyverse packages that also includes many other tools some find useful but are beyond the usual scope of this mailing list. > > As an example, if you have a vector in mydata$col1 then code like: > > mydata$col1 <- factor(mydata$col1) > > No matter which way you do it, you can now access the levels and make whatever changes, and save the changes. One example could be to apply some variant of grep to make the substitution. There is a family of functions build in such as sub() that matches a Regular Expression and replaces it with what you want. > > This has a similar result to changing all entries without doing all the work. I mean if item 5 used to be "OLD" and is now "NEW" then any of you quarter million entries that have a 5 will now be seen as having a value of "NEW". > > I will stop here and suggest you may want to read some book that explains R as a unified set of features with some emphasis on using it for the features it is intended to have that can make life easier, rather than using just features it shares with most languages. Some of your questions indicate you have less grounding and are mainly following recipes you stumble across. > > Otherwise, you will have a collection of what you call "codes" and others like me call programming and that don't necessarily fit well together. > > > -----Original Message----- > From: R-help r-help-bounces at r-project.org On Behalf Of javad bayat > Sent: Tuesday, June 13, 2023 3:47 PM > To: Eric Berger ericjberger at gmail.com > Cc: R-help at r-project.org > Subject: Re: [R] Problem with filling dataframe's column > > Dear all; > I used these codes and I get what I wanted. > Sincerely > > pat = c("Level 12","Level 22","0") > data3 = data2[-which(data2$Layer == pat),] > dim(data2) > [1] 281549 9 > dim(data3) > [1] 244075 9 > > On Tue, Jun 13, 2023 at 11:36?AM Eric Berger < ericjberger at gmail.com> wrote: > > > Hi Javed, > > grep returns the positions of the matches. See an example below. > > > > > v <- c("abc", "bcd", "def") > > > v > > [1] "abc" "bcd" "def" > > > grep("cd",v) > > [1] 2 > > > w <- v[-grep("cd",v)] > > > w > > [1] "abc" "def" > > > > > > > > > On Tue, Jun 13, 2023 at 8:50?AM javad bayat < j.bayat194 at gmail.com> wrote: > > > > > > Dear Rui; > > > Hi. I used your codes, but it seems it didn't work for me. > > > > > > > pat <- c("_esmdes|_Des Section|0") > > > > dim(data2) > > > [1] 281549 9 > > > > grep(pat, data2$Layer) > > > > dim(data2) > > > [1] 281549 9 > > > > > > What does grep function do? I expected the function to remove 3 rows of > > the > > > dataframe. > > > I do not know the reason. > > > > > > > > > > > > > > > > > > > > > On Mon, Jun 12, 2023 at 5:16?PM Rui Barradas < ruipbarradas at sapo.pt> > > wrote: > > > > > > > ?s 23:13 de 12/06/2023, javad bayat escreveu: > > > > > Dear Rui; > > > > > Many thanks for the email. I tried your codes and found that the > > length > > > > of > > > > > the "Values" and "Names" vectors must be equal, otherwise the results > > > > will > > > > > not be useful. > > > > > For some of the characters in the Layer column that I do not need to > > be > > > > > filled in the LU column, I used "NA". > > > > > But I need to delete some of the rows from the table as they are > > useless > > > > > for me. I tried this code to delete entire rows of the dataframe > > which > > > > > contained these three value in the Layer column: It gave me the > > following > > > > > error. > > > > > > > > > >> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),] > > > > > Warning message: > > > > > In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > > > argument 'pattern' has length > 1 and only the first element > > will > > > > be > > > > > used > > > > > > > > > >> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),] > > > > > Warning message: > > > > > In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) : > > > > > argument 'pattern' has length > 1 and only the first element > > will be > > > > > used > > > > > > > > > > How can I do this? > > > > > Sincerely > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Sun, Jun 11, 2023 at 5:03?PM Rui Barradas < ruipbarradas at sapo.pt> > > > > wrote: > > > > > > > > > >> ?s 13:18 de 11/06/2023, Rui Barradas escreveu: > > > > >>> ?s 22:54 de 11/06/2023, javad bayat escreveu: > > > > >>>> Dear Rui; > > > > >>>> Many thanks for your email. I used one of your codes, > > > > >>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it > > works > > > > >>>> correctly for me. > > > > >>>> Actually I need to expand the codes so as to consider all > > "Levels" in > > > > >> the > > > > >>>> "Layer" column. There are more than hundred levels in the Layer > > > > column. > > > > >>>> If I use your provided code, I have to write it hundred of time as > > > > >> below: > > > > >>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park"; > > > > >>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri"; > > > > >>>> ... > > > > >>>> ... > > > > >>>> ... > > > > >>>> . > > > > >>>> Is there any other way to expand the code in order to consider > > all of > > > > >> the > > > > >>>> levels simultaneously? Like the below code: > > > > >>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3", > > ...))] > > > > >> <- > > > > >>>> c("Park", "Agri", "GS", ...) > > > > >>>> > > > > >>>> > > > > >>>> Sincerely > > > > >>>> > > > > >>>> > > > > >>>> > > > > >>>> > > > > >>>> On Sun, Jun 11, 2023 at 1:43?PM Rui Barradas < > > ruipbarradas at sapo.pt> > > > > >>>> wrote: > > > > >>>> > > > > >>>>> ?s 21:05 de 11/06/2023, javad bayat escreveu: > > > > >>>>>> Dear R users; > > > > >>>>>> I am trying to fill a column based on a specific value in > > another > > > > >>>>>> column > > > > >>>>> of > > > > >>>>>> a dataframe, but it seems there is a problem with the codes! > > > > >>>>>> The "Layer" and the "LU" are two different columns of the > > dataframe. > > > > >>>>>> How can I fix this? > > > > >>>>>> Sincerely > > > > >>>>>> > > > > >>>>>> > > > > >>>>>> for (i in 1:nrow(data2$Layer)){ > > > > >>>>>> if (data2$Layer == "Level 12") { > > > > >>>>>> data2$LU == "Park" > > > > >>>>>> } > > > > >>>>>> } > > > > >>>>>> > > > > >>>>>> > > > > >>>>>> > > > > >>>>>> > > > > >>>>> Hello, > > > > >>>>> > > > > >>>>> There are two bugs in your code, > > > > >>>>> > > > > >>>>> 1) the index i is not used in the loop > > > > >>>>> 2) the assignment operator is `<-`, not `==` > > > > >>>>> > > > > >>>>> > > > > >>>>> Here is the loop corrected. > > > > >>>>> > > > > >>>>> for (i in 1:nrow(data2$Layer)){ > > > > >>>>> if (data2$Layer[i] == "Level 12") { > > > > >>>>> data2$LU[i] <- "Park" > > > > >>>>> } > > > > >>>>> } > > > > >>>>> > > > > >>>>> > > > > >>>>> > > > > >>>>> But R is a vectorized language, the following two ways are the > > > > idiomac > > > > >>>>> ways of doing what you want to do. > > > > >>>>> > > > > >>>>> > > > > >>>>> > > > > >>>>> i <- data2$Layer == "Level 12" > > > > >>>>> data2$LU[i] <- "Park" > > > > >>>>> > > > > >>>>> # equivalent one-liner > > > > >>>>> data2$LU[data2$Layer == "Level 12"] <- "Park" > > > > >>>>> > > > > >>>>> > > > > >>>>> > > > > >>>>> If there are NA's in data2$Layer it's probably safer to use > > ?which() > > > > in > > > > >>>>> the logical index, to have a numeric one. > > > > >>>>> > > > > >>>>> > > > > >>>>> > > > > >>>>> i <- which(data2$Layer == "Level 12") > > > > >>>>> data2$LU[i] <- "Park" > > > > >>>>> > > > > >>>>> # equivalent one-liner > > > > >>>>> data2$LU[which(data2$Layer == "Level 12")] <- "Park" > > > > >>>>> > > > > >>>>> > > > > >>>>> Hope this helps, > > > > >>>>> > > > > >>>>> Rui Barradas > > > > >>>>> > > > > >>>> > > > > >>>> > > > > >>> Hello, > > > > >>> > > > > >>> You don't need to repeat the same instruction 100+ times, there is > > a > > > > way > > > > >>> of assigning all new LU values at the same time with match(). > > > > >>> This assumes that you have the new values in a vector. > > > > >> > > > > >> Sorry, this is not clear. I mean > > > > >> > > > > >> > > > > >> This assumes that you have the new values in a vector, the vector > > Names > > > > >> below. The vector of values to be matched is created from the data. > > > > >> > > > > >> > > > > >> Rui Barradas > > > > >> > > > > >>> > > > > >>> > > > > >>> Values <- sort(unique(data2$Layer)) > > > > >>> Names <- c("Park", "Agri", "GS") > > > > >>> > > > > >>> i <- match(data2$Layer, Values) > > > > >>> data2$LU <- Names[i] > > > > >>> > > > > >>> > > > > >>> Hope this helps, > > > > >>> > > > > >>> Rui Barradas > > > > >>> > > > > >>> ______________________________________________ > > > > >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > > >>> https://stat.ethz.ch/mailman/listinfo/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, > > > > > > > > Please cc the r-help list, R-Help is threaded and this can in the > > future > > > > be helpful to others. > > > > > > > > You can combine several patters like this: > > > > > > > > > > > > pat <- c("_esmdes|_Des Section|0") > > > > grep(pat, data2$Layer) > > > > > > > > or, programatically, > > > > > > > > > > > > pat <- paste(c("_esmdes","_Des Section","0"), collapse = "|") > > > > > > > > > > > > Hope this helps, > > > > > > > > Rui Barradas > > > > > > > > > > > > > > -- > > > Best Regards > > > Javad Bayat > > > M.Sc. Environment Engineering > > > Alternative Mail: bayat194 at yahoo.com > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- > Best Regards > Javad Bayat > M.Sc. Environment Engineering > Alternative Mail: bayat194 at yahoo.com > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com Wed Jun 14 00:20:33 2023 From: @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com (Ana Marija) Date: Tue, 13 Jun 2023 17:20:33 -0500 Subject: [R] log transform a data frame In-Reply-To: References: Message-ID: Thank you so much David, here is correction: d1=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv", stringsAsFactors=FALSE, header=TRUE)) d1$X <- NULL d2=as.matrix(sapply(d1, as.numeric)) pdf("~/graph.pdf") b<-barplot(d2, legend= c("SYCL", "CUDA"), beside= TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", "#6a51a3")) dev.off() > dput(head(d1)) structure(list(Domain.decomp. = c("2. 1", "2"), DD.com..load = c(0L, 0L), Neighbor.search = c("3.7", "3. 1"), Launch.PP.GPU.ops. = c("0. 1", "0"), Comm..coord. = c("1 .6", "1 .0"), Force = c("1 . 5", "1 .2" ), Wait...Comm..F = c("1 .3", "1 .7"), PIE.mesh = c(65.6, 70.9 ), Wait.Bonded.GPU = c(0L, 0L), wait.GPU.NB.nonloc. = c(0L, 0L ), Wait.GPU.NB.local = c(0L, 0L), NB.X.F.buffer.ops. = c(7.3, 4.4), Write.traje = c(0.3, 0.3), Update = c(6.3, 4.3), Constraints = c(8.9, 9.7), Comm..energies = c(0.9, 0.9), PIE.redist..X.F = c("8. 1", "8.7"), PIE.spread = c(29.7, 30.6), PIE.gather = c("19.9", "21 .3" ), PIE.3D.FFT = c(6, 8.6), PIE.3D.FFT.comm. = c("1 .2", "1 .0" ), PIE.solve.Elec = c(0.7, 0.5)), row.names = 1:2, class = "data.frame") Now my problem is that when I save my plot as PDF my labels on X axis are cut off. Any advice about that? On Tue, Jun 13, 2023 at 5:14?PM David Carlson wrote: > Your first data column appears to contain character data (e.g. SYCL) which > cannot be converted to numeric. You also appear to have 0's in the numeric > columns which will cause problems since log(0) is -Inf. Barplots are useful > for categorical data, but not continuous, numeric data which are better > handled with box plots or strip charts. > > Do not use printouts of your data since it hides important information. > Use str(a11) and dput(a11) or dput(head(a11)) to provide useful information > about your data. > > David L Carlson > Texas A&M University > > > On Tue, Jun 13, 2023 at 4:08?PM Ana Marija > wrote: > >> Hello, I have a data frame like this: d11=suppressWarnings(read. >> csv("/Users/anamaria/Downloads/B1. csv", stringsAsFactors=FALSE, >> header=TRUE)) > d11 X Domain. decomp. DD. com. . load Neighbor. search >> Launch. PP. GPU. ops. Comm. . coord. 1 SYCL 2. 1 >> ZjQcmQRYFpfptBannerStart >> This Message Is From an External Sender >> This message came from outside your organization. >> >> ZjQcmQRYFpfptBannerEnd >> >> Hello, >> >> I have a data frame like this: >> >> d11=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv", >> stringsAsFactors=FALSE, header=TRUE)) >> >> > d11 >> X Domain.decomp. DD.com..load Neighbor.search Launch.PP.GPU.ops. >> Comm..coord. >> 1 SYCL 2. 1 0 3.7 0. 1 >> 1 .6 >> 2 CUDA 2 0 3. 1 0 >> 1 .0 >> Force Wait...Comm..F PIE.mesh Wait.Bonded.GPU wait.GPU.NB.nonloc. >> 1 1 . 5 1 .3 65.6 0 0 >> 2 1 .2 1 .7 70.9 0 0 >> Wait.GPU.NB.local NB.X.F.buffer.ops. Write.traje Update Constraints >> Comm..energies >> 1 0 7.3 0.3 6.3 8.9 >> 0.9 >> 2 0 4.4 0.3 4.3 9.7 >> 0.9 >> PIE.redist..X.F PIE.spread PIE.gather PIE.3D.FFT PIE.3D.FFT.comm. >> PIE.solve.Elec >> 1 8. 1 29.7 19.9 6.0 1 .2 >> 0.7 >> 2 8.7 30.6 21 .3 8.6 1 .0 >> 0.5 >> >> I am trying to log transform the whole data frame, but I get this error: >> >> > d1=log(d11) >> Error in Math.data.frame(d11) : >> non-numeric variable(s) in data frame: X, Domain.decomp., >> Neighbor.search, Launch.PP.GPU.ops., Comm..coord., Force, Wait...Comm..F, >> PIE.redist..X.F, PIE.gather, PIE.3D.FFT.comm >> >> >> My goal is to make a stacked barplot like this: >> d2=as.matrix(sapply(d1, as.numeric)) >> b<-barplot(d2, legend= rownames(data2), beside= >> TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", >> "#6a51a3")) >> >> If I don't log transform my code runs. >> >> Please advise, >> Ana >> >> [[alternative HTML version deleted]] >> >> ______________________________________________R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czR4zGIstg$ >> PLEASE do read the posting guide https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czRLvLqcYM$ >> and provide commented, minimal, self-contained, reproducible code. >> >> [[alternative HTML version deleted]] From @vi@e@gross m@iii@g oii gm@ii@com Wed Jun 14 01:24:45 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Tue, 13 Jun 2023 19:24:45 -0400 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: <00d901d99e3c$a0fc83b0$e2f58b10$@gmail.com> Message-ID: <010401d99e4e$3d48f710$b7dae530$@gmail.com> Bert, I stand corrected. What I said may have once been true but apparently the implementation seems to have changed at some level. I did not factor that in. Nevertheless, whether you use an index as a key or as an offset into an attached vector of labels, it seems to work the same and I think my comment applies well enough that changing a few labels instead of scanning lots of entries can sometimes be a good think. As far as I can tell, external interface seem the same for now. One issue with R for a long time was how they did not do something more like a Python dictionary and it looks like ? ABOVE From: Bert Gunter Sent: Tuesday, June 13, 2023 6:15 PM To: avi.e.gross at gmail.com Cc: javad bayat ; R-help at r-project.org Subject: Re: [R] Problem with filling dataframe's column Below. On Tue, Jun 13, 2023 at 2:18?PM > wrote: > > > Javad, > > There may be nothing wrong with the methods people are showing you and if it satisfied you, great. > > But I note you have lots of data in over a quarter million rows. If much of the text data is redundant, and you want to simplify some operations such as changing some of the values to others I multiple ways, have you done any learning about an R feature very useful for dealing with categorical data called "factors"? > > If you have a vector or a column in a data.frame that contains text, then it can be replaced by a factor that often takes way less space as it stores a sort of dictionary of all the unique values and just records numbers like 1,2,3 to tell which one each item is. -- This is false. It used to be true a **long time ago**, but R has for quite a while used hashing/global string tables to avoid this problem. See here for details/references. As a result, I think many would argue that working with strings *as strings,* not factors, if often a better default, though of course there are still situations where factors are useful (e.g. in ordering results by factor levels where the desired level order is not alphabetical). **I would appreciate correction/ clarification if my claims are wrong or misleading! ** In any case, please do check such claims before making them on this list. Cheers, Bert [[alternative HTML version deleted]] From dc@r|@on @end|ng |rom t@mu@edu Wed Jun 14 04:55:54 2023 From: dc@r|@on @end|ng |rom t@mu@edu (David Carlson) Date: Tue, 13 Jun 2023 21:55:54 -0500 Subject: [R] log transform a data frame In-Reply-To: References: Message-ID: Try this pdf("~/graph.pdf") par(mar=c(8, 4, 4, 2)) barplot(d2, legend= c("SYCL", "CUDA"), beside= TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", "#6a51a3")) dev.off() See ?par to see the details for adjusting margins and other plot features. David On Tue, Jun 13, 2023 at 5:20?PM Ana Marija wrote: > Thank you so much David, here is correction: d1=suppressWarnings(read. > csv("/Users/anamaria/Downloads/B1. csv", stringsAsFactors=FALSE, > header=TRUE)) d1$X <- NULL d2=as. matrix(sapply(d1, as. numeric)) > pdf("~/graph. pdf")b<-barplot(d2, > ZjQcmQRYFpfptBannerStart > This Message Is From an External Sender > This message came from outside your organization. > > ZjQcmQRYFpfptBannerEnd > Thank you so much David, here is correction: > > d1=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv", > stringsAsFactors=FALSE, header=TRUE)) > d1$X <- NULL > d2=as.matrix(sapply(d1, as.numeric)) > pdf("~/graph.pdf") > b<-barplot(d2, legend= c("SYCL", "CUDA"), beside= > TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", > "#6a51a3")) > dev.off() > > > dput(head(d1)) > structure(list(Domain.decomp. = c("2. 1", "2"), DD.com..load = c(0L, > 0L), Neighbor.search = c("3.7", "3. 1"), Launch.PP.GPU.ops. = c("0. 1", > "0"), Comm..coord. = c("1 .6", "1 .0"), Force = c("1 . 5", "1 .2" > ), Wait...Comm..F = c("1 .3", "1 .7"), PIE.mesh = c(65.6, 70.9 > ), Wait.Bonded.GPU = c(0L, 0L), wait.GPU.NB.nonloc. = c(0L, 0L > ), Wait.GPU.NB.local = c(0L, 0L), NB.X.F.buffer.ops. = c(7.3, > 4.4), Write.traje = c(0.3, 0.3), Update = c(6.3, 4.3), Constraints = > c(8.9, > 9.7), Comm..energies = c(0.9, 0.9), PIE.redist..X.F = c("8. 1", > "8.7"), PIE.spread = c(29.7, 30.6), PIE.gather = c("19.9", "21 .3" > ), PIE.3D.FFT = c(6, 8.6), PIE.3D.FFT.comm. = c("1 .2", "1 .0" > ), PIE.solve.Elec = c(0.7, 0.5)), row.names = 1:2, class = "data.frame") > > Now my problem is that when I save my plot as PDF my labels on X axis are > cut off. Any advice about that? > > > > On Tue, Jun 13, 2023 at 5:14?PM David Carlson wrote: > >> Your first data column appears to contain character data (e.g. SYCL) which >> cannot be converted to numeric. You also appear to have 0's in the numeric >> columns which will cause problems since log(0) is -Inf. Barplots are useful >> for categorical data, but not continuous, numeric data which are better >> handled with box plots or strip charts. >> >> Do not use printouts of your data since it hides important information. >> Use str(a11) and dput(a11) or dput(head(a11)) to provide useful information >> about your data. >> >> David L Carlson >> Texas A&M University >> >> >> On Tue, Jun 13, 2023 at 4:08?PM Ana Marija >> wrote: >> >>> Hello, I have a data frame like this: d11=suppressWarnings(read. >>> csv("/Users/anamaria/Downloads/B1. csv", stringsAsFactors=FALSE, >>> header=TRUE)) > d11 X Domain. decomp. DD. com. . load Neighbor. search >>> Launch. PP. GPU. ops. Comm. . coord. 1 SYCL 2. 1 >>> ZjQcmQRYFpfptBannerStart >>> This Message Is From an External Sender >>> This message came from outside your organization. >>> >>> ZjQcmQRYFpfptBannerEnd >>> >>> Hello, >>> >>> I have a data frame like this: >>> >>> d11=suppressWarnings(read.csv("/Users/anamaria/Downloads/B1.csv", >>> stringsAsFactors=FALSE, header=TRUE)) >>> >>> > d11 >>> X Domain.decomp. DD.com..load Neighbor.search Launch.PP.GPU.ops. >>> Comm..coord. >>> 1 SYCL 2. 1 0 3.7 0. 1 >>> 1 .6 >>> 2 CUDA 2 0 3. 1 0 >>> 1 .0 >>> Force Wait...Comm..F PIE.mesh Wait.Bonded.GPU wait.GPU.NB.nonloc. >>> 1 1 . 5 1 .3 65.6 0 0 >>> 2 1 .2 1 .7 70.9 0 0 >>> Wait.GPU.NB.local NB.X.F.buffer.ops. Write.traje Update Constraints >>> Comm..energies >>> 1 0 7.3 0.3 6.3 8.9 >>> 0.9 >>> 2 0 4.4 0.3 4.3 9.7 >>> 0.9 >>> PIE.redist..X.F PIE.spread PIE.gather PIE.3D.FFT PIE.3D.FFT.comm. >>> PIE.solve.Elec >>> 1 8. 1 29.7 19.9 6.0 1 .2 >>> 0.7 >>> 2 8.7 30.6 21 .3 8.6 1 .0 >>> 0.5 >>> >>> I am trying to log transform the whole data frame, but I get this error: >>> >>> > d1=log(d11) >>> Error in Math.data.frame(d11) : >>> non-numeric variable(s) in data frame: X, Domain.decomp., >>> Neighbor.search, Launch.PP.GPU.ops., Comm..coord., Force, Wait...Comm..F, >>> PIE.redist..X.F, PIE.gather, PIE.3D.FFT.comm >>> >>> >>> My goal is to make a stacked barplot like this: >>> d2=as.matrix(sapply(d1, as.numeric)) >>> b<-barplot(d2, legend= rownames(data2), beside= >>> TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,80), col=c("#9e9ac8", >>> "#6a51a3")) >>> >>> If I don't log transform my code runs. >>> >>> Please advise, >>> Ana >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czR4zGIstg$ >>> PLEASE do read the posting guide https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!GkOclaf0NPpoVxF8zs_a2pCGlBelsouhJKKR4wG4cG_gEycZ6t-N6nbPvxD1AxnYureFFthr_Nc-zXCU0czRLvLqcYM$ >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> [[alternative HTML version deleted]] From r@oknz @end|ng |rom gm@||@com Thu Jun 15 04:34:20 2023 From: r@oknz @end|ng |rom gm@||@com (Richard O'Keefe) Date: Thu, 15 Jun 2023 14:34:20 +1200 Subject: [R] Problem with filling dataframe's column In-Reply-To: <010401d99e4e$3d48f710$b7dae530$@gmail.com> References: <00d901d99e3c$a0fc83b0$e2f58b10$@gmail.com> <010401d99e4e$3d48f710$b7dae530$@gmail.com> Message-ID: Consider m <- list(foo=c(1,2),"B'ar"=as.matrix(1:4,2,2),"!*#"=c(FALSE,TRUE)) It is a collection of elements of different types/structures, accessible via string keys (and also by position). Entries can be added: m[["fred"]] <- 47 Entries can be removed: m[["!*#"]] <- NULL How much more like a Python dictionary do you need it to be? On Wed, 14 Jun 2023 at 11:25, wrote: > Bert, > > I stand corrected. What I said may have once been true but apparently the > implementation seems to have changed at some level. > > I did not factor that in. > > Nevertheless, whether you use an index as a key or as an offset into an > attached vector of labels, it seems to work the same and I think my comment > applies well enough that changing a few labels instead of scanning lots of > entries can sometimes be a good think. As far as I can tell, external > interface seem the same for now. > > One issue with R for a long time was how they did not do something more > like a Python dictionary and it looks like ? > > ABOVE > > From: Bert Gunter > Sent: Tuesday, June 13, 2023 6:15 PM > To: avi.e.gross at gmail.com > Cc: javad bayat ; R-help at r-project.org > Subject: Re: [R] Problem with filling dataframe's column > > Below. > > > On Tue, Jun 13, 2023 at 2:18?PM avi.e.gross at gmail.com> > wrote: > > > > > > Javad, > > > > There may be nothing wrong with the methods people are showing you and > if it satisfied you, great. > > > > But I note you have lots of data in over a quarter million rows. If much > of the text data is redundant, and you want to simplify some operations > such as changing some of the values to others I multiple ways, have you > done any learning about an R feature very useful for dealing with > categorical data called "factors"? > > > > If you have a vector or a column in a data.frame that contains text, > then it can be replaced by a factor that often takes way less space as it > stores a sort of dictionary of all the unique values and just records > numbers like 1,2,3 to tell which one each item is. > > -- This is false. It used to be true a **long time ago**, but R has for > quite a while used hashing/global string tables to avoid this problem. See > here < > https://stackoverflow.com/questions/50310092/why-does-r-use-factors-to-store-characters> > for details/references. > As a result, I think many would argue that working with strings *as > strings,* not factors, if often a better default, though of course there > are still situations where factors are useful (e.g. in ordering results by > factor levels where the desired level order is not alphabetical). > > **I would appreciate correction/ clarification if my claims are wrong or > misleading! ** > > In any case, please do check such claims before making them on this list. > > Cheers, > Bert > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From @vi@e@gross m@iii@g oii gm@ii@com Thu Jun 15 07:51:47 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Thu, 15 Jun 2023 01:51:47 -0400 Subject: [R] Problem with filling dataframe's column In-Reply-To: References: <00d901d99e3c$a0fc83b0$e2f58b10$@gmail.com> <010401d99e4e$3d48f710$b7dae530$@gmail.com> Message-ID: <017b01d99f4d$795ff410$6c1fdc30$@gmail.com> Richard, it is indeed possible for different languages to choose different approaches. If your point is that an R named list can simulate a Python dictionary (or for that manner, a set) there is some validity to that. You can also use environments similarly. Arguably there are differences including in things like what notations are built into the language. If you look the other way, Python chose to make lists a major feature which can hold any combination of things and can even be used to emulate a matrix with sub-lists and also had a tuple version that is similar but immutable and initially neglected something as simple as a vector containing just one kind of content. If you look at it now, many people simply load numpy (and often pandas) to get functionality that is faster and comes by default in R. I think this discussion was about my (amended) offhand remark suggesting R factors stored plain text in a vector attached to the variable and the offset was the number stored in the main factor vector. If that changed to internally use something hashed like a dictionary, fine. I have often made data structures such as in your example to store named items but did not call it a dictionary but simply a named list. In one sense, the two map into each other but I could argue there remain differences. For example, you can use something immutable like a tuple as a key in python. This is not an argument about which language is better. Each has developed to fill ideas and has been extended and quite a few things can now be done in either one. Still, it can be interesting to combine the two inside RSTUDIO so each does some of what it may do better or faster or in a way you find more natural. From: Richard O'Keefe Sent: Wednesday, June 14, 2023 10:34 PM To: avi.e.gross at gmail.com Cc: Bert Gunter ; R-help at r-project.org Subject: Re: [R] Problem with filling dataframe's column Consider m <- list(foo=c(1,2),"B'ar"=as.matrix(1:4,2,2),"!*#"=c(FALSE,TRUE)) It is a collection of elements of different types/structures, accessible via string keys (and also by position). Entries can be added: m[["fred"]] <- 47 Entries can be removed: m[["!*#"]] <- NULL How much more like a Python dictionary do you need it to be? On Wed, 14 Jun 2023 at 11:25, > wrote: Bert, I stand corrected. What I said may have once been true but apparently the implementation seems to have changed at some level. I did not factor that in. Nevertheless, whether you use an index as a key or as an offset into an attached vector of labels, it seems to work the same and I think my comment applies well enough that changing a few labels instead of scanning lots of entries can sometimes be a good think. As far as I can tell, external interface seem the same for now. One issue with R for a long time was how they did not do something more like a Python dictionary and it looks like ? ABOVE From: Bert Gunter > Sent: Tuesday, June 13, 2023 6:15 PM To: avi.e.gross at gmail.com Cc: javad bayat >; R-help at r-project.org Subject: Re: [R] Problem with filling dataframe's column Below. On Tue, Jun 13, 2023 at 2:18?PM > > wrote: > > > Javad, > > There may be nothing wrong with the methods people are showing you and if it satisfied you, great. > > But I note you have lots of data in over a quarter million rows. If much of the text data is redundant, and you want to simplify some operations such as changing some of the values to others I multiple ways, have you done any learning about an R feature very useful for dealing with categorical data called "factors"? > > If you have a vector or a column in a data.frame that contains text, then it can be replaced by a factor that often takes way less space as it stores a sort of dictionary of all the unique values and just records numbers like 1,2,3 to tell which one each item is. -- This is false. It used to be true a **long time ago**, but R has for quite a while used hashing/global string tables to avoid this problem. See here for details/references. As a result, I think many would argue that working with strings *as strings,* not factors, if often a better default, though of course there are still situations where factors are useful (e.g. in ordering results by factor levels where the desired level order is not alphabetical). **I would appreciate correction/ clarification if my claims are wrong or misleading! ** In any case, please do check such claims before making them on this list. Cheers, Bert [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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]] From d@@tt@|| @end|ng |rom gm@||@com Wed Jun 14 15:22:27 2023 From: d@@tt@|| @end|ng |rom gm@||@com (Dean Attali) Date: Wed, 14 Jun 2023 09:22:27 -0400 Subject: [R] Why install.packages(repos = X) does not override the 'repos' R option? Message-ID: There is a default R option for which repos to install from - `getOption("repos")`. When installing a package using install.packages(), you can provide a `repos` parameter. The default value of that parameter is `getOption("repos")`. I assumed that this parameter would override the R option. In other words, I assumed that if the parameter is provided, then the R option would not even be looked at. But after testing this, it seems this is not the case. For example, running the following two lines in an R session: options(repos=c(CRAN="https://BADNAME.com")) install.packages("vctrs", repos = "https://cloud.R-project.org") I would have expected the first line to be rendered meaningless, but in fact after running the second line I see errors about the BADNAME repository. This feels like a bug to me, but I'm sure there's a reason behind this. Does anyone know why this is the case? [[alternative HTML version deleted]] From murdoch@dunc@n @end|ng |rom gm@||@com Thu Jun 15 19:42:18 2023 From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch) Date: Thu, 15 Jun 2023 13:42:18 -0400 Subject: [R] Why install.packages(repos = X) does not override the 'repos' R option? In-Reply-To: References: Message-ID: <117c90bd-eaf5-c789-7953-12f3fa8ecdbd@gmail.com> (Sorry, forgot "Reply all" last time.) That's an RStudio bug. It doesn't happen if you use install.packages() from R. Duncan Murdoch On 14/06/2023 9:22 a.m., Dean Attali wrote: > There is a default R option for which repos to install from - > `getOption("repos")`. > > When installing a package using install.packages(), you can provide a > `repos` parameter. The default value of that parameter is > `getOption("repos")`. I assumed that this parameter would override the R > option. In other words, I assumed that if the parameter is provided, then > the R option would not even be looked at. But after testing this, it seems > this is not the case. > > For example, running the following two lines in an R session: > > options(repos=c(CRAN="https://BADNAME.com")) > install.packages("vctrs", repos = "https://cloud.R-project.org") > > I would have expected the first line to be rendered meaningless, but in > fact after running the second line I see errors about the BADNAME > repository. This feels like a bug to me, but I'm sure there's a reason > behind this. Does anyone know why this is the case? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From @ndrewzh@ng20052005 @end|ng |rom gm@||@com Fri Jun 16 00:14:57 2023 From: @ndrewzh@ng20052005 @end|ng |rom gm@||@com (Andrew Zhang) Date: Thu, 15 Jun 2023 15:14:57 -0700 Subject: [R] Feature selection for multiclass classification Message-ID: Hello everyone, can someone share a list of packages that can do feature selection for multiclass (more than binary) classification? I have large genomic datasets with thousands of genes that I'm trying to use for cancer type (>10) classification, I am wondering if there are any specific packages/methods for feature selection prior to building a classification model using machine learning models. Thanks, Andrew [[alternative HTML version deleted]] From er|cjberger @end|ng |rom gm@||@com Fri Jun 16 09:28:33 2023 From: er|cjberger @end|ng |rom gm@||@com (Eric Berger) Date: Fri, 16 Jun 2023 10:28:33 +0300 Subject: [R] Feature selection for multiclass classification In-Reply-To: References: Message-ID: you might want to search bioconductor https://www.bioconductor.org/ https://bioconductor.org/books/3.13/OSCA.basic/feature-selection.html On Fri, Jun 16, 2023 at 9:04?AM Andrew Zhang wrote: > Hello everyone, can someone share a list of packages that can do feature > selection for multiclass (more than binary) classification? I have large > genomic datasets with thousands of genes that I'm trying to use for cancer > type (>10) classification, I am wondering if there are any specific > packages/methods for feature selection prior to building a classification > model using machine learning models. > > Thanks, > > Andrew > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From pd@me@ @end|ng |rom cb@@dk Fri Jun 16 10:36:58 2023 From: pd@me@ @end|ng |rom cb@@dk (Peter Dalgaard) Date: Fri, 16 Jun 2023 08:36:58 +0000 Subject: [R] [Rd] R 4.3.1 is released Message-ID: <766DF86F-36F4-4144-829E-DCB1B6A59DE5@cbs.dk> The build system rolled up R-4.3.1.tar.gz (codename "Beagle Scouts") this morning. This is a minor update, with a few bug fixes. The list below details the changes in this release. You can get the source code from https://cran.r-project.org/src/base/R-4/R-4.3.1.tar.gz or wait for it to be mirrored at a CRAN site nearer to you. Binaries for various platforms will appear in due course. For the R Core Team, Peter Dalgaard These are the checksums (md5 and SHA-256) for the freshly created files, in case you wish to check that they are uncorrupted: MD5 (AUTHORS) = 320967884b547734d6279dedbc739dd4 MD5 (COPYING) = eb723b61539feef013de476e68b5c50a MD5 (COPYING.LIB) = a6f89e2100d9b6cdffcea4f398e37343 MD5 (FAQ) = 97a3ddc25aab502a70bfb1a79ab6f862 MD5 (INSTALL) = 7893f754308ca31f1ccf62055090ad7b MD5 (NEWS) = 7ea998dffa2b8d4f5a6aee84c45a383a MD5 (NEWS.0) = bfcd7c147251b5474d96848c6f57e5a8 MD5 (NEWS.1) = 4108ab429e768e29b1c3b418c224246e MD5 (NEWS.2) = b38d94569700664205a76a7de836ba83 MD5 (NEWS.3) = e55ed2c8a547b827b46e08eb7137ba23 MD5 (R-latest.tar.gz) = b83cee497046d4aef649eb79e6df83e8 MD5 (README) = f468f281c919665e276a1b691decbbe6 MD5 (RESOURCES) = a79b9b338cab09bd665f6b62ac6f455b MD5 (THANKS) = 45b6d2e88a6ecb5b24fa33a781351cd5 MD5 (VERSION-INFO.dcf) = 3d4c6bf5bf44d34766f90ed67d05c34a MD5 (R-4/R-4.3.1.tar.gz) = b83cee497046d4aef649eb79e6df83e8 60a0d150e6fc1f424be76ad7b645d236b56e747692a4679f81ce6536c550e949 AUTHORS e6d6a009505e345fe949e1310334fcb0747f28dae2856759de102ab66b722cb4 COPYING 6095e9ffa777dd22839f7801aa845b31c9ed07f3d6bf8a26dc5d2dec8ccc0ef3 COPYING.LIB 3a47bca1e2a7db27c0ca12be388c238e2608ff2f768e627650a71a0ffc826038 FAQ f87461be6cbaecc4dce44ac58e5bd52364b0491ccdadaf846cb9b452e9550f31 INSTALL a8167cfe28e748b67476d4a21a968cfa24d0935da89cd4514c483f45f3f2a83b NEWS 4e21b62f515b749f80997063fceab626d7258c7d650e81a662ba8e0640f12f62 NEWS.0 5de7657c5e58e481403c0dd1a74a5c090b3ef481ce75a91dfe05d4b03f63163f NEWS.1 cde079b6beab7d700d3d4ecda494e2681ad3b7f8fab13b68be090f949393ec62 NEWS.2 1910a2405300b9bc7c76beeb0753a5249cf799afe175ce28f8d782fab723e012 NEWS.3 8dd0bf24f1023c6f618c3b317383d291b4a494f40d73b983ac22ffea99e4ba99 R-latest.tar.gz 2fdd3e90f23f32692d4b3a0c0452f2c219a10882033d1774f8cadf25886c3ddc README 8b7d3856100220f4555d4d57140829f2e81c27eccec5b441f5dce616e9ec9061 RESOURCES 8319c5415de58ee10d4bc058d79c370fd8e6b2ad09e25d7a1e04b74ca5f380a6 THANKS 032260f31c56c011a9724930e356eac4d7ddfcaa63c559f95986063ede3bf91a VERSION-INFO.dcf 8dd0bf24f1023c6f618c3b317383d291b4a494f40d73b983ac22ffea99e4ba99 R-4/R-4.3.1.tar.gz This is the relevant part of the NEWS file CHANGES IN R 4.3.1: C-LEVEL FACILITIES: * The C-level API version of R's integrate(), Rdqags() in Applic.h, now returns the correct number of integrand evaluations neval, fixing PR#18515 reported and diagnosed by Stephen Wade. * The C prototypes for LAPACK calls dspgv and dtptrs in R_exts/Lapack.h had one too many and one too few character length arguments - but this has not caused any known issues. To get the corrected prototypes, include #include // for PR18534fixed #ifdef PR18534fixed # define usePR18534fix 1 #endif #include in your C/C++ code (PR#18534). INSTALLATION: * Many of the checks of esoteric Internet operations and those using unreliable external sites have been moved to a new target that is not run by default and primarily intended for the core developers. To run them use cd tests; make test-Internet-dev BUG FIXES: * .S3methods(), typically called from methods(), again marks methods from package base as visible. Also, the visibility of non-base methods is again determined by the method's presence in search(). * tools::Rdiff() is now more robust against invalid strings, fixing installation tests on Windows without Rtools installed (PR#18530). * Fix (new) bug in hcl.colors(2, *), by Achim Zeileis (PR#18523). * head(., ) and tail(..) now produce more useful "Error in ...." error messages, fixing PR#18362. * Package code syntax on Windows is checked in UTF-8 when UTF-8 is the native encoding. * na.contiguous(x) now also returns the first run, when it is at the beginning and there is a later one of the same length; reported to R-devel, including a fix, by Georgi Boshnakov. Further, by default, it modifies only an existing attr(*,"tsp") but otherwise no longer sets one. * chol(, pivot = ) now gives a correct error or warning message (depending on pivot), thanks to Mikael Jagan's (PR#18541). -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com _______________________________________________ R-announce at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-announce From @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com Sat Jun 17 01:07:37 2023 From: @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com (Ana Marija) Date: Fri, 16 Jun 2023 18:07:37 -0500 Subject: [R] Issue with crammed Y axis Message-ID: Hi, I have a data frame like this: > dput(df) structure(list(ID = 1:8, Type = c("gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps 10000 -resethway", "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps 10000 -resethway", "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps 4000 -resetstep 3000", "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps 4000 -resetstep 3000", "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway", "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway", "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway -noconfout", "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway -noconfout" ), Annee = c("SYCL", "CUDA", "SYCL", "CUDA", "SYCL", "CUDA", "SYCL", "CUDA"), Domain.decomp. = c("2. 1", "2", "2. 1", "2. 1", "2.1", "2", "2. 1", "2"), DD.com..load = c(0, 0, 0, 0, 3.7, 3, 0, 0), Neighbor.search = c("3.7", "3. 1", "3.7", "3.9", "0. 1", "O. 1", "3.5", "3. 1"), Launch.PP.GPU.ops. = c("0. 1", "0", "0.2", "0", "1 .6", "1 . 5", "0.2", "0. 1"), Comm..coord. = c("1 .6", "1 .0", "1 .5", "1 .3", "1 .5", "1 .3", "1 . 5", "1 .6"), Force = c("1 . 5", "1 .2", "1 .4", "1 .2", "1 .3", "1 . 1", "1 .5", "1 .2"), Wait...Comm..F = c("1 .3", "1 .7", "1 .2", "1 .0", "66.7", "68.8", "1 .2", "1 .2"), PIE.mesh = c("65.6", "70.9", "61 .0", "61 .4", "0", "0", "67.6", "69.2"), Wait.Bonded.GPU = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), wait.GPU.NB.nonloc. = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Wait.GPU.NB.local = c(0, 0, 0, 0, 7.4, 5.7, 0, 0), NB.X.F.buffer.ops. = c("7.3", "4.4", "6. 7", "5", "0. 1", "0. 1", "7.2", "5.5"), Write.traje = c("0.3", "0.3", "1 .2", "1 .3", "6.4", "6. 1", "O. 1", "0. 1"), Update = c(6.3, 4.3, 5.7, 4.9, 8.2, 9.5, 6.2, 5.6), Constraints = c("8.9", "9.7", "1 1 .6", "13.3", "0.3", "0.4", "8. 1", "9.5"), Comm..energies = c("0.9", "0.9", "3.3", "3.9", "8.4", "8. 5", "0.3", "0.4"), PIE.redist..X.F = c("8. 1", "8.7", "7.9", "7.4", "29.9", "30.1", "8. 1", "8. 1"), PIE.spread = c("29.7", "30.6", "27.2", "29.6", "20.3", "20.2", "30. 1", "30.4"), PIE.gather = c("19.9", "21 .3", "18.7", "19", "6.4", "8.4", "20", "20.6"), PIE.3D.FFT = c("6", "8.6", "5.7", "4.3", "1 .0", "1 .1", "7.6", "8.4"), PIE.3D.FFT.comm. = c("1 .2", "1 .0", "0.9", "0.7", "1 .2", "0. 5", "1 .0", "1 .1"), PIE.solve.Elec = c(0.7, 0.5, 0.6, 0.3, 0.7, 0.5, 0.7, 0.5)), class = "data.frame", row.names = c(NA, -8L)) I am plotting this data with: library(reshape2) library(ggplot2) df <- read.csv("/Users/anamaria/Downloads/B5.csv", stringsAsFactors=FALSE, header=TRUE) df.long<-melt(df,id.vars=c("ID","Type","Annee")) myplot =ggplot(df.long,aes(variable,value,fill=as.factor(Annee)))+ geom_bar(position="dodge",stat="identity")+ ylab("Simulation Progress (%)") + facet_wrap(~Type,nrow=3) myplot + theme(panel.grid.major = element_blank(), legend.title=element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.title.x = element_blank(), axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), axis.line = element_line(colour = "black")) My issue is that Y axis is crammed. How it can be cleaned up and say feature only say these values: 0, 10, 20,30, ...80. I tried using: scale_y_continuous(breaks = breaks_width(10))+ But I got this error: Error in breaks_width(10) : could not find function "breaks_width" Also can anything be done about the subtitle of the top left plot, which is not quite fitting in that gray box: " gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps 10000 -resethway" Thanks Ana [[alternative HTML version deleted]] From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 17 19:16:18 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 17 Jun 2023 17:16:18 +0000 Subject: [R] warnng to an error.... Message-ID: Dear members, I have the following code: > FUN(OHLCDataEP[[63]]) Error in (class(x) == "xts") || (class(x) == "zoo") : 'length = 2' in coercion to 'logical(1)' > traceback() 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]]) > class(OHLCDataEP[[63]]) [1] "xts" "zoo" The following is in ygix() : if((class(x) == "xts") || (class(x) == "zoo") I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. What should I do? Change it to: if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... or is there any workaround? THanking you, Yours sincerely, AKSHAY M KULKARNI [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded] R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)' Using R 4.1.3 I observe: var <- 0 > if(is.data.frame(var) || is.vector(var)) var <- as.matrix(var) > is.null(var) || (!is.matrix(var) && var == 0) || (dim(var)==c(1,1) &&... stackoverflow.com ? [[alternative HTML version deleted]] From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 17 19:27:24 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 17 Jun 2023 17:27:24 +0000 Subject: [R] warnng to an error.... In-Reply-To: References: Message-ID: Dear members, AN update: I have changed the if clause to: if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code} but am bootless..... PLease help... THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: R-help on behalf of akshay kulkarni Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing list Subject: [R] warnng to an error.... Dear members, I have the following code: > FUN(OHLCDataEP[[63]]) Error in (class(x) == "xts") || (class(x) == "zoo") : 'length = 2' in coercion to 'logical(1)' > traceback() 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]]) > class(OHLCDataEP[[63]]) [1] "xts" "zoo" The following is in ygix() : if((class(x) == "xts") || (class(x) == "zoo") I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. What should I do? Change it to: if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... or is there any workaround? THanking you, Yours sincerely, AKSHAY M KULKARNI [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded] R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)' Using R 4.1.3 I observe: var <- 0 > if(is.data.frame(var) || is.vector(var)) var <- as.matrix(var) > is.null(var) || (!is.matrix(var) && var == 0) || (dim(var)==c(1,1) &&... stackoverflow.com ? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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]] From bgunter@4567 @end|ng |rom gm@||@com Sat Jun 17 19:58:42 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Sat, 17 Jun 2023 10:58:42 -0700 Subject: [R] warnng to an error.... In-Reply-To: References: Message-ID: What is class(x) ?? I think you need to (re?) learn about S3 classes, which can in general be vectors. See ?class (the S3 portion) or any tutorial on S3 classes in R. I have no idea what you are trying to do, but I *suspect* it may be accomplished through S3 inheritance rather than changing the class vector. That is just a guess, however. -- Bert On Sat, Jun 17, 2023 at 10:27?AM akshay kulkarni wrote: > Dear members, > AN update: > I have changed the if clause to: > > if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code} > > but am bootless..... > > PLease help... > > THanking you, > Yours sincerely, > AKSHAY M KULKARNI > > ________________________________ > From: R-help on behalf of akshay kulkarni < > akshay_e4 at hotmail.com> > Sent: Saturday, June 17, 2023 10:46 PM > To: R help Mailing list > Subject: [R] warnng to an error.... > > Dear members, > > I have the following code: > > > FUN(OHLCDataEP[[63]]) > Error in (class(x) == "xts") || (class(x) == "zoo") : > 'length = 2' in coercion to 'logical(1)' > > traceback() > 2: ygix(x, "c") at #9 > 1: FUN(OHLCDataEP[[63]]) > > class(OHLCDataEP[[63]]) > [1] "xts" "zoo" > > The following is in ygix() : > > if((class(x) == "xts") || (class(x) == "zoo") > > I think this would have been a warning ( > https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) > but I am on a ubuntu22.04 machine with R 4.3.0. > > What should I do? Change it to: > if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... > > or is there any workaround? > > THanking you, > Yours sincerely, > AKSHAY M KULKARNI > [ > https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded > ]< > https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1 > > > R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)'< > https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1 > > > Using R 4.1.3 I observe: var <- 0 > if(is.data.frame(var) || > is.vector(var)) var <- as.matrix(var) > is.null(var) || > (!is.matrix(var) && var == 0) || (dim(var)==c(1,1) &&... > stackoverflow.com > ? > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From murdoch@dunc@n @end|ng |rom gm@||@com Sat Jun 17 20:06:05 2023 From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch) Date: Sat, 17 Jun 2023 14:06:05 -0400 Subject: [R] warnng to an error.... In-Reply-To: References: Message-ID: On 17/06/2023 1:16 p.m., akshay kulkarni wrote: > Dear members, > > I have the following code: > >> FUN(OHLCDataEP[[63]]) > Error in (class(x) == "xts") || (class(x) == "zoo") : > 'length = 2' in coercion to 'logical(1)' >> traceback() > 2: ygix(x, "c") at #9 > 1: FUN(OHLCDataEP[[63]]) >> class(OHLCDataEP[[63]]) > [1] "xts" "zoo" > > The following is in ygix() : > > if((class(x) == "xts") || (class(x) == "zoo") > > I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. > > What should I do? Change it to: > if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... Changing it to `if (inherits(x, c("xts", "zoo")))` should do the same. The vector of classes in the second argument is read as "any of these classes". Duncan Murdoch From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 17 20:34:11 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 17 Jun 2023 18:34:11 +0000 Subject: [R] warnng to an error.... In-Reply-To: References: Message-ID: Dear Duncan, THankls a lot... THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Duncan Murdoch Sent: Saturday, June 17, 2023 11:36 PM To: akshay kulkarni ; R help Mailing list Subject: Re: [R] warnng to an error.... On 17/06/2023 1:16 p.m., akshay kulkarni wrote: > Dear members, > > I have the following code: > >> FUN(OHLCDataEP[[63]]) > Error in (class(x) == "xts") || (class(x) == "zoo") : > 'length = 2' in coercion to 'logical(1)' >> traceback() > 2: ygix(x, "c") at #9 > 1: FUN(OHLCDataEP[[63]]) >> class(OHLCDataEP[[63]]) > [1] "xts" "zoo" > > The following is in ygix() : > > if((class(x) == "xts") || (class(x) == "zoo") > > I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. > > What should I do? Change it to: > if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... Changing it to `if (inherits(x, c("xts", "zoo")))` should do the same. The vector of classes in the second argument is read as "any of these classes". Duncan Murdoch [[alternative HTML version deleted]] From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 17 20:35:53 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 17 Jun 2023 18:35:53 +0000 Subject: [R] warnng to an error.... In-Reply-To: References: Message-ID: Dear Bert, Duncan's theory is working....probably the same as yours... THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Bert Gunter Sent: Saturday, June 17, 2023 11:28 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] warnng to an error.... What is class(x) ?? I think you need to (re?) learn about S3 classes, which can in general be vectors. See ?class (the S3 portion) or any tutorial on S3 classes in R. I have no idea what you are trying to do, but I *suspect* it may be accomplished through S3 inheritance rather than changing the class vector. That is just a guess, however. -- Bert On Sat, Jun 17, 2023 at 10:27?AM akshay kulkarni > wrote: Dear members, AN update: I have changed the if clause to: if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code} but am bootless..... PLease help... THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: R-help > on behalf of akshay kulkarni > Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing list > Subject: [R] warnng to an error.... Dear members, I have the following code: > FUN(OHLCDataEP[[63]]) Error in (class(x) == "xts") || (class(x) == "zoo") : 'length = 2' in coercion to 'logical(1)' > traceback() 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]]) > class(OHLCDataEP[[63]]) [1] "xts" "zoo" The following is in ygix() : if((class(x) == "xts") || (class(x) == "zoo") I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. What should I do? Change it to: if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... or is there any workaround? THanking you, Yours sincerely, AKSHAY M KULKARNI [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded] R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)' Using R 4.1.3 I observe: var <- 0 > if(is.data.frame(var) || is.vector(var)) var <- as.matrix(var) > is.null(var) || (!is.matrix(var) && var == 0) || (dim(var)==c(1,1) &&... stackoverflow.com ? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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]] From @k@h@y_e4 @end|ng |rom hotm@||@com Sat Jun 17 20:54:43 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Sat, 17 Jun 2023 18:54:43 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: <20230610172016.0fe28e0a@Tarkus> References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> <20230610151242.38cd3980@Tarkus> <20230610172016.0fe28e0a@Tarkus> Message-ID: Dear Ivan, I am reopening this thread because there are some new developments. I have switched to ubuntu and have used ropenblas() in ropenblas package to download the latest openblas (it is a version of skylake as you can see below in sessionInfo()). mclapply() is working fine now... My questions: 1. I was working on a two core machine just to test the code...tomorrow will be switching to a 48 core machine. Should I again download the latest openblas from ropenblas() or do you suggest testing the native openblas that is bundled in Ubuntu( it was a basic version of openblas..in my two core machine I tried the ropenblas() function without testing the native openblas...just for curiosity) ? 2. How do you pass the version of openblas to be installed with ropenblas()? The full file name? or just something like this: libopenblas_skylakexp-r0.3.23.so ? > sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.2 LTS Matrix products: default BLAS/LAPACK: /opt/OpenBLAS/lib/libopenblas_skylakexp-r0.3.23.so; LAPACK version 3.11.0 locale: [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C time zone: Etc/UTC tzcode source: system (glibc) attached base packages: [1] parallel stats graphics grDevices utils datasets methods [8] base other attached packages: [1] pbmcapply_1.5.1 forecast_8.21 attempt_0.3.1 imputeTS_3.3 loaded via a namespace (and not attached): [1] gtable_0.3.3 compiler_4.3.0 Rcpp_1.0.10 xml2_1.3.4 [5] scales_1.2.1 lattice_0.20-45 ggplot2_3.4.2 R6_2.5.1 [9] generics_0.1.3 curl_5.0.1 lmtest_0.9-40 ggtext_0.1.2 [13] tibble_3.2.1 munsell_0.5.0 nnet_7.3-17 timeDate_4022.108 [17] pillar_1.9.0 rlang_1.1.1 quantmod_0.4.22 utf8_1.2.3 [21] urca_1.3-3 quadprog_1.5-8 cli_3.6.1 magrittr_2.0.3 [25] xts_0.13.1 grid_4.3.0 gridtext_0.1.5 lifecycle_1.0.3 [29] nlme_3.1-155 fracdiff_1.5-2 vctrs_0.6.2 glue_1.6.2 [33] tseries_0.10-54 zoo_1.8-12 fansi_1.0.4 colorspace_2.1-0 [37] TTR_0.24.3 stinepack_1.4 pkgconfig_2.0.3 ________________________________ From: Ivan Krylov Sent: Saturday, June 10, 2023 7:50 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] inconsistency in mclapply..... On Sat, 10 Jun 2023 13:46:12 +0000 akshay kulkarni wrote: > What if I switch to Ubuntu? > I had a similar ( but not exactly the same) problem way back in 2018 > and switching to Ubuntu solved it. You shouldn't have to switch distros for problems like this one. What you need to switch is your OpenBLAS build: instead of using OpenBLAS built with OpenMP support (which isn't even the default when compiling OpenBLAS), use OpenBLAS built with pthreads support. It's also likely, but not 100% guaranteed, that setting OMP_NUM_THREADS=1 will avoid the issue by never starting any additional threads for OpenBLAS purposes. At least some documentation says that OPENBLAS_NUM_THREADS is ignored on OpenMP builds of OpenBLAS, you actually have to set OMP_NUM_THREADS=1 for it to take any effect. I know very little about RHEL, but it seems that you already have a pthreads build of OpenBLAS installed in /usr/lib64/libopenblasp-r0.3.15.so; you just need to adjust the path to the BLAS implementation used by R. If not, install the openblas-threads package. Can you use flexiblas to switch the BLAS implementation to OPENBLAS-THREADS? This should be possible by using the flexiblas R package or by setting environment variables . That said, I know for sure that on Debian and Ubuntu you get a choice between libopenblas0-openmp / libopenblas0-pthread / libopenblas0-serial, and installing any one of these packages except libopenblas0-openmp should avoid the problem. (And the thread limit should be set to 1 if you're running your tasks in parallel by other means.) -- Best regards, Ivan [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Sat Jun 17 21:12:24 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Sat, 17 Jun 2023 22:12:24 +0300 Subject: [R] inconsistency in mclapply..... In-Reply-To: References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> <20230610151242.38cd3980@Tarkus> <20230610172016.0fe28e0a@Tarkus> Message-ID: <20230617221224.26285c37@parabola> ? Sat, 17 Jun 2023 18:54:43 +0000 akshay kulkarni ?????: > 1. I was working on a two core machine just to test the > code...tomorrow will be switching to a 48 core machine. Should I > again download the latest openblas from ropenblas() or do you suggest > testing the native openblas that is bundled in Ubuntu What's the version of OpenBLAS in the Ubuntu release you are running? Unless you can see significant improvements regarding your CPU architecture appearing since the version included in Ubuntu was released, there's little reason to install a different version manually. The whole point of a GNU/Linux distro is not having to compile everything yourself. Ubuntu's build of OpenBLAS contains multiple copies of the code targeted at different processors, including yours. > 2. How do you pass the version of openblas to be installed with > ropenblas()? The full file name? or just something like this: > libopenblas_skylakexp-r0.3.23.so ? It looks like this function accepts the names of git tags in the official OpenBLAS Git repository, but it's really the job of the package maintainer to document important arguments like this one properly. You can call bug.report(package = 'ropenblas') or write an e-mail to maintainer('ropenblas') or locate the author's GitHub and ask a question there. -- Best regards, Ivan From ru|pb@rr@d@@ @end|ng |rom @@po@pt Sun Jun 18 09:11:13 2023 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Sun, 18 Jun 2023 08:11:13 +0100 Subject: [R] Issue with crammed Y axis In-Reply-To: References: Message-ID: <23f20b64-f27d-0195-683c-7e9824c2d651@sapo.pt> ?s 00:07 de 17/06/2023, Ana Marija escreveu: > Hi, > > I have a data frame like this: > >> dput(df) > structure(list(ID = 1:8, Type = c("gmx mdrun -ntmpi 8 -ntomp 1 -s > benchPEP.tpr -nsteps 10000 -resethway", > "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps 10000 -resethway", > "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps 4000 -resetstep 3000", > "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps 4000 -resetstep 3000", > "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway", > "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway", > "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps -1 -maxh 1.0 > -resethway -noconfout", > "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps -1 -maxh 1.0 > -resethway -noconfout" > ), Annee = c("SYCL", "CUDA", "SYCL", "CUDA", "SYCL", "CUDA", > "SYCL", "CUDA"), Domain.decomp. = c("2. 1", "2", "2. 1", "2. 1", > "2.1", "2", "2. 1", "2"), DD.com..load = c(0, 0, 0, 0, 3.7, 3, > 0, 0), Neighbor.search = c("3.7", "3. 1", "3.7", "3.9", "0. 1", > "O. 1", "3.5", "3. 1"), Launch.PP.GPU.ops. = c("0. 1", "0", "0.2", > "0", "1 .6", "1 . 5", "0.2", "0. 1"), Comm..coord. = c("1 .6", > "1 .0", "1 .5", "1 .3", "1 .5", "1 .3", "1 . 5", "1 .6"), Force = c("1 . > 5", > "1 .2", "1 .4", "1 .2", "1 .3", "1 . 1", "1 .5", "1 .2"), Wait...Comm..F = > c("1 .3", > "1 .7", "1 .2", "1 .0", "66.7", "68.8", "1 .2", "1 .2"), PIE.mesh = > c("65.6", > "70.9", "61 .0", "61 .4", "0", "0", "67.6", "69.2"), Wait.Bonded.GPU = > c(0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L), wait.GPU.NB.nonloc. = c(0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L), Wait.GPU.NB.local = c(0, 0, 0, 0, 7.4, > 5.7, 0, 0), NB.X.F.buffer.ops. = c("7.3", "4.4", "6. 7", "5", > "0. 1", "0. 1", "7.2", "5.5"), Write.traje = c("0.3", "0.3", > "1 .2", "1 .3", "6.4", "6. 1", "O. 1", "0. 1"), Update = c(6.3, > 4.3, 5.7, 4.9, 8.2, 9.5, 6.2, 5.6), Constraints = c("8.9", "9.7", > "1 1 .6", "13.3", "0.3", "0.4", "8. 1", "9.5"), Comm..energies = c("0.9", > "0.9", "3.3", "3.9", "8.4", "8. 5", "0.3", "0.4"), PIE.redist..X.F = c("8. > 1", > "8.7", "7.9", "7.4", "29.9", "30.1", "8. 1", "8. 1"), PIE.spread = > c("29.7", > "30.6", "27.2", "29.6", "20.3", "20.2", "30. 1", "30.4"), PIE.gather = > c("19.9", > "21 .3", "18.7", "19", "6.4", "8.4", "20", "20.6"), PIE.3D.FFT = c("6", > "8.6", "5.7", "4.3", "1 .0", "1 .1", "7.6", "8.4"), PIE.3D.FFT.comm. = c("1 > .2", > "1 .0", "0.9", "0.7", "1 .2", "0. 5", "1 .0", "1 .1"), PIE.solve.Elec = > c(0.7, > 0.5, 0.6, 0.3, 0.7, 0.5, 0.7, 0.5)), class = "data.frame", row.names = > c(NA, > -8L)) > > I am plotting this data with: > > library(reshape2) > library(ggplot2) > > df <- read.csv("/Users/anamaria/Downloads/B5.csv", stringsAsFactors=FALSE, > header=TRUE) > > df.long<-melt(df,id.vars=c("ID","Type","Annee")) > > myplot =ggplot(df.long,aes(variable,value,fill=as.factor(Annee)))+ > geom_bar(position="dodge",stat="identity")+ > ylab("Simulation Progress (%)") + > facet_wrap(~Type,nrow=3) > > myplot + theme(panel.grid.major = element_blank(), > legend.title=element_blank(), panel.grid.minor = element_blank(), > panel.background = element_blank(), axis.title.x = element_blank(), > axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), > axis.line = element_line(colour = "black")) > > My issue is that Y axis is crammed. How it can be cleaned up and say > feature only say these values: 0, 10, 20,30, ...80. > > I tried using: scale_y_continuous(breaks = breaks_width(10))+ > But I got this error: > Error in breaks_width(10) : could not find function "breaks_width" > > Also can anything be done about the subtitle of the top left plot, which is > not quite fitting in that gray box: " > gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps 10000 -resethway" > > Thanks > Ana > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 problem seems to be that df.long$value is character and that it has spaces and "O" (upper case letter O) in it. Try, before plotting df.long$value <- gsub(" ", "", df.long$value) df.long$value <- sub("O", "0", df.long$value) df.long$value <- as.numeric(df.long$value) With me it solved the problem. As for breaks_width, that's a function in package scales, so if the above doesn't solve it, qualify the function name: scale_y_continuous(breaks = scales::breaks_width(10)) + Hope this helps, Rui Barradas From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch Mon Jun 19 09:45:48 2023 From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler) Date: Mon, 19 Jun 2023 09:45:48 +0200 Subject: [R] warnng to an error.... In-Reply-To: References: Message-ID: <25744.1964.693581.693355@stat.math.ethz.ch> >>>>> akshay kulkarni >>>>> on Sat, 17 Jun 2023 18:35:53 +0000 writes: > Dear Bert, Duncan's theory is working....probably the same > as yours... "theory" .. well *truth*. Note that I wrote a blog post I had hope would be read more ( --> and be cited more .. when helping peopling with such problems ;-)) Simple search ("google") for "class think R blog" or directly https://blog.r-project.org/2019/11/09/when-you-think-class.-think-again/ To say it again: Using something like if(... class(x) == "" ..) is almost always (*) bad code. Everyone should learn about inherits() and why sane R code should use that instead. --- *) It may be ok, e.g., when `x` was very expliclitly constructed in the same part of code a bit earlier Martin > THanking you, Yours sincerely, AKSHAY M KULKARNI > ________________________________ From: Bert Gunter > Sent: Saturday, June 17, 2023 > 11:28 PM To: akshay kulkarni Cc: R > help Mailing list Subject: Re: [R] > warnng to an error.... > What is class(x) ?? > I think you need to (re?) learn about S3 classes, which > can in general be vectors. See ?class (the S3 portion) or > any tutorial on S3 classes in R. I have no idea what you > are trying to do, but I *suspect* it may be accomplished > through S3 inheritance rather than changing the class > vector. That is just a guess, however. > -- Bert > On Sat, Jun 17, 2023 at 10:27?AM akshay kulkarni > > > wrote: Dear members, AN update: I have changed the if > clause to: > if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code} > but am bootless..... > PLease help... > THanking you, Yours sincerely, AKSHAY M KULKARNI > ________________________________ From: R-help > > > on behalf of akshay kulkarni > > > Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing > list > > Subject: [R] warnng to an error.... > Dear members, > I have the following code: >> FUN(OHLCDataEP[[63]]) > Error in (class(x) == "xts") || (class(x) == "zoo") : > 'length = 2' in coercion to 'logical(1)' >> traceback() > 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]]) >> class(OHLCDataEP[[63]]) > [1] "xts" "zoo" > The following is in ygix() : > if((class(x) == "xts") || (class(x) == "zoo") > I think this would have been a warning > (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) > but I am on a ubuntu22.04 machine with R 4.3.0. > What should I do? Change it to: if((class(x)[1] == "xts") > || (class(x)[2] == "zoo")) {code}... > or is there any workaround? > THanking you, Yours sincerely, AKSHAY M KULKARNI > [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded] > R Warning 'length(x) = 2 > 1' in coercion to > 'logical(1)' > Using R 4.1.3 I observe: var <- 0 > > if(is.data.frame(var) || is.vector(var)) var <- > as.matrix(var) > is.null(var) || (!is.matrix(var) > && var == 0) || (dim(var)==c(1,1) &&... > stackoverflow.com ? > [[alternative HTML version deleted]] > ______________________________________________ > R-help at r-project.org mailing > list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing > list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and > more, see https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide > commented, minimal, self-contained, reproducible code. From @k@h@y_e4 @end|ng |rom hotm@||@com Mon Jun 19 12:57:03 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Mon, 19 Jun 2023 10:57:03 +0000 Subject: [R] warnng to an error.... In-Reply-To: <25744.1964.693581.693355@stat.math.ethz.ch> References: <25744.1964.693581.693355@stat.math.ethz.ch> Message-ID: Dear Martin, THanks for your exhortation....! THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Martin Maechler Sent: Monday, June 19, 2023 1:15 PM To: akshay kulkarni Cc: Bert Gunter ; R help Mailing list Subject: Re: [R] warnng to an error.... >>>>> akshay kulkarni >>>>> on Sat, 17 Jun 2023 18:35:53 +0000 writes: > Dear Bert, Duncan's theory is working....probably the same > as yours... "theory" .. well *truth*. Note that I wrote a blog post I had hope would be read more ( --> and be cited more .. when helping peopling with such problems ;-)) Simple search ("google") for "class think R blog" or directly https://blog.r-project.org/2019/11/09/when-you-think-class.-think-again/ To say it again: Using something like if(... class(x) == "" ..) is almost always (*) bad code. Everyone should learn about inherits() and why sane R code should use that instead. --- *) It may be ok, e.g., when `x` was very expliclitly constructed in the same part of code a bit earlier Martin > THanking you, Yours sincerely, AKSHAY M KULKARNI > ________________________________ From: Bert Gunter > Sent: Saturday, June 17, 2023 > 11:28 PM To: akshay kulkarni Cc: R > help Mailing list Subject: Re: [R] > warnng to an error.... > What is class(x) ?? > I think you need to (re?) learn about S3 classes, which > can in general be vectors. See ?class (the S3 portion) or > any tutorial on S3 classes in R. I have no idea what you > are trying to do, but I *suspect* it may be accomplished > through S3 inheritance rather than changing the class > vector. That is just a guess, however. > -- Bert > On Sat, Jun 17, 2023 at 10:27?AM akshay kulkarni > > > wrote: Dear members, AN update: I have changed the if > clause to: > if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code} > but am bootless..... > PLease help... > THanking you, Yours sincerely, AKSHAY M KULKARNI > ________________________________ From: R-help > > > on behalf of akshay kulkarni > > > Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing > list > > Subject: [R] warnng to an error.... > Dear members, > I have the following code: >> FUN(OHLCDataEP[[63]]) > Error in (class(x) == "xts") || (class(x) == "zoo") : > 'length = 2' in coercion to 'logical(1)' >> traceback() > 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]]) >> class(OHLCDataEP[[63]]) > [1] "xts" "zoo" > The following is in ygix() : > if((class(x) == "xts") || (class(x) == "zoo") > I think this would have been a warning > (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) > but I am on a ubuntu22.04 machine with R 4.3.0. > What should I do? Change it to: if((class(x)[1] == "xts") > || (class(x)[2] == "zoo")) {code}... > or is there any workaround? > THanking you, Yours sincerely, AKSHAY M KULKARNI > [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded] > R Warning 'length(x) = 2 > 1' in coercion to > 'logical(1)' > Using R 4.1.3 I observe: var <- 0 > > if(is.data.frame(var) || is.vector(var)) var <- > as.matrix(var) > is.null(var) || (!is.matrix(var) > && var == 0) || (dim(var)==c(1,1) &&... > stackoverflow.com ? > [[alternative HTML version deleted]] > ______________________________________________ > R-help at r-project.org mailing > list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing > list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and > more, see https://stat.ethz.ch/mailman/listinfo/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]] From pd@|gd @end|ng |rom gm@||@com Mon Jun 19 14:16:23 2023 From: pd@|gd @end|ng |rom gm@||@com (peter dalgaard) Date: Mon, 19 Jun 2023 14:16:23 +0200 Subject: [R] Why install.packages(repos = X) does not override the 'repos' R option? In-Reply-To: <117c90bd-eaf5-c789-7953-12f3fa8ecdbd@gmail.com> References: <117c90bd-eaf5-c789-7953-12f3fa8ecdbd@gmail.com> Message-ID: Yes. Specifically, RStudio overrides utils::install.packages() with their own > install.packages function (...) .rs.callAs(name, hook, original, ...) which is paved with good intentions, but does deflect blame towards R Core things go wrong. -pd > On 15 Jun 2023, at 19:42 , Duncan Murdoch wrote: > > (Sorry, forgot "Reply all" last time.) > > That's an RStudio bug. It doesn't happen if you use install.packages() > from R. > > Duncan Murdoch > > On 14/06/2023 9:22 a.m., Dean Attali wrote: >> There is a default R option for which repos to install from - >> `getOption("repos")`. >> When installing a package using install.packages(), you can provide a >> `repos` parameter. The default value of that parameter is >> `getOption("repos")`. I assumed that this parameter would override the R >> option. In other words, I assumed that if the parameter is provided, then >> the R option would not even be looked at. But after testing this, it seems >> this is not the case. >> For example, running the following two lines in an R session: >> options(repos=c(CRAN="https://BADNAME.com")) >> install.packages("vctrs", repos = "https://cloud.R-project.org") >> I would have expected the first line to be rendered meaningless, but in >> fact after running the second line I see errors about the BADNAME >> repository. This feels like a bug to me, but I'm sure there's a reason >> behind this. Does anyone know why this is the case? >> [[alternative HTML version deleted]] >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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.mes at cbs.dk Priv: PDalgd at gmail.com From ro||turner @end|ng |rom po@teo@net Mon Jun 19 22:52:41 2023 From: ro||turner @end|ng |rom po@teo@net (Rolf Turner) Date: Mon, 19 Jun 2023 20:52:41 +0000 Subject: [R] Testing. Message-ID: <20230620085241.08da3344@rolf-Latitude-E7470> I have just changed my email address with the R-help mailing lists, and I want to check that things are working. Sorry for the noise. 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 From @k@h@y_e4 @end|ng |rom hotm@||@com Tue Jun 20 13:21:49 2023 From: @k@h@y_e4 @end|ng |rom hotm@||@com (akshay kulkarni) Date: Tue, 20 Jun 2023 11:21:49 +0000 Subject: [R] inconsistency in mclapply..... In-Reply-To: <20230617221224.26285c37@parabola> References: <20230609231300.6a937f88@Tarkus> <20230610102450.7acdbef1@Tarkus> <20230610121624.042f3d0a@Tarkus> <20230610151242.38cd3980@Tarkus> <20230610172016.0fe28e0a@Tarkus> <20230617221224.26285c37@parabola> Message-ID: Dear Ivan, Yes, you were right....the native BLAS version of my ubuntu system is: Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0 Updating BLAS with ropenblas(), as you said,is superficial. Will reverting back to you if stuck again....with mclapply.. A million thanks again... THanking you, Yours sincerely, AKSHAY M KULKKARNI ________________________________ From: Ivan Krylov Sent: Sunday, June 18, 2023 12:42 AM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] inconsistency in mclapply..... ? Sat, 17 Jun 2023 18:54:43 +0000 akshay kulkarni ?????: > 1. I was working on a two core machine just to test the > code...tomorrow will be switching to a 48 core machine. Should I > again download the latest openblas from ropenblas() or do you suggest > testing the native openblas that is bundled in Ubuntu What's the version of OpenBLAS in the Ubuntu release you are running? Unless you can see significant improvements regarding your CPU architecture appearing since the version included in Ubuntu was released, there's little reason to install a different version manually. The whole point of a GNU/Linux distro is not having to compile everything yourself. Ubuntu's build of OpenBLAS contains multiple copies of the code targeted at different processors, including yours. > 2. How do you pass the version of openblas to be installed with > ropenblas()? The full file name? or just something like this: > libopenblas_skylakexp-r0.3.23.so ? It looks like this function accepts the names of git tags in the official OpenBLAS Git repository, but it's really the job of the package maintainer to document important arguments like this one properly. You can call bug.report(package = 'ropenblas') or write an e-mail to maintainer('ropenblas') or locate the author's GitHub and ask a question there. -- Best regards, Ivan [[alternative HTML version deleted]] From ph|| @end|ng |rom pr|com@com@@u Tue Jun 20 17:38:17 2023 From: ph|| @end|ng |rom pr|com@com@@u (Philip Rhoades) Date: Wed, 21 Jun 2023 01:38:17 +1000 Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size Message-ID: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> People, I am assuming that what I want to do is easier in R than say Ruby. I want to do what the Subject says ie multiply the cells in the same position of two vectors (A and B) to give a result in the same position in a third vector (C) BUT: - The values in the cells of A and B are floats between 0.0 and 1.0 or NULL - If there is a NULL in the multiplication, then the result in the cell for C is also a NULL - If there is a value less than (say) 0.01 in the multiplication, then the result in the cell for C is 0.0 Any suggestions appreciated! Phil. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From @vi@e@gross m@iii@g oii gm@ii@com Tue Jun 20 17:55:08 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Tue, 20 Jun 2023 11:55:08 -0400 Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size In-Reply-To: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> References: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> Message-ID: <00ac01d9a38f$96da9ae0$c48fd0a0$@gmail.com> Phil, What have you tried. This seems straightforward enough. Could you clarify what you mean by NULL? In R, it is common to use NA or a more specific version of it. So assuming you have two vectors containing floats with some NA, then: C <- A*B Will give you the products one at a time if the lengths are the same. NA times anything is NA. Your second condition is also simple as you want anything below a threshold to be set to a fixes value. Since you already have C, above, your condition of: threshold <- 0.1 C < threshold The last line returns a Boolean vector you can use to index C to get just the ones you select as TRUE and thus can change: Result <- C[C < threshold] And you can of course do all the above as a one-liner. Is that what you wanted? -----Original Message----- From: R-help On Behalf Of Philip Rhoades via R-help Sent: Tuesday, June 20, 2023 11:38 AM To: r-help at r-project.org Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size People, I am assuming that what I want to do is easier in R than say Ruby. I want to do what the Subject says ie multiply the cells in the same position of two vectors (A and B) to give a result in the same position in a third vector (C) BUT: - The values in the cells of A and B are floats between 0.0 and 1.0 or NULL - If there is a NULL in the multiplication, then the result in the cell for C is also a NULL - If there is a value less than (say) 0.01 in the multiplication, then the result in the cell for C is 0.0 Any suggestions appreciated! Phil. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From ph|| @end|ng |rom pr|com@com@@u Tue Jun 20 19:04:24 2023 From: ph|| @end|ng |rom pr|com@com@@u (Philip Rhoades) Date: Wed, 21 Jun 2023 03:04:24 +1000 Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size In-Reply-To: <00ac01d9a38f$96da9ae0$c48fd0a0$@gmail.com> References: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> <00ac01d9a38f$96da9ae0$c48fd0a0$@gmail.com> Message-ID: avi, On 2023-06-21 01:55, avi.e.gross at gmail.com wrote: > Phil, > > What have you tried. This seems straightforward enough. > > Could you clarify what you mean by NULL? I guess in R in would just be an empty cell? - ie NOT a zero. > In R, it is common to use NA or a more specific version of it. Ah yes, that would be it I think. > So assuming you have two vectors containing floats with some NA, then: > > C <- A*B > > Will give you the products one at a time if the lengths are the same. > NA > times anything is NA. Right - yes that works! - thanks! > Your second condition is also simple as you want anything below a > threshold > to be set to a fixes value. > > Since you already have C, above, your condition of: > > threshold <- 0.1 > C < threshold > > The last line returns a Boolean vector you can use to index C to get > just > the ones you select as TRUE and thus can change: > > Result <- C[C < threshold] Ah, I see . . > And you can of course do all the above as a one-liner. Yes. > Is that what you wanted? Exactly except I meant: Result <- C[C > threshold] Thanks! Phil. > -----Original Message----- > From: R-help On Behalf Of Philip Rhoades > via > R-help > Sent: Tuesday, June 20, 2023 11:38 AM > To: r-help at r-project.org > Subject: [R] Multiplying two vectors of the same size to give a third > vector > of the same size > > People, > > I am assuming that what I want to do is easier in R than say Ruby. > > I want to do what the Subject says ie multiply the cells in the same > position of two vectors (A and B) to give a result in the same position > in a third vector (C) BUT: > > - The values in the cells of A and B are floats between 0.0 and 1.0 or > NULL > > - If there is a NULL in the multiplication, then the result in the cell > for C is also a NULL > > - If there is a value less than (say) 0.01 in the multiplication, then > the result in the cell for C is 0.0 > > Any suggestions appreciated! > > Phil. > > -- > Philip Rhoades > > PO Box 896 > Cowra NSW 2794 > Australia > E-mail: phil at pricom.com.au > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From ph|| @end|ng |rom pr|com@com@@u Tue Jun 20 19:13:52 2023 From: ph|| @end|ng |rom pr|com@com@@u (Philip Rhoades) Date: Wed, 21 Jun 2023 03:13:52 +1000 Subject: [R] OK, next Q - a sort of factorial on a vector Message-ID: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> People, What I mean is, is there an elegant way to do this: This: !(1,2,3,4,5) would give this: (2,3,4,5, 6,8,10, 12,15, 20) and this: !(1,2,NA,4,5) would give this: (2,4,5, 8,10, 20) ? Thanks! Phil. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From bgunter@4567 @end|ng |rom gm@||@com Tue Jun 20 19:31:11 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Tue, 20 Jun 2023 10:31:11 -0700 Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size In-Reply-To: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> References: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> Message-ID: IMO: You need to do your due diligence. This list is not meant to serve as a substitute for learning the basics of R, which you have clearly not done. Please go through an R tutorial or two (there is even one that ships with R, "An Inroduction to R") before posting further here. There are many good ones online, of course. Here is one compendium, but a simple search will find many more: https://support.posit.co/hc/en-us/articles/200552336-Getting-Help-with-R Cheers, Bert even on On Tue, Jun 20, 2023 at 8:38?AM Philip Rhoades via R-help < r-help at r-project.org> wrote: > People, > > I am assuming that what I want to do is easier in R than say Ruby. > > I want to do what the Subject says ie multiply the cells in the same > position of two vectors (A and B) to give a result in the same position > in a third vector (C) BUT: > > - The values in the cells of A and B are floats between 0.0 and 1.0 or > NULL > > - If there is a NULL in the multiplication, then the result in the cell > for C is also a NULL > > - If there is a value less than (say) 0.01 in the multiplication, then > the result in the cell for C is 0.0 > > Any suggestions appreciated! > > Phil. > > -- > Philip Rhoades > > PO Box 896 > Cowra NSW 2794 > Australia > E-mail: phil at pricom.com.au > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From kry|ov@r00t @end|ng |rom gm@||@com Tue Jun 20 19:32:01 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Tue, 20 Jun 2023 20:32:01 +0300 Subject: [R] OK, next Q - a sort of factorial on a vector In-Reply-To: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> References: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> Message-ID: <20230620203201.24f95152@Tarkus> ? Wed, 21 Jun 2023 03:13:52 +1000 Philip Rhoades via R-help ?????: > This: > > !(1,2,3,4,5) > > would give this: > > (2,3,4,5, 6,8,10, 12,15, 20) Do you mean taking a product of every element of the vector with all following vector elements? A relatively straightforward way would be (given your vector stored in `x`): unlist(lapply(seq_along(x), function(i) x[i] * x[-(1:i)])) (I'm sure it could be golfed further.) > and this: > > !(1,2,NA,4,5) > > would give this: > > (2,4,5, 8,10, 20) The previous solution seems to give your vector interspersed a bunch of NAs, so one way to continue would be to filter it using v[!is.na(v)]. -- Best regards, Ivan From @@r@h@go@|ee @end|ng |rom gm@||@com Tue Jun 20 19:38:19 2023 From: @@r@h@go@|ee @end|ng |rom gm@||@com (Sarah Goslee) Date: Tue, 20 Jun 2023 13:38:19 -0400 Subject: [R] OK, next Q - a sort of factorial on a vector In-Reply-To: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> References: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> Message-ID: Well, I think this is reasonable elegant, but ymmv. Turning it into a function and removing NA values is left for you. > x <- 1:5 > unlist(sapply(seq(1, length(x) - 1), function(i){x[i] * x[seq(i + 1, length(x))]})) [1] 2 3 4 5 6 8 10 12 15 20 > > x <- c(1, 2, NA, 4, 5) > unlist(sapply(seq(1, length(x) - 1), function(i){x[i] * x[seq(i + 1, length(x))]})) [1] 2 NA 4 5 NA 8 10 NA NA 20 Sarah On Tue, Jun 20, 2023 at 1:15?PM Philip Rhoades via R-help wrote: > > People, > > What I mean is, is there an elegant way to do this: > > This: > > !(1,2,3,4,5) > > would give this: > > (2,3,4,5, 6,8,10, 12,15, 20) > > and this: > > !(1,2,NA,4,5) > > would give this: > > (2,4,5, 8,10, 20) > > ? > > Thanks! > > Phil. > -- > Philip Rhoades > > PO Box 896 > Cowra NSW 2794 > Australia > E-mail: phil at pricom.com.au > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com From ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de Tue Jun 20 19:45:38 2023 From: ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de (Uwe Ligges) Date: Tue, 20 Jun 2023 19:45:38 +0200 Subject: [R] OK, next Q - a sort of factorial on a vector In-Reply-To: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> References: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> Message-ID: <364e32a2-5c76-9469-93ad-57a9639a2fe9@statistik.tu-dortmund.de> vf <- function(x){ o <- outer(x, x) as.vector(na.omit(o[lower.tri(o)])) } vf(1:5) vf(c(1,2,NA,4,5)) Best, Uwe Ligges On 20.06.2023 19:13, Philip Rhoades via R-help wrote: > People, > > What I mean is, is there an elegant way to do this: > > This: > > ? !(1,2,3,4,5) > > would give this: > > ? (2,3,4,5, 6,8,10, 12,15, 20) > > and this: > > ? !(1,2,NA,4,5) > > would give this: > > ? (2,4,5, 8,10, 20) > > ? > > Thanks! > > Phil. From ph|| @end|ng |rom pr|com@com@@u Tue Jun 20 19:45:59 2023 From: ph|| @end|ng |rom pr|com@com@@u (Philip Rhoades) Date: Wed, 21 Jun 2023 03:45:59 +1000 Subject: [R] OK, next Q - a sort of factorial on a vector In-Reply-To: <20230620203201.24f95152@Tarkus> References: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> <20230620203201.24f95152@Tarkus> Message-ID: <5827b1ec8b2587d71195d22cbb3a0b2f@pricom.com.au> Ivan, On 2023-06-21 03:32, Ivan Krylov wrote: > ? Wed, 21 Jun 2023 03:13:52 +1000 > Philip Rhoades via R-help ?????: > >> This: >> >> !(1,2,3,4,5) >> >> would give this: >> >> (2,3,4,5, 6,8,10, 12,15, 20) > > Do you mean taking a product of every element of the vector with all > following vector elements? A relatively straightforward way would be > (given your vector stored in `x`): > > unlist(lapply(seq_along(x), function(i) x[i] * x[-(1:i)])) Perfect! > (I'm sure it could be golfed further.) I will look at Sarah's suggestion too. >> and this: >> >> !(1,2,NA,4,5) >> >> would give this: >> >> (2,4,5, 8,10, 20) > > The previous solution seems to give your vector interspersed a bunch of > NAs, so one way to continue would be to filter it using v[!is.na(v)]. Exactly! Thanks people - it would have taken forever to work that out myself (it has been decades since I looked at R). Phil. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From ph|| @end|ng |rom pr|com@com@@u Tue Jun 20 19:52:32 2023 From: ph|| @end|ng |rom pr|com@com@@u (Philip Rhoades) Date: Wed, 21 Jun 2023 03:52:32 +1000 Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size In-Reply-To: References: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> Message-ID: <465b7141c8b89a85c4abe1e480e3455e@pricom.com.au> Bert, On 2023-06-21 03:31, Bert Gunter wrote: > IMO: > You need to do your due diligence. This list is not meant to serve as > a substitute for learning the basics of R, which you have clearly not > done. Please go through an R tutorial or two (there is even one that > ships with R, "An Inroduction to R") before posting further here. > There are many good ones online, of course. Here is one compendium, > but a simple search will find many more: > > https://support.posit.co/hc/en-us/articles/200552336-Getting-Help-with-R It has been a long time since I looked at R and I thought at least my second Q was something reasonable to ask the list? Anyway now that I need to use R again, the basics should come back to me I hope - but I will check out the tutorials again in any case . . Thanks to Uwe as well (very nice!), Phil. > On Tue, Jun 20, 2023 at 8:38?AM Philip Rhoades via R-help > wrote: > >> People, >> >> I am assuming that what I want to do is easier in R than say Ruby. >> >> I want to do what the Subject says ie multiply the cells in the same >> >> position of two vectors (A and B) to give a result in the same >> position >> in a third vector (C) BUT: >> >> - The values in the cells of A and B are floats between 0.0 and 1.0 >> or >> NULL >> >> - If there is a NULL in the multiplication, then the result in the >> cell >> for C is also a NULL >> >> - If there is a value less than (say) 0.01 in the multiplication, >> then >> the result in the cell for C is 0.0 >> >> Any suggestions appreciated! >> >> Phil. >> >> -- >> Philip Rhoades >> >> PO Box 896 >> Cowra NSW 2794 >> Australia >> E-mail: phil at pricom.com.au >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From er|cjberger @end|ng |rom gm@||@com Tue Jun 20 20:02:25 2023 From: er|cjberger @end|ng |rom gm@||@com (Eric Berger) Date: Tue, 20 Jun 2023 21:02:25 +0300 Subject: [R] OK, next Q - a sort of factorial on a vector In-Reply-To: <5827b1ec8b2587d71195d22cbb3a0b2f@pricom.com.au> References: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> <20230620203201.24f95152@Tarkus> <5827b1ec8b2587d71195d22cbb3a0b2f@pricom.com.au> Message-ID: Hi Philip, In the decades since you learned R there have been some additions to the language. In particular, R now supports lambda functions. Applying this feature to Ivan's beautiful solution cuts down 7 characters (continuing his golfing analogy) unlist(lapply(seq_along(x), \(i) x[i] * x[-(1:i)])) Enjoy your return to R! On Tue, Jun 20, 2023 at 8:46?PM Philip Rhoades via R-help < r-help at r-project.org> wrote: > Ivan, > > > On 2023-06-21 03:32, Ivan Krylov wrote: > > ? Wed, 21 Jun 2023 03:13:52 +1000 > > Philip Rhoades via R-help ?????: > > > >> This: > >> > >> !(1,2,3,4,5) > >> > >> would give this: > >> > >> (2,3,4,5, 6,8,10, 12,15, 20) > > > > Do you mean taking a product of every element of the vector with all > > following vector elements? A relatively straightforward way would be > > (given your vector stored in `x`): > > > > unlist(lapply(seq_along(x), function(i) x[i] * x[-(1:i)])) > > > Perfect! > > > > (I'm sure it could be golfed further.) > > > I will look at Sarah's suggestion too. > > > >> and this: > >> > >> !(1,2,NA,4,5) > >> > >> would give this: > >> > >> (2,4,5, 8,10, 20) > > > > The previous solution seems to give your vector interspersed a bunch of > > NAs, so one way to continue would be to filter it using v[!is.na(v)]. > > > Exactly! > > Thanks people - it would have taken forever to work that out myself (it > has been decades since I looked at R). > > Phil. > -- > Philip Rhoades > > PO Box 896 > Cowra NSW 2794 > Australia > E-mail: phil at pricom.com.au > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From ph|| @end|ng |rom pr|com@com@@u Tue Jun 20 20:52:23 2023 From: ph|| @end|ng |rom pr|com@com@@u (Philip Rhoades) Date: Wed, 21 Jun 2023 04:52:23 +1000 Subject: [R] OK, next Q - a sort of factorial on a vector In-Reply-To: References: <9c3bb633e42075fe3a4ae93ed53f502e@pricom.com.au> <20230620203201.24f95152@Tarkus> <5827b1ec8b2587d71195d22cbb3a0b2f@pricom.com.au> Message-ID: <7a6c6a0d0858a937a3872d605f0e3887@pricom.com.au> Eric, On 2023-06-21 04:02, Eric Berger wrote: > Hi Philip, > In the decades since you learned R there have been some additions to > the language. > In particular, R now supports lambda functions. > Applying this feature to Ivan's beautiful solution cuts down 7 > characters (continuing his golfing analogy) > > unlist(lapply(seq_along(x), \(i) x[i] * x[-(1:i)])) Amazing! - it reminds me of the old days when there were competitions to write the smallest C programs . . > Enjoy your return to R! Thanks! I think I was right to look at R first - it is exactly what I need I think - and the model I am thinking of shouldn't need any grunt that would require rewriting any functions in C or Rust or something . . P. > On Tue, Jun 20, 2023 at 8:46?PM Philip Rhoades via R-help > wrote: > >> Ivan, >> >> On 2023-06-21 03:32, Ivan Krylov wrote: >>> ? Wed, 21 Jun 2023 03:13:52 +1000 >>> Philip Rhoades via R-help ?????: >>> >>>> This: >>>> >>>> !(1,2,3,4,5) >>>> >>>> would give this: >>>> >>>> (2,3,4,5, 6,8,10, 12,15, 20) >>> >>> Do you mean taking a product of every element of the vector with >> all >>> following vector elements? A relatively straightforward way would >> be >>> (given your vector stored in `x`): >>> >>> unlist(lapply(seq_along(x), function(i) x[i] * x[-(1:i)])) >> >> Perfect! >> >>> (I'm sure it could be golfed further.) >> >> I will look at Sarah's suggestion too. >> >>>> and this: >>>> >>>> !(1,2,NA,4,5) >>>> >>>> would give this: >>>> >>>> (2,4,5, 8,10, 20) >>> >>> The previous solution seems to give your vector interspersed a >> bunch of >>> NAs, so one way to continue would be to filter it using v[!is.na >> [1](v)]. >> >> Exactly! >> >> Thanks people - it would have taken forever to work that out myself >> (it >> has been decades since I looked at R). >> >> Phil. >> -- >> Philip Rhoades >> >> PO Box 896 >> Cowra NSW 2794 >> Australia >> E-mail: phil at pricom.com.au >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > Links: > ------ > [1] http://is.na -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From @vi@e@gross m@iii@g oii gm@ii@com Wed Jun 21 04:46:35 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Tue, 20 Jun 2023 22:46:35 -0400 Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size In-Reply-To: References: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> <00ac01d9a38f$96da9ae0$c48fd0a0$@gmail.com> Message-ID: <00f501d9a3ea$98883b80$c998b280$@gmail.com> I was rushing out Phil so let me amend what I wrote. As others noted, this is fairly beginner stuff. If you have more such questions, besides reading up, please consider sending questions to the Tutor mailing list where there is more patience. ? You wanted to change selected small values to 0.0. So you do not want the code I supplied as illustration as it removes small elements making a smaller vector. Assume this test: A <- c(NA, 0.3, 0.6, NA, 0.9) B <- c(NA, 0.2, 0.6, 0.9, 0.9) C <- A * B print(C) The result at this point is: [1] NA 0.06 0.36 NA 0.81 As expected, anything with an NA in either vector will generate an NA in the componentwise multiplication. Note the second item at 0.06 is under your threshold of 0.1. What you want is not this: Result <- C[C < 0.1] > Result [1] NA 0.06 NA That threw away anything above the threshold. What you want may be this: C[C < 0.1] <- 0.0 print(C) This returns [1] NA 0.00 0.36 NA 0.81 Everything that is NA or at or above 0.1 is kept and anything below 0.1 is zeroed and kept. Of course, if you do not want to keep the NA, that can trivially be removed: C[!is.na(C)] [1] 0.00 0.36 0.81 -----Original Message----- From: Philip Rhoades Sent: Tuesday, June 20, 2023 1:04 PM To: avi.e.gross at gmail.com Cc: r-help at r-project.org Subject: Re: [R] Multiplying two vectors of the same size to give a third vector of the same size avi, On 2023-06-21 01:55, avi.e.gross at gmail.com wrote: > Phil, > > What have you tried. This seems straightforward enough. > > Could you clarify what you mean by NULL? I guess in R in would just be an empty cell? - ie NOT a zero. > In R, it is common to use NA or a more specific version of it. Ah yes, that would be it I think. > So assuming you have two vectors containing floats with some NA, then: > > C <- A*B > > Will give you the products one at a time if the lengths are the same. > NA > times anything is NA. Right - yes that works! - thanks! > Your second condition is also simple as you want anything below a > threshold > to be set to a fixes value. > > Since you already have C, above, your condition of: > > threshold <- 0.1 > C < threshold > > The last line returns a Boolean vector you can use to index C to get > just > the ones you select as TRUE and thus can change: > > Result <- C[C < threshold] Ah, I see . . > And you can of course do all the above as a one-liner. Yes. > Is that what you wanted? Exactly except I meant: Result <- C[C > threshold] Thanks! Phil. > -----Original Message----- > From: R-help On Behalf Of Philip Rhoades > via > R-help > Sent: Tuesday, June 20, 2023 11:38 AM > To: r-help at r-project.org > Subject: [R] Multiplying two vectors of the same size to give a third > vector > of the same size > > People, > > I am assuming that what I want to do is easier in R than say Ruby. > > I want to do what the Subject says ie multiply the cells in the same > position of two vectors (A and B) to give a result in the same position > in a third vector (C) BUT: > > - The values in the cells of A and B are floats between 0.0 and 1.0 or > NULL > > - If there is a NULL in the multiplication, then the result in the cell > for C is also a NULL > > - If there is a value less than (say) 0.01 in the multiplication, then > the result in the cell for C is 0.0 > > Any suggestions appreciated! > > Phil. > > -- > Philip Rhoades > > PO Box 896 > Cowra NSW 2794 > Australia > E-mail: phil at pricom.com.au > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From ph|| @end|ng |rom pr|com@com@@u Wed Jun 21 07:19:37 2023 From: ph|| @end|ng |rom pr|com@com@@u (Philip Rhoades) Date: Wed, 21 Jun 2023 15:19:37 +1000 Subject: [R] Multiplying two vectors of the same size to give a third vector of the same size In-Reply-To: <00f501d9a3ea$98883b80$c998b280$@gmail.com> References: <02f586371e564a0e4da57afd7d7ea3e0@pricom.com.au> <00ac01d9a38f$96da9ae0$c48fd0a0$@gmail.com> <00f501d9a3ea$98883b80$c998b280$@gmail.com> Message-ID: avi, On 2023-06-21 12:46, avi.e.gross at gmail.com wrote: > I was rushing out Phil so let me amend what I wrote. As others noted, > this is fairly beginner stuff. If you have more such questions, > besides reading up, please consider sending questions to the Tutor > mailing list where there is more patience. ? No worries - thanks! > You wanted to change selected small values to 0.0. > > So you do not want the code I supplied as illustration as it removes > small elements making a smaller vector. > > Assume this test: > > A <- c(NA, 0.3, 0.6, NA, 0.9) > B <- c(NA, 0.2, 0.6, 0.9, 0.9) > > C <- A * B > print(C) > > The result at this point is: > > [1] NA 0.06 0.36 NA 0.81 > > As expected, anything with an NA in either vector will generate an NA > in the componentwise multiplication. Note the second item at 0.06 is > under your threshold of 0.1. > > What you want is not this: > > Result <- C[C < 0.1] >> Result > [1] NA 0.06 NA > > That threw away anything above the threshold. Yes, I realised that later . . > What you want may be this: > > C[C < 0.1] <- 0.0 > print(C) > > This returns > > [1] NA 0.00 0.36 NA 0.81 > > Everything that is NA or at or above 0.1 is kept and anything below > 0.1 is zeroed and kept. > > Of course, if you do not want to keep the NA, that can trivially be > removed: > > C[!is.na(C)] > [1] 0.00 0.36 0.81 I actually got there myself after a bit of experimenting! - but you pointed me in the right direction! Thanks! Phil. > -----Original Message----- > From: Philip Rhoades > Sent: Tuesday, June 20, 2023 1:04 PM > To: avi.e.gross at gmail.com > Cc: r-help at r-project.org > Subject: Re: [R] Multiplying two vectors of the same size to give a > third vector of the same size > > avi, > > > On 2023-06-21 01:55, avi.e.gross at gmail.com wrote: >> Phil, >> >> What have you tried. This seems straightforward enough. >> >> Could you clarify what you mean by NULL? > > > I guess in R in would just be an empty cell? - ie NOT a zero. > > >> In R, it is common to use NA or a more specific version of it. > > > Ah yes, that would be it I think. > > >> So assuming you have two vectors containing floats with some NA, then: >> >> C <- A*B >> >> Will give you the products one at a time if the lengths are the same. >> NA >> times anything is NA. > > > Right - yes that works! - thanks! > > >> Your second condition is also simple as you want anything below a >> threshold >> to be set to a fixes value. >> >> Since you already have C, above, your condition of: >> >> threshold <- 0.1 >> C < threshold >> >> The last line returns a Boolean vector you can use to index C to get >> just >> the ones you select as TRUE and thus can change: >> >> Result <- C[C < threshold] > > > Ah, I see . . > > >> And you can of course do all the above as a one-liner. > > > Yes. > > >> Is that what you wanted? > > > Exactly except I meant: > > Result <- C[C > threshold] > > Thanks! > > Phil. > > >> -----Original Message----- >> From: R-help On Behalf Of Philip >> Rhoades >> via >> R-help >> Sent: Tuesday, June 20, 2023 11:38 AM >> To: r-help at r-project.org >> Subject: [R] Multiplying two vectors of the same size to give a third >> vector >> of the same size >> >> People, >> >> I am assuming that what I want to do is easier in R than say Ruby. >> >> I want to do what the Subject says ie multiply the cells in the same >> position of two vectors (A and B) to give a result in the same >> position >> in a third vector (C) BUT: >> >> - The values in the cells of A and B are floats between 0.0 and 1.0 or >> NULL >> >> - If there is a NULL in the multiplication, then the result in the >> cell >> for C is also a NULL >> >> - If there is a value less than (say) 0.01 in the multiplication, then >> the result in the cell for C is 0.0 >> >> Any suggestions appreciated! >> >> Phil. >> >> -- >> Philip Rhoades >> >> PO Box 896 >> Cowra NSW 2794 >> Australia >> E-mail: phil at pricom.com.au >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: phil at pricom.com.au From re|chm@nj @end|ng |rom @bcg|ob@|@net Thu Jun 22 04:03:02 2023 From: re|chm@nj @end|ng |rom @bcg|ob@|@net (Jeff Reichman) Date: Wed, 21 Jun 2023 21:03:02 -0500 Subject: [R] R/Spark References: <005901d9a4ad$adbf4070$093dc150$.ref@sbcglobal.net> Message-ID: <005901d9a4ad$adbf4070$093dc150$@sbcglobal.net> r-help Trying to install Spark (Windows 11) and R gives me the following error: spark_install(version = "3.4") Error in validVersions[with(validVersions, order(hadoop, decreasing = TRUE)), : subscript out of bounds Any idea what the error is telling me. I guess I can load it manually. Jeff [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Thu Jun 22 09:12:08 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Thu, 22 Jun 2023 10:12:08 +0300 Subject: [R] R/Spark In-Reply-To: <005901d9a4ad$adbf4070$093dc150$@sbcglobal.net> References: <005901d9a4ad$adbf4070$093dc150$.ref@sbcglobal.net> <005901d9a4ad$adbf4070$093dc150$@sbcglobal.net> Message-ID: <20230622101208.2bb0bbb1@Tarkus> ? Wed, 21 Jun 2023 21:03:02 -0500 "Jeff Reichman" ?????: > spark_install(version = "3.4") My psychic debugging powers tell me that you're trying to use the sparklyr package. Is that correct? > Error in validVersions[with(validVersions, order(hadoop, decreasing = > TRUE)), : > > subscript out of bounds The error seems to come from the non-CRAN package sparkinstall, last updated in 2019: https://github.com/rstudio/spark-install/blob/master/R/R/versions.R Try updating all involved packages to their latest versions. If that doesn't help, opening an issue at might be a more direct route to success. -- Best regards, Ivan From Roger@B|v@nd @end|ng |rom nhh@no Sat Jun 24 16:53:49 2023 From: Roger@B|v@nd @end|ng |rom nhh@no (Roger Bivand) Date: Sat, 24 Jun 2023 14:53:49 +0000 Subject: [R] [R-pkgs] sp 2.0-0 released Message-ID: A new version of the sp package, 2.0-0, has been published on CRAN. This new version defaults to using the sf package rather than the rgdal package, and deprecates use of the rgeos package. These changes are described in https://r-spatial.org/r/2023/05/15/evolution4.html, and lead up to the planned archiving of the retiring packages: maptools, rgdal and rgeos in October 2023. This version issues invasive start-up messages in order to alert users to impending changes; maintainers of affected packages have already been warned. -- Roger Bivand Emeritus Professor Norwegian School of Economics Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway Roger.Bivand at nhh.no _______________________________________________ R-packages mailing list R-packages at r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages From m@@@hton @end|ng |rom endur|ng|nve@tment@@com Sat Jun 24 20:01:49 2023 From: m@@@hton @end|ng |rom endur|ng|nve@tment@@com (Michael Ashton) Date: Sat, 24 Jun 2023 18:01:49 +0000 Subject: [R] post tweets with media attachment - and with retirement of rtweet Message-ID: <5ffec51961b14c3296cc9b7e3b512a50@enduringinvestments.com> All - I run an automated script that pulls in some market data, makes some charts, and posts them to twitter. A couple of them per day, and then once per month there's a little flurry around the CPI report. For a while rtweet() worked great. Then v2 happened and Oauth2.0. The package broke, was fixed, and then broke (on 1.1 endpoints) for good. It works with 2.0 endpoints, but I can only post text...not media. Most of the R packages for Twitter focus on retrieving tweets and information from Twitter, and not on posting to Twitter. So the options were already pretty limited. And now, even if I were to get rtweet to work for me (with respect to attaching media...and is there any way to auto-refresh the Oauth2.0 token without manually re-authorizing it every two hours???) it appears that rtweet is no longer going to be updated. The immediate issue is figuring out how to get rtweet to work for me to post media along with the text post. But maybe there's a better package. Can anyone suggest a course of action? (I guess worst case is that I continue to generate the media with R, then switch over to Python or something to post the tweet, but that's far more manual than I want - the whole point is for this to run unattended.) Open to ideas! I've been wrestling with this for three days and finally realized that r-help is a resource. All ideas welcome! Mike [[alternative HTML version deleted]] From ro||turner @end|ng |rom po@teo@net Sun Jun 25 03:36:40 2023 From: ro||turner @end|ng |rom po@teo@net (Rolf Turner) Date: Sun, 25 Jun 2023 01:36:40 +0000 Subject: [R] depmixs4 standardError() issue In-Reply-To: References: Message-ID: <20230625133640.7b6b073c@rolf-Latitude-E7470> On Tue, 30 May 2023 17:43:31 +0000 Heather Lucas wrote: > Hello, > > I've been enjoying using the "Mixture and Hidden Markov Models in R" > by Visser & Speekenbrink to learn how to apply these analyses to my > own data using depmixS4. > > I currently have a fitted 4-state mixture model with three emissions > variables and one binomial covariate (HS). I am trying to compute > confidence intervals using the following code, where fmms4s is the > model: > > fmms4Svov <- vcov(fmms4S)$vcov #this line runs fine > fmms4Sse <- standardError(fmms4S) #this is where I get the error > fmms4SCI <- confint(fmms4S) > > This worked fine before I added the covariate, but with the covariate > I receive a warning message: In sqrt(diag(vc$vcov)) : NaNs produced. > As a result, several of my parameters have NaNs as CIs. In general, > I get this error more frequently for more complex models (even when > these models converge and show a better fit than simpler models) but > I cannot find any information as to why this happens. Getting rid of > one of the emissions variables but leaving the covariate also seems > to ?fix? the issue but it crops up quite often for me in general. > > Many thanks, Greetings. I hope, given the very belated nature of my response, that you are still interested in this issue. I have seen no answers to your enquiry, so I am chipping in, despite my woeful lack of expertise. Basically my guess would be that the NaNs result from the covariance matrix vc$vcov having negative diagonal entries --- negative variance estimates. I believe that vc$vcov would have been produced, at some level, by inverting the negative of the Hessian matrix of the parameter estimates. In my experience, the Hessian matrices that arise in the hidden Markov model context can be, shall we say, a bit delicate. (Downright flaky, not to put too fine a point on it.) It may be the case that the Hessian is not negative definite. Theoretically the Hessian matrix will be negative definite at the maximum (or at a local maximum) of the log likelihood of the model. Convergence issues may be such that, even though the algorithm is judged to have converged, the parameter estimates are sufficiently far from the maximum point so that the Hessian will have some positive eigenvalues (equivalently its negative will have some negative eigenvalues) leading to the negative variance estimates. If you could look at it, you would probably find that the gradient vector (which should theoretically be zero at the maximum) has some unacceptably large entries. The numerical analysis considerations that arise in maximising the log likelihood of a hidden Markov model are fraught with difficulties and subtleties. The more complex the model, the more likely it is that these difficulties will rear their ugly little heads. When they do, it seems to me, there is not much that an ordinary mortal can do about it. A couple of other comments. (a) In the past I have communicated a bit with the maintainer of the depmixS4 package (Ingmar Visser ) and found him to be reasonably helpful and responsive. You might try contacting him directly and see if he has any useful suggestions. You would of course have to make your data available to him, in order for him to get anywhere. (b) You might like to try experimenting with my package "eglhmm" ("extended generalised linear hidden Markov models"). This package has considerable overlap with depmixS4, but has a very different syntax and a different set of bells an whistles. However I note that in your enquiry you say that you have "three emission variables" so it appears that you are dealing with a multivariate problem. My package does not do multivariate stuff, except in one restricted (and rather r?cherch?) context so my package probably won't be of any real use to you. Also my package does not do mixtures as such. If you *should* be interested in trying my package, you can get it from my web page (https://www.stat.auckland.ac.nz/~rolf; scroll to the bottom and click on "Eglhmm"). The source package and a Windoze binary are available. I have not yet submitted my package to CRAN, although I hope to do so in the fairly (???) near future. My package may well have a fair few bugs lurking in its innards. (But then, don't they all?) If you do experiment with eglhmm, please let me know about any bugs that you encounter. I hope this of some help and interest. 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 From @|d@@run91 @end|ng |rom gm@||@com Sun Jun 25 16:34:38 2023 From: @|d@@run91 @end|ng |rom gm@||@com (Siddharth Arun) Date: Sun, 25 Jun 2023 20:04:38 +0530 Subject: [R] To UNSUBSCRIBE Message-ID: Please unsubscribe me from your mailing list. -- Thanks & Regards, Siddharth Arun, [[alternative HTML version deleted]] From ||@t@ @end|ng |rom dewey@myzen@co@uk Sun Jun 25 16:49:51 2023 From: ||@t@ @end|ng |rom dewey@myzen@co@uk (Michael Dewey) Date: Sun, 25 Jun 2023 15:49:51 +0100 Subject: [R] To UNSUBSCRIBE In-Reply-To: References: Message-ID: <90806f4b-6fdc-64ee-a8a5-25e8733bd875@dewey.myzen.co.uk> You can find instructions on how to do this on the bottom of e-mailas from the list. On 25/06/2023 15:34, Siddharth Arun wrote: > Please unsubscribe me from your mailing list. > -- Michael http://www.dewey.myzen.co.uk/home.html From cry@n @end|ng |rom b|ngh@mton@edu Mon Jun 26 15:04:31 2023 From: cry@n @end|ng |rom b|ngh@mton@edu (Christopher Ryan) Date: Mon, 26 Jun 2023 09:04:31 -0400 Subject: [R] free copy of Harrell's Regression Modeling Strategies, first edition Message-ID: I have both the 1st and the 2nd edition of Frank Harrell's book. I'll send you the 1st edition if you cover the postage. (4th class book rate would probably not be all that expensive.) Let me know off-list, if interested. --Chris Ryan [[alternative HTML version deleted]] From venkyvu|p|ne @end|ng |rom gm@||@com Tue Jun 27 07:33:23 2023 From: venkyvu|p|ne @end|ng |rom gm@||@com (Venky Vulpine) Date: Tue, 27 Jun 2023 11:03:23 +0530 Subject: [R] 32bit application Message-ID: Hi Team, It seems from 4.2.3, R setup is not having a 32bit package as like the previous version. Is there a way to build a 32bit R setup or is there any solution for the people who definitely need 32bit R on windows. Please let me know. Thanks, Venkatesh U [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Tue Jun 27 17:26:32 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Tue, 27 Jun 2023 18:26:32 +0300 Subject: [R] 32bit application In-Reply-To: References: Message-ID: <20230627182632.2b9f1ed8@arachnoid> ? Tue, 27 Jun 2023 11:03:23 +0530 Venky Vulpine ?????: > Is there a way to build a 32bit R setup or is there any solution for > the people who definitely need 32bit R on windows. While 32-bit builds of R are not supported on Windows, they might still work (and they do work on other platforms). Try following the guide at to compile R. (I think you'll need a 64-bit Windows installation in order to follow the guide. If you don't have one, setting up cross-compilation from a 32-bit computer for 64-bit Windows ought to be possible but may be tricky.) When you run `make all recommended`, add WIN=32 to the command line: make all recommended WIN=32 Does it give you a 32-bit R.exe? -- Best regards, Ivan From chr|@ho|d @end|ng |rom p@yctc@org Tue Jun 27 19:16:23 2023 From: chr|@ho|d @end|ng |rom p@yctc@org (Chris Evans) Date: Tue, 27 Jun 2023 18:16:23 +0100 Subject: [R] Help with regex replacements Message-ID: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> I am sure this is easy for people who are good at regexps but I'm failing with it.? The situation is that I have hundreds of lines of Ukrainian translations of some English. They contain things like this: 1"? ????? ????, ???? ?????"2"???? ??????? ??????? ??????"3"? ????? (???????) ????, ???? ????? (??????)"4"? ?????(-??) ?????, ???? ???????? ???????"5"? ?????/?? ????, ???? ?????/??"6"? ?????\\??????? ????, ???? ???????\\????????."7"? ????????(??) ????, ???? ?????(??)" Using dput(): tmp <- structure(list(Text = c("? ????? ????, ???? ?????", "???? ??????? ??????? ??????", "? ????? (???????) ????, ???? ????? (??????)", "? ?????(-??) ?????, ???? ???????? ???????", "? ?????/?? ????, ???? ?????/??", "? ?????\\??????? ????, ???? ???????\\????????", "? ????????(??) ????, ???? ?????(??)" )), row.names = c(NA, -7L), class = c("tbl_df", "tbl", "data.frame" )) Those show four different ways translators have handled gendered words: 1) Ignore them and (I'm guessing) only give the masculine 2) Give the feminine form of the word (or just the feminine suffix) in brackets 3) Give the feminine form/suffix prefixed by a forward slash 4) Give the feminine form/suffix prefixed by backslash (here a double backslash) I would like just to drop all these feminine gendered options. (Don't worry, they'll get back in later.) So I would like to replace 1) anything between brackets with nothing! 2) anything between a forward slash and the next space with nothing 3) anything between a backslash and the next space with nothing but preserving the rest of the text. I have been trying to achieve this using str_replace_all() but I am failing utterly. Here's a silly little example of my failures. This was just trying to get the text I wanted to replace (as I was trying to simplify the issues for my tired wetware): > tmp %>%+ as_tibble() %>% + rename(Text = value) %>% + mutate(Text = str_replace_all(Text, fixed("."), "")) %>% + filter(row_number() < 4) %>% + mutate(Text2 = str_replace(Text, "\\(.*\\)", "\\1")) Errorin `mutate()`:?In argument: `Text2 = str_replace(Text, "\\(.*\\)", "\\1")`.Caused by error in `stri_replace_first_regex()`:!Trying to access the index that is out of bounds. (U_INDEX_OUTOFBOUNDS_ERROR) Run `rlang::last_trace()` to see where the error occurred. I have tried gurgling around the internet but am striking out so throwing myself on the list. Apologies if this is trivial but I'd hate to have to clean these hundreds of lines by hand though it's starting to look as if I'd achieve that faster by hand than I will by banging my ignorance of R regexp syntax on the problem. TIA, Chris -- Chris Evans (he/him) Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, University of Roehampton, London, UK. Work web site: https://www.psyctc.org/psyctc/ CORE site: http://www.coresystemtrust.org.uk/ Personal site: https://www.psyctc.org/pelerinage2016/ From @vi@e@gross m@iii@g oii gm@ii@com Tue Jun 27 19:27:45 2023 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Tue, 27 Jun 2023 13:27:45 -0400 Subject: [R] Help with regex replacements In-Reply-To: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> References: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> Message-ID: <004901d9a91c$afbb81e0$0f3285a0$@gmail.com> Chris, Consider breaking up your task into multiple passes. And do them in whatever order preserves what you need. First, are you talking about brackets as in square brackets, or as in your example, parentheses? If you are sure you have no nested brackets, your requirement seems to be that anything matching [ stuff ] be replaced with nothing. Or if using parentheses, something similar. Your issue here is both sets of symbols are special so you must escape them so they are seen as part of the pattern and not the instructions. The idea would be to pass through the text once and match all instances on a line and then replace with nothing or whatever is needed. But there is no guarantee some of your constructs will be on the same line completely so be wary. -----Original Message----- From: R-help On Behalf Of Chris Evans via R-help Sent: Tuesday, June 27, 2023 1:16 PM To: r-help at r-project.org Subject: [R] Help with regex replacements I am sure this is easy for people who are good at regexps but I'm failing with it. The situation is that I have hundreds of lines of Ukrainian translations of some English. They contain things like this: 1"? ????? ????, ???? ?????"2"???? ??????? ??????? ??????"3"? ????? (???????) ????, ???? ????? (??????)"4"? ?????(-??) ?????, ???? ???????? ???????"5"? ?????/?? ????, ???? ?????/??"6"? ?????\\??????? ????, ???? ???????\\????????."7"? ????????(??) ????, ???? ?????(??)" Using dput(): tmp <- structure(list(Text = c("? ????? ????, ???? ?????", "???? ??????? ??????? ??????", "? ????? (???????) ????, ???? ????? (??????)", "? ?????(-??) ?????, ???? ???????? ???????", "? ?????/?? ????, ???? ?????/??", "? ?????\\??????? ????, ???? ???????\\????????", "? ????????(??) ????, ???? ?????(??)" )), row.names = c(NA, -7L), class = c("tbl_df", "tbl", "data.frame" )) Those show four different ways translators have handled gendered words: 1) Ignore them and (I'm guessing) only give the masculine 2) Give the feminine form of the word (or just the feminine suffix) in brackets 3) Give the feminine form/suffix prefixed by a forward slash 4) Give the feminine form/suffix prefixed by backslash (here a double backslash) I would like just to drop all these feminine gendered options. (Don't worry, they'll get back in later.) So I would like to replace 1) anything between brackets with nothing! 2) anything between a forward slash and the next space with nothing 3) anything between a backslash and the next space with nothing but preserving the rest of the text. I have been trying to achieve this using str_replace_all() but I am failing utterly. Here's a silly little example of my failures. This was just trying to get the text I wanted to replace (as I was trying to simplify the issues for my tired wetware): > tmp %>%+ as_tibble() %>% + rename(Text = value) %>% + mutate(Text = str_replace_all(Text, fixed("."), "")) %>% + filter(row_number() < 4) %>% + mutate(Text2 = str_replace(Text, "\\(.*\\)", "\\1")) Errorin `mutate()`:?In argument: `Text2 = str_replace(Text, "\\(.*\\)", "\\1")`.Caused by error in `stri_replace_first_regex()`:!Trying to access the index that is out of bounds. (U_INDEX_OUTOFBOUNDS_ERROR) Run `rlang::last_trace()` to see where the error occurred. I have tried gurgling around the internet but am striking out so throwing myself on the list. Apologies if this is trivial but I'd hate to have to clean these hundreds of lines by hand though it's starting to look as if I'd achieve that faster by hand than I will by banging my ignorance of R regexp syntax on the problem. TIA, Chris -- Chris Evans (he/him) Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, University of Roehampton, London, UK. Work web site: https://www.psyctc.org/psyctc/ CORE site: http://www.coresystemtrust.org.uk/ Personal site: https://www.psyctc.org/pelerinage2016/ ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From chr|@ho|d @end|ng |rom p@yctc@org Tue Jun 27 20:08:44 2023 From: chr|@ho|d @end|ng |rom p@yctc@org (Chris Evans) Date: Tue, 27 Jun 2023 19:08:44 +0100 Subject: [R] Help with regex replacements In-Reply-To: <004901d9a91c$afbb81e0$0f3285a0$@gmail.com> References: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> <004901d9a91c$afbb81e0$0f3285a0$@gmail.com> Message-ID: <0b2e82c9-a31e-76b9-b585-04b35ae74d89@psyctc.org> Thanks Avi (I am a keen follower or your, and other stalwart helpers here). On 27/06/2023 18:27, avi.e.gross at gmail.com wrote: > Chris, > > Consider breaking up your task into multiple passes. Sorry, I could have explained more of what I had tried.? I never know how long to make things here. I had been doing that. My plan was to pick them off, one by one but I think I am banging my head on a fundamental incomprehension on my part. > And do them in whatever order preserves what you need. Agree. > First, are you talking about brackets as in square brackets, or as in your example, parentheses? Sorry, always get that wrong, parentheses. Mea culpa. > If you are sure you have no nested brackets, your requirement seems to be that anything matching [ stuff ] be replaced with nothing. Or if using parentheses, something similar. > 99% sure there are no nested parentheses.? However, there are lines with none, one or sometimes (as in the little reprex) more than one set of parentheses. > Your issue here is both sets of symbols are special so you must escape them so they are seen as part of the pattern and not the instructions. So, sorry to be stupid but I thought I was doing that using "\(.*\)"? Could you reply showing me the correct escaping and the correct replacing?? I was using str_replace_all() but happy to use gsub() if that's easier/safer/better. > The idea would be to pass through the text once and match all instances on a line and then replace with nothing or whatever is needed. Nothing. > But there is no guarantee some of your constructs will be on the same line completely so be wary. Totally agree. I also see that my Emailer (Thunderbird) despite my exhorting it not to, mangled the Email.? Have tried to fix that.? The mess below should have said: I am sure this is easy for people who are good at regexps but I'm failing with it.? The situation is that I have hundreds of lines of Ukrainian translations of some English. They contain things like this: 1"? ????? ????, ???? ?????" 2"???? ??????? ??????? ??????" 3"? ????? (???????) ????, ???? ????? (??????)" 4"? ?????(-??) ?????, ???? ???????? ???????" 5"? ?????/?? ????, ???? ?????/??" 6"? ?????\\??????? ????, ???????????\\????????."7"? ????????(??) ????, ???? ?????(??)" Using dput(): tmp <- structure(list(Text = c("? ????? ????, ???? ?????", "???? ??????? ??????? ??????", "? ????? (???????) ????, ???? ????? (??????)", "? ?????(-??) ?????, ???? ???????? ???????", "? ?????/?? ????, ???? ?????/??", "? ?????\\??????? ????, ???? ???????\\????????", "? ????????(??) ????, ???? ?????(??)" )), row.names = c(NA, -7L), class = c("tbl_df", "tbl", "data.frame" )) Those show four different ways translators have handled gendered words: 1) Ignore them and (I'm guessing) only give the masculine 2) Give the feminine form of the word (or just the feminine suffix) in brackets 3) Give the feminine form/suffix prefixed by a forward slash 4) Give the feminine form/suffix prefixed by backslash (here a double backslash) I would like just to drop all these feminine gendered options. (Don't worry, they'll get back in later.) So I would like to replace 1) anything between brackets with nothing! 2) anything between a forward slash and the next space with nothing 3) anything between a backslash and the next space with nothing but preserving the rest of the text. I have been trying to achieve this using str_replace_all() but I am failing utterly. Here's a silly little example of my failures. This was just trying to get the text I wanted to replace (as I was trying to simplify the issues for my tired wetware): > tmp %>% + as_tibble() %>% + rename(Text = value) %>% + mutate(Text = str_replace_all(Text, fixed("."), "")) %>% + filter(row_number() < 4) %>% + mutate(Text2 = str_replace(Text, "\\(.*\\)", "\\1")) Error in `mutate()`:?In argument: `Text2 = str_replace(Text, "\\(.*\\)", "\\1")`. Caused by error in `stri_replace_first_regex()`:! Trying to access the index that is out of bounds. (U_INDEX_OUTOFBOUNDS_ERROR) Run `rlang::last_trace()` to see where the error occurred. I have tried gurgling around the internet but am striking out so throwing myself on the list. Apologies if this is trivial but I'd hate to have to clean these hundreds of lines by hand though it's starting to look as if I'd achieve that faster by hand than I will by banging my ignorance of R regexp syntax on the problem. TIA, Chris > > > > -----Original Message----- > From: R-help On Behalf Of Chris Evans via R-help > Sent: Tuesday, June 27, 2023 1:16 PM > To: r-help at r-project.org > Subject: [R] Help with regex replacements > > I am sure this is easy for people who are good at regexps but I'm > failing with it. The situation is that I have hundreds of lines of > Ukrainian translations of some English. They contain things like this: > > 1"? ????? ????, ???? ?????"2"???? ??????? ??????? ??????"3"? ????? > (???????) ????, ???? ????? (??????)"4"? ?????(-??) ?????, ???? ???????? > ???????"5"? ?????/?? ????, ???? ?????/??"6"? ?????\\??????? ????, ???? > ???????\\????????."7"? ????????(??) ????, ???? ?????(??)" > > Using dput(): > > tmp <- structure(list(Text = c("? ????? ????, ???? ?????", "???? ??????? > ??????? ??????", "? ????? (???????) ????, ???? ????? (??????)", "? > ?????(-??) ?????, ???? ???????? ???????", "? ?????/?? ????, ???? > ?????/??", "? ?????\\??????? ????, ???? ???????\\????????", "? > ????????(??) ????, ???? ?????(??)" )), row.names = c(NA, -7L), class = > c("tbl_df", "tbl", "data.frame" )) Those show four different ways > translators have handled gendered words: 1) Ignore them and (I'm > guessing) only give the masculine 2) Give the feminine form of the word > (or just the feminine suffix) in brackets 3) Give the feminine > form/suffix prefixed by a forward slash 4) Give the feminine form/suffix > prefixed by backslash (here a double backslash) I would like just to > drop all these feminine gendered options. (Don't worry, they'll get back > in later.) So I would like to replace 1) anything between brackets with > nothing! 2) anything between a forward slash and the next space with > nothing 3) anything between a backslash and the next space with nothing > but preserving the rest of the text. I have been trying to achieve this > using str_replace_all() but I am failing utterly. Here's a silly little > example of my failures. This was just trying to get the text I wanted to > replace (as I was trying to simplify the issues for my tired wetware): > > tmp %>%+ as_tibble() %>% + rename(Text = value) %>% + mutate(Text = > str_replace_all(Text, fixed("."), "")) %>% + filter(row_number() < 4) > %>% + mutate(Text2 = str_replace(Text, "\\(.*\\)", "\\1")) Errorin > `mutate()`:?In argument: `Text2 = str_replace(Text, "\\(.*\\)", > "\\1")`.Caused by error in `stri_replace_first_regex()`:!Trying to > access the index that is out of bounds. (U_INDEX_OUTOFBOUNDS_ERROR) Run > `rlang::last_trace()` to see where the error occurred. I have tried > gurgling around the internet but am striking out so throwing myself on > the list. Apologies if this is trivial but I'd hate to have to clean > these hundreds of lines by hand though it's starting to look as if I'd > achieve that faster by hand than I will by banging my ignorance of R > regexp syntax on the problem. TIA, Chris > -- Chris Evans (he/him) Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, University of Roehampton, London, UK. Work web site: https://www.psyctc.org/psyctc/ CORE site: http://www.coresystemtrust.org.uk/ Personal site: https://www.psyctc.org/pelerinage2016/ Emeetings (Thursdays): https://www.psyctc.org/psyctc/booking-meetings-with-me/ (Beware: French time, generally an hour ahead of UK) From bgunter@4567 @end|ng |rom gm@||@com Tue Jun 27 20:09:39 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Tue, 27 Jun 2023 11:09:39 -0700 Subject: [R] Help with regex replacements In-Reply-To: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> References: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> Message-ID: Does this do it for you (or get you closer): gsub("\\[.*\\]|[\\\\] |/ ","",tmp$Text) [1] "? ????? ????, ???? ?????" [2] "???? ???????\n??????? ??????" [3] "? ????? (???????) ????, ???? ????? (??????)" [4] "?\n?????(-??) ?????, ???? ???????? ???????" [5] "? ?????/?? ????, ????\n?????/??" [6] "? ?????\\??????? ????, ???? ???????\\????????" [7] "?\n????????(??) ????, ???? ?????(??)" On Tue, Jun 27, 2023 at 10:16?AM Chris Evans via R-help < r-help at r-project.org> wrote: > I am sure this is easy for people who are good at regexps but I'm > failing with it. The situation is that I have hundreds of lines of > Ukrainian translations of some English. They contain things like this: > > 1"? ????? ????, ???? ?????"2"???? ??????? ??????? ??????"3"? ????? > (???????) ????, ???? ????? (??????)"4"? ?????(-??) ?????, ???? ???????? > ???????"5"? ?????/?? ????, ???? ?????/??"6"? ?????\\??????? ????, ???? > ???????\\????????."7"? ????????(??) ????, ???? ?????(??)" > > Using dput(): > > tmp <- structure(list(Text = c("? ????? ????, ???? ?????", "???? ??????? > ??????? ??????", "? ????? (???????) ????, ???? ????? (??????)", "? > ?????(-??) ?????, ???? ???????? ???????", "? ?????/?? ????, ???? > ?????/??", "? ?????\\??????? ????, ???? ???????\\????????", "? > ????????(??) ????, ???? ?????(??)" )), row.names = c(NA, -7L), class = > c("tbl_df", "tbl", "data.frame" )) Those show four different ways > translators have handled gendered words: 1) Ignore them and (I'm > guessing) only give the masculine 2) Give the feminine form of the word > (or just the feminine suffix) in brackets 3) Give the feminine > form/suffix prefixed by a forward slash 4) Give the feminine form/suffix > prefixed by backslash (here a double backslash) I would like just to > drop all these feminine gendered options. (Don't worry, they'll get back > in later.) So I would like to replace 1) anything between brackets with > nothing! 2) anything between a forward slash and the next space with > nothing 3) anything between a backslash and the next space with nothing > but preserving the rest of the text. I have been trying to achieve this > using str_replace_all() but I am failing utterly. Here's a silly little > example of my failures. This was just trying to get the text I wanted to > replace (as I was trying to simplify the issues for my tired wetware): > > tmp %>%+ as_tibble() %>% + rename(Text = value) %>% + mutate(Text = > str_replace_all(Text, fixed("."), "")) %>% + filter(row_number() < 4) > %>% + mutate(Text2 = str_replace(Text, "\\(.*\\)", "\\1")) Errorin > `mutate()`:?In argument: `Text2 = str_replace(Text, "\\(.*\\)", > "\\1")`.Caused by error in `stri_replace_first_regex()`:!Trying to > access the index that is out of bounds. (U_INDEX_OUTOFBOUNDS_ERROR) Run > `rlang::last_trace()` to see where the error occurred. I have tried > gurgling around the internet but am striking out so throwing myself on > the list. Apologies if this is trivial but I'd hate to have to clean > these hundreds of lines by hand though it's starting to look as if I'd > achieve that faster by hand than I will by banging my ignorance of R > regexp syntax on the problem. TIA, Chris > > -- > Chris Evans (he/him) > Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, > University of Roehampton, London, UK. > Work web site: https://www.psyctc.org/psyctc/ > CORE site: http://www.coresystemtrust.org.uk/ > Personal site: https://www.psyctc.org/pelerinage2016/ > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]] From bgunter@4567 @end|ng |rom gm@||@com Tue Jun 27 21:48:59 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Tue, 27 Jun 2023 12:48:59 -0700 Subject: [R] Help with regex replacements In-Reply-To: References: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> Message-ID: OK, so you want parentheses, not "brackets" + I think I misinterpreted your specification, which I think is actually incomplete. Based on what I think you meant, how does this work: gsub("((\\\\|/)[[:alnum:]]+)|(\\([[:alnum:]-]+\\))", "",tmp$Text) [1] "? ????? ????, ???? ?????" "???? ???????\n??????? ??????" [3] "? ????? ????, ???? ????? " "?\n????? ?????, ???? ???????? ???????" [5] "? ????? ????, ????\n?????" "? ????? ????, ???? ???????" [7] "?\n???????? ????, ???? ?????" If you want it without the \n's, cat the above to get: cat(gsub("((\\\\|/)[[:alnum:]]+)|(\\([[:alnum:]-]+\\))", "",tmp$Text)) ? ????? ????, ???? ????? ???? ??????? ??????? ?????? ? ????? ????, ???? ????? ? ????? ?????, ???? ???????? ??????? ? ????? ????, ???? ????? ? ????? ????, ???? ??????? ? ???????? ????, ???? ????? Cheers, Bert On Tue, Jun 27, 2023 at 11:09?AM Bert Gunter wrote: > Does this do it for you (or get you closer): > > gsub("\\[.*\\]|[\\\\] |/ ","",tmp$Text) > [1] "? ????? ????, ???? ?????" > [2] "???? ???????\n??????? ??????" > [3] "? ????? (???????) ????, ???? ????? (??????)" > [4] "?\n?????(-??) ?????, ???? ???????? ???????" > [5] "? ?????/?? ????, ????\n?????/??" > [6] "? ?????\\??????? ????, ???? ???????\\????????" > [7] "?\n????????(??) ????, ???? ?????(??)" > > On Tue, Jun 27, 2023 at 10:16?AM Chris Evans via R-help < > r-help at r-project.org> wrote: > >> I am sure this is easy for people who are good at regexps but I'm >> failing with it. The situation is that I have hundreds of lines of >> Ukrainian translations of some English. They contain things like this: >> >> 1"? ????? ????, ???? ?????"2"???? ??????? ??????? ??????"3"? ????? >> (???????) ????, ???? ????? (??????)"4"? ?????(-??) ?????, ???? ???????? >> ???????"5"? ?????/?? ????, ???? ?????/??"6"? ?????\\??????? ????, ???? >> ???????\\????????."7"? ????????(??) ????, ???? ?????(??)" >> >> Using dput(): >> >> tmp <- structure(list(Text = c("? ????? ????, ???? ?????", "???? ??????? >> ??????? ??????", "? ????? (???????) ????, ???? ????? (??????)", "? >> ?????(-??) ?????, ???? ???????? ???????", "? ?????/?? ????, ???? >> ?????/??", "? ?????\\??????? ????, ???? ???????\\????????", "? >> ????????(??) ????, ???? ?????(??)" )), row.names = c(NA, -7L), class = >> c("tbl_df", "tbl", "data.frame" )) Those show four different ways >> translators have handled gendered words: 1) Ignore them and (I'm >> guessing) only give the masculine 2) Give the feminine form of the word >> (or just the feminine suffix) in brackets 3) Give the feminine >> form/suffix prefixed by a forward slash 4) Give the feminine form/suffix >> prefixed by backslash (here a double backslash) I would like just to >> drop all these feminine gendered options. (Don't worry, they'll get back >> in later.) So I would like to replace 1) anything between brackets with >> nothing! 2) anything between a forward slash and the next space with >> nothing 3) anything between a backslash and the next space with nothing >> but preserving the rest of the text. I have been trying to achieve this >> using str_replace_all() but I am failing utterly. Here's a silly little >> example of my failures. This was just trying to get the text I wanted to >> replace (as I was trying to simplify the issues for my tired wetware): > >> tmp %>%+ as_tibble() %>% + rename(Text = value) %>% + mutate(Text = >> str_replace_all(Text, fixed("."), "")) %>% + filter(row_number() < 4) >> %>% + mutate(Text2 = str_replace(Text, "\\(.*\\)", "\\1")) Errorin >> `mutate()`:?In argument: `Text2 = str_replace(Text, "\\(.*\\)", >> "\\1")`.Caused by error in `stri_replace_first_regex()`:!Trying to >> access the index that is out of bounds. (U_INDEX_OUTOFBOUNDS_ERROR) Run >> `rlang::last_trace()` to see where the error occurred. I have tried >> gurgling around the internet but am striking out so throwing myself on >> the list. Apologies if this is trivial but I'd hate to have to clean >> these hundreds of lines by hand though it's starting to look as if I'd >> achieve that faster by hand than I will by banging my ignorance of R >> regexp syntax on the problem. TIA, Chris >> >> -- >> Chris Evans (he/him) >> Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, >> University of Roehampton, London, UK. >> Work web site: https://www.psyctc.org/psyctc/ >> CORE site: http://www.coresystemtrust.org.uk/ >> Personal site: https://www.psyctc.org/pelerinage2016/ >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/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]] From chr|@ho|d @end|ng |rom p@yctc@org Tue Jun 27 22:26:32 2023 From: chr|@ho|d @end|ng |rom p@yctc@org (Chris Evans) Date: Tue, 27 Jun 2023 21:26:32 +0100 Subject: [R] Help with regex replacements In-Reply-To: References: <1ca085ec-5268-179a-58df-3dd22715d558@psyctc.org> Message-ID: <16f38a57-61cc-6195-7af6-1dd553093f80@psyctc.org> Magic! tmp %>% ? as_tibble() %>% ? rename(Text = value) %>% ? mutate(Text = str_replace_all(Text, fixed("."), "")) %>% ? # filter(row_number() < 4) %>% ? mutate(Text2 = gsub("((\\\\|/)[[:alnum:]]+)|(\\([[:alnum:]-]+\\))", "", Text)) Which (as you have already shown!) gave me this: # A tibble: 7 ? 2 ? Text Text2 ? 1 "? ????? ????, ???? ?????"????????????????????? "? ????? ????, ???? ?????" 2 "???? ??????? ??????? ??????"?????????????????? "???? ??????? ??????? ??????" 3 "? ????? (???????) ????, ???? ????? (??????)"?? "? ????? ????, ???? ????? " 4 "? ?????(-??) ?????, ???? ???????? ???????"???? "? ????? ?????, ???? ???????? ???????" 5 "? ?????/?? ????, ???? ?????/??"??????????????? "? ????? ????, ???? ?????" 6 "? ?????\\??????? ????, ???? ???????\\????????" "? ????? ????, ???? ???????" 7 "? ????????(??) ????, ???? ?????(??)"?????????? "? ???????? ????, ???? ?????" perfect and I will spend some time tomorrow unpacking that regex and trying to drive the learning points into my thick skull! Deeply indebted, as so often here though generally only when I'm reading others questions and the answers! Chris On 27/06/2023 20:48, Bert Gunter wrote: > OK, so you want parentheses, not "brackets" + I think I misinterpreted > your specification, which I think is actually incomplete. Based on > what I think you meant, how does this work: > > gsub("((\\\\|/)[[:alnum:]]+)|(\\([[:alnum:]-]+\\))", "",tmp$Text) > [1] "? ????? ????, ???? ?????" ? ? ? ? ? ? ?"???? ???????\n??????? > ??????" > [3] "? ????? ?????, ???? ????? " ? ? ? ? ? ?"?\n????? ?????, ???? > ???????? ???????" > [5] "? ????? ????, ????\n?????" ? ? ? ? ? ? "? ????? ????, ???? ???????" > [7] "?\n???????? ????, ???? ?????" > > If you want it without the \n's, cat the above to get: > cat(gsub("((\\\\|/)[[:alnum:]]+)|(\\([[:alnum:]-]+\\))", "",tmp$Text)) > > ? ????? ????, ???? ????? ???? ??????? > ??????? ?????? ? ????? ?????, ???? ????? ?? > ????? ?????, ???? ???????? ??????? ? ????? ????, ???? > ????? ? ????? ????, ???? ??????? ? > ???????? ????, ???? ????? > > Cheers, > Bert > > On Tue, Jun 27, 2023 at 11:09?AM Bert Gunter > wrote: > > Does this do it for you (or get you closer): > > ?gsub("\\[.*\\]|[\\\\] |/ ","",tmp$Text) > [1] "? ????? ????, ???? ?????" > [2] "???? ???????\n??????? ??????" > [3] "? ????? (???????) ????, ???? ????? (??????)" > [4] "?\n?????(-??) ?????, ???? ???????? ???????" > [5] "? ?????/?? ????, ????\n?????/??" > [6] "? ?????\\??????? ????, ???? ???????\\????????" > [7] "?\n????????(??) ????, ???? ?????(??)" > > On Tue, Jun 27, 2023 at 10:16?AM Chris Evans via R-help > wrote: > > I am sure this is easy for people who are good at regexps but I'm > failing with it.? The situation is that I have hundreds of > lines of > Ukrainian translations of some English. They contain things > like this: > > 1"? ????? ????, ???? ?????"2"???? ??????? ??????? ??????"3"? > ????? > (???????) ????, ???? ????? (??????)"4"? ?????(-??) ?????, ???? > ???????? > ???????"5"? ?????/?? ????, ???? ?????/??"6"? ?????\\??????? > ????, ???? > ???????\\????????."7"? ????????(??) ????, ???? ?????(??)" > > Using dput(): > > tmp <- structure(list(Text = c("? ????? ????, ???? ?????", > "???? ??????? > ??????? ??????", "? ????? (???????) ????, ???? ????? > (??????)", "? > ?????(-??) ?????, ???? ???????? ???????", "? ?????/?? ????, ???? > ?????/??", "? ?????\\??????? ????, ???? ???????\\????????", "? > ????????(??) ????, ???? ?????(??)" )), row.names = c(NA, -7L), > class = > c("tbl_df", "tbl", "data.frame" )) Those show four different ways > translators have handled gendered words: 1) Ignore them and (I'm > guessing) only give the masculine 2) Give the feminine form of > the word > (or just the feminine suffix) in brackets 3) Give the feminine > form/suffix prefixed by a forward slash 4) Give the feminine > form/suffix > prefixed by backslash (here a double backslash) I would like > just to > drop all these feminine gendered options. (Don't worry, > they'll get back > in later.) So I would like to replace 1) anything between > brackets with > nothing! 2) anything between a forward slash and the next > space with > nothing 3) anything between a backslash and the next space > with nothing > but preserving the rest of the text. I have been trying to > achieve this > using str_replace_all() but I am failing utterly. Here's a > silly little > example of my failures. This was just trying to get the text I > wanted to > replace (as I was trying to simplify the issues for my tired > wetware): > > tmp %>%+ as_tibble() %>% + rename(Text = value) %>% + > mutate(Text = > str_replace_all(Text, fixed("."), "")) %>% + > filter(row_number() < 4) > %>% + mutate(Text2 = str_replace(Text, "\\(.*\\)", "\\1")) > Errorin > `mutate()`:?In argument: `Text2 = str_replace(Text, "\\(.*\\)", > "\\1")`.Caused by error in > `stri_replace_first_regex()`:!Trying to > access the index that is out of bounds. > (U_INDEX_OUTOFBOUNDS_ERROR) Run > `rlang::last_trace()` to see where the error occurred. I have > tried > gurgling around the internet but am striking out so throwing > myself on > the list. Apologies if this is trivial but I'd hate to have to > clean > these hundreds of lines by hand though it's starting to look > as if I'd > achieve that faster by hand than I will by banging my > ignorance of R > regexp syntax on the problem. TIA, Chris > > -- > Chris Evans (he/him) > Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, > University of Roehampton, London, UK. > Work web site: https://www.psyctc.org/psyctc/ > CORE site: http://www.coresystemtrust.org.uk/ > Personal site: https://www.psyctc.org/pelerinage2016/ > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > -- Chris Evans (he/him) Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, University of Roehampton, London, UK. Work web site: https://www.psyctc.org/psyctc/ CORE site: http://www.coresystemtrust.org.uk/ Personal site: https://www.psyctc.org/pelerinage2016/ Emeetings (Thursdays): https://www.psyctc.org/psyctc/booking-meetings-with-me/ (Beware: French time, generally an hour ahead of UK) From kry|ov@r00t @end|ng |rom gm@||@com Wed Jun 28 09:22:28 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Wed, 28 Jun 2023 10:22:28 +0300 Subject: [R] 32bit application In-Reply-To: References: <20230627182632.2b9f1ed8@arachnoid> Message-ID: <20230628102228.7bc4d3eb@Tarkus> On Wed, 28 Jun 2023 08:54:14 +0530 Venky Vulpine wrote: > [image: image.png] Please copy and paste the error text from the command line window. For historical reasons, you need to use Ctrl+Insert in order to copy text from it and Shift+Insert in order to paste text into it. It seems that the assembler is being invoked in 64-bit mode for 32-bit assembly. I think I gave you the wrong parameter to set in order to switch into 32-bit mode. Run `make clean` in order to remove the already existing object files (I think they ended up being 64-bit) and then run: make all recommended MULTI=32 -- Best regards, Ivan From kry|ov@r00t @end|ng |rom gm@||@com Wed Jun 28 09:45:52 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Wed, 28 Jun 2023 10:45:52 +0300 Subject: [R] 32bit application In-Reply-To: References: <20230627182632.2b9f1ed8@arachnoid> <20230628102228.7bc4d3eb@Tarkus> Message-ID: <20230628104552.68808790@Tarkus> On Wed, 28 Jun 2023 13:02:41 +0530 Venky Vulpine wrote: > C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping > incompatible > c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a > when searching for -lmingw32 This is what progress looks like! The current problem is that you have 64-bit import libraries installed under .../x86_64-w64-mingw32.static.posix/... and there are probably no 32-bit import libraries bundled with Rtools. If you run `pacman -S mingw-w64-i686-gcc`, do you get a number of packages installed? When you retry the command, does it still fail with the same error message? (In that case, more adjustments will be needed in order to tell the linker where to find the 32-bit import libraries.) -- Best regards, Ivan From @nupty@g| @end|ng |rom gm@||@com Wed Jun 28 10:33:45 2023 From: @nupty@g| @end|ng |rom gm@||@com (Anupam Tyagi) Date: Wed, 28 Jun 2023 14:03:45 +0530 Subject: [R] Plotting factors in graph panel Message-ID: Hello, I want to plot the following kind of data (percentage of respondents from a survey) that varies by Income into many small *line* graphs in a panel of graphs. I want to omit "No Answer" categories. I want to see how each one of the categories (percentages), "None", " Equity", etc. varies by Income. How can I do this? How to organize the data well and how to plot? I thought Lattice may be a good package to plot this, but I don't know for sure. I prefer to do this in Base-R if possible, but I am open to ggplot. Any ideas will be helpful. Income $10 $25 $40 $75 > $75 No Answer MF 1 2 3 4 5 9 None 1 3.05 2.29 2.24 1.71 1.30 2.83 Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 46.54 54.01 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 Thanks. -- Anupam. [[alternative HTML version deleted]] From petr@p|k@| @end|ng |rom prechez@@cz Wed Jun 28 10:43:36 2023 From: petr@p|k@| @end|ng |rom prechez@@cz (PIKAL Petr) Date: Wed, 28 Jun 2023 08:43:36 +0000 Subject: [R] Plotting factors in graph panel In-Reply-To: References: Message-ID: <34c06e5607db44d6ab6a1369e0f9239f@SRVEXCHCM1302.precheza.cz> Hi You probably can use any package including base R for such plots. 1. Posting in HTML scrambles your date so they are barely readable. 2. Use dput(head(yourdata, 20)) and copy the output to your mail to show how your data look like. Although it seems to be not readable, R will consumes it freely. 3. If I understand correctly you should have an Income column, Percentage column and Category column. If this is the case ggplot(yourdata, aes(x=Income, y=Percentage)) + geom_line() + facet_grid(~Category) should give you what you want. But without data it is hard to say. Cheers Petr > -----Original Message----- > From: R-help On Behalf Of Anupam Tyagi > Sent: Wednesday, June 28, 2023 10:34 AM > To: R-help at r-project.org > Subject: [R] Plotting factors in graph panel > > Hello, > > I want to plot the following kind of data (percentage of respondents from a > survey) that varies by Income into many small *line* graphs in a panel of > graphs. I want to omit "No Answer" categories. I want to see how each one of > the categories (percentages), "None", " Equity", etc. varies by Income. > How can I do this? How to organize the data well and how to plot? I thought > Lattice may be a good package to plot this, but I don't know for sure. I prefer > to do this in Base-R if possible, but I am open to ggplot. Any ideas will be > helpful. > > Income > $10 $25 $40 $75 > $75 No Answer > MF 1 2 3 4 5 9 > None 1 3.05 2.29 2.24 1.71 1.30 2.83 > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 > 37.59 33.15 Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 > 46.54 54.01 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 > Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 13.4 1.746 > 1.208 4.577 > > Thanks. > -- > Anupam. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. From drj|m|emon @end|ng |rom gm@||@com Wed Jun 28 14:00:04 2023 From: drj|m|emon @end|ng |rom gm@||@com (Jim Lemon) Date: Wed, 28 Jun 2023 22:00:04 +1000 Subject: [R] Plotting factors in graph panel In-Reply-To: References: Message-ID: Hi Anupam, Haven't heard from you in a long time. Perhaps you want something like this: at_df<-read.table(text= "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current Bank_Savings Bank_NA $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307 $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891 $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4 $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746 >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208 No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577", header=TRUE,stringsAsFactors=FALSE) at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")] png("MF_Bank.png",height=600) par(mfrow=c(2,1)) matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")], type="l",col=1:4,lty=1:4,lwd=3, main="Percentages by Income and MF type", xlab="Income",ylab="Percentage of group",xaxt="n") axis(1,at=1:5,labels=at_df$Income) legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"), lty=1:4,lwd=3,col=1:4) matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")], type="l",col=1:3,lty=1:4,lwd=3, main="Percentages by Income and Bank type", xlab="Income",ylab="Percentage of group",xaxt="n") axis(1,at=1:5,labels=at_df$Income) legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"), lty=1:4,lwd=3,col=1:3) dev.off() Jim On Wed, Jun 28, 2023 at 6:33?PM Anupam Tyagi wrote: > > Hello, > > I want to plot the following kind of data (percentage of respondents from a > survey) that varies by Income into many small *line* graphs in a panel of > graphs. I want to omit "No Answer" categories. I want to see how each one > of the categories (percentages), "None", " Equity", etc. varies by Income. > How can I do this? How to organize the data well and how to plot? I thought > Lattice may be a good package to plot this, but I don't know for sure. I > prefer to do this in Base-R if possible, but I am open to ggplot. Any ideas > will be helpful. > > Income > $10 $25 $40 $75 > $75 No Answer > MF 1 2 3 4 5 9 > None 1 3.05 2.29 2.24 1.71 1.30 2.83 > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 > Bank AC > None 1 46.54 54.01 59.1 62.17 67.67 60.87 > Current 2 24.75 24.4 25 24.61 24.02 21.09 > Savings 3 25.4 18.7 29 11.48 7.103 13.46 > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 > > Thanks. > -- > Anupam. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -------------- next part -------------- A non-text attachment was scrubbed... Name: MF_Bank.png Type: image/png Size: 45142 bytes Desc: not available URL: From |kw@|mmo @end|ng |rom gm@||@com Wed Jun 28 07:39:19 2023 From: |kw@|mmo @end|ng |rom gm@||@com (Iris Simmons) Date: Wed, 28 Jun 2023 01:39:19 -0400 Subject: [R] Line Directives in Sweave Document Message-ID: Hello, I'm trying to demonstrate the behaviour of my R package and how line directives change that behaviour. So I've got an R chunk like this: <>= { #line 1 "file1.R" fun <- function() { pkg::fun() } #line 1 "file2.R" fun() } @ but when it is rendered, the line directives do not appear: > { + fun <- function() { + pkg::fun() + } + + + fun() + } I tried faking a line directive by writing it twice: <>= { #line 1 "file1.R" #line 1 "file1.R" fun <- function() { pkg::fun() } #line 1 "file2.R" #line 1 "file2.R" fun() } @ but then the rendered fake line directive looks bad because it's out by one space so if it is copy-pasted, it wouldn't actually function as shown. So is there an option I can set to have the line directives displayed, or something else I can change to get it working? Thank you! From venkyvu|p|ne @end|ng |rom gm@||@com Wed Jun 28 09:32:41 2023 From: venkyvu|p|ne @end|ng |rom gm@||@com (Venky Vulpine) Date: Wed, 28 Jun 2023 13:02:41 +0530 Subject: [R] 32bit application In-Reply-To: <20230628102228.7bc4d3eb@Tarkus> References: <20230627182632.2b9f1ed8@arachnoid> <20230628102228.7bc4d3eb@Tarkus> Message-ID: After doing "make clean". I entered the "make all recommended MULTI=32" and got the following error: make all recommended MULTI=32 make[1]: 'MkRules' is up to date. make --no-print-directory -C front-ends Rpwd make -C ../../include -f Makefile.win version make Rpwd.exe gcc -std=gnu99 -m32 -I../../include -DR_ARCH='"i386"' -O3 -Wall -pedantic -c rpwd.c -o rpwd.o windres -F pe-i386 -i rcico.rc -o rcico.o gcc -std=gnu99 -m32 -s -o Rpwd.exe rpwd.o rcico.o C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0\libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmsvcrt.a when searching for -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmsvcrt.a when searching for -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmsvcrt.a when searching for -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmsvcrt.a when searching for -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libpthread.a when searching for -lpthread C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libpthread.a when searching for -lpthread C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libpthread.a when searching for -lpthread C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lpthread C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libpthread.a when searching for -lpthread C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libadvapi32.a when searching for -ladvapi32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libadvapi32.a when searching for -ladvapi32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libadvapi32.a when searching for -ladvapi32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -ladvapi32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libadvapi32.a when searching for -ladvapi32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libshell32.a when searching for -lshell32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libshell32.a when searching for -lshell32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libshell32.a when searching for -lshell32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lshell32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libshell32.a when searching for -lshell32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libuser32.a when searching for -luser32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libuser32.a when searching for -luser32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libuser32.a when searching for -luser32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -luser32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libuser32.a when searching for -luser32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libkernel32.a when searching for -lkernel32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libkernel32.a when searching for -lkernel32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libkernel32.a when searching for -lkernel32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lkernel32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libkernel32.a when searching for -lkernel32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a when searching for -lmingw32 C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0\libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/libgcc.a when searching for -lgcc C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmoldname.a when searching for -lmoldname C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingwex.a when searching for -lmingwex C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmsvcrt.a when searching for -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../..\libmsvcrt.a when searching for -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmsvcrt.a when searching for -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lmsvcrt C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping incompatible c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmsvcrt.a when searching for -lmsvcrt collect2.exe: error: ld returned 1 exit status make[4]: *** [../MkRules:161: Rpwd.exe] Error 1 make[3]: *** [Makefile:124: Rpwd] Error 2 make[2]: *** [Makefile:106: front-ends/Rpwd.exe] Error 2 make[1]: *** [Makefile:110: rbuild] Error 2 make: *** [Makefile:17: all] Error 2 On Wed, Jun 28, 2023 at 12:52?PM Ivan Krylov wrote: > On Wed, 28 Jun 2023 08:54:14 +0530 > Venky Vulpine wrote: > > > [image: image.png] > > Please copy and paste the error text from the command line window. For > historical reasons, you need to use Ctrl+Insert in order to copy text > from it and Shift+Insert in order to paste text into it. > > It seems that the assembler is being invoked in 64-bit mode for 32-bit > assembly. I think I gave you the wrong parameter to set in order to > switch into 32-bit mode. Run `make clean` in order to remove the already > existing object files (I think they ended up being 64-bit) and then run: > > make all recommended MULTI=32 > > -- > Best regards, > Ivan > [[alternative HTML version deleted]] From venkyvu|p|ne @end|ng |rom gm@||@com Wed Jun 28 09:55:21 2023 From: venkyvu|p|ne @end|ng |rom gm@||@com (Venky Vulpine) Date: Wed, 28 Jun 2023 13:25:21 +0530 Subject: [R] 32bit application In-Reply-To: <20230628104552.68808790@Tarkus> References: <20230627182632.2b9f1ed8@arachnoid> <20230628102228.7bc4d3eb@Tarkus> <20230628104552.68808790@Tarkus> Message-ID: After running " pacman -S mingw-w64-i686-gcc", it installed 15 packages. Then I ran the " make all recommended MULTI=32" command. But it still shows the same issue. It will be great if somewhere I get a 32bit installer for newer R versions. But it seems it is discontinued. Anyway, thanks @Ivan Krylov for responding to mails. It really means a lot. Have a nice day! Thanks, Venkatesh U On Wed, Jun 28, 2023 at 1:15?PM Ivan Krylov wrote: > On Wed, 28 Jun 2023 13:02:41 +0530 > Venky Vulpine wrote: > > > C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: skipping > > incompatible > > > c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../libmingw32.a > > when searching for -lmingw32 > > This is what progress looks like! > > The current problem is that you have 64-bit import libraries installed > under .../x86_64-w64-mingw32.static.posix/... and there are probably no > 32-bit import libraries bundled with Rtools. > > If you run `pacman -S mingw-w64-i686-gcc`, do you get a number of > packages installed? When you retry the command, does it still fail with > the same error message? (In that case, more adjustments will be needed > in order to tell the linker where to find the 32-bit import libraries.) > > -- > Best regards, > Ivan > [[alternative HTML version deleted]] From murdoch@dunc@n @end|ng |rom gm@||@com Wed Jun 28 17:05:55 2023 From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch) Date: Wed, 28 Jun 2023 11:05:55 -0400 Subject: [R] Line Directives in Sweave Document In-Reply-To: References: Message-ID: On 28/06/2023 1:39 a.m., Iris Simmons wrote: > Hello, > > > I'm trying to demonstrate the behaviour of my R package and how line > directives change that behaviour. So I've got an R chunk like this: > > <>= > { > #line 1 "file1.R" > fun <- function() { > pkg::fun() > } > > > #line 1 "file2.R" > fun() > } > @ > > but when it is rendered, the line directives do not appear: > >> { > + fun <- function() { > + pkg::fun() > + } > + > + > + fun() > + } > > I tried faking a line directive by writing it twice: > > <>= > { > #line 1 "file1.R" > #line 1 "file1.R" > fun <- function() { > pkg::fun() > } > > > #line 1 "file2.R" > #line 1 "file2.R" > fun() > } > @ > > but then the rendered fake line directive looks bad because it's out > by one space so if it is copy-pasted, it wouldn't actually function as > shown. > > So is there an option I can set to have the line directives displayed, > or something else I can change to get it working? Thank you! Maybe if you put a zero-width space before the fake version, instead of a regular space? That's \u200B in Unicode; there are various other encodings of it. Put it after the # so that it isn't a syntax error, i.e. #\u200Bline 1 "file1.R" or if that shows the escape, print that string and copy the actual character into your document. Duncan Murdoch From kry|ov@r00t @end|ng |rom gm@||@com Wed Jun 28 17:11:33 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Wed, 28 Jun 2023 18:11:33 +0300 Subject: [R] 32bit application In-Reply-To: References: <20230627182632.2b9f1ed8@arachnoid> <20230628102228.7bc4d3eb@Tarkus> <20230628104552.68808790@Tarkus> Message-ID: <20230628181133.5ea061ec@arachnoid> ? Wed, 28 Jun 2023 13:25:21 +0530 Venky Vulpine ?????: > After running " pacman -S mingw-w64-i686-gcc", it installed 15 > packages. Then I ran the " make all recommended MULTI=32" command. > But it still shows the same issue. Here's what I've been able to find out. In addition to mingw-w64-i686-gcc, you also need to install the following packages: mingw-w64-i686-gcc-fortran mingw-w64-i686-bzip2 mingw-w64-i686-xz mingw-w64-i686-pcre2 mingw-w64-i686-icu mingw-w64-i686-curl mingw-w64-i686-libgcrypt mingw-w64-i686-libpng mingw-w64-i686-libjpeg mingw-w64-i686-libtiff (Type pacman -Sy followed by the package names, space-separated.) When setting the $PATH, use the following prefix instead of x86_64-w64-mingw32.static.posix: export PATH=/mingw32/bin:"$PATH" This gets you most of the way to start compiling R, except there are quite a few things that the compiler doesn't like about the code for some reason. They can be patched around using terrible hacks, making me wonder how this worked in the past. I also had to disable the tcltk package because the Tcl bundle is understandably 64-bit only. Did I forget another setting that enables 32-bit compatibility? The resulting command line to compile R is as follows: make MULTI=32 BUILD_TCLTK=no all recommended \ ICU_LIBS="-licuin -licuuc -licudt -lstdc++" \ CURL_LIBS="-lcurl -lbcrypt -lzstd -lssl -lssh2 -lgcrypt -lcrypto -lgdi32 -lz -lws2_32 -lgdi32 -lcrypt32 -lidn2 -lunistring -liconv -lgpg-error -lwldap32 -lwinmm" And I had to apply the following patches: Index: src/extra/intl/dcigettext.c =================================================================== --- src/extra/intl/dcigettext.c (revision 84610) +++ src/extra/intl/dcigettext.c (working copy) @@ -157,7 +157,7 @@ # else /* This is naughty if already declared, but harmful on Win64 */ # ifndef _WIN64 -char *getcwd (char *, size_t); +//char *getcwd (char *, size_t); # endif # endif # endif Index: src/extra/trio/compat.c =================================================================== --- src/extra/trio/compat.c (revision 84610) +++ src/extra/trio/compat.c (working copy) @@ -1,5 +1,6 @@ /* Compatibility wrapper for R */ -#include +//#include +typedef struct FILE_ FILE; #include #include int trio_printf(const char *format, ...); Index: src/gnuwin32/front-ends/graphappmain.c =================================================================== --- src/gnuwin32/front-ends/graphappmain.c (revision 84610) +++ src/gnuwin32/front-ends/graphappmain.c (working copy) @@ -15,7 +15,7 @@ { extern void AppMain(int argc, char **argv); -#ifdef _W64 +#if 0 __declspec(dllimport) extern int __argc; __declspec(dllimport) extern char **__argv; @@ -22,11 +22,11 @@ GA_startgraphapp(Instance, PrevInstance, CmdShow); AppMain(__argc, __argv); #else - __declspec(dllimport) extern int _argc; - __declspec(dllimport) extern char **_argv; + extern int __argc; + extern char **__argv; GA_startgraphapp(Instance, PrevInstance, CmdShow); - AppMain(_argc, _argv); + AppMain(__argc, __argv); #endif return 0; } Index: src/main/main.c =================================================================== --- src/main/main.c (revision 84610) +++ src/main/main.c (working copy) @@ -798,7 +798,7 @@ extern void _invoke_watson(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t); - +#if 0 static void invalid_parameter_handler_watson( const wchar_t* expression, const wchar_t* function, @@ -809,6 +809,7 @@ _invoke_watson(expression, function, file, line, reserved); } #endif +#endif void setup_Rmainloop(void) { @@ -823,8 +824,10 @@ char *p = getenv("_R_WIN_CHECK_INVALID_PARAMETERS_"); if (p && StringTrue(p)) _set_invalid_parameter_handler(invalid_parameter_handler_abort); +#if 0 else if (p && !strcmp(p, "watson")) _set_invalid_parameter_handler(invalid_parameter_handler_watson); +#endif } #endif I don't like these patches one bit and I'm sorry to post them here, but I did get a 32-bit R.exe in the end. It seems to install packages (from source) and run example code successfully. -- Best regards, Ivan -------------- next part -------------- A non-text attachment was scrubbed... Name: Rgui_x32.png Type: image/png Size: 27016 bytes Desc: not available URL: From @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com Wed Jun 28 17:59:54 2023 From: @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com (Ana Marija) Date: Wed, 28 Jun 2023 10:59:54 -0500 Subject: [R] horizontal grouped stacked plots and removing space between bars Message-ID: I have code like this: data <- read.csv("test1.csv", stringsAsFactors=FALSE, header=TRUE) # Graph myplot=ggplot(data, aes(fill=condition, y=value, x=condition)) + geom_bar(position="dodge", stat="identity", width=0.5) + scale_fill_manual(values=c("#7b3294", "#c2a5cf", "#a6dba0", "#008837"))+ ylab("Performance (ns/day)") + facet_wrap(~specie,nrow=3, labeller = label_wrap_gen(width = 85), strip.position="bottom") + theme_bw() + theme(panel.grid = element_blank(), panel.spacing = unit(0, "mm"), legend.title=element_blank(), axis.title.x = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.ticks.x=element_blank(), axis.title.y = element_text(angle = 90, hjust = 0.5)) myplot + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), legend.title=element_blank(), panel.background = element_blank(), axis.title.x = element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), axis.title.y = element_text(angle = 90, hjust = 0.5)) And my data is this: > dput(data) structure(list(specie = c("gmx mdrun -gpu_id 1 -ntomp 16 -s benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s MD_15NM_WATER.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s MD_15NM_WATER.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s MD_15NM_WATER.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s MD_15NM_WATER.tpr -nsteps 10000"), condition = c("Tesla P100-SYCL", "Tesla V100-SYCL", "Tesla P100-CUDA", "Tesla V100-CUDA", "Tesla P100-SYCL", "Tesla V100-SYCL", "Tesla P100-CUDA", "Tesla V100-CUDA"), value = c(75.8, 77.771, 63.297, 78.046, 34.666, 50.052, 32.07, 59.815)), class = "data.frame", row.names = c(NA, -8L)) How do I: 1. have these two plots next to each other, not on the top of each other 2. How do I remove spaces between those bars? [[alternative HTML version deleted]] From du@@@@dr|@n @end|ng |rom gm@||@com Wed Jun 28 21:09:28 2023 From: du@@@@dr|@n @end|ng |rom gm@||@com (=?UTF-8?B?QWRyaWFuIER1yJlh?=) Date: Wed, 28 Jun 2023 22:09:28 +0300 Subject: [R] replacing unicode characters Message-ID: Dear list, Building on the example from ?iconv: x <- "fa\xE7ile" xx <- iconv(x, "latin1", "UTF-8") # "fa?ile" and: iconv(xx, "UTF-8", "ASCII", "Unicode") # "faile" This is the type of result I sometimes get from an R script that I cannot reproduce here, because it depends on a terminal process started in a compiled Electron (Node.js) application, under MacOS. I was wondering, is there a standard way, perhaps also using iconv(), to convert this type of result to a more manageable unicode representation? Something like: "fa\u00e7ile" Or perhaps a clever regexp, for any number of such occurrences in a string? Thanks a lot in advance, Adrian [[alternative HTML version deleted]] From kev|n @end|ng |rom zembower@org Wed Jun 28 22:29:23 2023 From: kev|n @end|ng |rom zembower@org (=?UTF-8?Q?Kevin_Zembower?=) Date: Wed, 28 Jun 2023 20:29:23 +0000 Subject: [R] Processing a hierarchical string name References: Message-ID: <0100018903b24b19-edbdce44-1d45-4f32-9244-284c0bcd5a32-000000@email.amazonses.com> Hello, all I'm trying to process the names of the variables in the US Census database, that I'm retrieving with tidycensus. My end goal is to produce nicely formatted tables with natural labels. The labels as downloaded from the US Census look like this: ## Get the P1 table for block group 3 in census tract 2711.01: bg3_race <- get_decennial( geography = "block group", state = "MD", county = "Baltimore city", table = "P1", cache_table = TRUE, year = "2020", sumfile = "pl")%>% filter(substr(GEOID, 6, 12) == "2711013") ## Load the names and labels of the variables: pl_vars <- load_variables(year = "2020", dataset = "pl", cache = TRUE) ## Join the labels to the variables, and drop the zero counts bg3_race_sum <- bg3_race %>% left_join(pl_vars, by=c("variable" = "name")) %>% filter(value > 0) %>% select(c(GEOID, value, label)) head(bg3_race_sum$label) [1] " !!Total:" [2] " !!Total:!!Population of one race:" [3] " !!Total:!!Population of one race:!!White alone" [4] " !!Total:!!Population of one race:!!Black or African American alone" [5] " !!Total:!!Population of one race:!!American Indian and Alaska Native alone" [6] " !!Total:!!Population of one race:!!Asian alone" I think my algorithm for the labels is: 1. keep everything from the last "!!" up to and including the last character 2. for everything remaining, replace each "!!.*:" group with a single space. This turns head() into: "Total:" " Population of one race:" " White alone" " Black or African American alone" " American Indian and Alaska Native alone" " Asian alone" [may not be clearly visible if not rendered in a monospaced font] I think that I need lapply here, but I'm not sure of that, and of what to do next. I can split the label using str_split(label, pattern = "!!") to get a vector of strings, but don't know how to work on the last string and all the rest of the strings separately. Thank you for any suggestions to nudge me along towards a workable solution. -Kevin From kry|ov@r00t @end|ng |rom gm@||@com Wed Jun 28 22:56:33 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Wed, 28 Jun 2023 23:56:33 +0300 Subject: [R] Processing a hierarchical string name In-Reply-To: <0100018903b24b19-edbdce44-1d45-4f32-9244-284c0bcd5a32-000000@email.amazonses.com> References: <0100018903b24b19-edbdce44-1d45-4f32-9244-284c0bcd5a32-000000@email.amazonses.com> Message-ID: <20230628235633.2ec668dc@Tarkus> On Wed, 28 Jun 2023 20:29:23 +0000 Kevin Zembower via R-help wrote: > I think my algorithm for the labels is: > 1. keep everything from the last "!!" up to and including the last > character > 2. for everything remaining, replace each "!!.*:" group with a single > space. If you remove the initial ' !!', the problem becomes a more tractable "replace each group of non-'!' followed by '!!' with one space": bg3_race_sum$label |> (\(.) sub('^ !!', '', .))() |> (\(.) gsub('[^!]*!!', ' ', .))() But that solution could have been impossible if the task was slightly different. > I can split the label using str_split(label, pattern = "!!") to get a > vector of strings, but don't know how to work on the last string and > all the rest of the strings separately. str_split() would have given you a list of character vectors. You can use lapply to evaluate a function on each vector inside that list. Inside the function, use length(x) (if `x` is the argument of the function) to find out how many spaces to produce and which element of the vector is the last one. (For code golf points, use rev(x)[1] to get the last element.) -- Best regards, Ivan From bgunter@4567 @end|ng |rom gm@||@com Thu Jun 29 01:18:14 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Wed, 28 Jun 2023 16:18:14 -0700 Subject: [R] Processing a hierarchical string name In-Reply-To: <20230628235633.2ec668dc@Tarkus> References: <0100018903b24b19-edbdce44-1d45-4f32-9244-284c0bcd5a32-000000@email.amazonses.com> <20230628235633.2ec668dc@Tarkus> Message-ID: I probably misunderstand what you want to do, but for: test <- c(" !!Total:", " !!Total:!!Population of one race:", " !!Total:!!Population of one race:!!White alone", " !!Total:!!Population of one race:!!Black or African American alone", " !!Total:!!Population of one race:!!American Indian and Alaska Native alone", " !!Total:!!Population of one race:!!Asian alone" ) gsub(".+!","",test) gives: [1] "Total:" "Population of one race:" [3] "White alone" "Black or African American alone" [5] "American Indian and Alaska Native alone" "Asian alone" which is what you said you wanted afaics. Note that this depends on the strict structure of the input character vector(test) and the greediness of the regex matching. Feel free to ignore without response if I have misunderstood. Cheers, Bert On Wed, Jun 28, 2023 at 1:56?PM Ivan Krylov wrote: > > On Wed, 28 Jun 2023 20:29:23 +0000 > Kevin Zembower via R-help wrote: > > > I think my algorithm for the labels is: > > 1. keep everything from the last "!!" up to and including the last > > character > > 2. for everything remaining, replace each "!!.*:" group with a single > > space. > > If you remove the initial ' !!', the problem becomes a more tractable > "replace each group of non-'!' followed by '!!' with one space": > > bg3_race_sum$label |> > (\(.) sub('^ !!', '', .))() |> > (\(.) gsub('[^!]*!!', ' ', .))() > > But that solution could have been impossible if the task was slightly > different. > > > I can split the label using str_split(label, pattern = "!!") to get a > > vector of strings, but don't know how to work on the last string and > > all the rest of the strings separately. > > str_split() would have given you a list of character vectors. You can > use lapply to evaluate a function on each vector inside that list. > Inside the function, use length(x) (if `x` is the argument of the > function) to find out how many spaces to produce and which element of > the vector is the last one. (For code golf points, use rev(x)[1] to get > the last element.) > > -- > Best regards, > Ivan > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From bgunter@4567 @end|ng |rom gm@||@com Thu Jun 29 01:32:01 2023 From: bgunter@4567 @end|ng |rom gm@||@com (Bert Gunter) Date: Wed, 28 Jun 2023 16:32:01 -0700 Subject: [R] Fwd: Processing a hierarchical string name In-Reply-To: References: <0100018903b24b19-edbdce44-1d45-4f32-9244-284c0bcd5a32-000000@email.amazonses.com> <20230628235633.2ec668dc@Tarkus> Message-ID: Sorry, not cc'ed to the list. ---------- Forwarded message --------- From: Bert Gunter Date: Wed, Jun 28, 2023 at 4:18?PM Subject: Re: [R] Processing a hierarchical string name To: Ivan Krylov Cc: Kevin Zembower via R-help I probably misunderstand what you want to do, but for: test <- c(" !!Total:", " !!Total:!!Population of one race:", " !!Total:!!Population of one race:!!White alone", " !!Total:!!Population of one race:!!Black or African American alone", " !!Total:!!Population of one race:!!American Indian and Alaska Native alone", " !!Total:!!Population of one race:!!Asian alone" ) gsub(".+!","",test) gives: [1] "Total:" "Population of one race:" [3] "White alone" "Black or African American alone" [5] "American Indian and Alaska Native alone" "Asian alone" which is what you said you wanted afaics. Note that this depends on the strict structure of the input character vector(test) and the greediness of the regex matching. Feel free to ignore without response if I have misunderstood. Cheers, Bert On Wed, Jun 28, 2023 at 1:56?PM Ivan Krylov wrote: > > On Wed, 28 Jun 2023 20:29:23 +0000 > Kevin Zembower via R-help wrote: > > > I think my algorithm for the labels is: > > 1. keep everything from the last "!!" up to and including the last > > character > > 2. for everything remaining, replace each "!!.*:" group with a single > > space. > > If you remove the initial ' !!', the problem becomes a more tractable > "replace each group of non-'!' followed by '!!' with one space": > > bg3_race_sum$label |> > (\(.) sub('^ !!', '', .))() |> > (\(.) gsub('[^!]*!!', ' ', .))() > > But that solution could have been impossible if the task was slightly > different. > > > I can split the label using str_split(label, pattern = "!!") to get a > > vector of strings, but don't know how to work on the last string and > > all the rest of the strings separately. > > str_split() would have given you a list of character vectors. You can > use lapply to evaluate a function on each vector inside that list. > Inside the function, use length(x) (if `x` is the argument of the > function) to find out how many spaces to produce and which element of > the vector is the last one. (For code golf points, use rev(x)[1] to get > the last element.) > > -- > Best regards, > Ivan > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From j@nn|e@pretor|u@ @end|ng |rom up@@c@z@ Wed Jun 28 13:55:33 2023 From: j@nn|e@pretor|u@ @end|ng |rom up@@c@z@ (Jannie Pretorius) Date: Wed, 28 Jun 2023 16:55:33 +0500 Subject: [R] LINUX SuSE15.4 (GNU & Intel) compiler problem in "configure" file Message-ID: Dear R-Support Team: I am fully aware that you are all extremely busy and forward this request as brief and clear as possible: Thank you for the comprehensive Documentation for R-4.3.1 (very helpful) A limitation seems to have emerged, using SuSE SP15.4 (kernel: 5.14.21-150400.22) on an INTEL Skylake-e SERVER, applying both the GNU and Intel (2023.0.0) compilers. a) The "configure" step complains about a syntax in the: .... R-4.3.1/ *configure* file As: ........ Partial "configure" output checking if libtool supports shared libraries... no checking whether to build shared libraries... no checking whether to build static libraries... yes checking how to run the C++ preprocessor... g++ -E checking for ld used by g++... /usr/x86_64-suse-linux/bin/ld checking if the linker (/usr/x86_64-suse-linux/bin/ld) is GNU ld... yes checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld) supports shared libraries... no checking for g++ option to produce PIC... -fPIC -DPIC checking if g++ PIC flag -fPIC -DPIC works... yes checking if g++ static flag -static works... yes checking if g++ supports -c -o file.o... yes checking if g++ supports -c -o file.o... (cached) yes checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld) supports shared libraries... no checking dynamic linker characteristics... no checking how to hardcode library paths into programs... immediate checking if libtool supports shared libraries... no checking whether to build shared libraries... no checking whether to build static libraries... yes checking for gfortran option to produce PIC... -fPIC checking if gfortran PIC flag -fPIC works... yes checking if gfortran static flag -static works... yes checking if gfortran supports -c -o file.o... yes checking if gfortran supports -c -o file.o... (cached) yes checking whether the gfortran linker (/usr/x86_64-suse-linux/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... no checking how to hardcode library paths into programs... immediate ./configure: line 24446: ${}: bad substitution b) Removing this dual inscripted *${* ${ }*}* obviously solves the limitation encountered during the configure step (below) ## Export LD_LIBRARY_PATH or equivalent. if eval "test -z \"\*${*${Rshlibpath_var}*}*\""; then eval "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}\"" else eval "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}${PATH_SEPARATOR}\${${Rshlibpath_var}}\"" fi *And offers a clean pre-compilation result as*: R is now configured for x86_64-pc-none Source directory: . Installation directory: /opt/R/v4.3.1 C compiler: gcc -g -O2 Fortran fixed-form compiler: gfortran -g -O2 Default C++ compiler: g++ -std=gnu++17 -g -O2 C++11 compiler: g++ -std=gnu++11 -g -O2 C++14 compiler: g++ -std=gnu++14 -g -O2 C++17 compiler: g++ -std=gnu++17 -g -O2 C++20 compiler: C++23 compiler: Fortran free-form compiler: gfortran -g -O2 Obj-C compiler: gcc -g -O2 -fobjc-exceptions Interfaces supported: X11 External libraries: pcre2, readline, BLAS(OpenBLAS), LAPACK(in blas), curl Additional capabilities: PNG, NLS, cairo, ICU Options enabled: shared R library, R profiling, memory profiling Capabilities skipped: JPEG, TIFF Options not enabled: shared BLAS Recommended packages: yes c) But this seemingly relates to an error in the "ldpath" file at: ...R-4.3.1/etc/ldpath during the subsequent compilation step: /SOFTWARE/CODE-R/R-BASE/v4.3.1/etc/*ldpaths*: line 16: *${}*: bad substitution make[4]: *** [../../../share/make/basepkg.mk:151: sysdata] Error 1 make[4]: Leaving directory '/SOFTWARE/CODE-R/R-BASE/v4.3.1/src/library/tools' make[3]: *** [Makefile:36: all] Error 2 make[3]: Leaving directory '/SOFTWARE/CODE-R/R-BASE/v4.3.1/src/library/tools' make[2]: *** [Makefile:37: R] Error 1 make[2]: Leaving directory '/SOFTWARE/CODE-R/R-BASE/v4.3.1/src/library' make[1]: *** [Makefile:28: R] Error 1 make[1]: Leaving directory '/SOFTWARE/CODE-R/R-BASE/v4.3.1/src' make: *** [Makefile:62: R] Error 1 Obviously, irrespective if the eliminaton of *${ }* under b) above has been applied or not. d) Can you offer a work around to this please ? Kind Regards Jan Pretorius Dr Jannie Pretorius Research Fellow (Senior Scientist) Centre for the Advancement of Scholarship & Chemistry Dept. OLD COLLEGE HOUSE (1-15) University of Pretoria Hatfield Campus, Pretoria Tel: +27 12 420 5305 -- This message and attachments are subject to a disclaimer. Please refer to? http://upnet.up.ac.za/services/it/documentation/docs/004167.pdf ?for full details. [[alternative HTML version deleted]] From |kw@|mmo @end|ng |rom gm@||@com Thu Jun 29 00:58:57 2023 From: |kw@|mmo @end|ng |rom gm@||@com (Iris Simmons) Date: Wed, 28 Jun 2023 18:58:57 -0400 Subject: [R] replacing unicode characters In-Reply-To: References: Message-ID: Hiya! You can do this by specifying sub="c99" instead of "Unicode": ```R x <- "fa\xE7ile" xx <- iconv(x, "latin1", "UTF-8") iconv(xx, "UTF-8", "ASCII", "c99") ``` produces: ``` > x <- "fa\xE7ile" > xx <- iconv(x, "latin1", "UTF-8") > iconv(xx, "UTF-8", "ASCII", "c99") [1] "fa\\u00e7ile" > ``` For future reference, you can find this in section Examples of the help page ?iconv I hope this helps! On Wed, Jun 28, 2023 at 3:09?PM Adrian Du?a wrote: > > Dear list, > > Building on the example from ?iconv: > x <- "fa\xE7ile" > xx <- iconv(x, "latin1", "UTF-8") # "fa?ile" > > and: > > iconv(xx, "UTF-8", "ASCII", "Unicode") > # "faile" > > This is the type of result I sometimes get from an R script that I cannot > reproduce here, because it depends on a terminal process started in a > compiled Electron (Node.js) application, under MacOS. > > I was wondering, is there a standard way, perhaps also using iconv(), to > convert this type of result to a more manageable unicode representation? > > Something like: "fa\u00e7ile" > > Or perhaps a clever regexp, for any number of such occurrences in a string? > > Thanks a lot in advance, > Adrian > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From @nupty@g| @end|ng |rom gm@||@com Thu Jun 29 05:48:47 2023 From: @nupty@g| @end|ng |rom gm@||@com (Anupam Tyagi) Date: Thu, 29 Jun 2023 09:18:47 +0530 Subject: [R] Plotting factors in graph panel In-Reply-To: References: Message-ID: Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have been well. Pikal, thanks. Your solution may be close to what I want. I did not know that I was posting in HTML. I just copied the data from Excel and posted in the email in Gmail. The data is still in Excel, because I have not yet figured out what is a good way to organize it in R. I am posting it again below as text. These are rows in Excel: 1,2,3,5,9 after MF are income categories and No Answer category (9). Down the second column are categories of MF and Bank AC. Rest of the columns are percentages. Jim, thanks for the graph. I am looking to plot only one line (category) each in many small plots on the same page. I don't want to compare different categories on the same graph as you do, but see how each category varies by income, one category in each graph. Like Excel does with Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories for many variables. I am only showing two MF and Bank AC. Income $10 $25 $40 $75 > $75 No Answer MF 1 2 3 4 5 9 None 1 3.05 2.29 2.24 1.71 1.30 2.83 Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 46.54 54.01 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 On Wed, 28 Jun 2023 at 17:30, Jim Lemon wrote: > Hi Anupam, > Haven't heard from you in a long time. Perhaps you want something like > this: > > at_df<-read.table(text= > "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current > Bank_Savings Bank_NA > $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307 > $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891 > $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4 > $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746 > >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208 > No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577", > header=TRUE,stringsAsFactors=FALSE) > at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")] > png("MF_Bank.png",height=600) > par(mfrow=c(2,1)) > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")], > type="l",col=1:4,lty=1:4,lwd=3, > main="Percentages by Income and MF type", > xlab="Income",ylab="Percentage of group",xaxt="n") > axis(1,at=1:5,labels=at_df$Income) > legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"), > lty=1:4,lwd=3,col=1:4) > matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")], > type="l",col=1:3,lty=1:4,lwd=3, > main="Percentages by Income and Bank type", > xlab="Income",ylab="Percentage of group",xaxt="n") > axis(1,at=1:5,labels=at_df$Income) > legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"), > lty=1:4,lwd=3,col=1:3) > dev.off() > > Jim > > On Wed, Jun 28, 2023 at 6:33?PM Anupam Tyagi wrote: > > > > Hello, > > > > I want to plot the following kind of data (percentage of respondents > from a > > survey) that varies by Income into many small *line* graphs in a panel of > > graphs. I want to omit "No Answer" categories. I want to see how each one > > of the categories (percentages), "None", " Equity", etc. varies by > Income. > > How can I do this? How to organize the data well and how to plot? I > thought > > Lattice may be a good package to plot this, but I don't know for sure. I > > prefer to do this in Base-R if possible, but I am open to ggplot. Any > ideas > > will be helpful. > > > > Income > > $10 $25 $40 $75 > $75 No Answer > > MF 1 2 3 4 5 9 > > None 1 3.05 2.29 2.24 1.71 1.30 2.83 > > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 > > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 > > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 > > Bank AC > > None 1 46.54 54.01 59.1 62.17 67.67 60.87 > > Current 2 24.75 24.4 25 24.61 24.02 21.09 > > Savings 3 25.4 18.7 29 11.48 7.103 13.46 > > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 > > > > Thanks. > > -- > > Anupam. > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > -- Anupam. [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Thu Jun 29 08:01:31 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Thu, 29 Jun 2023 09:01:31 +0300 Subject: [R] LINUX SuSE15.4 (GNU & Intel) compiler problem in "configure" file In-Reply-To: References: Message-ID: <20230629090131.7a4d3789@Tarkus> On Wed, 28 Jun 2023 16:55:33 +0500 Jannie Pretorius wrote: > ./configure: line 24446: ${}: bad substitution > ## Export LD_LIBRARY_PATH or equivalent. > if eval "test -z \"\*${*${Rshlibpath_var}*}*\""; then > eval "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}\"" > else > eval > "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}${PATH_SEPARATOR}\${${Rshlibpath_var}}\"" > fi What's your /bin/sh? Is it a symlink to bash, dash, or something else? Does the config.log file created in the directory where you ran .../configure contain mentions of variables Rshlibpath_var and shlibpath_var? Which values do they have? (Are they really empty?) The configure script should have noticed that you're building for GNU/Linux and set these variables appropriately (the value should be 'LD_LIBRARY_PATH' in both cases). What is the output of tools/config.guess? -- Best regards, Ivan From petr@p|k@| @end|ng |rom prechez@@cz Thu Jun 29 08:28:14 2023 From: petr@p|k@| @end|ng |rom prechez@@cz (PIKAL Petr) Date: Thu, 29 Jun 2023 06:28:14 +0000 Subject: [R] horizontal grouped stacked plots and removing space between bars In-Reply-To: References: Message-ID: Hi Anamaria Thanks for the data. See in line. > -----Original Message----- > From: R-help On Behalf Of Ana Marija > Sent: Wednesday, June 28, 2023 6:00 PM > To: r-help > Subject: [R] horizontal grouped stacked plots and removing space between > bars > > I have code like this: > > data <- read.csv("test1.csv", stringsAsFactors=FALSE, header=TRUE) > # Graph > myplot=ggplot(data, aes(fill=condition, y=value, x=condition)) + > geom_bar(position="dodge", stat="identity", width=0.5) + > scale_fill_manual(values=c("#7b3294", "#c2a5cf", "#a6dba0", "#008837"))+ You have only 4 colours, you need 5 so I removed the line > ylab("Performance (ns/day)") + > facet_wrap(~specie,nrow=3, labeller = label_wrap_gen(width = 85), > strip.position="bottom") + > theme_bw() + > theme(panel.grid = element_blank(), > panel.spacing = unit(0, "mm"), > legend.title=element_blank(), > axis.title.x = element_blank(), > panel.grid.major = element_blank(), > panel.grid.minor = element_blank(), > panel.background = element_blank(), > axis.ticks.x=element_blank(), > axis.title.y = element_text(angle = 90, hjust = 0.5)) > > > > myplot + theme(panel.grid.major = element_blank(), panel.grid.minor = > element_blank(), legend.title=element_blank(), > panel.background = element_blank(), axis.title.x = element_blank(), > axis.text.x=element_blank(), axis.ticks.x=element_blank(), > axis.title.y = element_text(angle = 90, hjust = 0.5)) And here I got 2 plots one above the other so I presume this is what you wanted. Spacing between bars https://www.statology.org/ggplot2-space-between-bars/ Cheers Petr > > And my data is this: > > > dput(data) > structure(list(specie = c("gmx mdrun -gpu_id 1 -ntomp 16 -s > benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s > benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s > benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s > benchMEM.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s > MD_15NM_WATER.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s > MD_15NM_WATER.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s > MD_15NM_WATER.tpr -nsteps 10000", "gmx mdrun -gpu_id 1 -ntomp 16 -s > MD_15NM_WATER.tpr -nsteps 10000"), condition = c("Tesla P100-SYCL", > "Tesla V100-SYCL", "Tesla P100-CUDA", "Tesla V100-CUDA", "Tesla > P100-SYCL", "Tesla V100-SYCL", "Tesla P100-CUDA", "Tesla V100-CUDA"), > value = c(75.8, 77.771, 63.297, 78.046, 34.666, 50.052, 32.07, > 59.815)), class = "data.frame", row.names = c(NA, -8L)) > > How do I: > > 1. have these two plots next to each other, not on the top of each other > 2. How do I remove spaces between those bars? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. From petr@p|k@| @end|ng |rom prechez@@cz Thu Jun 29 08:46:58 2023 From: petr@p|k@| @end|ng |rom prechez@@cz (PIKAL Petr) Date: Thu, 29 Jun 2023 06:46:58 +0000 Subject: [R] Plotting factors in graph panel In-Reply-To: References: Message-ID: Hi Anupam Using Jim's data library(reshape2) at_long <- melt(at_df) at_long$innum <- as.numeric(as.factor(at_long$Income)) ggplot(at_long, aes(x=innum, y=value)) + geom_path() + facet_wrap(~variable, ncol=1) is probably close to what you want. You need to fiddle with labels, facets variable names to fit your needs. Cheers Petr > -----Original Message----- > From: R-help On Behalf Of Anupam Tyagi > Sent: Thursday, June 29, 2023 5:49 AM > To: r-help at r-project.org > Subject: Re: [R] Plotting factors in graph panel > > Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have been > well. > > Pikal, thanks. Your solution may be close to what I want. I did not know that I > was posting in HTML. I just copied the data from Excel and posted in the email > in Gmail. The data is still in Excel, because I have not yet figured out what is a > good way to organize it in R. I am posting it again below as text. These are > rows in Excel: 1,2,3,5,9 after MF are income categories and No Answer > category (9). Down the second column are categories of MF and Bank AC. > Rest of the columns are percentages. > > Jim, thanks for the graph. I am looking to plot only one line (category) each in > many small plots on the same page. I don't want to compare different > categories on the same graph as you do, but see how each category varies by > income, one category in each graph. Like Excel does with Sparklines (Top > menu: Insert, Sparklines, Lines). I have many categories for many variables. I > am only showing two MF and Bank AC. > > Income $10 $25 $40 $75 > $75 No Answer > MF 1 2 3 4 5 9 > None 1 3.05 2.29 2.24 1.71 1.30 2.83 > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 > 37.59 33.15 Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 > 46.54 54.01 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 > Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 13.4 1.746 > 1.208 4.577 > > > On Wed, 28 Jun 2023 at 17:30, Jim Lemon wrote: > > > Hi Anupam, > > Haven't heard from you in a long time. Perhaps you want something like > > this: > > > > at_df<-read.table(text= > > "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None > Bank_Current > > Bank_Savings Bank_NA > > $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307 > > $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891 > > $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4 > > $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746 > > >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208 No_Answer 9 > > 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577", > > header=TRUE,stringsAsFactors=FALSE) > > at_df<- > at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")] > > png("MF_Bank.png",height=600) > > par(mfrow=c(2,1)) > > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")], > > type="l",col=1:4,lty=1:4,lwd=3, > > main="Percentages by Income and MF type", > > xlab="Income",ylab="Percentage of group",xaxt="n") > > axis(1,at=1:5,labels=at_df$Income) > > legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"), > > lty=1:4,lwd=3,col=1:4) > > matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")], > > type="l",col=1:3,lty=1:4,lwd=3, > > main="Percentages by Income and Bank type", > > xlab="Income",ylab="Percentage of group",xaxt="n") > > axis(1,at=1:5,labels=at_df$Income) > > legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"), > > lty=1:4,lwd=3,col=1:3) > > dev.off() > > > > Jim > > > > On Wed, Jun 28, 2023 at 6:33?PM Anupam Tyagi > wrote: > > > > > > Hello, > > > > > > I want to plot the following kind of data (percentage of respondents > > from a > > > survey) that varies by Income into many small *line* graphs in a > > > panel of graphs. I want to omit "No Answer" categories. I want to > > > see how each one of the categories (percentages), "None", " Equity", > > > etc. varies by > > Income. > > > How can I do this? How to organize the data well and how to plot? I > > thought > > > Lattice may be a good package to plot this, but I don't know for > > > sure. I prefer to do this in Base-R if possible, but I am open to > > > ggplot. Any > > ideas > > > will be helpful. > > > > > > Income > > > $10 $25 $40 $75 > $75 No Answer > > > MF 1 2 3 4 5 9 > > > None 1 3.05 2.29 2.24 1.71 1.30 2.83 Equity 2 29.76 28.79 29.51 > > > 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 Hybrid > > > 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 46.54 54.01 > > > 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 > > > Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 > > > 13.4 1.746 1.208 4.577 > > > > > > Thanks. > > > -- > > > Anupam. > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- > Anupam. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. From tebert @end|ng |rom u||@edu Thu Jun 29 14:37:23 2023 From: tebert @end|ng |rom u||@edu (Ebert,Timothy Aaron) Date: Thu, 29 Jun 2023 12:37:23 +0000 Subject: [R] Plotting factors in graph panel In-Reply-To: References: Message-ID: Reposting the data did not help. We do not like to guess, and doing so takes a great deal of time that is likely wasted. Rows are observations. Columns are variables. In Excel, the first row will be variable names and all subsequent rows will be observations. Income is the first variable. It has seven states: $10, $25, $40, $75, >$75, "No", "Answer" MF is the second variable. It has six values: 1, 2, 3, 4, 5, 9 None is the third variable. It has seven values: 1, 3.05, 2.29, 2.24, 1.71, 1.30, 2.83 Equity is the last variable with many states, both numeric and text. A computer will read it all as text. As written the data cannot be analyzed. Equity looks like it should be numeric. However, it has text values: "Debt", "Hybrid", Bank", "AC", "None", "Current", "Savings", "No", and "Answer" In looking at the data I try to find some organization where every variable has the same number of rows as every other variable. I fail with these data. I could combine "No" and "Answer" into one name "No Answer" to make it agree with MF, but then it does not work for None. Please rework the data in Excel so that we can properly interpret the content. If it is badly organized in Excel, moving it to R will not help. Below, I tried adding carriage returns and spaces to organize the data, but I have a column of numbers that are not identified. The values below $10 do not make much sense compared to other values. I am tired of guessing. Tim -----Original Message----- From: R-help On Behalf Of Anupam Tyagi Sent: Wednesday, June 28, 2023 11:49 PM To: r-help at r-project.org Subject: Re: [R] Plotting factors in graph panel [External Email] Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have been well. Pikal, thanks. Your solution may be close to what I want. I did not know that I was posting in HTML. I just copied the data from Excel and posted in the email in Gmail. The data is still in Excel, because I have not yet figured out what is a good way to organize it in R. I am posting it again below as text. These are rows in Excel: 1,2,3,5,9 after MF are income categories and No Answer category (9). Down the second column are categories of MF and Bank AC. Rest of the columns are percentages. Jim, thanks for the graph. I am looking to plot only one line (category) each in many small plots on the same page. I don't want to compare different categories on the same graph as you do, but see how each category varies by income, one category in each graph. Like Excel does with Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories for many variables. I am only showing two MF and Bank AC. Income $10 $25 $40 $75 > $75 No Answer MF 1 2 3 4 5 9 None 1 3.05 2.29 2.24 1.71 1.30 2.83 Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 46.54 54.01 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 On Wed, 28 Jun 2023 at 17:30, Jim Lemon wrote: > Hi Anupam, > Haven't heard from you in a long time. Perhaps you want something like > this: > > at_df<-read.table(text= > "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current > Bank_Savings Bank_NA > $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307 > $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891 > $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4 > $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746 > >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208 No_Answer 9 > 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577", > header=TRUE,stringsAsFactors=FALSE) > at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")] > png("MF_Bank.png",height=600) > par(mfrow=c(2,1)) > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")], > type="l",col=1:4,lty=1:4,lwd=3, > main="Percentages by Income and MF type", > xlab="Income",ylab="Percentage of group",xaxt="n") > axis(1,at=1:5,labels=at_df$Income) > legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"), > lty=1:4,lwd=3,col=1:4) > matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")], > type="l",col=1:3,lty=1:4,lwd=3, > main="Percentages by Income and Bank type", > xlab="Income",ylab="Percentage of group",xaxt="n") > axis(1,at=1:5,labels=at_df$Income) > legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"), > lty=1:4,lwd=3,col=1:3) > dev.off() > > Jim > > On Wed, Jun 28, 2023 at 6:33?PM Anupam Tyagi wrote: > > > > Hello, > > > > I want to plot the following kind of data (percentage of respondents > from a > > survey) that varies by Income into many small *line* graphs in a > > panel of graphs. I want to omit "No Answer" categories. I want to > > see how each one of the categories (percentages), "None", " Equity", > > etc. varies by > Income. > > How can I do this? How to organize the data well and how to plot? I > thought > > Lattice may be a good package to plot this, but I don't know for > > sure. I prefer to do this in Base-R if possible, but I am open to > > ggplot. Any > ideas > > will be helpful. > > > > Income > > $10 $25 $40 $75 > $75 No Answer > > MF 1 2 3 4 5 9 > > None 1 3.05 2.29 2.24 1.71 1.30 2.83 Equity 2 29.76 28.79 29.51 > > 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 Hybrid > > 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 46.54 54.01 > > 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 > > Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 > > 13.4 1.746 1.208 4.577 > > > > Thanks. > > -- > > Anupam. > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://st/ > > at.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl > > .edu%7C59874e74164c46133f2c08db7853d28f%7C0d4da0f84a314d76ace60a6233 > > 1e1b84%7C0%7C0%7C638236073642897221%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi > > MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C > > %7C%7C&sdata=xoaDMG7ogY4tMtqe30pONZrBdk0eq2cW%2BgdwlDHneWY%3D&reserv > > ed=0 > > PLEASE do read the posting guide > http://www.r/ > -project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C59 > 874e74164c46133f2c08db7853d28f%7C0d4da0f84a314d76ace60a62331e1b84%7C0% > 7C0%7C638236073642897221%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL > CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=H7 > 6XCa%2FULBGUn0Lok93l6mtHzo0snq5G0a%2BL4sEH8%2F8%3D&reserved=0 > > and provide commented, minimal, self-contained, reproducible code. > -- Anupam. [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From jrkr|de@u @end|ng |rom gm@||@com Thu Jun 29 17:41:40 2023 From: jrkr|de@u @end|ng |rom gm@||@com (John Kane) Date: Thu, 29 Jun 2023 11:41:40 -0400 Subject: [R] Plotting factors in graph panel In-Reply-To: References: Message-ID: Anupa, I think your best bet with your data would be to tidy it up in Excel, read it into R using something like the readxl package and then supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where *mydata* is your data. Copy the output and paste it here. On Thu, 29 Jun 2023 at 08:37, Ebert,Timothy Aaron wrote: > Reposting the data did not help. We do not like to guess, and doing so > takes a great deal of time that is likely wasted. > Rows are observations. > Columns are variables. > In Excel, the first row will be variable names and all subsequent rows > will be observations. > > Income is the first variable. It has seven states: $10, $25, $40, $75, > >$75, "No", "Answer" > MF is the second variable. It has six values: 1, 2, 3, 4, 5, 9 > None is the third variable. It has seven values: 1, 3.05, 2.29, 2.24, > 1.71, 1.30, 2.83 > Equity is the last variable with many states, both numeric and text. A > computer will read it all as text. > > As written the data cannot be analyzed. > > Equity looks like it should be numeric. However, it has text values: > "Debt", "Hybrid", Bank", "AC", "None", "Current", "Savings", "No", and > "Answer" > > In looking at the data I try to find some organization where every > variable has the same number of rows as every other variable. I fail with > these data. > I could combine "No" and "Answer" into one name "No Answer" to make it > agree with MF, but then it does not work for None. > > > Please rework the data in Excel so that we can properly interpret the > content. If it is badly organized in Excel, moving it to R will not help. > Below, I tried adding carriage returns and spaces to organize the data, > but I have a column of numbers that are not identified. The values below > $10 do not make much sense compared to other values. > > I am tired of guessing. > > Tim > > -----Original Message----- > From: R-help On Behalf Of Anupam Tyagi > Sent: Wednesday, June 28, 2023 11:49 PM > To: r-help at r-project.org > Subject: Re: [R] Plotting factors in graph panel > > [External Email] > > Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have > been well. > > Pikal, thanks. Your solution may be close to what I want. I did not know > that I was posting in HTML. I just copied the data from Excel and posted in > the email in Gmail. The data is still in Excel, because I have not yet > figured out what is a good way to organize it in R. I am posting it again > below as text. These are rows in Excel: 1,2,3,5,9 after MF are income > categories and No Answer category (9). Down the second column are > categories of MF and Bank AC. Rest of the columns are percentages. > > Jim, thanks for the graph. I am looking to plot only one line (category) > each in many small plots on the same page. I don't want to compare > different categories on the same graph as you do, but see how each category > varies by income, one category in each graph. Like Excel does with > Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories > for many variables. I am only showing two MF and Bank AC. > > Income $10 $25 $40 $75 > $75 No Answer > MF 1 2 3 4 5 9 > None 1 3.05 2.29 2.24 1.71 1.30 > 2.83 > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 > > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 > > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 > > Bank AC None 1 46.54 54.01 59.1 62.17 67.67 60.87 > > Current 2 24.75 24.4 25 24.61 24.02 21.09 > > Savings 3 25.4 18.7 29 11.48 7.103 13.46 > > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 > > > On Wed, 28 Jun 2023 at 17:30, Jim Lemon wrote: > > > Hi Anupam, > > Haven't heard from you in a long time. Perhaps you want something like > > this: > > > > at_df<-read.table(text= > > "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current > > Bank_Savings Bank_NA > > $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307 > > $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891 > > $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4 > > $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746 > > >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208 No_Answer 9 > > 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577", > > header=TRUE,stringsAsFactors=FALSE) > > at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")] > > png("MF_Bank.png",height=600) > > par(mfrow=c(2,1)) > > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")], > > type="l",col=1:4,lty=1:4,lwd=3, > > main="Percentages by Income and MF type", > > xlab="Income",ylab="Percentage of group",xaxt="n") > > axis(1,at=1:5,labels=at_df$Income) > > legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"), > > lty=1:4,lwd=3,col=1:4) > > matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")], > > type="l",col=1:3,lty=1:4,lwd=3, > > main="Percentages by Income and Bank type", > > xlab="Income",ylab="Percentage of group",xaxt="n") > > axis(1,at=1:5,labels=at_df$Income) > > legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"), > > lty=1:4,lwd=3,col=1:3) > > dev.off() > > > > Jim > > > > On Wed, Jun 28, 2023 at 6:33?PM Anupam Tyagi > wrote: > > > > > > Hello, > > > > > > I want to plot the following kind of data (percentage of respondents > > from a > > > survey) that varies by Income into many small *line* graphs in a > > > panel of graphs. I want to omit "No Answer" categories. I want to > > > see how each one of the categories (percentages), "None", " Equity", > > > etc. varies by > > Income. > > > How can I do this? How to organize the data well and how to plot? I > > thought > > > Lattice may be a good package to plot this, but I don't know for > > > sure. I prefer to do this in Base-R if possible, but I am open to > > > ggplot. Any > > ideas > > > will be helpful. > > > > > > Income > > > $10 $25 $40 $75 > $75 No Answer > > > MF 1 2 3 4 5 9 > > > None 1 3.05 2.29 2.24 1.71 1.30 2.83 Equity 2 29.76 28.79 29.51 > > > 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 Hybrid > > > 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1 46.54 54.01 > > > 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09 > > > Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 > > > 13.4 1.746 1.208 4.577 > > > > > > Thanks. > > > -- > > > Anupam. > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > https://st/ > > > at.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl > > > .edu%7C59874e74164c46133f2c08db7853d28f%7C0d4da0f84a314d76ace60a6233 > > > 1e1b84%7C0%7C0%7C638236073642897221%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi > > > MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C > > > %7C%7C&sdata=xoaDMG7ogY4tMtqe30pONZrBdk0eq2cW%2BgdwlDHneWY%3D&reserv > > > ed=0 > > > PLEASE do read the posting guide > > http://www.r/ > > -project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C59 > > 874e74164c46133f2c08db7853d28f%7C0d4da0f84a314d76ace60a62331e1b84%7C0% > > 7C0%7C638236073642897221%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL > > CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=H7 > > 6XCa%2FULBGUn0Lok93l6mtHzo0snq5G0a%2BL4sEH8%2F8%3D&reserved=0 > > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- > Anupam. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- John Kane Kingston ON Canada [[alternative HTML version deleted]] From kev|n @end|ng |rom zembower@org Thu Jun 29 20:35:25 2023 From: kev|n @end|ng |rom zembower@org (=?UTF-8?Q?Kevin_Zembower?=) Date: Thu, 29 Jun 2023 18:35:25 +0000 Subject: [R] Processing a hierarchical string name In-Reply-To: <20230628235633.2ec668dc@Tarkus> References: <0100018903b24b19-edbdce44-1d45-4f32-9244-284c0bcd5a32-000000@email.amazonses.com> <20230628235633.2ec668dc@Tarkus> Message-ID: <0100018908704e90-ac1abe3b-b801-4437-b29c-1ce3ef79f3bc-000000@email.amazonses.com> Ivan and Bert, thank you so much for your help. Ivan, your solution worked perfectly. I didn't really understand how to do string processing on a vector of strings, and your solution demonstrated it for me. I modified it to work with the tidyverses' stringr library in this way: bg3_race_sum <- bg3_race %>% left_join(pl_vars, by=c("variable" = "name")) %>% group_by(variable) %>% summarize(count = sum(value)) %>% left_join(pl_vars, by=c("variable" = "name")) %>% filter(count > 0) %>% .$label %>% str_replace("^ !!", "") %>% #Drop the leading ' !!' str_replace_all("[^!]*!!", " ") #Replace each !!.* with space Bert, your solution was close to correct. It correctly dropped the right text, but didn't insert a space for each piece of text between "!!" and after the ":". I'm using those spaces to preserve the hierarchical nature of the numbers, how lower numbers (in the chart) are included in higher numbers. For instance, the "Total:" number is the sum of "Population of one race" and "Population of two or more races". Thank you both for helping me with this specific problem and for increasing my knowledge and abilities with R. -Kevin On 6/28/23 16:56, Ivan Krylov wrote: > On Wed, 28 Jun 2023 20:29:23 +0000 > Kevin Zembower via R-help wrote: > >> I think my algorithm for the labels is: >> 1. keep everything from the last "!!" up to and including the last >> character >> 2. for everything remaining, replace each "!!.*:" group with a single >> space. > > If you remove the initial ' !!', the problem becomes a more tractable > "replace each group of non-'!' followed by '!!' with one space": > > bg3_race_sum$label |> > (\(.) sub('^ !!', '', .))() |> > (\(.) gsub('[^!]*!!', ' ', .))() > > But that solution could have been impossible if the task was slightly > different. > >> I can split the label using str_split(label, pattern = "!!") to get a >> vector of strings, but don't know how to work on the last string and >> all the rest of the strings separately. > > str_split() would have given you a list of character vectors. You can > use lapply to evaluate a function on each vector inside that list. > Inside the function, use length(x) (if `x` is the argument of the > function) to find out how many spaces to produce and which element of > the vector is the last one. (For code golf points, use rev(x)[1] to get > the last element.) > From drj|m|emon @end|ng |rom gm@||@com Fri Jun 30 01:10:53 2023 From: drj|m|emon @end|ng |rom gm@||@com (Jim Lemon) Date: Fri, 30 Jun 2023 09:10:53 +1000 Subject: [R] Plotting factors in graph panel In-Reply-To: References: Message-ID: Okay. Here is a modification that does four single line plots. at_df<-read.table(text= "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current Bank_Savings Bank_NA $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307 $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891 $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4 $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746 >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208 No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577", header=TRUE,stringsAsFactors=FALSE) at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")] png("Income_pcts.png",height=700) par(mfrow=c(4,1)) plot(at_df[,"Bank_Current"], type="l",lwd=3,main="Bsnk_Current", xlab="Income",ylab="%",xaxt="n") axis(1,at=1:5,labels=at_df$Income) plot(at_df[,"Bank_Savings"], type="l",lwd=3,main="Bank_Sasvings", xlab="Income",ylab="%",xaxt="n") axis(1,at=1:5,labels=at_df$Income) plot(at_df[,"MF_Equity"], type="l",lwd=3,main="MF_Equity", xlab="Income",ylab="%",xaxt="n") axis(1,at=1:5,labels=at_df$Income) plot(at_df[,"MF_Debt"], type="l",lwd=3,main="MF_Debt", xlab="Income",ylab="%",xaxt="n") axis(1,at=1:5,labels=at_df$Income) dev.off() Jim On Thu, Jun 29, 2023 at 1:49?PM Anupam Tyagi wrote: > > Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have > been well. > > Pikal, thanks. Your solution may be close to what I want. I did not know > that I was posting in HTML. I just copied the data from Excel and posted in > the email in Gmail. The data is still in Excel, because I have not yet > figured out what is a good way to organize it in R. I am posting it again > below as text. These are rows in Excel: 1,2,3,5,9 after MF are income > categories and No Answer category (9). Down the second column are > categories of MF and Bank AC. Rest of the columns are percentages. > > Jim, thanks for the graph. I am looking to plot only one line (category) > each in many small plots on the same page. I don't want to compare > different categories on the same graph as you do, but see how each category > varies by income, one category in each graph. Like Excel does with > Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories > for many variables. I am only showing two MF and Bank AC. > > Income $10 $25 $40 $75 > $75 No Answer > MF 1 2 3 4 5 9 > None 1 3.05 2.29 2.24 1.71 1.30 2.83 > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 > Bank AC > None 1 46.54 54.01 59.1 62.17 67.67 60.87 > Current 2 24.75 24.4 25 24.61 24.02 21.09 > Savings 3 25.4 18.7 29 11.48 7.103 13.46 > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 > > > On Wed, 28 Jun 2023 at 17:30, Jim Lemon wrote: > > > Hi Anupam, > > Haven't heard from you in a long time. Perhaps you want something like > > this: > > > > at_df<-read.table(text= > > "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current > > Bank_Savings Bank_NA > > $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307 > > $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891 > > $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4 > > $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746 > > >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208 > > No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577", > > header=TRUE,stringsAsFactors=FALSE) > > at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")] > > png("MF_Bank.png",height=600) > > par(mfrow=c(2,1)) > > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")], > > type="l",col=1:4,lty=1:4,lwd=3, > > main="Percentages by Income and MF type", > > xlab="Income",ylab="Percentage of group",xaxt="n") > > axis(1,at=1:5,labels=at_df$Income) > > legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"), > > lty=1:4,lwd=3,col=1:4) > > matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")], > > type="l",col=1:3,lty=1:4,lwd=3, > > main="Percentages by Income and Bank type", > > xlab="Income",ylab="Percentage of group",xaxt="n") > > axis(1,at=1:5,labels=at_df$Income) > > legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"), > > lty=1:4,lwd=3,col=1:3) > > dev.off() > > > > Jim > > > > On Wed, Jun 28, 2023 at 6:33?PM Anupam Tyagi wrote: > > > > > > Hello, > > > > > > I want to plot the following kind of data (percentage of respondents > > from a > > > survey) that varies by Income into many small *line* graphs in a panel of > > > graphs. I want to omit "No Answer" categories. I want to see how each one > > > of the categories (percentages), "None", " Equity", etc. varies by > > Income. > > > How can I do this? How to organize the data well and how to plot? I > > thought > > > Lattice may be a good package to plot this, but I don't know for sure. I > > > prefer to do this in Base-R if possible, but I am open to ggplot. Any > > ideas > > > will be helpful. > > > > > > Income > > > $10 $25 $40 $75 > $75 No Answer > > > MF 1 2 3 4 5 9 > > > None 1 3.05 2.29 2.24 1.71 1.30 2.83 > > > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 > > > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15 > > > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 > > > Bank AC > > > None 1 46.54 54.01 59.1 62.17 67.67 60.87 > > > Current 2 24.75 24.4 25 24.61 24.02 21.09 > > > Savings 3 25.4 18.7 29 11.48 7.103 13.46 > > > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577 > > > > > > Thanks. > > > -- > > > Anupam. > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- > Anupam. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -------------- next part -------------- A non-text attachment was scrubbed... Name: Income_pcts.png Type: image/png Size: 13289 bytes Desc: not available URL: From du@@@@dr|@n @end|ng |rom un|buc@ro Fri Jun 30 10:33:34 2023 From: du@@@@dr|@n @end|ng |rom un|buc@ro (=?UTF-8?B?QWRyaWFuIER1yJlh?=) Date: Fri, 30 Jun 2023 11:33:34 +0300 Subject: [R] replacing unicode characters In-Reply-To: References: Message-ID: Hello Iris, Thanks for your answer. The thing is not that I want to obtain , but that it gets produced regardless. In the meantime, I have assessed the real culprit is somehow (perhaps) related to the locale or encoding of the terminal process that I use to run R, in that particular MacOS Electron application (it doesn't happen on Windows). In a very simple test, I tried creating a text file from the Electron app embedded R: sink("test.txt") cat("\u00e7") sink() which resulted in: I don't quite understand how this works, my best guess is it matters less how R interprets these characters, but how they are passed through the child process that started R. I'd be grateful for any hint in this direction, if anyone has experience. Best wishes, Adrian On Thu, Jun 29, 2023 at 1:59?AM Iris Simmons wrote: > Hiya! > > > You can do this by specifying sub="c99" instead of "Unicode": > > ```R > x <- "fa\xE7ile" > xx <- iconv(x, "latin1", "UTF-8") > iconv(xx, "UTF-8", "ASCII", "c99") > ``` > > produces: > > ``` > > x <- "fa\xE7ile" > > xx <- iconv(x, "latin1", "UTF-8") > > iconv(xx, "UTF-8", "ASCII", "c99") > [1] "fa\\u00e7ile" > > > ``` > > For future reference, you can find this in section Examples of the > help page ?iconv > I hope this helps! > > On Wed, Jun 28, 2023 at 3:09?PM Adrian Du?a wrote: > > > > Dear list, > > > > Building on the example from ?iconv: > > x <- "fa\xE7ile" > > xx <- iconv(x, "latin1", "UTF-8") # "fa?ile" > > > > and: > > > > iconv(xx, "UTF-8", "ASCII", "Unicode") > > # "faile" > > > > This is the type of result I sometimes get from an R script that I cannot > > reproduce here, because it depends on a terminal process started in a > > compiled Electron (Node.js) application, under MacOS. > > > > I was wondering, is there a standard way, perhaps also using iconv(), to > > convert this type of result to a more manageable unicode representation? > > > > Something like: "fa\u00e7ile" > > > > Or perhaps a clever regexp, for any number of such occurrences in a > string? > > > > Thanks a lot in advance, > > Adrian > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > -- Adrian Dusa University of Bucharest Romanian Social Data Archive Soseaua Panduri nr. 90-92 050663 Bucharest sector 5 Romania https://adriandusa.eu [[alternative HTML version deleted]] From kry|ov@r00t @end|ng |rom gm@||@com Fri Jun 30 13:10:27 2023 From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov) Date: Fri, 30 Jun 2023 14:10:27 +0300 Subject: [R] replacing unicode characters In-Reply-To: References: Message-ID: <20230630141027.3b45a7ab@Tarkus> On Fri, 30 Jun 2023 11:33:34 +0300 Adrian Du?a wrote: > In a very simple test, I tried creating a text file from the Electron > app embedded R: > sink("test.txt") > cat("\u00e7") > sink() > > which resulted in: > > > > I don't quite understand how this works, my best guess is it matters > less how R interprets these characters, but how they are passed > through the child process that started R. Something goes wrong with the locale setting when the R child process is being launched. For example, Rscript -e 'cat("\ue7\n")' # ? but: LC_ALL=C Rscript -e 'cat("\ue7\n")' # When preparing \ue7 for output, R decides that it's not representable in the session encoding. What's the output of sessionInfo() and l10n_info() in the child process? -- Best regards, Ivan From du@@@@dr|@n @end|ng |rom un|buc@ro Fri Jun 30 16:34:37 2023 From: du@@@@dr|@n @end|ng |rom un|buc@ro (Adrian Dusa) Date: Fri, 30 Jun 2023 17:34:37 +0300 Subject: [R] replacing unicode characters In-Reply-To: <20230630141027.3b45a7ab@Tarkus> References: <20230630141027.3b45a7ab@Tarkus> Message-ID: Right on the point, Ivan, that was the issue. The output from l10n_info() was: $MBCS [1] FALSE $`UTF-8` [1] FALSE $`Latin-1` [1] FALSE $codeset [1] "US-ASCII" (and the locale was just "C") I simply needed to write something like: export LC_ALL='en_US.UTF-8' before starting the child process, and everything looks good now. Thanks a lot, much obliged, Adrian On Fri, Jun 30, 2023 at 2:10?PM Ivan Krylov wrote: > On Fri, 30 Jun 2023 11:33:34 +0300 > Adrian Du?a wrote: > > > In a very simple test, I tried creating a text file from the Electron > > app embedded R: > > sink("test.txt") > > cat("\u00e7") > > sink() > > > > which resulted in: > > > > > > > > I don't quite understand how this works, my best guess is it matters > > less how R interprets these characters, but how they are passed > > through the child process that started R. > > Something goes wrong with the locale setting when the R child process > is being launched. For example, > > Rscript -e 'cat("\ue7\n")' > # ? > > but: > LC_ALL=C Rscript -e 'cat("\ue7\n")' > # > > When preparing \ue7 for output, R decides that it's not representable > in the session encoding. What's the output of sessionInfo() and > l10n_info() in the child process? > > -- > Best regards, > Ivan > [[alternative HTML version deleted]]