Re: [R] Getting individual co-ordinate points in k medoids cluster
Hi Nick, If you're asking about the coordinates used in the plot produced by fviz_cluster(), you're looking in the wrong place. The 2D plot isn't anything intrinsic to the clustering. Instead, that plot is of the first two principal components. From the help: "Observations are represented by points in the plot, using principal components if ncol(data) > 2." The easiest way to get the coordinates is probably to use prcomp yourself, as fviz_cluster does. Specifically, it does: pca <- stats::prcomp(data, scale = FALSE, center = FALSE) That's also where the percentage values in the axis labels come from: those are the variance explained by each of the first two PCA axes. Sarah On Tue, Sep 17, 2024 at 8:01 AM Nick Wray wrote: > > Hello I am using k medoids in R to generate sets of clusters for datasets > through time. I can plot the individual clusters OK but what I cannot find > is a way of pulling out the co-ordinates of the individual points in the > cluster diagrams - none of the kmed$... info sets seems to be this. > > Beneath is an example of a k medoid prog using the built in US arrests > dataset - this is not the data I am working with but it illustrates the > issue easily > > library(factoextra) > library(cluster) > set.seed(170924) > df <- USArrests > df <- na.omit(df) > df <- scale(df) > kmed <- pam(df, k = 4) > fviz_cluster(kmed, data = df) > > Thanks for any help or pointers > Nick Wray > > [[alternative HTML version deleted]] > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting .grib to excel file
Hi, While Bert is correct that there are plenty of tools, my preferred approach is to use the terra package to load a grib as a raster stack. >From there, it's straightforward to use all the spatial tools with the data, or to extract it in whatever form and with whatever dimensions you wish. GIven the multidimensional nature of the data, "straightforward" may require some fiddling to get the format and variables you want in the way you want them. Sarah On Tue, Jun 25, 2024 at 4:33 AM javad bayat wrote: > Dear all; > I have downloaded meteorology data from " > > https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=form > " > as .grib format. It has hourly data of a complete year (every hour of every > day of 12 months) and has 6 meteorology parameters. The file has been > attached. > I am trying to convert it to an excel file that puts every parameter in a > separated column. For instance, the first col represents Date, 2nd > represents Temperature and so on. > Is there any way to do it? > I used these codes but did not work: > # install.packages("rNOMADS") > > library(rNOMADS) > > # Read GRIB data > grib_data <- ReadGrib("C:/Users/admin/Downloads/Met.grib") > > # Convert to a data frame > grib_df <- as.data.frame(grib_data) > > # Write the data frame to a CSV file > write.csv(grib_df, file = "output.csv") > > > I would be more than happy if anyone could help me. > Sincerely > > -- > Best Regards > Javad Bayat > M.Sc. Environment Engineering > Alternative Mail: bayat...@yahoo.com > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Sarah Goslee (she/her) http://www.sarahgoslee.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Issues with R's forecast function
.6 > pracma_2.4.4 uroot_2.1-3 > [66] coda_0.19-4.1timeDate_4032.109hardhat_1.3.1 > lava_1.7.3 statmod_1.5.0 > [71] TH.data_1.1-2ipred_0.9-14 xts_0.13.1 > rstan_2.32.6 tensorA_0.36.2.1 > [76] rpart_4.1.21 nnet_7.3-19 tidyselect_1.2.0 > emmeans_1.10.0 compiler_4.3.2 > [81] curl_5.2.0 ahead_0.10.0 htmlTable_2.4.2 > posterior_1.5.0 checkmate_2.3.1 > [86] DEoptimR_1.1-3 fracdiff_1.5-2 quadprog_1.5-8 > tfruns_1.5.1 digest_0.6.34 > [91] minqa_1.2.6 rmarkdown_2.25 htmltools_0.5.7 > pkgconfig_2.0.3 base64enc_0.1-3 > [96] lme4_1.1-35.1lhs_1.1.6fastmap_1.1.1 > rlang_1.1.3 htmlwidgets_1.6.4 > [101] quantmod_0.4.26 farver_2.1.1 jsonlite_1.8.8 > ModelMetrics_1.2.2.2 R.oo_1.26.0 > [106] Formula_1.2-5bayesplot_1.11.1 texreg_1.39.3 > GPfit_1.0-8 munsell_0.5.0 > [111] furrr_0.3.1 stringi_1.8.3pROC_1.18.5 > pkgbuild_1.4.3 plyr_1.8.9 > [116] expint_0.1-8 listenv_0.9.1splines_4.3.2 > hms_1.1.3ranger_0.16.0 > [121] rngtools_1.5.2 reshape2_1.4.4 rstantools_2.4.0 > evaluate_0.23RcppParallel_5.1.7 > [126] laeken_0.5.3 nloptr_2.0.3 tzdb_0.4.0 > future_1.33.1xtable_1.8-4 > [131] class_7.3-22 snow_0.4-4 arm_1.13-1 > cluster_2.1.4timechange_0.2.0 > [136] globals_0.16.2 bridgesampling_1.1-2 > > Cheers, > > Paul > > El lun, 27 may 2024 a las 12:15, Sarah Goslee () > escribió: >> >> Hi Paul, >> >> It looks like you're using the forecast package, right? Have you loaded it? >> >> What is the output of sessionInfo() ? >> >> It looks to me like you either haven't loaded the needed packages, or >> there's some kind of conflict. Your examples don't give me errors when >> I run them, so we need more information. >> >> Sarah >> >> >> >> On Mon, May 27, 2024 at 12:25 PM Paul Bernal wrote: >> > >> > Dear all, >> > >> > I am currently using R 4.3.2 and the data I am working with is the >> > following: >> > >> > ts_ingresos_reservas= ts(ingresos_reservaciones$RESERVACIONES, start = >> > c(1996,11), end = c(2024,4), frequency = 12) >> > >> > structure(c(11421.54, 388965.46, 254774.78, 228066.02, 254330.44, >> > 272561.38, 377802.1, 322810.02, 490996.48, 581998.3, 557009.96, >> > 619568.56, 578893.9, 938765.36, 566374.38, 582678.46, 931035.04, >> > 855661.3, 839760.22, 745521.4, 816424.96, 899616.64, 921462.88, >> > 942825, 1145845.74, 1260554.36, 1003983.5, 855516.22, 1273913.68, >> > 1204626.54, 1034135.18, 904641.14, 1003094.3, 1073084.74, 928515.64, >> > 854864.4, 928927.48, 1076922.34, 1031265.04, 1043755.7, 1238565.12, >> > 1343609.54, 1405817.92, 1243192.86, 1235505.44, 1280514.56, 1314029.08, >> > 1562841.28, 1405662.96, 1315083.12, 1363980.02, 1126195.72, 1542338.98, >> > 1577437.94, 1474855.98, 1287170.56, 1404118.3, 1528979.66, 1286690.34, >> > 1544495.16, 1527018.22, 1462908.72, 1682739.76, 1439027.72, 1531060.44, >> > 1793606.88, 1835054.26, 1616743.96, 1779745.24, 1772628, 1736200.18, >> > 1736792.72, 1835714.4, 2031238.04, 1937816.14, 1942473.52, 2131666.68, >> > 2099279.26, 1939093.78, 2135231.54, 2187614.52, 2150766.28, 2179862.62, >> > 2467330.32, 2421603.34, 2585889.54, 4489381.11, 4915745.55, 5313521.43, >> > 5185438.48, 5346116.46, 4507418.33, 5028489.81, 4931266.16, 5529189.46, >> > 5470279.34, 5354912.01, 5937028.11, 6422819.13, 5989941.72, 6549070.26, >> > 6710738.34, 6745949.78, 6345832.78, 6656868.36, 6836903.51, 6456545.14, >> > 7039815.42, 7288665.89, 7372047.96, 8116822.48, 7318300.42, 8742429.72, >> > 8780764.44, 8984081.22, 8221966.77, 8594896.69, 8319125.91, 8027227.8, >> > 9241082.48, 8765799.78, 9360643.68, 9384937.59, 8237007.99, 9251122.07, >> > 8703017.5, 9004464.9, 8099029.39, 8883214.99, 8360815.05, 8408082.51, >> > 9126756.64, 8610501.05, 9109139.05, 8904803.6, 12766215.9, 14055014.03, >> > 12789865.86, 13251587.21, 13731917.7, 14925330.72, 14295954.4, >> > 13346681.84, 14233732.03, 12743141.34, 13742979.78, 11770238.46, >> > 11655300, 12327000, 10096000, 8712000, 6742500, 7199000, 5459000, >> > 4442000, 7448500, 6322500, 6030500, 5521000, 4752000, 6248500, >> > 5233000, 7440500, 5604500, 6516500, 6001500,
Re: [R] Issues with R's forecast function
_etsmod= ets(ts_ingresos_reservas) > ingresos_reservas_etsfor= forecast(ingresos_reservas_etsmod, level > = c(90,99), h = 151) > > ingresos_reservas_batsmod = bats(ts_ingresos_reservas) > ingresos_reservas_batsfor = forecast(ingresos_reservas_batsmod, level > = c(90,99), h = 151, robust = TRUE) > > ingresos_reservas_tbatsmod = tbats(ts_ingresos_reservas) > ingresos_reservas_tbatsfor = forecast(ingresos_reservas_tbatsmod, > level = c(90,99), h = 151, robust = TRUE) > > ingresos_reservas_nnetarmod = nnetar(ts_ingresos_reservas) > ingresos_reservas_nnetarfor = forecast(ingresos_reservas_nnetarmod, > PI = TRUE, h = 151, robust = TRUE) > > This code used to work, but now, I keep getting the following error: > Error in UseMethod("forecast", object) : > no applicable method for 'forecast' applied to an object of class "ets" > > Error in UseMethod("forecast", object) : > no applicable method for 'forecast' applied to an object of class "nnetar" > > Error in UseMethod("forecast", object) : > no applicable method for 'forecast' applied to an object of class "bats" > > Error in UseMethod("forecast", object) : > no applicable method for 'forecast' applied to an object of class "bats" > > It seems like the forecast function is not working for these models > anymore. Any idea of how to solve this issue? > > Kind regards, > > Paul > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) https://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange behavior in base::as.double
Hi Carl, Not that strange: R thinks you're using scientific notation. Also not a Mac bug. > as.double('123e') [1] 123 > as.double('123e+0') [1] 123 > as.double('123e+1') [1] 1230 > as.double('123e-1') [1] 12.3 Can you explain what you're trying to accomplish? Sarah On Wed, May 1, 2024 at 3:24 PM Carl Witthoft wrote: > > Hello. > I'm running R 4.4.0 on an iMac Venture 13.5.2 . There appears to be a bug > in as.double(). > > Create a string with a numeric digits followed by a single letter a thru f > (as tho' it's base 16). > > for K in (a,b,c,d, and f ) , as.double( '123K') returns NA > but as.double('123e') returns 123 -- or whatever the first digit is. > > Please let me know if there are additional tests I can try . > > > thanks > Carl Witthoft > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Volume of polygon
There's also an excellent discussion of various methods with R code here: https://dewey.dunnington.ca/post/2019/bathymetry-lake-volume-estimation-using-r/ On Wed, Dec 6, 2023 at 8:52 AM Sarah Goslee wrote: > > Hi, > > As already mentioned, this is a great topic for R-sig-geo, where you'd > probably get specialist answers like the lake morphology package > https://cran.r-project.org/web/packages/lakemorpho/index.html which is > explicitly designed for this kind of question. > > Sarah > > On Tue, Dec 5, 2023 at 11:13 PM javad bayat wrote: > > > > Dear all; > > I am trying to calculate the volume of a polygon shapefile according to a > > DEM raster. I have provided some codes at the end of this email.I dont know > > if the codes are correct or not. Following this, I have another question > > too. > > I want to know if the volume of the reservoir rises or doubles, what would > > be the elevation? > > I would be more than happy if anyone could help me. > > Sincerely > > > > " > > library(raster) > > library(terra) > > library(exactextractr) > > library(dplyr) > > library(sf) > > r <- raster("Base.tif") > > p <- shapefile("p.shp") > > r <- crop(r, p) > > r <- mask(r, p) > > x <- exact_extract(r, p, coverage_area = TRUE) > > > > x1 = as.data.frame(x[1]) > > head(x1) > > x1 = na.omit(x1) > > > > x1$Height = max(x1[,1]) - x1[,1] > > > > x1$Vol = x1[,2] * x1[,3] > > > > sum(x1$Vol) > > > > " > > > > -- > > Best Regards > > Javad Bayat > > M.Sc. Environment Engineering > > Alternative Mail: bayat...@yahoo.com > > > > [[alternative HTML version deleted]] > > > > ______ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > -- > Sarah Goslee (she/her) > http://www.sarahgoslee.com -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Volume of polygon
Hi, As already mentioned, this is a great topic for R-sig-geo, where you'd probably get specialist answers like the lake morphology package https://cran.r-project.org/web/packages/lakemorpho/index.html which is explicitly designed for this kind of question. Sarah On Tue, Dec 5, 2023 at 11:13 PM javad bayat wrote: > > Dear all; > I am trying to calculate the volume of a polygon shapefile according to a > DEM raster. I have provided some codes at the end of this email.I dont know > if the codes are correct or not. Following this, I have another question > too. > I want to know if the volume of the reservoir rises or doubles, what would > be the elevation? > I would be more than happy if anyone could help me. > Sincerely > > " > library(raster) > library(terra) > library(exactextractr) > library(dplyr) > library(sf) > r <- raster("Base.tif") > p <- shapefile("p.shp") > r <- crop(r, p) > r <- mask(r, p) > x <- exact_extract(r, p, coverage_area = TRUE) > > x1 = as.data.frame(x[1]) > head(x1) > x1 = na.omit(x1) > > x1$Height = max(x1[,1]) - x1[,1] > > x1$Vol = x1[,2] * x1[,3] > > sum(x1$Vol) > > " > > -- > Best Regards > Javad Bayat > M.Sc. Environment Engineering > Alternative Mail: bayat...@yahoo.com > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Yext in parentheses.
Hi, It isn't at all clear to me what you're trying to do. For one thing, you never actually add more items to cat.ref in the code snippet you give. You do use c() on zx.ref - is that what you mean? But you aren't adding cat.ref to it, you're adding v$cat.ref, and I have no idea what that might contain. Lots of things, apparently. It's possible that something in pred0 is stripping things out of cat.ref, I suppose, since c() alone won't do that. > cat.ref<-"dilemma1(ref.)" > cat.ref <- c(cat.ref, "scigrn1(ref.)") > cat.ref [1] "dilemma1(ref.)" "scigrn1(ref.)" I think we need a reproducible example showing the actual problem, or at least very clear explanation. For instance, what's dput(v$cat.ref) Is it the same as cat.ref, or is that where the alteration happens? Sarah On Thu, Oct 26, 2023 at 12:18 PM Steven Yen wrote: > > Dear All > > My program is long and sorry I do not have a replicable set of codes to > present. But I present a chunk of codes at the end below. Essentially, > > 1. I initialize cat.ref as NUL (see line 1) > > 2. Then, I repeatedly add elements to cat.ref, where each element > include parentheses in double quotations (see line 2). > > I had expected cat.ref to eventually contain the list > > dilemma1(ref),scigrn1(ref),... > > Not so, I end up getting the following (see first column; not in > parentheses, like (ref.)). > > dilemma1.ref.. 22.356 2.619 8.535 0.000 *** scigrn1.ref.. 22.474 2.697 > 8.334 0.000 *** > > Any idea how I might revise lines like the following (first line below): > > dv.group<-c("dilemma2","dilemma3"); cat.ref<-"dilemma1(ref.)" > > etc. Thanks. > >ap0<-zx.ref<-NULL > >dv.group<-c("dilemma2","dilemma3"); cat.ref<-"dilemma1(ref.)" >if(any(dv.group%in%jindex)){ > v<-pred0(dv.group,cat.ref) > ap0<-rbind(ap0,v$ap0); zx.ref<-c(zx.ref,v$cat.ref) >} > >dv.group<-c("scigrn2","scigrn3"); cat.ref<-"scigrn1(ref.)" >if(any(dv.group%in%jindex)){ > v<-pred0(dv.group,cat.ref) > ap0<-rbind(ap0,v$ap0); zx.ref<-c(zx.ref,v$cat.ref) >} > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to Calculate the Mean by Multiple Groups in R
Hi, I think you're misunderstanding which set of variables go on either side of the formula. Is this what you're looking for? > aggregate(OD ~ Time + Target + Conc, data = df, FUN = "mean") Time Target Conc OD 11 BACT1 765. 21 BACT2 745. 31 BACT3 675. > aggregate(ODnorm ~ Time + Target + Conc, data = df, FUN = "mean") Time Target ConcODnorm 11 BACT1 108.3 21 BACT2 88.3 31 BACT3 18.0 Or using a different form, that might be more straightforward to you: > aggregate(df[, c("OD", "ODnorm")], by = df[, c("Time", "Target", "Conc")], > data = df, FUN = "mean") Time Target Conc ODODnorm 11 BACT1 765. 108.3 21 BACT2 745. 88.3 31 BACT3 675. 18.0 Sarah On Tue, Oct 24, 2023 at 8:31 AM Luigi Marongiu wrote: > > Hello, > I have a data frame with different groups (Time, Target, Conc) and > each entry has a triplicate value of the measurements OD and ODnorm. > How can I merge the triplicates into a single mean value? > I tried the following: > ``` > df = data.frame(Time=rep(1, 9), Well=paste("A", 1:9, sep=""), > OD=c(666, 815, 815, 702, 739, 795, 657, 705, 663), > Target=rep("BACT", 9), > Conc=c(1,1,1,2,2,2,3,3,3), > ODnorm=c(9, 158, 158, 45, 82, 138, 0, 48, 6), > stringsAsFactors = FALSE) > aggregate(.~ODnorm, df, mean) > > > aggregate(.~ODnorm, df, mean) > ODnorm Time Well OD Target Conc > 1 0 NA NA NA NA NA > 2 6 NA NA NA NA NA > 3 9 NA NA NA NA NA > 4 45 NA NA NA NA NA > 5 48 NA NA NA NA NA > 6 82 NA NA NA NA NA > 7138 NA NA NA NA NA > 8158 NA NA NA NA NA > > aggregate(cbind(Time, Target, Conc) ~ ODnorm, df, mean) > ODnorm Time Target Conc > 1 0 NA NA NA > 2 6 NA NA NA > 3 9 NA NA NA > 4 45 NA NA NA > 5 48 NA NA NA > 6 82 NA NA NA > 7138 NA NA NA > 8158 NA NA NA > ``` > > Thank you. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] OK, next Q - a sort of factorial on a vector
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: p...@pricom.com.au > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] environments: functions within functions
Very nice, thank you! Sarah On Thu, May 25, 2023 at 8:20 PM Iris Simmons wrote: > > Hi, > > > I think there are two easy ways to fix this. The first is to use a `switch` > to call the intended function, this should not be a problem since there are a > small number of print functions in **mixR** > > ```R > print.mixfitEM <- function (x, digits = getOption("digits"), ...) > { > switch(x$family, > gamma = printgamma (x, digits), > lnorm = printlnorm (x, digits), > normal = printnormal (x, digits), > weibull = printweibull(x, digits), > stop(gettextf("invalid '%s' value", "x$family", domain = "R"))) > invisible(x) > } > environment(print.mixfitEM) <- getNamespace("mixR") > print.mixfitEM <- compiler::cmpfun(print.mixfitEM) > ``` > > This is nice because 'x' is no longer evaluated twice (you could try this > yourself with something like `mixR:::print.mixfitEM(writeLines("testing"))`, > you'll see the output twice, once for `x$family` and a second for evaluating > `match.call()` expression), it follows standard evaluation, and 'x' is > returned invisibly at the end, like most other `print` methods. If you really > wanted to continue using `eval`, you could instead do something like > > ```R > print.mixfitEM <- function (x, digits = getOption("digits"), ...) > { > expr <- quote(printfunction(x, digits)) > expr[[1L]] <- as.symbol(paste0("print", x$family)) > eval(expr) > invisible(x) > } > environment(print.mixfitEM) <- getNamespace("mixR") > print.mixfitEM <- compiler::cmpfun(print.mixfitEM) > ``` > > This also solves the same issues, but it's ugly and slower. > > At least for now, I would copy one of the functions above into the site-wide > startup profile file or your user profile, along with > > ```R > utils::assignInNamespace("print.mixfitEM", print.mixfitEM, "mixR") > ``` > > This does have the unfortunate side effect of loading **mixR** every time an > R session is launched, but you could also put it inside another function like: > > ```R > fix.mixR.print.mixfitEM <- function () > { > print.mixfitEM <- function(x, digits = getOption("digits"), ...) { > switch(x$family, > gamma = printgamma (x, digits), > lnorm = printlnorm (x, digits), > normal = printnormal (x, digits), > weibull = printweibull(x, digits), > stop(gettextf("invalid '%s' value", "x$family", domain = "R"))) > invisible(x) > } > environment(print.mixfitEM) <- getNamespace("mixR") > print.mixfitEM <- compiler::cmpfun(print.mixfitEM) > utils::assignInNamespace("print.mixfitEM", print.mixfitEM, "mixR") > } > ``` > > which you would then call in your scripts before using **mixR**. I hope this > helps! > > On Thu, May 25, 2023 at 10:19 AM Sarah Goslee wrote: >> >> Hi, >> >> I ran into a problem with S3 method dispatch and scoping while trying >> to use functions from the mixR package within my own functions. I know >> enough to find the problem (I think!), but not enough to fix it >> myself. The problem isn't really a package-specific problem, so I'm >> starting here, and will file an issue with the maintainer once I have >> a solution. >> >> Detailed explanation below, but briefly, the S3 methods in this >> package use match.call() and then eval() to select the correct >> internal method. This works fine from the command line, but if the >> method is called from within another function, the use of >> environment() within eval() means that the objects passed to the >> wrapper function are no longer visible within the eval() call. >> >> I have a two-part question: >> A. How do I get around this right now? >> B. What would the correct approach be for the package authors? >> >> library(mixR) >> >> # first example from ?mixfit >> ## fitting the normal mixture models >> set.seed(103) >> x <- rmixnormal(200, c(0.3, 0.7), c(2, 5), c(1, 1)) >> data <- bin(x, seq(-1, 8, 0.25)) >> fit1 <- mixfit(x, ncomp = 2) # raw data >> rm(x, data) >> ### >> >> # simple function >> funworks <- function(x) { >> print(x) >> } >> >> ### >> >> # almost identical simple function >> funfails <- function(thisx) { >> print(thisx) >> } >> >> ### >
Re: [R] environments: functions within functions
Thank you to both Duncan and Ivan for the detailed answers. I'll point the mixR maintainer at this thread in the list archive, because your suggestions were so clear, and I can't explain them as thoroughly. I'll keep using x as the argument name for now. Much appreciated, Sarah On Thu, May 25, 2023 at 10:18 AM Sarah Goslee wrote: > > Hi, > > I ran into a problem with S3 method dispatch and scoping while trying > to use functions from the mixR package within my own functions. I know > enough to find the problem (I think!), but not enough to fix it > myself. The problem isn't really a package-specific problem, so I'm > starting here, and will file an issue with the maintainer once I have > a solution. > > Detailed explanation below, but briefly, the S3 methods in this > package use match.call() and then eval() to select the correct > internal method. This works fine from the command line, but if the > method is called from within another function, the use of > environment() within eval() means that the objects passed to the > wrapper function are no longer visible within the eval() call. > > I have a two-part question: > A. How do I get around this right now? > B. What would the correct approach be for the package authors? > > library(mixR) > > # first example from ?mixfit > ## fitting the normal mixture models > set.seed(103) > x <- rmixnormal(200, c(0.3, 0.7), c(2, 5), c(1, 1)) > data <- bin(x, seq(-1, 8, 0.25)) > fit1 <- mixfit(x, ncomp = 2) # raw data > rm(x, data) > ### > > # simple function > funworks <- function(x) { > print(x) > } > > ### > > # almost identical simple function > funfails <- function(thisx) { > print(thisx) > } > > ### > > funworks(fit1) > funfails(fit1) > > ### > > The explanation as I understand it... > > print called on this object gets passed to print.mixfitEM(), which is: > > > function (x, digits = getOption("digits"), ...) > { > family <- x$family > mc <- match.call() > mc$digits <- digits > fun.name <- paste0("print", family) > mc[[1]] <- as.name(fun.name) > eval(mc, environment()) > } > > > Working through the calls, when eval() is called from within funfails(), mc is > printnormal(x = thisx, digits = 7) > and the calling environment does not contain thisx. > > In funworks(), it's > printnormal(x = x, digits = 7) > > and x is found. > > So, I can get around the problem by naming my argument x, as in > funworks(), but that's unsatisfying. Is there something else I can do > to get my functions to work? > > And what's the correct way to do what print.mixfitEM() is doing, so > that it works regardless? I poked around for a while, but didn't find > a clear (to me!) answer. > > Thanks, > Sarah > > -- > Sarah Goslee (she/her) > http://www.numberwright.com -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] environments: functions within functions
Hi, I ran into a problem with S3 method dispatch and scoping while trying to use functions from the mixR package within my own functions. I know enough to find the problem (I think!), but not enough to fix it myself. The problem isn't really a package-specific problem, so I'm starting here, and will file an issue with the maintainer once I have a solution. Detailed explanation below, but briefly, the S3 methods in this package use match.call() and then eval() to select the correct internal method. This works fine from the command line, but if the method is called from within another function, the use of environment() within eval() means that the objects passed to the wrapper function are no longer visible within the eval() call. I have a two-part question: A. How do I get around this right now? B. What would the correct approach be for the package authors? library(mixR) # first example from ?mixfit ## fitting the normal mixture models set.seed(103) x <- rmixnormal(200, c(0.3, 0.7), c(2, 5), c(1, 1)) data <- bin(x, seq(-1, 8, 0.25)) fit1 <- mixfit(x, ncomp = 2) # raw data rm(x, data) ### # simple function funworks <- function(x) { print(x) } ### # almost identical simple function funfails <- function(thisx) { print(thisx) } ### funworks(fit1) funfails(fit1) ### The explanation as I understand it... print called on this object gets passed to print.mixfitEM(), which is: function (x, digits = getOption("digits"), ...) { family <- x$family mc <- match.call() mc$digits <- digits fun.name <- paste0("print", family) mc[[1]] <- as.name(fun.name) eval(mc, environment()) } Working through the calls, when eval() is called from within funfails(), mc is printnormal(x = thisx, digits = 7) and the calling environment does not contain thisx. In funworks(), it's printnormal(x = x, digits = 7) and x is found. So, I can get around the problem by naming my argument x, as in funworks(), but that's unsatisfying. Is there something else I can do to get my functions to work? And what's the correct way to do what print.mixfitEM() is doing, so that it works regardless? I poked around for a while, but didn't find a clear (to me!) answer. Thanks, Sarah -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error in exists.....
Hi, I can't create the desired object using the code you provided, but if I create it in two steps so that E$L[[i]]$T1A1 does exist, exist() returns TRUE. E <- new.env() E$L <- list() i <- 1 E$L[[i]]$T1A1 <- Sys.time() # returns: Error in `*tmp*`[[i]] : subscript out of bounds E$L[[i]] <- list() E$L[[i]]$T1A1 <- Sys.time() exists("T1A1", where = E$L[[i]]) # returns: [1] TRUE > str(E$L) List of 1 $ :List of 1 ..$ T1A1: POSIXct[1:1], format: "2022-12-27 12:47:26" Sarah On Tue, Dec 27, 2022 at 12:36 PM akshay kulkarni wrote: > > Dear members, > I have the following code: > > E <- new.env() > > E$L <- list() > > i <- 1 > > E$L[[i]]$T1A1 <- Sys.time() > > exists("T1A1", where = E$L[[i]]) > Error in list2env(list(1, T1A1 = 1672161002.38743), NULL, ) : > attempt to use zero-length variable name > > I want the output of the exists() function to be TRUE. In any case: > > > E$L[[1]]$T1A1 > [1] "2022-12-27 22:40:02 IST" > > Please help me solve this conundrum > > Thanking you, > Yours sincerely, > AKSHAY M KULKARNI > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question concerning side effects of treating invalid factor levels
J>PP","PP>OBJ": 2 2 2 2 1 1 NA > > $ RT: chr "11478" "15819" "8305" "8852" ... > > > > You see that RT has changed from _num_ to _chr_ as a side effect of adding > > the invalid factor level as NA. I would appreciate understanding what the > > purpose of the type coercion is. > > > > Thanks in advance > > > > > > Tibor > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu%7C6ee1a1f50c14442beef508da9a301bde%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637991828670135028%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=sNDYEJKhjSu%2FtrTIwZx5yVemKgDheQYXLrcQqJ2mOgo%3D&reserved=0 > > PLEASE do read the posting guide > > https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C6ee1a1f50c14442beef508da9a301bde%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637991828670135028%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=AP%2B4fa5pvbGr3IfwdiQvjXwkOdY90CIWIWWWmpIHH7w%3D&reserved=0 > > and provide commented, minimal, self-contained, reproducible code. > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] extracting numeric values returned when using the by function to run the acf function
Hi, You can either write a small function that returns just the values you want, or use a convenience function within by, as in: > by(RecallSmall[1:4,"value"],RecallSmall[1:4,"ID"], FUN=function(x){acf(x, > na.action=na.pass,plot=FALSE)$acf}) RecallSmall[1:4, "ID"]: 1 , , 1 [,1] [1,] 1.00 [2,] 0.15 [3,] -0.50 [4,] -0.15 But I suspect that you would get something more like what you want by splitting the data on ID, and then using sapply: > RecallSmall <- data.frame(ID=c(1,1,1,1,2,2,2,2), value=c(6,5,3,4,6,5,3,4)) > result <- split(RecallSmall[["value"]], RecallSmall[["ID"]]) > result <- sapply(result, FUN=function(x){acf(x, > na.action=na.pass,plot=FALSE)$acf}) > result 1 2 [1,] 1.00 1.00 [2,] 0.15 0.15 [3,] -0.50 -0.50 [4,] -0.15 -0.15 Sarah On Tue, May 10, 2022 at 1:29 PM Sorkin, John wrote: > > I am using the by function to run the acf function. Each run of the by > function returns more information than I want. All I want is the four values > that acf returns, which using the data below would be > 1.00 0.15 -0.50 -0.15 > How can I isolate these four values from the output returned by the by > function. > > Sample code: > > RecallSmall <- data.frame(ID=c(1,1,1,1),value=c(6,5,3,4)) > cat("Here are the data\n") > RecallSmall > cat("All I want is autocorrerlations, e.g. 1.00 0.15 -0.50 -0.15 \n ") > # attempting to subset does not work at all > by(RecallSmall[1:4,"value"],RecallSmall[1:4,"ID"],acf,na.action=na.pass,plot=FALSE)$acf > # this gives me more than I want, not just the numeric results. > by(RecallSmall[1:4,"value"],RecallSmall[1:4,"ID"],acf,na.action=na.pass,plot=FALSE) > > # For your reference, this is what the acf function returns > acf(RecallSmall[1:4,"value"],na.action=na.pass,plot=FALSE) > # For your reference, this is what the acf function returns when the output > is subset > acf(RecallSmall[1:4,"value"],na.action=na.pass,plot=FALSE)Thank you, John > > Thank you, > John > > > > > > > > > > [[alternative HTML version deleted]] > > ______ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Pixel Image Reshaping using R
Hi Paul, I may be missing something, but you can transform a vector to a matrix of any desired size by using matrix(). For more nuanced processing of images, you might look into one of the many image processing packages in R, or even the raster package (or the newer terra). Sarah On Thu, Feb 24, 2022 at 11:00 AM Paul Bernal wrote: > > Dear friends, > > I apologize if the description is a bit long, but I think that I need to > be as specific as possible so that you guys can help. > > I wil share with you a file (train.csv), which contains gray-scale images > of hand-drawn digits, from zero through 9. > > Each image is 28 pixels in height and 28 pixels in width, for a total of > 784 pixels in total. Each pixel has a single pixel-value associated with > it, indicating the lightness or darkness of that pixel, with higher numbers > meaning darker. This pixel-value is an integer between 0 and 255, > inclusive. The training data set, (train.csv), has 785 columns. The first > column, called ”label”, is the digit that was drawn by the user. The rest > of the columns contain the pixel-values of the associated image. Each pixel > column in the training set has a name like pixel x, where x is an integer > between 0 and 783, inclusive. To locate this pixel on the image, suppose > that we have decomposed x as x = i ∗ 28 + j, where i and j are integers > between 0 and 27, inclusive. Then pixel x is located on row i and column j > of a 28 x 28 matrix, (indexing by zero). or example, pixel 31 indicates the > pixel that is in the fourth column from the left, and the second row from > the top, as in the ascii-diagram below. > > This data is set up in a csv file which will require the reshaping of the > data to be 28 × 28 matrix representing images. There are 42000 images in > the train.csv file. For this problem it is only necessary to process > approximately 100 images, 10 each of the numbers from 0 through 9. The goal > is to learn how to generate features from images using transforms and first > order statistics. > > So I need to develop an algorithm to store the data in a data structure > such that the data is reshaped into a matrix of size 28 x 28 and then I > have to plot the developed matrix for indices 1, 2, 4, 7, 8, 9, 11. 12, 17 > and 22. > > I have been looking for information about how to process this with R, but > have not found anything yet. > > The dataset is attached in this e-mail for your reference. > > Any help and/or guidance will be greatly appreciated. > > Best regards, > Paul > train.csv > <https://drive.google.com/file/d/1WPb7bKHJ8BlzuLKJogMOAOqb-VCoXDMp/view?usp=drive_web> > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with lm Giving Wrong Results
) > > #~~~ > # This works > n <- 1000# OK <= 4095 > Z <- qnorm(ppoints(n)) > > k <- sort(rlnorm(n,log(2131),log(1.61)) / rlnorm(n,log(355),log(1.61))) > > quantile(k,probs=c(0.025,0.5,0.975)) > summary(k) > > fit <- lm(log(k) ~ Z) > summary(fit) > > gm <- exp(coef(fit)[1]) > gsd <- exp(coef(fit)[2]) > gm > gsd > > plot(Z,k,log="y",xlim=c(-4,4),ylim=c(0.1,100)) > lines(Z,gm*gsd^Z,col="red") > > #~~~ > #this does not > n <- 1# fails >= 4096 = 2^12 > Z <- qnorm(ppoints(n)) > > k <- sort(rlnorm(n,log(2131),log(1.61)) / rlnorm(n,log(355),log(1.61))) > > quantile(k,probs=c(0.025,0.5,0.975)) > summary(k) > > fit <- lm(log(k) ~ Z) > summary(fit) > > gm <- exp(coef(fit)[1]) > gsd <- exp(coef(fit)[2]) > gm > gsd > > plot(Z,k,log="y",xlim=c(-4,4),ylim=c(0.1,100)) > lines(Z,gm*gsd^Z,col="red") > > > #~~~ > > sessionInfo() #for two Linux machines having problem > R version 4.1.2 (2021-11-01) > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Linux Mint 20.2 > > Matrix products: default > BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libmkl_rt.so > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 > [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=en_US.UTF-8 LC_NAME=C > LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] compiler_4.1.2 Matrix_1.3-4tools_4.1.2 expm_0.999-6 > grid_4.1.2 lattice_0.20-45 > > #~~ > > sessionInfo() # for a third Linux machine not having the problem > R version 4.1.1 (2021-08-10) > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Linux Mint 19.3 > > Matrix products: default > BLAS/LAPACK: > /opt/intel/compilers_and_libraries_2020.0.166/linux/mkl/lib/intel64_lin/libmkl_rt.so > > 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=C LC_ADDRESS=C > [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] compiler_4.1.1 tools_4.1.1 > > > > Thomas R. LaBone > PhD student > Department of Epidemiology and Biostatistics > Arnold School of Public Health > University of South Carolina > Columbia, South Carolina USA > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To > UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is 'temp' a reserved/key word in R?
Andrew is right - it's a typo. More broadly, there's no restriction of that sort on the contents of your data frame - reserved words can't be used for object names. The R Language Definition is the best resource for identifying those words. It would help if you provided the package for read_csv, since not everyone uses tidyverse by default, although it isn't necessary for this question. Sarah On Tue, Nov 30, 2021 at 9:45 AM Andrew Simmons wrote: > > It seems like the headers are misnamed, that should be a comma between > sampdate and param, not a period > > On Tue, Nov 30, 2021, 09:35 Rich Shepard wrote: > > > A short data file: > > site_nbr,sampdate.param,quant,unit > > 31731,2005-07-12,temp,19.7,oC > > 31731,2007-03-28,temp,9,oC > > 31731,2007-06-27,temp,18.3,oC > > 31731,2007-09-26,temp,15.8,oC > > 31731,2008-01-17,temp,5.4,oC > > 31731,2008-03-27,temp,7.4,oC > > 31731,2010-04-05,temp,8.1,oC > > 31731,2010-07-26,temp,20.5,oC > > 31731,2010-10-18,temp,12.5,oC > > 31731,2011-01-10,temp,5.4,oC > > > > The import function: > > sal_temp <- read_csv("../data/geochem/sal-temp.csv", col_names = TRUE, > > col_types = list ( > > site_nbr = col_character(), > > sampdate = col_date(), > > param = col_character(), > > quant = col_double(), > > unit = col_character() > > )) > > > > The response from R: > > source('../scripts/test.r') > > Warning message: > > The following named parsers don't match the column names: sampdate, param > > > > I searched the web to see if 'temp' is causing the problem and didn't find > > an answer; my search term might have been flawed. > > > > If that string is a problem please suggest an alternative. > > > > TIA, > > > > Rich > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use ifelse without invoking warnings
Bert's approach is much less risky! On Thu, Oct 7, 2021 at 1:37 PM Bert Gunter wrote: > > ?suppressWarnings > > > p <- .05 > > k <- c(-1.2,-0.5, 1.5, 10.4) > > n <- 10 > > > > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), > ifelse (k < -1, 0, 1) ) > Warning message: > In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced > > > > suppressWarnings(ans <- ifelse (k >= -1 & k <= n, > pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k < -1, 0, 1) )) > ## no warnings > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Thu, Oct 7, 2021 at 10:21 AM Ravi Varadhan via R-help < > r-help@r-project.org> wrote: > > > Hi, > > I would like to execute the following vectorized calculation: > > > > ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), > > ifelse (k < -1, 0, 1) ) > > > > For example: > > > > > > > k <- c(-1.2,-0.5, 1.5, 10.4) > > > n <- 10 > > > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), > > ifelse (k < -1, 0, 1) ) > > Warning message: > > In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced > > > print(ans) > > [1] 0.0 0.006821826 0.254991551 1.0 > > > > The answer is correct. However, I would like to eliminate the annoying > > warnings. Is there a better way to do this? > > > > Thank you, > > Ravi > > > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use ifelse without invoking warnings
If you are positive the warnings don't matter for your application, you can disable them: see ?options for details of warn. But that can be dangerous, so be careful! Sarah On Thu, Oct 7, 2021 at 1:21 PM Ravi Varadhan via R-help wrote: > > Hi, > I would like to execute the following vectorized calculation: > > ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), > ifelse (k < -1, 0, 1) ) > > For example: > > > > k <- c(-1.2,-0.5, 1.5, 10.4) > > n <- 10 > > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse > > (k < -1, 0, 1) ) > Warning message: > In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced > > print(ans) > [1] 0.0 0.006821826 0.254991551 1.0 > > The answer is correct. However, I would like to eliminate the annoying > warnings. Is there a better way to do this? > > Thank you, > Ravi > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to combine logic test on vectors in R?
Hi, The OR operator you used is working as expected: || starts from the left and evaluates only enough of the options to determine the results. The first test is TRUE, so the result is TRUE. It sounds like you might actually want an AND operator, & or &&, which will only return TRUE if all elements are TRUE, More on logical operators: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Logic.html Sarah On Thu, Sep 30, 2021 at 9:07 AM Luigi Marongiu wrote: > > Hello, > I have two data frames, each with three rows: > ``` > df_a <- data.frame(a = letters[1:3], b = LETTERS[1:3], q = c("", "", ""), > stringsAsFactors = FALSE) > df_b <- data.frame(a = letters[4:6], b = LETTERS[4:6], q = c("", "", "1.5"), > stringsAsFactors = FALSE) > ``` > I need to test whether the dataframe has been selected and if there is > a value in the q column. I combined in the following test: > ``` > if (nrow(df_a) == 0 || unique(df_a$q) == "") { > print("empty") > } > if (nrow(df_b) == 0 || unique(df_b$q) == "") { > print("empty") > } > ``` > The test for df_a worked as expected: > ``` > > nrow(df_a) == 0 > [1] FALSE > > unique(df_a$q) == "" > [1] TRUE > > (nrow(df_a) == 0 || unique(df_a$q) == "") > [1] TRUE > > if (nrow(df_a) == 0 || unique(df_a$q) == "") { > + print("empty") > + } > [1] "empty" > ``` > but the one for df_b did not: > ``` > > nrow(df_b) == 0 > [1] FALSE > > unique(df_b$q) == "" > [1] TRUE FALSE > > (nrow(df_b) == 0 || unique(df_b$q) == "") > [1] TRUE > > unique(df_b$q) > [1] """1.5" > ``` > I say that it did not work because unique(df_b$q) IS NOT "", hence > `(nrow(df_b) == 0 || unique(df_b$q) == "")` should be FALSE, instead R > evaluated the first element of unique(df_b$q) == "", which is TRUE. > How can I properly implement a logic test on vectors? > Thank you > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] extraction of last observation date from many observations in each row/column
Hi Marna, This very short function deletes everything before the last , if there is a comma. Some of your entries have comma-space and some just have comma, so it deletes the optional space as well. lastdate <- function(x) { sub("^.*, *", "", x) } data.frame(apply(daT, 2, lastdate)) Sarah On Fri, Apr 2, 2021 at 10:15 AM Marna Wagley wrote: > > Dear R-Users, > I have a dataset containing more than two observation dates in some of the > columns and sites but I wanted to extract only the last date of the > observation. > Is there any easiest way to get that last observation in each column/row? > > Here is the example data: > daT<-structure(list(ID = c("M3", "M5", "M1"), Site1 = > c("12/20/2018,12/28/2018", > "12/17/18", ""), Site2 = c("", "", "1/19/2019"), Site3 = c("9/25/2019", "", > "1/10/2019, 1/11/2019, 1/17/2019")), class = "data.frame", row.names = > c(NA,-3L)) > > #I wanted to make the table like this: > output<-structure(list(ID = c("M3", "M5", "M1"), Site1 = c("12/28/2018", > "12/7/2018", ""), Site2 = c("", "", "1/19/2019"), Site3 = c("9/25/2019", > "", "1/17/2019")), class = "data.frame", row.names = c(NA, -3L)) > > Thank you for your help. > Sincerely, > MW > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FD package_dbFD error
istant > Department of Biology > Faculty of Science > University of Zagreb > Rooseveltov trg 6, 1 Zagreb, Croatia > > ______ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] About fviz_famd_ind()
The way to start is looking at the help for that function, which includes: ... Arguments to be passed to the function fviz() so you may have more low-level control through those arguments. If fviz() itself doesn't do what you want, it also allows you to pass additional arguments to its lower-level functions. If you go down far enough, you should be able to control everything. Sarah On Sun, Mar 21, 2021 at 1:12 PM Mahmood Naderan-Tahan wrote: > > Hi > > I use fviz_famd_ind() from factoextra and I would like to know > > 1) How can I decrease the font size? > > 2) How to increase max.overlaps? > > > ind <- get_famd_ind(res.famd) > fviz_famd_ind(res.famd, col.ind = "cos2", > gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"), > repel = TRUE) > > > Regards, > Mahmood > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Colorizing contribution of variables
Hi, I am going to assume that you are using factoextra, and are working the example from the function in question, but it would be useful for you to explicitly state that when you're asking a question about a particular package and function. When you choose the argument "contrib" the colors are based on the strength of the relationship overall (the length of the arrow), not the contribution of any individual direction. See here http://www.sthda.com/english/wiki/factoextra-r-package-easy-multivariate-data-analyses-and-elegant-visualization and the various other sources of documentation for the packages. Sarah On Sun, Mar 21, 2021 at 1:32 PM Mahmood Naderan-Tahan wrote: > > Hi > > I use the following function to plot the variables with their contributions. > > > fviz_famd_var(res.famd, "quanti.var", col.var = "contrib", > gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"), > repel = TRUE) > > > The result can be seen at https://i.stack.imgur.com/Kbq1j.png > > When I use "quanti.var$contrib" I see multiple dimensions and the question is > which dimension is used for colorizing the contributions? For example, is the > blue color of V2 related to low contribution on Dim1 or Dim2? > > > Regards, > Mahmood > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to plot dates
Hi, It doesn't have anything to do with having a Mac - you have POSIX. It's because something is wrong with your data import. Looking at the head() output you provided, it looks like your data file does NOT have a header, because there's no datetime column, and the column name is actually X2021.03.11.10.00.0 So you specified a nonexistent column, and got a zero-length answer. With correct specification, the as.POSIXct function works as expected on Mac: myDat <- read.table(text = "datetime 2021-03-11 10:00:00 2021-03-11 14:17:00 2021-03-12 05:16:46 2021-03-12 09:17:02 2021-03-12 13:31:43 2021-03-12 22:00:32 2021-03-13 09:21:43", sep = ",", header = TRUE) myDat$datetime <- as.POSIXct(myDat$datetime, tz = "", format = "%Y-%M-%d %H:%M:%OS") Sarah On Tue, Mar 16, 2021 at 9:26 AM Gregory Coats via R-help wrote: > > My computer is an Apple MacBook. I do not have POSIX. > The command > myDat$datetime <- as.POSIXct(myDat$datetime, tz = "", format = "%Y-%M-%d > %H:%M:%OS") > yields the error > Error in `$<-.data.frame`(`*tmp*`, datetime, value = numeric(0)) : > replacement has 0 rows, data has 13 > Please advise, How to proceed? > Greg Coats > > > library(ggplot2) > > # Read a txt file on the Desktop, named "myDat.txt" > > myDat <- read.delim("~/Desktop/myDat.txt", header = TRUE, sep = ",") > > head(myDat) > X2021.03.11.10.00.00 > 1 2021-03-11 14:17:00 > 2 2021-03-12 05:16:46 > 3 2021-03-12 09:17:02 > 4 2021-03-12 13:31:43 > 5 2021-03-12 22:00:32 > 6 2021-03-13 09:21:43 > > # convert data to date time object > > myDat$datetime <- as.POSIXct(myDat$datetime, tz = "", format = "%Y-%M-%d > > %H:%M:%OS") > Error in `$<-.data.frame`(`*tmp*`, datetime, value = numeric(0)) : > replacement has 0 rows, data has 13 > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Col names in a data frame
Hi, data.frame() checks names by default to ensure that column names are legal, but there's an argument to change that. >From ?data.frame() check.names: logical. If ‘TRUE’ then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names and are not duplicated. If necessary they are adjusted (by ‘make.names’) so that they are. Sarah On Thu, Jan 21, 2021 at 3:59 PM Bernard McGarvey wrote: > > Here is an example piece of code to illustrate an issue: > > rm(list=ls()) # Clear Workspace > # > Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3) > Colnames1 <- c("(A)","(B)","(C)") > colnames(Data1) <- Colnames1 > print(Data1) > DataFrame1 <- data.frame(Data1) > print(DataFrame1) > colnames(DataFrame1) <- Colnames1 > print(DataFrame1) > > The results I get are: > > (A)(B)(C) > [1,] 0.4739417 1.3138868 0.4262165 > [2,] -2.1288083 1.0333770 1.1543404 > [3,] -0.3401786 -0.7023236 -0.2336880 > X.A. X.B. X.C. > 1 0.4739417 1.3138868 0.4262165 > 2 -2.1288083 1.0333770 1.1543404 > 3 -0.3401786 -0.7023236 -0.2336880 > (A)(B)(C) > 1 0.4739417 1.3138868 0.4262165 > 2 -2.1288083 1.0333770 1.1543404 > 3 -0.3401786 -0.7023236 -0.2336880 > > so that when I make the matrix with headings the parentheses are replaced by > periods but I can add them after creating the data frame and the column > headings are correct. > > Any ideas on why this occurs? > > Thanks > > > Bernard McGarvey > Director, Fort Myers Beach Lions Foundation, Inc. > Retired (Lilly Engineering Fellow). > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with changing date format in R
Hi, If the date format is determined by observer, you could for instance use subset to divide it into two data frames, fix the dates and recombine, or use ifelse to use the correct format based on observer. This is a basic data manipulation task, and there are lots of ways approach it. Sarah On Wed, Jan 20, 2021 at 1:32 PM krissievdh wrote: > > Hi, > > I have a big database where one-third of the data is in a different date > format than the rest. I'll add an example table to show you. > > | plot | observer | date| > | 1 | K | 31012020 | > | 2 | K | 07022020 | > | 3 | B | 01282020 | > | 4 | B | 01292020 | > So I have two different date formats; the first is in d m y while the other > one is in m d y. > > My question is how can I change all the date data into the same format? > Preferably in dd/mm/yy. (31-01-2020) > I know I could use: > d$date <- as.Date(d$date, format = "%d%m%Y") > d$date <- as.Date(d$date, format = "%m%d%Y") > > but I can only do one and then it doesn't work. Is there a way i can use > the first line for the date of observer K and the other line for the date > of observer B? > > Thanks > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finance & R
CRAN Task Views, available thru your favorite mirror, are very useful for this sort of question. There's a Finance task view, and others of possible interest. R being Open Source, you can also implement the LatestGreatest yourself, or hire a programmer, if the available tools aren't to your taste. Sarah On Wed, Dec 23, 2020 at 12:58 PM Ben van den Anker via R-help wrote: > > > > Hello everyone, > Could anyonre recommend some good resources for finance applications in R? I > find the packages quantmod, TTR and PerformanceAnalytics a bit outdated. > There must be something more recent on the market. Any suggestions will be > much appreciated! > Cheers, > Ben van den Anker > > > > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FInd packages in need of Update (like RStudio)
Does update.packages() meet your needs? Sarah On Wed, Dec 23, 2020 at 9:39 AM Dr Eberhard W Lisse wrote: > > Hi, > > does anyone know how one would look which packages require an update > (like the Tools -> Update Packages) but can do it from R (ie Rscript) or > any other way from the command line (on the MAc) > > I would like to build this into my update script which currently does > brew, cpan and pip3 :-)-O > > greetings, el > -- > Dr. Eberhard W. Lisse \ / Obstetrician & Gynaecologist > e...@lisse.na / * | Telephone: +264 81 124 6733 (cell) > PO Box 8421 Bachbrecht \ / If this email is signed with GPG/PGP > 10007, Namibia ;/ Sect 20 of Act No. 4 of 2019 may apply > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to correct my error message
Hi, a is of length 60. b is of length 60. z is of length 57. What do you expect to have happen when you create y_model ? What happens to those other 3 observations? Sarah On Tue, Oct 27, 2020 at 3:07 PM varin sacha via R-help wrote: > > Dear R-experts, > > Here below my R code. The warning message is not a problem to me but there is > an error message more problematic. I understand the error message but I don't > know if it is possible to correct the error and if yes, how to correct it. > > Many thanks. > > > n <- 60 > b <- runif(n, 0, 5) > a <- runif(n, 0, 5) > z <- rnorm(n*0.95,2,3) + rnorm(n*0.05,2,9) > y_model <- 0.1 * b - 0.5 * z - a + 10 > y_obs <- y_model +c( rnorm(n*0.95, 0, 0.1), rnorm(n*0.05, 0, 0.5) ) > df<-data.frame(b,a,z,y_obs) > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with strings
Your desired output seems to be the same as your desired input in your example, and your data frames have different column names. Nonetheless, this bit of code will find rows with "alcohol" in column 3, and for those rows replace the contents of column 4 with column 3. That may not be exactly what you're after, but should get you started. lapply(mylist, function(x){ x[grepl("alcohol", x[, 3]), 4] <- x[grepl("alcohol", x[, 3]), 3] x }) Sarah On Tue, Sep 29, 2020 at 4:24 PM André Luis Neves wrote: > > Dear all, > > I have had difficulties copying the word "alcohol" in the "vehicle" column > to replace the string in the column "accident_type". It is a huge list but > I have prepared a workable and simple example below and the desired > output. I am sure you guys can give me some advice on how to deal with > this. > > sapply( all_files, function(x) dim(x)) > [,1] [,2] [,3] [,4] > [1,] 89563 69295 67446 39709 > [2,]33333333 > > > > ###Simple List > > A= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "byke", "alcohol", > "motocycle"), c("alcohol", "cell_phone", "some_string", "fog")) > colnames(A) <- c("id", "km","vehicle","accident_cause") > A > > > B= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car", > "motocycle"), c("alcohol", "some_string", "rain", "fog")) > colnames(B) <- c("id", "km", "vehicle", "accident_type") > B > > > C= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car", > "alcohol"), c("alcohol", "some_string", "rain", "some_string")) > colnames(C) <- c("id", "km", "vehicle", "accident_type") > C > > mylist <- list(A=A,B=B,C=C) > mylist > > > ###Desired output > > A= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "byke", "alcohol", > "motocycle"), c("alcohol", "cell_phone", "alcohol", "fog")) > colnames(A) <- c("id", "km","vehicle","accident_cause") > A > > > B= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car", > "motocycle"), c("alcohol", "alcohol", "rain", "fog")) > colnames(B) <- c("id", "km", "vehicle", "accident_type") > B > > > C= data.frame(c("1", "2", "3", "4"),c(4:7),c("car", "alcohol", "car", > "alcohol"), c("alcohol", "alcohol", "rain", "alcohol")) > colnames(C) <- c("id", "km", "vehicle", "accident_type") > C > > mylist <- list(A=A,B=B,C=C) > mylist > > > ##Thank you very much, > > -- > Andre > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] date
Hi, Nice reproducible example. rev(df$date2) isn't doing what you think it's doing - try looking at it by itself. Some digging into ?order will get you what you are after: df[order(df$ID, df$date2, decreasing=c(FALSE, TRUE), method="radix"),] > df[order(df$ID, df$date2, decreasing=c(FALSE, TRUE), method="radix"),] ID date2 2 A1 2005-01-27 1 A1 2004-09-17 3 A1 2003-05-07 4 A2 2017-05-21 5 A2 2016-09-12 6 A3 2013-01-25 7 A4 2019-09-27 Sarah On Mon, Sep 21, 2020 at 2:41 PM Val wrote: > > Hi All, > > I am trying to sort dates within a group. My sample data is > > df <-read.table(text="ID date > A1 09/17/04 > A1 01/27/05 > A1 05/07/03 > A2 05/21/17 > A2 09/12/16 > A3 01/25/13 > A4 09/27/19",header=TRUE,stringsAsFactors=F) > df$date2 = as.Date(strptime(df$date,format="%m/%d/%y")) > df$date =NULL > > I want to sort date2 from recent to oldest. within the ID group and > I used this, > df <- df[order(df$ID, rev((df$date2))),]. It did not work and teh > output is shown below. > > ID date2 > 2 A1 2005-01-27 > 3 A1 2003-05-07 > 1 A1 2004-09-17 > 5 A2 2016-09-12 > 4 A2 2017-05-21 > 6 A3 2013-01-25 > 7 A4 2019-09-27 > What am I missing? > Thank you. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] .grb2 Files
GDAL supports GRIB2 so it should be easy using rgdal and raster packages. Sarah On Wed, Sep 2, 2020 at 8:32 PM Philip wrote: > > Any advise about how to get NOAA .grb2 files into R? > > Thanks. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to extract information from .Rdata format
Hi Ana, You are making this far too complicated. load("paired_example.Rdata") ls() str(rawdata) str(treatment) str(patient) load() puts all of them into your current environment. If you assign the result of load() to something, in your example a, that object contains the names of the objects, but the objects themselves are in your workspace. You should probably try a basic R tutorial; it will help you with this kind of thing. Sarah On Fri, Jul 31, 2020 at 10:18 PM Ana Marija wrote: > > Hello, > > I have this file: > > a=load("paired_example.Rdata") > > a > [1] "rawdata" "treatment" "patient" > > I can extract "rawdata" with: > dat<-local(get(load("paired_example.Rdata"))) > > Can you please advise how would I extract in data frame "treatment" > and "patient"? > > Thanks > Ana > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looping thorugh dataframe
Hi, Your sample code suggests that you don't yet understand how R works, and might benefit from a tutorial or two. However, your verbal description of what you want is quite straightforward. Here's a R-style way to count the number of times each company appears, and to get the mean value of Turnover for each company: All_companies <- read.table(text = "COMPANY_NUMBER COMPANY_NAMEYEAR_END_DATE Turnover 22705 AA 30/09/1042 22705 AA 30/09/09406000 113560 BB 30/06/19474000 192761 CC 31/01/19796000 192761 CC 31/01/18909000 192761 CC 31/01/17788000 5625107 DD 30/06/193254002 5625107 DD 30/06/181840436", header=TRUE) table(All_companies$COMPANY_NAME) AA BB CC DD 2 1 3 2 aggregate(Turnover ~ COMPANY_NAME, data = All_companies, FUN = mean) COMPANY_NAME Turnover 1 AA 413000 2 BB 474000 3 CC 831000 4 DD 2547219 On Wed, Jul 22, 2020 at 7:36 PM e-mail ma015k3113 via R-help wrote: > > Bert, thanks for responding to my email. I do realise that newbie's like my > can expect curt answers but not to worry. I am definitely learning 'R' and > what I posted are also statements from R. The statements run perfectly well > but don't do what I want them to do. My mistake I have posted sample data. > Here is the data: > > COMPANY_NUMBER COMPANY_NAMEYEAR_END_DATE Turnover > 22705 AA 30/09/10420,000 > 22705 AA 30/09/09406,000 > 113560 BB 30/06/19474,000 > 192761 CC 31/01/19796,000 > 192761 CC 31/01/18909,000 > 192761 CC 31/01/17788,000 > 5625107 DD 30/06/193,254,002 > 5625107 DD 30/06/181,840,436 > > All_companies$count <-0 > while All_companies$COMPANY_NAME == All_companies$COMPANY_NAME + 1 > + {All_companies$count=All_companies$count+1} > > I want to find out many times each company has appeared in the dataframe and > the average of the turnover for the years. Like company AA appears twice and > average turnover is 413,000. > > 'All_companies' is the name of the dataframe. > > In the end apologies for not being more clear the first time around and of > course many thanks for your help in advance. > > Kind regards > > > Ahson > > On 21 July 2020 at 18:41 Bert Gunter wrote: > > What language are you programming in? -- it certainly isn't R. > > I suggest that you stop what you're doing and go through an R tutorial or two > before proceeding. This list cannot serve as a substitute for doing such > homework (is this homework, btw? -- that's off topic here) nor can we provide > such tutorials. > > I'm pretty sure the answer is quite simple, though it's a bit unclear as you > did not provide a reprex (see the posting guide linked below for how to post > here). However, I see no purpose in my blurting it out when you do not seem > aware of even the most basic R constructs -- e.g. see ?while. Of course, > others may disagree and provide you what you seek. > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Estimate garch model by GMM
Hi, The very useful search engine rseek.org lists a lot of packages, functions, and tutorials for Garch modeling in R. Perhaps some of those meet your requirements. Sarah On Wed, Jul 8, 2020 at 3:02 PM Osama Mostafa wrote: > > Dear Professors > > > > Hope this e-mail find you well. I am currently doing my Masters in > statistics and econometrics and my thesis is about the Properties and > Estimation of Garch Models and their applications I need to know if it is > to possible to estimate Garch model by Generalized Method of Moments > <http://cameron.econ.ucdavis.edu/mmabook/transparencies/ct06_gmm.pdf> > > (GMM) method using R . and If it possible I need a example of it by coding > > > > My sincere regards, > > ossama > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] algorithms that cluster time series data
Hi, Unsupervised classification (clustering) is a huge field. There's an entire task view devoted to it, where you can see many of the large array of R packages that perform some sort of clustering. https://cran.r-project.org/web/views/Cluster.html Since that is an overwhelming list, you may be best served by looking at how others in your field have approached similar problems, and then look for R packages that perform the relevant analyses. Sarah On Mon, Jul 6, 2020 at 1:11 PM Bogdan Tanasa wrote: > > Dear all, > > please may I ask for a suggestion regarding the algorithms to cluster the > expression data in single cells (scRNA-seq) at multiple time points : > > we do have expression data for 30 000 genes in 10 datasets that have been > collected at multiple time points, > > and i was wondering if you could please recommend *any algorithms/R > packages that could help with the clustering of the gene expression at > different time points.* thanks a lot, and all the best, > > -- bogdan > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] argument "x" is missing in minpack.lm
You create objects A, B, and K, but then use A, B, and X in the call to nls.lm(). I have no idea if nls.lm is the right tool for your job, but I do know that you need to use the same names. Sarah On Tue, Jun 30, 2020 at 6:01 AM Luigi Marongiu wrote: > Hello, > I am trying to optimize a function with the function nls.lm from the > package minpack.lm. But I can't get it right: > ``` > A = 3261 > B = 10 > K = c(8, 24, 39, 63, 89, 115, 153, 196, 242, 287, 344, > 408, 473, > 546, 619, 705, 794, 891, 999, 1096, 1242, 1363, 1506, 1648, > 1753, > 1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646, 2698, 2727, 2771, > 2818, > 2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080, 3102, 3119, 3141, > 3152, > 3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239, 3246, 3252, 3261) > O = nls.lm(list(a=A, b=B, x=X), holling, >lower=NULL, upper=NULL, jac = NULL) > > Error in fn(par, ...) : argument "x" is missing, with no default > ``` > What am I missing? > Is nls.lm the right function for functions that are not linear? > Thank you > -- > Best regards, > Luigi > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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.sarahgoslee.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with sqldf
WIthout knowing anything about your research domain, take a look at what your sql looks like: "select * from r where V1 like markerinfo$flank1[1] " You are asking to match literally "markerinfo$flank1[1]" and not the R object referred to. Try something more like, paste("select * from r where V1 like", markerinfo$flank1[1]) Sarah On Sun, Jun 28, 2020 at 4:35 PM Yuan Chun Ding wrote: > > Hi R Users, > > I tried to use sql in R; test1 works well, > library(sqldf) > test1 <- sqldf("select * from r where V1 like > '%GCCATGTCAGCACACTACC%TGAAACCTTTAACTATTT%'") > test2 <- sqldf("select * from r where V1 like markerinfo$flank1[1] ") > > but I want to store the search content in a markerinfo file as shown below > > markerinfo$flank1[1] > [1] "%GCCATGTCAGCACACTACC%TGAAACCTTTAACTATTT%" > > However, test2 does not work well. > How to make test2 work? > Thank you, > > Ding > > > -- -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Obtaining p values from t-test run with a by function
Where you have result[1]$p.value result[2]$p.value You need result[[1]]$p.value result[[2]]$p.value to get the first component of the list. Sarah On Fri, Jun 12, 2020 at 5:35 PM Sorkin, John wrote: > > Colleagues, > I am trying to retrieve the p values produced by a Student's t-test run using > a by function, but can not do so. I can easily get the p value when I run s > Student's t-test without a by function. What is the secret to obtaining > results returned from a function run within a by function. > > An annotated repeatable example (including data) can be found below. > Thank you, > John > > > # Test data > mydata <- structure(list(Group = structure(c(2L, 1L, 2L, 2L, 1L, 2L, 1L, >2L, 2L, 1L, 2L, 1L, 2L), .Label = c("EPA", "P"), class = "factor"), >WtBaseline = c(76.6, 73.8, 77.6, 91.7, 110.3, 121.7, 82.1, >82.8, 119, 88.4, 75.7, 71.4, 72.1)), class = "data.frame", > row.names = c(NA,-13L)) > > cat("This is what mydata looks like\n") > mydata > > result <- by(mydata$WtBaseline,mydata$Group,t.test) > cat("Student's t-test run using by command\n") > cat("Result has results for both groups, EPA and P\n") > result > > cat("I can isolate the collective results for group EPA\n") > result[1] > cat("I can isolate the collective results for group P\n") > result[2] > > cat("I cant get the p-values for the gruops") > result[1]$p.value > result[2]$p.value > > cat("When run without by function, one can get the p value\n") > xxx <- t.test(WtBaseline~Group,data=mydata) > cat("t-test run without by fundtion\n") > xxx > cat("p value isolated from t-test run without by function\n") > xxx$p.value > > > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and > Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automating package updates after major version change
If you don't mind, I'm curious what didn't work - I would like to be able to update the document accordingly. When you used .libPaths() what did it tell you? Did you edit that result to be for the previous version, and swap that into the list.files() command? I thought about automating it, but I can't be sure what previous version you're upgrading from. I suspect you tried to run the code by copy and paste, and not by putting in your own path, but if so then I'd like to improve the directions. Sarah On Thu, May 14, 2020 at 2:19 PM Rich Shepard wrote: > > On Thu, 14 May 2020, Sarah Goslee wrote: > > > Note that install.packages requires "character vector of the names of > > packages whose current versions should be downloaded from the > > repositories" as stated in the help file. > > Sarah, > > Ah, yes. I missed that. > > > If you aren't going to do it the way I did, then you need to read your > > text file into R and create that character vector there. > > I tried to translate your MacOS R commands to my linux system but failed in > my attempts. > > I'll create a one-line list of packages, demarked as strings, and read that > into R as a vector. > > Thanks, > > Rich > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automating package updates after major version change
Hi Rich, Note that install.packages requires "character vector of the names of packages whose current versions should be downloaded from the repositories" as stated in the help file. If you aren't going to do it the way I did, then you need to read your text file into R and create that character vector there. Sarah On Thu, May 14, 2020 at 1:06 PM Rich Shepard wrote: > > On Sun, 26 Apr 2020, Sarah Goslee wrote: > > > Not so coincidentally, I just worked thru this for myself. > > http://numberwright.com/2020/04/clean-and-new/ > > Sarah, > > This isn't working for me on Slackware-14.2/x86_64. My R library is in > /usr/lib64/R/library/ and I copied the contents to a text file, one package > per line. > > Using the filename, packagelist, as an argument to install.packages() fails: > > install.packages(packagelist) > Error in install.packages(packagelist) : object 'packagelist' not found > > Adding quotes didn't help. > > Creating a script, newversionupdate.R, containing the line, > install.packages(packagelist) > > and sourcing it also failed. > > What might I be doing incorrectly? > > Regards, > > Rich > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the 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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convex hulls after nMDS or PCoA
Hi, I use a modified version of dbscan::hullplot() but https://rseek.org turns up a bunch of possibilities. Sarah On Tue, May 12, 2020 at 2:11 AM Fernando Archuby wrote: > > Dear all. I need to build convex hulls around groups of points of an > ordination (nMDS or PCoA). The groups were independently established with > cluster analysis. I have learnt to plot convex hulls but would need to > create every of the 21 groups independently. Do you know how could I just > add the hulls to the ordination plot in an easier way? > Thank you very much, > Fernando. > > -- -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automating package updates after major version change
Not so coincidentally, I just worked thru this for myself. I did want to rebuild and reinstall everything, but as automatically as possible, although in a way that let me see what happened and what went wrong. http://numberwright.com/2020/04/clean-and-new/ There are several things to consider: CRAN packages (easy), GitHub packages (less easy), and random other packages (require manual intervention). I'm sure there are other possible workflows. Sarah On Sun, Apr 26, 2020 at 12:00 PM Rich Shepard wrote: > > After upgrading from -3.6.2 to -4.0.0 I ran 'update.packages()' and spent > time rebuilding dependencies, too. Is there a script or method that > automates package updates after a major version change in R? > > My web searches on this topic found tips for only regular package updates > without rebuilding multiple dependencies. > > TIA, > > Rich > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] incidence_fit model for simulation
According to this handy vignette, the object contains the predicted values in $pred https://cran.r-project.org/web/packages/incidence/vignettes/overview.html early.fit <- fit(i.7[1:20]) early.fit #> #> #> $model: regression of log-incidence over time #> #> $info: list containing the following items: #> $r (daily growth rate): #> [1] 0.03175771 #> #> $r.conf (confidence interval): #> 2.5 % 97.5 % #> [1,] 0.02596229 0.03755314 #> #> $doubling (doubling time in days): #> [1] 21.8261 #> #> $doubling.conf (confidence interval): #> 2.5 % 97.5 % #> [1,] 18.45777 26.69823 #> #> $pred: data.frame of incidence predictions (20 rows, 5 columns) Sarah On Fri, Apr 24, 2020 at 11:52 AM wrote: > > Hello > > How can I make a prediction with object type incidence_fit. > incidence_fit object is returned by the function fit in library(incidence). > > Best regard > maicel > > > > > > > > -- > Este mensaje le ha llegado mediante el servicio de correo electronico que > ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema > Nacional de Salud. La persona que envia este correo asume el compromiso de > usar el servicio a tales fines y cumplir con las regulaciones establecidas > > Infomed: http://www.sld.cu/ > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with loop in folders
I suspect much if not all of your trouble would be eliminated by using file.path() instead of paste0(). https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/file.path (Also check your file name - you probably want a . between name and csv, so using paste(name, "csv", sep = ".") would create a more usual file name. It's always a good idea to work thru your loop by hand once, and look at all the intermediate steps. Often that quickly shows you where you went wrong. Sarah On Fri, Apr 24, 2020 at 10:08 AM Shubhasmita Sahani wrote: > > Hi Everyone, > I am trying to loop through the folders in the major working directory. > Read the dbf file into the data frame then save the data frame as CSV file > in another folder. > For this, I have written this code, But not able to figure out where it is > going wrong. Any ideas will be of great support. > > > setwd(choose.dir()) > csvpath= "C:/plan/Learning/dummydata/csv/" > a<-list.dirs() > inpath<-"C:/workplan/Q2/Project1" > > for (folder in list.dirs()[-1]) { > >path<-setwd(paste0("inpath",folder)) >dbf<-list.files(path, pattern = "*ward.dbf") >df <- read.dbf(dbf) >dbfname<-basename(dbf) >name<-file_path_sans_ext(dbfname) # get the name of the file like > agra_ward >write.csv( df, file = paste0("csvpath",name,"csv")) >print(path) > > } > > > > > > -- > Thanks & Regards, > Shubhasmita Sahani > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Shape / Colour Configuration
Without an actual question, it's hard to know what you want. But take a look at hullplot in the dbscan package. Sarah On Thu, Mar 5, 2020 at 3:54 PM Amber Kobes wrote: > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Isolating Distinct Dates between two data frames
Look at the all arguments to merge() - you can keep the non-matching dates, and look for NA values in the data. Sarah On Sun, Mar 1, 2020 at 4:12 PM Ogbos Okike wrote: > > Dear Friends, > I have two data frame of the form: > 1997-11-2219 -2.54910135429339 > 1997-11- -2.66865640466636 > 1997-11-2305 -2.60761691358946 > 1997-12-1104 -2.5323738405159 > 1997-12-1106 -2.6020470080341 > 1998-05-0204 -4.49745020062937 > 1998-05-0209 -4.9462725263541 > 1998-05-0213 -4.60533021405541 > 1998-05-0218 -4.24415210827579 > 1998-05-0220 -4.04368079911755 > 1998-05-0222 -4.05320945184028 > 1998-05-0302 -4.97226664313875 > 1998-05-0307 -3.59108791877756 > 1998-05-0310 -4.06038057061717 > 1998-05-0313 -4.25967313751507 > 1998-05-0316 -3.51896561964782 > 1998-05-0318 -3.43849389406503 > 1998-05-0321 -2.85778623531446 > 1998-05-0323 -2.75731441597261 > 1998-05-0401 -2.85684255921844 > 1998-05-0403 -2.69637066510405 > 1998-05-0408 -4.47519076670884 > 1998-05-0411 -4.2644827160855 > 1998-05-0414 -4.20377458198688 > 1998-05-0417 -4.27306636458818 > 1998-05-0420 -4.05235806406442 > 1998-05-0500 -4.19141353436269 > 1998-05-0506 -4.23999646421515 > 1998-05-0510 -3.95905156765632 > 1998-05-0512 -3.63857906459363 > > and > 1997-11-2221 -2.04916867404692 > 1997-11-2303 -1.7285761175751 > 1998-04-3010 -1.51968127380408 > 1998-04-3016 -1.51845077174125 > 1998-05-0101 -1.91660416876407 > 1998-05-0104 -2.11598840871961 > 1998-05-0107 -1.99537253619755 > 1998-05-0109 -1.81496189214167 > 1998-05-0112 -1.7343458326657 > 1998-05-0114 -1.77393506418581 > 1998-05-0121 -1.57249698394961 > 1998-05-0204 -3.64105829839415 > 1998-05-0207 -3.5504415342881 > 1998-05-0209 -3.71003029685917 > 1998-05-0213 -3.31920767504605 > 1998-05-0219 -3.98797337595274 > 1998-05-0300 -3.17694445869443 > 1998-05-0304 -3.09612110658432 > 1998-05-0306 -3.29570935794719 > 1998-05-0308 -3.24529756101203 > 1998-05-0310 -3.20488571584633 > 1998-05-0312 -3.16447382251761 > 1998-05-0314 -2.86406188109331 > 1998-05-0319 -2.5430318175571 > 1998-05-0321 -2.87261970832946 > 1998-05-0400 -2.55200145489882 > 1998-05-0407 -3.27055844665711 > 1998-05-0409 -3.24014605168738 > 1998-05-0412 -3.29952737040137 > 1998-05-0414 -3.44911485708791 > > Some dates are common among the two. > > I use few lines of code to select the common dates: > setwd("./") > list1<-read.table("THUL1",col.names=c("V1","V2")) > list2<-read.table("INVK1",col.names=c("V1","V2")) > B<-merge(list1,list2, by ="V1") > > Now, I wish to do something differently. I want to identify the dates that > are in THUL1 but are not in INVK1 or vise versa, that is to identify > uncommon dates among the two lists. > > Could you please assist me to achieve it. > > Thank you. > Best regards > Ogbos > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Text search
Hi, > dat$new[grep("Tall", dat$char)] <- "Tall" > dat$new[grep("Short", dat$char)] <- "Short" > dat obs Year charnew 1 1 2001 Tall156 Tall 2 2 2002 12565Tall Tall 3 3 2003 all54 4 4 2004 Short Short 5 5 2005 54all 6 6 2006 7Short12 Short Assuming that no entries contain both Tall and Short. Sarah On Sat, Jan 25, 2020 at 6:23 PM Ashta wrote: > > Hi all, > From one of the columns of the data frame I want to search and > extract a text that contains Tall or Short and create new column > that should contain these texts in a corresponding row. > My example data and the desired output are shown below > > dat<-read.table(text="obs Year char > 1 2001 Tall156 > 2 2002 12565Tall > 3 2003 all54 > 4 2004 Short > 5 2005 54all > 6 2006 7Short12 ",header=TRUE,stringsAsFactors=F) > dat$new <- " " > > Desired out put > obs Year charnew >1 2001 Tall156 Tall >2 2002 12565TallTall >3 2003 all54 >5 2004 Short Short >6 2005 Shall54 >7 2006 7Short12 Short > > How do I get my desired output? > Thank you. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] table and unique seems to behave differently
Back to the table part of the question, but using Duncan's example. > x <- c(3.4, 3.4 + 1e-15) > unique(x) [1] 3.4 3.4 > table(x) x 3.4 2 The question was, why are these different. table() only works on factors, so it converts the numeric vector to a factor before tabulation. factor() tries to do something sensible, and implicitly rounds the numeric data. > factor(x) [1] 3.4 3.4 Levels: 3.4 Whether you think that is actually sensible or not is up to you, but if it isn't then you shouldn't use table. That table uses factors is documented in ?table. A quick read of ?factor didn't find any explicit discussion, other than the acknowledgement that factor() is lossy in: To transform a factor ‘f’ to approximately its original numeric values, ‘as.numeric(levels(f))[f]’ is recommended and slightly more efficient than ‘as.numeric(as.character(f))’. You can't even get table() to do what you want by being explicit: > table(factor(x, levels = unique(x))) Error in `levels<-`(`*tmp*`, value = as.character(levels)) : factor level [2] is duplicated Sarah On Tue, Dec 10, 2019 at 9:18 AM Alain Guillet wrote: > > Hi, > > I have a vector (see below the dput) and I use unique on it to get unique > values. If I then sort the result of the vector obtained by unique, I see > some elements that look like identical. I suspect it could be a matter of > rounded values but table gives a different result: unlike unique output which > contains "3.4 3.4", table has only one cell for 3.4. > > Can anybody know why I get results that look like incoherent between the two > functions? > > > Best regards, > Alain Guillet > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] pairs.panels ()
Hi, nameless querent, It's important to tell us where you got your function from. In this case, I'm assuming that you are using pairs.panels() from the psych package. Looking at the help for that function, I see, in the arguments section: … other options for pairs Which means that if you don't see a configuration option you want directly, you should look at the help for pairs(). I admit, that if you don't already know that cex controls font size, the help for pairs that says, cex.labels, font.labels: graphics parameters for the text panel. might not enlighten you, but if I understand your question, cex.labels is what you're looking for. ?par gives (possibly) more insight into controlling base graphics. Sarah On Tue, Nov 19, 2019 at 8:47 AM Medic wrote: > > Point me, please, the parameter for changing the font size for the > variable name in pairs.panels () > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] clusplot() and fviz_cluster() functions
The orientation of a principal components axis is entirely arbitrary, and can vary with implementation. It doesn't matter at all. Your code was hugely mangled by posting in HTML - see below. Sarah On Mon, Nov 4, 2019 at 12:33 PM Marco Besozzi wrote: > > Can't understand why with clusplot() and fviz_cluster() functions I obtain > two x-axis mirror graphs. That's the code... > > > *mydata <- USArrests* > > > > > > > > > > > > > > *z <- scale(mydata)## clustering MacQueen (k-means )#fit <- kmeans(z, 4, > algorithm = c("MacQueen"), nstart=50)#library(cluster)windows()clusplot(z, > fit$cluster, labels=3, lines=0, cex=0.6, col.txt="black", > col.p="black")#library(factoextra)windows()fviz_cluster(fit, data=z)#* > > Thanks if someone has a suggestion! > > --- > Marco Besozzi, MD > --- > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] my question is how to read pvcm file
What software creates a pvcm file? Is it binary or text? Where did it come from, and what do you expect to get out of it? Your question is too broad for us to be able to help you. When I google pvcm, I find some stuff about vocal cords, and also your Stack Overflow question, which was also closed as too broad and not clear enough. Sarah On Fri, Oct 4, 2019 at 11:04 AM Jui-Kun Chiang via R-help wrote: > > Dear Sir, >I got a pvcm file. > My question is how to read it by R. > Gratefully > > Jui-Kun Chiang > > [[alternative HTML version deleted]] > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help
You can use the vector of integer cluster numbers with silhouette() from the cluster package. https://www.rdocumentation.org/packages/cluster/versions/2.1.0/topics/silhouette But note that silhouette as an assessment metric makes roughly the same assumptions that k-means does about the data structure, and may not return useful results with other clustering methods. Sarah On Mon, Sep 9, 2019 at 12:01 PM Nicola Fiedler wrote: > > Hi together, > > I’m new using R and have a question concerning the Silhouette coefficient. > I’ve clustered very easy objects with Affinity Propagation. > My data just has one numeric attribute. > > apres <- apcluster(negDistMat(r=2), data, details=TRUE) > show(apres) > > > > This worked very well. To compare with other algorithms I want to know the > Silhouette coefficient. > The function I use for the other algorithms doesn’t work for AP (clvalid or > fviz_nbclust). > So my question is, how I can get the Silhouette coefficient for the > clustering with AP? > > Thank you very much in advance for your help. > -- Sarah Goslee (she/her) http://www.numberwrigtht.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] New Work Based on R
Hi R folks, After following this thread, I got curious, and tried to do a Web of Science search to see how many citations of R there are. It's a *mess*. Even limiting it to "R Core Team" as first author, there are so many variations in citation that WoS eventually gave up and told me that I couldn't add any more. Google Scholar gives "Cited by 134011 - All 118 versions." I think trying to create a repository might also be a mess! But it's clear from this attempt that it's harder than it should be to consistently and clearly cite R, even with the handy citation() function, or there wouldn't be such a mess in WoS. Perhaps it's time to create a DOI for R itself, to help standardize the mess. (If there is a DOI, it doesn't show up in citation().) Versioning would be a slight pain, but according to Zenodo at least, they maintain a DOI for each version, and a master DOI. Also, of course, make sure your students and colleagues cite R and the R packages they use! The authors should be properly credited, and it makes it possible for interested people to see where and how the software is used. And if you want to support R financially, there are worse things to do than donate to the R Foundation. https://www.r-project.org/foundation/ Sarah --- Sarah Goslee http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SVM - calculating values problem
You could download the package code from CRAN and look yourself at what the predict function is doing. Sarah On Wed, Aug 28, 2019 at 6:35 AM PELE Benoît (Acoss) wrote: > Hello everybody, > > That is the first time that I am working on a SVM modeling and I would > like to calculate by myself the result values from the SVM for each line of > my database (named x_appr_svm). > > First I tested a linear SVM model using the e1071 package and to calculate > the individual results by myself I did the next things : > Retrieving the model coefficients : coef_svm<-t(svm$coefs) %*% > x_appr_svm[svm$index,] > Calculating the values for each line : p2<-x_appr_svm %*% t(coef_svm) - > svm$rho > Using the predict function to compare : p1<-attr(predict(object=svm, > newdata=x_appr_svm, decision.values=T), "decision.values") > --> p1 and p2 are the same. > > Next I tested a polynomial SVM model using the same package and the same > method knowing that the model parameters are : > degree=2, gamma=0.02, coef0=0.01 > The calculation of the individual values becomes (I guess) : > p2<-(0.02*x_appr_svm %*% t(coef_svm)+0.01)^2-svm$rho > --> p1 and p2 are really different! > > Despite of my searching, I do not understand why or where is the problem > in my second p2 formula. Do you see the mistake? > > Thank you for your help and have a good day, Benoit (France). > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Sarah Goslee (she/her) http://www.sarahgoslee.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] File corrupted in R/magic number
Summoning my telepathy, I suspect that you tried to use load() to get your CSV file into R, instead of read.csv() Here's the first link that came up when I searched for "read csv file into R" http://rprogramming.net/read-csv-in-r/ On Tue, Aug 27, 2019 at 2:00 PM pusuluri madhu wrote: > > Please help me to get rid out of this situation. While loading the csv file > error msg like > Error: bad restore file manager (file may be corrupted)-- no data loaded. > In addition warning message: file "S_D.csv" has magic number GeneN. Use of > save versions more than 2 is deprecated. > > Please kindly suggest > > -- > > *Madhu Pusuluri, Ph D* > *Visiting Scientist.* > *Genomics & Trait discovery- Genetic Gains* > > *International Crops Research Institute for the Semi-Arid Tropics (ICRISAT)* > > *Patancheru, Hyderabad, Telangana 502324, INDIA.* > > *E-mail: **m.pusul...@cgiar.org **; > madhupusul...@gmail.com > <https://outlook.office.com/owa/madhupusul...@gmail.com>* > > *Tel: +91 9912241982.* > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Code that works when run as straight code, but that fails when run as a function
Since this isn't reproducible, my first guess would be that alldata, which is required for your model, is not visible within the environment of the function. Or something similar: that kind of problem is almost always a scoping issue. Sarah On Fri, Aug 23, 2019 at 3:46 PM Sorkin, John wrote: > > I have code that works perfectly when run as in-line code, but that fails > when the code is put into a function with the following message: > Error in contest1D.lmerModLmerTest(model, ll, rhs = rhs, ddf = ddf, confint = > confint, : > length(L) == length(model@beta) is not TRUE > > Why does moving the code to a function lead to an error? What can I do to > avoid the error? > Thank you, > John > > In-line code: > fit2aCort <- > lmer(SBP~age+jFStage+AHIgt5+jFStage*AHIgt5+(1|patid),data=alldata) > > c1 <-c(1, 5.99, 1, 0, 0, 1, 0 ) > c2 <-c(1, 5.99, 0, 1, 0, 0, 1 ) > > model <- fit2aCort > s1a <- contest(model,L=c1,joint=FALSE) > s1as1E <- s1a$Estimate > > s2a <- contest(model,L=c2,joint=FALSE) > s2E <- s2a$Estimate > > Time <- c(1,2) > SBP <- c(s1E,s2E) > plot(Time,SBP) > title("Predicted Sys SBP, age 5.99 yr (SS 524 obs with BP 190mmHg removed)") > plotCI(Time,SBP,uiw=1.96*c(s1a$"Std. Error",s2a$"Std. Error")) > > > Code put into a function that fails: > plotit <- function(c1,c2,model) > { > s1a <- contest(model,L=c1,joint=FALSE) > s1as1E <- s1a$Estimate > > s2a <- contest(model,L=c2,joint=FALSE) > s2E <- s2a$Estimate > > Time <- c(1,2) > SBP <- c(s1E,s2E) > plot(Time,SBP) > title("Predicted Sys SBP, age 5.99 yr (SS 524 obs with BP 190mmHg removed)") > plotCI(Time,SBP,uiw=1.96*c(s1a$"Std. Error",s2a$"Std. Error")) > } > > fit2aCort <- > lmer(SBP~age+jFStage+AHIgt5+jFStage*AHIgt5+(1|patid),data=alldata) > > c1 <-c(1, 5.99, 1, 0, 0, 1, 0 ) > c2 <-c(1, 5.99, 0, 1, 0, 0, 1 ) > plotit(c1,c2,fit2aCort) > > [[alternative HTML version deleted]] > > __________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ski.mack test in R
Hi Sophie, It's good form to reply to the list, not directly to me - I'm not able to help people individually. It's also good form to put the necessary info directly into your email, rather than expecting people to open attachments (which the mailing list might not even allow, depending on format). However, your problem is very simple: You need to load a package before using functions from it. Ski.Mack() is not found because you first need to do library(Skillings.Mack) to make it available to your R session. (Assuming you've installed the package; if not install.packages("Skillings.Mack") will do that for you. I strongly, strongly suggest that you read one of the good introductions to R out there, possibly even the one that comes with R, and is also available here: https://cran.r-project.org/doc/manuals/r-release/R-intro.pdf That you've had this problem shows that you don't understand the very basics of how to use R, so you should familiarize yourself with it first. Best, Sarah On Fri, Aug 23, 2019 at 6:24 AM Sophie Bleke wrote: > > Dear Sarah, > > Thank you for you kind and quick response. > > I attach the PDF in which I found the ski.mack instructions. This file is > available online. > I also attach some toy data, on which I am trying to perform the ski.mack > test. > Please also find attached a txt. file in which you can find the output of > str(a) and error message of ski.mack(a) etc. > > I would be very grateful to hear back from you or the list. > > With all my best, > Sophie > > Am Di., 20. Aug. 2019 um 19:18 Uhr schrieb Sarah Goslee > : >> >> Hi Sophie, >> >> We don't have enough information to help you. >> >> You DON'T need to type in the data for your test - that's how the >> package authors are creating a reproducible example for you. >> >> But you do need to have your data in the correct format, and we have >> no idea what your a looks like. >> >> >> a <- read.table(file.choose(), header=T) # good >> # attach(a) # don't do this >> a<-as.matrix(a) >> >> library(Skillings.Mack) # you forgot to tell us where you got the >> function you're using >> >> a needs to be "Either a numeric vector of data values, or a data >> matrix. If a matrix is used, columns and rows are correspondent to >> blocks and treatments (groups), respectively." >> >> Since your a is a matrix, then it should be the latter. Is that what you >> have? >> >> You say that >> >> Ski.Mack(a) >> >> "doesn't work." That isn't enough for us to help. What error message >> do you get? We need specifics about what "doesn't work" means. >> >> We also need a reproducible example, possibly with toy data like the >> package authors used >> [.https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example] >> The output of >> >> str(a) >> >> would also be very helpful. >> >> Sarah >> >> On Tue, Aug 20, 2019 at 12:02 PM Sophie Bleke >> wrote: >> > >> > Dear R-Help List, >> > >> > For part of my data, which I analyse with Friedman.test, there is data >> > missing, which is a normal result of the experimental setup. If I am >> > correct, I need to use the Ski.Mack test in R for it. >> > >> > Normally, I read my data in for Friedman or post hoc Wilcoxon like below: >> > >> > a <- read.table(file.choose(), header=T) >> > >> > attach(a) >> > a<-as.matrix(a) >> > >> > friedman.test(a) >> > >> > I tried to replace the friedman line with your ski.mack command, but it is >> > not getting me where I need to get. >> > >> > Ski.Mack(a, simulate.p.value = TRUE, B = 1000) >> > >> > or >> > >> > Ski.Mack(a) >> > >> > Both don't work. >> > >> > Is there as simple command way, as above, to read out the ski.mack test >> > from my txt file, without manually typing all the data points as rows and >> > colums in the R console, which is recommended in the ski.mack author's >> > online PDF? It's a lot of data and manually inputting rows and colums and >> > data points won't be doable in this case. >> > >> > I would be very grateful to hear of an elegant short solution, similar to >> > the friedman command / read-in lines above. >> > >> > Sophie >> > >> >> >> -- >> Sarah Goslee (she/her) >> http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cannot load vegan and vcd, "object vI not found"
Hi, You misunderstood the suggestion, which was to run update.packages() to update all packages, not just vegan (which doesn't need updated because you just reinstalled it). To make your own life easier, I'd run it as: update.packages(ask=FALSE, checkBuilt = TRUE) You could also try reinstalling the packages that vegan requires, which seems to be where the error actually is. (lattice, perhaps, but I'd reinstall Sarah On Tue, Aug 20, 2019 at 6:27 PM Camilo Bernardo Garcia Ramirez wrote: > > Hi again: First at all, thanks for your answer. My problem is still there. > Here the session. I did remove and (re)install vegan and then called for > update but no effect in the error. I included the sessionInfo() at the end. > Camilo > > > remove.packages("vegan") > Removing package from ‘C:/Users/Camilo/Documents/R/win-library/3.6’ > (as ‘lib’ is unspecified) > > install.packages("vegan", dependencies=TRUE) > Installing package into ‘C:/Users/Camilo/Documents/R/win-library/3.6’ > (as ‘lib’ is unspecified) > --- Please select a CRAN mirror for use in this session --- > probando la URL ' > https://cran.wu.ac.at/bin/windows/contrib/3.6/vegan_2.5-5.zip' > Content type 'application/zip' length 3862370 bytes (3.7 MB) > downloaded 3.7 MB > > package ‘vegan’ successfully unpacked and MD5 sums checked > > The downloaded binary packages are in > C:\Users\Camilo\AppData\Local\Temp\Rtmpu0yOZa\downloaded_packages > > update.packages("vegan") > > library(vegan) > Loading required package: permute > Loading required package: lattice > Error: package or namespace load failed for ‘vegan’ in loadNamespace(j <- > i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): > objeto 'vI' no encontrado > > > sessionInfo() > R version 3.6.1 (2019-07-05) > Platform: x86_64-w64-mingw32/x64 (64-bit) > Running under: Windows 10 x64 (build 17134) > > Matrix products: default > > locale: > [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 > [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C > [5] LC_TIME=Spanish_Spain.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] lattice_0.20-38 permute_0.9-5 > > loaded via a namespace (and not attached): > [1] compiler_3.6.1 parallel_3.6.1 tools_3.6.1grid_3.6.1 > > > > El mar., 20 ago. 2019 a las 5:31, Martin Maechler (< > maech...@stat.math.ethz.ch>) escribió: > > > > Jeff Newmiller > > > on Mon, 19 Aug 2019 17:38:19 -0700 writes: > > > > > Try closing all instances of R except for one and then run the > > update.packages() function. If that doesn't work then post the output of > > sessionInfo(). > > > > I also strongly suspect that some of the packages concerned were > > not correctly installed. > > > > > On August 19, 2019 5:11:11 AM PDT, Camilo Bernardo Garcia Ramirez < > > cbgarc...@unal.edu.co> wrote: > > >> Hi: Could you help me with the following issue?: > > >> > > >> I downloaded the packages vegan and vcd with R3.6.1. When I try to > > load > > >> them I got this error messages: > > >> > > >> > library(vegan) > > >> Loading required package: permute > > >> Loading required package: lattice > > >> Error: package or namespace load failed for ‘vegan’ in > > loadNamespace(j > > >> <- > > >> i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): > > >> objeto 'vI' no encontrado (translation: object vI not found - my R > > is > > >> in > > >> Spanish) > > > > The error message above comes from base R's function > > loadNamespace() [which calls itself recursively, when importing > > from other packages]. > > > > I think the error message is not really useful, and indeed I think > > should *not* happen at this time: 'vI' is not defined here, > > because earlier the 'pkgInfo' result was not really valid. > > > > So I think you may have touched on a "buglet" in R in the sense > > that for such semi-validly / invalidly installed packages, you > > should get a better error message. > > > > Martin Maechler > > ETH Zurich and R Core team. > > > > > > >>> library(vcd) > > >> Loading required package: grid > > >> Error: package or namespace load failed for ‘vcd’ in > > loadNamespace(j <- > > >> i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): > > >> objeto 'vI' no encontrado (translation: object vI not found - my R > > is > > >> in > > >> Spanish) > > >> > > >> Sofar no one knows what that means. I am not an R expert! Could you > > >> help > > >> me?. > > >> Regards, > > >> Camilo B. Garcia > > > > > -- __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ski.mack test in R
Hi Sophie, We don't have enough information to help you. You DON'T need to type in the data for your test - that's how the package authors are creating a reproducible example for you. But you do need to have your data in the correct format, and we have no idea what your a looks like. a <- read.table(file.choose(), header=T) # good # attach(a) # don't do this a<-as.matrix(a) library(Skillings.Mack) # you forgot to tell us where you got the function you're using a needs to be "Either a numeric vector of data values, or a data matrix. If a matrix is used, columns and rows are correspondent to blocks and treatments (groups), respectively." Since your a is a matrix, then it should be the latter. Is that what you have? You say that Ski.Mack(a) "doesn't work." That isn't enough for us to help. What error message do you get? We need specifics about what "doesn't work" means. We also need a reproducible example, possibly with toy data like the package authors used [.https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example] The output of str(a) would also be very helpful. Sarah On Tue, Aug 20, 2019 at 12:02 PM Sophie Bleke wrote: > > Dear R-Help List, > > For part of my data, which I analyse with Friedman.test, there is data > missing, which is a normal result of the experimental setup. If I am > correct, I need to use the Ski.Mack test in R for it. > > Normally, I read my data in for Friedman or post hoc Wilcoxon like below: > > a <- read.table(file.choose(), header=T) > > attach(a) > a<-as.matrix(a) > > friedman.test(a) > > I tried to replace the friedman line with your ski.mack command, but it is > not getting me where I need to get. > > Ski.Mack(a, simulate.p.value = TRUE, B = 1000) > > or > > Ski.Mack(a) > > Both don't work. > > Is there as simple command way, as above, to read out the ski.mack test > from my txt file, without manually typing all the data points as rows and > colums in the R console, which is recommended in the ski.mack author's > online PDF? It's a lot of data and manually inputting rows and colums and > data points won't be doable in this case. > > I would be very grateful to hear of an elegant short solution, similar to > the friedman command / read-in lines above. > > Sophie > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reading in csv files, some of which have column names and some of which don't
Like Bert, I can't see an easy approach for datasets that have character rather than numeric data. But here's a simple approach for distinguishing files that have possible character headers but numeric data. readheader <- function(filename) { possibleheader <- read.table(filename, nrows=1, sep=",", header=FALSE) if(all(is.numeric(possibleheader[,1]))) { # no header infile <- read.table(filename, sep=",", header=FALSE) } else { # has header infile <- read.table(filename, sep=",", header=TRUE) } infile } file noheader.csv 1,1,1 2,2,2 3,3,3 file hasheader.csv a,b,c 1,1,1 2,2,2 3,3,3 > readheader("noheader.csv") V1 V2 V3 1 1 1 1 2 2 2 2 3 3 3 3 > readheader("hasheader.csv") a b c 1 1 1 1 2 2 2 2 3 3 3 3 Sarah On Tue, Aug 13, 2019 at 2:00 PM Christopher W Ryan wrote: > > Alas, we spend so much time and energy on data wrangling . . . . > > I'm given a collection of csv files to work with---"found data". They arose > via saving Excel files to csv format. They all have the same column > structure, except that some were saved with column names and some were not. > > I have a code snippet that I've used before to traverse a directory and > read into R all the csv files of a certain filename pattern within it, and > combine them all into a single dataframe: > > library(dplyr) > ## specify the csv files that I will want to access > files.to.read <- list.files(path = "H:/EH", pattern = > "WICLeadLabOrdersDone.+", all.files = FALSE, full.names = TRUE, recursive = > FALSE, ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE) > > ## function to read csv files back in > read.csv.files <- function(filename) { > bb <- read.csv(filename, colClasses = "character", header = TRUE) > bb > } > > ## now read the csv files, as all character > b <- lapply(files.to.read, read.csv.files) > > ddd <- bind_rows(b) > > But this assumes that all files have column names in their first row. In > this case, some don't. Any advice how to handle it so that those with > column names and those without are read in and combined properly? The only > thing I've come up with so far is: > > ## function to read csv files back in > ## Unfortunately, some of the csv files are saved with column headers, and > some are saved without them. > ## This presents a problem when defining the function to read them: header > = TRUE or header = FALSE? > ## The best solution I can think of as of 13 August 2019 is to use header = > FALSE and skip the > ## first row of every file. This will sacrifice one record from each csv of > about 80 files > read.csv.files <- function(filename) { > bb <- read.csv(filename, colClasses = "character", header = FALSE, skip > = 1) > bb > } > > This sacrifices about 80 out of about 1600 records. For my purposes in this > instance, this may be acceptable, but of course I'd rather not. > > Thanks. > > --Chris Ryan > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create a data set from object/data frame?
Okay, at this point I have three suggestions, because you're clearly not yet understanding the R workflow. 1. Read at least the Intro to R manual. https://cran.r-project.org/doc/manuals/R-intro.pdf 2. Go through your sample code carefully, step by step, using functions like str() and head() to look at the R objects produced at each step, using ? to investigate functions you aren't familiar with, and thinking as you go how those R objects do and don't resemble the data you have. 3. If 1 and 2 don't help, you need to consult with your advisor, mentor, or if there's nobody local to you that can help, the author of the sample code you're using. I don't have your sample code, don't have your data, am not familiar with the specific functions you are using, and don't have time to become familiar. You need to both improve your R understanding and seek out guidance, ideally from someone whose job it is to help you. Best, Sarah On Fri, Jul 19, 2019 at 1:47 PM Spencer Brackett wrote: > > Okay. I am a little confused as to how to proceed with that. The next part of > the procedure as seen below appears to be substituting information from this > fake data set into the following arguments in order to > > sample.info <- data.frame( + spl=paste('A', 1:8, sep=''), + > stat=rep(c('cancer' , 'healthy'), each=4)) > > ##Then a meta data.frame object was created to give more intelligible labels## > > > meta.info <- data.frame (labelDescription = + c('Sample Name' , 'Cancer > > Status')) Then we put them all together: > pheno <- > > new("AnnotatedDataFrame", + data = sample.info, + varMetadata = meta.info) > > ##Which was then aggregated together## > > > pheno <- new("AnnotatedDataFrame", + data = sample.info, + varMetadata = > > meta.info) > > >my.experiments <- new("ExpressionSet", + exprs=fake.data, phenoData=pheno) >> my.experiments > ExpressionSet (storageMode: lockedEnvironment) assayData: 200 features, 8 > samples element names: exprs > > ##The following deals with further manipulating the phenoData## > phenoData >sampleNames: 1, 2, ..., 8 (8 total) varLabels and varMetadata description: > spl: Sample Name stat: Cancer Status > > featureData >featureNames: 1, 2, ..., 200 (200 total) >fvarLabels and fvarMetadata description: none > experimentData: use 'experimentData(object)' > Annotation: > > ##At this point is when the dataset 'Dilution' was read in through > data(Dilution) > > >library(affydata) > > data(Dilution) > > which was made an object of the AnnotatedDataFrame via > >Dilution > >phenoData(Dilution) > >pData(Dilution) > > ##To access the probesets### > > > geneNames(Dilution)[1:3] [1] "100_g_at" "1000_at" "1001_at" > > random.affyid <- sample(geneNames(Dilution), 1) > > # random.affyid <- '34803_at' > > ps <- probeset(Dilution, random.affyid)[[1]] > > How would I substitute in my anno object to achieve this? > > > > > On Fri, Jul 19, 2019 at 1:32 PM Sarah Goslee wrote: >> >> You don't need fake.data or rnorm(), which was used to generate the fake >> data. >> >> You need to use your real data for the analysis, not anything randomly >> generated for example purposes, or anything included with a package >> for example purposes. >> >> In both cases, those are just worked examples.You need to analyze your >> own comparable data. >> >> Sarah >> >> On Fri, Jul 19, 2019 at 12:17 PM Spencer Brackett >> wrote: >> > >> > Sarah, >> > >> > Thank you for the reference to ?data. Upon further research into the >> > matter, I think I can provide a simpler explanation than the one >> > previously provided. I am trying to reproduce the following code with an >> > object -- 'anno' -- in my data frame/environment. >> > >> > >fake.data <- matrix(rnorm(8*200), ncol=8) >> > >> > I found the number of columns with >ncol(anno) , which is 3 >> > >> > How do I find rnorm when I don't have the data table (saved as the 'anno' >> > object) mean or standard dev. ? >> > >> > I will try reading in the data object through read.table() now, though >> > won't that just print the data or a subset thereof into my R console? >> > >> > >> > >> > On Fri, Jul 19, 2019 at 10:46 AM Spencer Brackett >> > wrote: >> >> >> &g
Re: [R] How to create a data set from object/data frame?
You don't need fake.data or rnorm(), which was used to generate the fake data. You need to use your real data for the analysis, not anything randomly generated for example purposes, or anything included with a package for example purposes. In both cases, those are just worked examples.You need to analyze your own comparable data. Sarah On Fri, Jul 19, 2019 at 12:17 PM Spencer Brackett wrote: > > Sarah, > > Thank you for the reference to ?data. Upon further research into the matter, > I think I can provide a simpler explanation than the one previously provided. > I am trying to reproduce the following code with an object -- 'anno' -- in my > data frame/environment. > > >fake.data <- matrix(rnorm(8*200), ncol=8) > > I found the number of columns with >ncol(anno) , which is 3 > > How do I find rnorm when I don't have the data table (saved as the 'anno' > object) mean or standard dev. ? > > I will try reading in the data object through read.table() now, though won't > that just print the data or a subset thereof into my R console? > > > > On Fri, Jul 19, 2019 at 10:46 AM Spencer Brackett > wrote: >> >> Sarah, >> >> I am trying to extract phenoData (ie sample information) from the object >> as part of a procedure to analyze my array for probe sets, which I realize >> is under the BioConducter package Biobase and not relevant to this mailing >> list. >> >> Yes the original procedure uses data from the Dilution dataset hosted in >> the AffyBatch package affydata. Previous to this part of the procedure, a >> dataset was create via.. >> >> >fake.data <- matrix(rnorm(8*200), ncol=8) >> ##Then phenotype (sample) data was generated in this example through... ## >> >> sample.info <- data.frame( + spl=paste('A', 1:8, sep=''), + >> stat=rep(c('cancer' , 'healthy'), each=4)) >> >> ##Then a meta data.frame object was created to give more intelligible >> labels## >> >> > meta.info <- data.frame (labelDescription = + c('Sample Name' , 'Cancer >> > Status')) Then we put them all together: > pheno <- >> > new("AnnotatedDataFrame", + data = sample.info, + varMetadata = meta.info) >> >> ##Which was then aggregated together## >> >> > pheno <- new("AnnotatedDataFrame", + data = sample.info, + varMetadata = >> > meta.info) >> >> >my.experiments <- new("ExpressionSet", + exprs=fake.data, phenoData=pheno) >>> my.experiments >> ExpressionSet (storageMode: lockedEnvironment) assayData: 200 features, 8 >> samples element names: exprs >> >> ##The following deals with further manipulating the phenoData## >> phenoData >>sampleNames: 1, 2, ..., 8 (8 total) varLabels and varMetadata >> description: spl: Sample Name stat: Cancer Status >> >> featureData >> featureNames: 1, 2, ..., 200 (200 total) fvarLabels and fvarMetadata >> description: none >> experimentData: use 'experimentData(object)' >> Annotation: >> >> ##At this point is when the dataset 'Dilution was read in through >> data(Dilution) >> >> which was made an object of the AnnotatedDataFrame via >> >> >phenoData(Dilution) >> >> My apologies in advance as I know the above info. pertains to functions >> carried out strictly through BioConducor, but is the only context I can >> provide for what I am trying to do. >> >> Best, >> >> Spencer >> >> >> On Fri, Jul 19, 2019 at 10:23 AM Sarah Goslee wrote: >>> >>> Hi Spencer, >>> >>> Your description doesn't make any sense to me. If anno is already an R >>> object, what are you trying to do with it? >>> >>> data() is for loading datasets that come with packages; if your object >>> is already an R object in your environment, then there's no need for >>> it. >>> >>> It sounds like you are possibly working through an example provided >>> elsewhere, that has sample data loaded with data(). If so, then you do >>> not need that step for your own data. You just need to import it into >>> R in the correct format. >>> >>> If that doesn't help, then I think we need more information on what >>> you're trying to do. >>> >>> Sarah >>> >>> On Fri, Jul 19, 2019 at 10:18 AM Spencer Brackett >>> wrote: >>> > >>> > Hello, >>>
Re: [R] How to create a data set from object/data frame?
Right. If you have some equivalent to the Dilution dataset, then you need to get it into R in the appropriate way for whatever data you have. data() is merely a way to get stored R data into your R session. There's no reason you need to use data() rather than read.table() or whatever is appropriate for the data you have available. Or if you needed that exact dataset, data(Dilution) would get it into your R session. Do look at ?data if you haven't already. Sarah On Fri, Jul 19, 2019 at 10:46 AM Spencer Brackett wrote: > > Sarah, > > I am trying to extract phenoData (ie sample information) from the object as > part of a procedure to analyze my array for probe sets, which I realize is > under the BioConducter package Biobase and not relevant to this mailing list. > > Yes the original procedure uses data from the Dilution dataset hosted in > the AffyBatch package affydata. Previous to this part of the procedure, a > dataset was create via.. > > >fake.data <- matrix(rnorm(8*200), ncol=8) > ##Then phenotype (sample) data was generated in this example through... ## > > sample.info <- data.frame( + spl=paste('A', 1:8, sep=''), + > stat=rep(c('cancer' , 'healthy'), each=4)) > > ##Then a meta data.frame object was created to give more intelligible labels## > > > meta.info <- data.frame (labelDescription = + c('Sample Name' , 'Cancer > > Status')) Then we put them all together: > pheno <- > > new("AnnotatedDataFrame", + data = sample.info, + varMetadata = meta.info) > > ##Which was then aggregated together## > > > pheno <- new("AnnotatedDataFrame", + data = sample.info, + varMetadata = > > meta.info) > > >my.experiments <- new("ExpressionSet", + exprs=fake.data, phenoData=pheno) >> my.experiments > ExpressionSet (storageMode: lockedEnvironment) assayData: 200 features, 8 > samples element names: exprs > > ##The following deals with further manipulating the phenoData## > phenoData >sampleNames: 1, 2, ..., 8 (8 total) varLabels and varMetadata description: > spl: Sample Name stat: Cancer Status > > featureData > featureNames: 1, 2, ..., 200 (200 total) fvarLabels and fvarMetadata > description: none > experimentData: use 'experimentData(object)' > Annotation: > > ##At this point is when the dataset 'Dilution was read in through > data(Dilution) > > which was made an object of the AnnotatedDataFrame via > > >phenoData(Dilution) > > My apologies in advance as I know the above info. pertains to functions > carried out strictly through BioConducor, but is the only context I can > provide for what I am trying to do. > > Best, > > Spencer > > > On Fri, Jul 19, 2019 at 10:23 AM Sarah Goslee wrote: >> >> Hi Spencer, >> >> Your description doesn't make any sense to me. If anno is already an R >> object, what are you trying to do with it? >> >> data() is for loading datasets that come with packages; if your object >> is already an R object in your environment, then there's no need for >> it. >> >> It sounds like you are possibly working through an example provided >> elsewhere, that has sample data loaded with data(). If so, then you do >> not need that step for your own data. You just need to import it into >> R in the correct format. >> >> If that doesn't help, then I think we need more information on what >> you're trying to do. >> >> Sarah >> >> On Fri, Jul 19, 2019 at 10:18 AM Spencer Brackett >> wrote: >> > >> > Hello, >> > >> > I am trying to create a data set from an object called ‘anno’ in my >> > environment. I’ve tried arguments like saveRDS(anno, file = “”) and >> > save(anno, file “.RData”) to save the object as a file to see if that will >> > work, but it seems for the particular procedure I am trying to carry out, I >> > need to transpose the object to a data set. Any ideas as to how I might do >> > this? For reference, my next step in manipulating the data contained in the >> > object is data(), which evidently does not work for reading in data frame >> > objects as data(“file/object name). >> > >> > Best, >> > >> > Spencer >> >\ -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create a data set from object/data frame?
Hi Spencer, Your description doesn't make any sense to me. If anno is already an R object, what are you trying to do with it? data() is for loading datasets that come with packages; if your object is already an R object in your environment, then there's no need for it. It sounds like you are possibly working through an example provided elsewhere, that has sample data loaded with data(). If so, then you do not need that step for your own data. You just need to import it into R in the correct format. If that doesn't help, then I think we need more information on what you're trying to do. Sarah On Fri, Jul 19, 2019 at 10:18 AM Spencer Brackett wrote: > > Hello, > > I am trying to create a data set from an object called ‘anno’ in my > environment. I’ve tried arguments like saveRDS(anno, file = “”) and > save(anno, file “.RData”) to save the object as a file to see if that will > work, but it seems for the particular procedure I am trying to carry out, I > need to transpose the object to a data set. Any ideas as to how I might do > this? For reference, my next step in manipulating the data contained in the > object is data(), which evidently does not work for reading in data frame > objects as data(“file/object name). > > Best, > > Spencer > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] bizarre color space conversion problem
Peter, it appears to be the same as this bug: https://github.com/xianyi/OpenBLAS/issues/2168 I added my info to the discussion. Thanks for the reminder. And thank you again to Ivan for the help. Sarah On Thu, Jul 18, 2019 at 3:17 PM Peter Langfelder wrote: > > Sarah, if you haven't done so already, please do us (OpenBLAS users) a > big favor and report the bug, either to Fedora or directly to OpenBLAS > maintainers. > > Peter > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] bizarre color space conversion problem
Wow. You are entirely correct. I would not have been able to pinpoint the problem, or how to test it. Thank you. I am unhappy you are right, since these are the fast workstations I use for all of my heavy-duty analysis, and it's not even *possible* to rerun everything. Oh dear. Here, with the options you suggested, it produces the expected results: # env OPENBLAS_CORETYPE=Haswell R --vanilla > white <- c(x = 0.953205712549377, 1, y = 1.08538438164692) > red10.rgb <- structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(10L, 3L), .Dimnames = list( > NULL, c("r", "g", "b"))) > convertColor(red10.rgb, from = "sRGB", to = "Lab") Lab [1,] 53.48418 80.01027 67.38407 [2,] 53.48418 80.01027 67.38407 [3,] 53.48418 80.01027 67.38407 [4,] 53.48418 80.01027 67.38407 [5,] 53.48418 80.01027 67.38407 [6,] 53.48418 80.01027 67.38407 [7,] 53.48418 80.01027 67.38407 [8,] 53.48418 80.01027 67.38407 [9,] 53.48418 80.01027 67.38407 [10,] 53.48418 80.01027 67.38407 > red10.rgb %*% as.list(environment(grDevices::colorspaces$sRGB$toXYZ))$M [,1] [,2] [,3] [1,] 0.4168213 0.2149235 0.0195385 [2,] 0.4168213 0.2149235 0.0195385 [3,] 0.4168213 0.2149235 0.0195385 [4,] 0.4168213 0.2149235 0.0195385 [5,] 0.4168213 0.2149235 0.0195385 [6,] 0.4168213 0.2149235 0.0195385 [7,] 0.4168213 0.2149235 0.0195385 [8,] 0.4168213 0.2149235 0.0195385 [9,] 0.4168213 0.2149235 0.0195385 [10,] 0.4168213 0.2149235 0.0195385 On Thu, Jul 18, 2019 at 1:59 PM Ivan Krylov wrote: > > On Thu, 18 Jul 2019 13:30:09 -0400 > Sarah Goslee wrote: > > > I'm not even remotely a hardware expert: if the difference is due to > > changes in the instruction set, I assume that has potential > > consequences for other things, and I just happened to spot it in this > > particular case because it's visualization-based? (Yikes.) > > Yes, this might be bad. I have heard about OpenBLAS (specifically, the > matrix product routine) misbehaving on certain AVX-512 capable > processors, so much that they had to disable some optimizations in > 0.3.6 [*], which you already have installed. Still, would `env > OPENBLAS_CORETYPE=Haswell R --vanilla` give a better result? > > > As it says in my first email (but way at the bottom), I'd already > > gotten as far as locating the problem in this line from > > grDevices::convertColor() > > > > xyz <- from$toXYZ(color, from.ref.white) > > Thanks for confirming this! It felt that I had to make sure, since the > behaviour we observe is so confusing. > > > > (red.xyz <- grDevices::colorspaces$sRGB$toXYZ(red.rgb, > > > white.point))[1,] > > [1] 0.7733981 0.9280769 0.1383974 > > > # [1] 0.4168213 0.2149235 0.0195385 > > One last check: would > > red.rgb %*% as.list(environment(grDevices::colorspaces$sRGB$toXYZ))$M > > still produce different results on your computers? > > > blas.x86_64 3.8.0-12.fc30 > > openblas.x86_64 0.3.6-2.fc30 > > I do not know enough about Fedora's "alternatives" system, but it does > look like R is using OpenBLAS. > > > A: working > > Model name: Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz > > > B: not working > > Model name: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz > > Again, this points in the direction of OpenBLAS not doing AVX-512 math > properly. Let's hope that OPENBLAS_CORETYPE=Haswell solves it. > > -- > Best regards, > Ivan > > [*] > https://github.com/xianyi/OpenBLAS/issues/1955 > https://github.com/xianyi/OpenBLAS/issues/2029 > https://github.com/xianyi/OpenBLAS/issues/2168 > https://github.com/xianyi/OpenBLAS/issues/2182 -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] bizarre color space conversion problem
@updates openblas-openmp.x86_64 0.3.6-2.fc30 @updates openblas-serial.x86_64 0.3.6-2.fc30 @updates openblas-srpm-macros.noarch 2-5.fc30 @fedora openblas-threads.x86_64 0.3.6-2.fc30 @updates openblas-threads64_.x86_64 0.3.6-2.fc30 @updates -rwxr-xr-x. 1 root root 60204008 Jul 2 10:15 /usr/lib64/R/lib/libRblas.so lscpu Architecture:x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 46 bits physical, 48 bits virtual CPU(s): 20 On-line CPU(s) list: 0-19 Thread(s) per core: 2 Core(s) per socket: 10 Socket(s): 1 NUMA node(s):1 Vendor ID: GenuineIntel CPU family: 6 Model: 85 Model name: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz Stepping:4 CPU MHz: 1200.180 CPU max MHz: 4500. CPU min MHz: 1200. BogoMIPS:6600.00 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache:1024K L3 cache:14080K NUMA node0 CPU(s): 0-19 On Thu, Jul 18, 2019 at 1:05 PM Ivan Krylov wrote: > > On Thu, 18 Jul 2019 11:50:17 -0400 > Sarah Goslee wrote: > > > The problem is in the conversion from RGB to Lab. > > Hmm. Assuming defaults and skipping all checks, convertColor(red.rgb, > from = "sRGB", to = "Lab") amounts to the following: > > red.rgb <- t(col2rgb(rep('red',8), alpha = 0)/255) > # let's hope this implementation detail wasn't changed in 3.6.1 > white.point <- grDevices:::c2to3(grDevices:::white.points[,'D65']) > (red.xyz <- grDevices::colorspaces$sRGB$toXYZ(red.rgb, white.point))[1,] > # [1] 0.4168213 0.2149235 0.0195385 > (red.lab <- grDevices::colorspaces$Lab$fromXYZ(red.xyz,white.point))[1,] # > Lab > # 53.48418 80.01027 67.38407 > convertColor(red.rgb, from = "sRGB", to = "Lab")[1,] > #Lab > # 53.48418 80.01027 67.38407 > > Does the manual way result in a different output? If so, do the > differences appear in red.xyz or red.lab? > > grDevices::colorspaces$sRGB$toXYZ is pretty simple, just a matrix > product. (I hope there are no differences in > as.list(environment(grDevices::colorspaces$sRGB$toXYZ))[c('dogamma','M')] > on different computers - that would be strange.) > grDevices::colorspaces$Lab$fromXYZ looks more complicated but is just a > bunch of vectorised element-wise algebra, so tracing the intermediate > results should also be possible. > > > And to make it even more bizarre, it fails with eight or more colors, > > but works correctly with seven or fewer. > > This is just a wild guess, but could /usr/lib64/R/lib/libRblas.so per > chance be a symlink to an OpenBLAS copy? Could any of the computers > exhibiting the bizarre behaviour be equipped with an AVX-512-capable > CPU? > > -- > Best regards, > Ivan -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] bizarre color space conversion problem
I didn't include enough detail, despite the length of my original email. The problem is in the conversion from RGB to Lab. I converted it back to RGB because most of us are more familiar with that. Below are the intermediate steps. And to make it even more bizarre, it fails with eight or more colors, but works correctly with seven or fewer. Ivan's suggestion works fine; the Lab to RGB conversion is okay. I tried to figure out how colorspaces() works, but couldn't get it to agree with convertColors(), although they're both reversible using the same function. > white <- c(x = 0.953205712549377, 1, y = 1.08538438164692) > grDevices::convertColor(c(1, 0, 0), from = "sRGB", to = "Lab") Lab [1,] 53.48418 80.01027 67.38407 > > grDevices::colorspaces[['Lab']][['fromXYZ']](c(1, 0, 0), white) L a b 0.000 439.086 0.000 #-#-# Here's a more complete example. red.in <- rep("red", 8) red.rgb <- t(col2rgb(red.in, alpha = 0)/255) red.rgb red.lab <- convertColor(red.rgb, from = "sRGB", to = "Lab") red.lab convertColor(red.lab, from = "Lab", to = "sRGB") # > red.in <- rep("red", 8) > > red.rgb <- t(col2rgb(red.in, alpha = 0)/255) > red.rgb red green blue [1,] 1 00 [2,] 1 00 [3,] 1 00 [4,] 1 00 [5,] 1 00 [6,] 1 00 [7,] 1 00 [8,] 1 00 > > red.lab <- convertColor(red.rgb, from = "sRGB", to = "Lab") > red.lab L ab [1,] 97.1495 -21.36677 94.42044 [2,] 97.1495 -21.36677 94.42044 [3,] 97.1495 -21.36677 94.42044 [4,] 97.1495 -21.36677 94.42044 [5,] 0. 0.0 0.0 [6,] 0. 0.0 0.0 [7,] 0. 0.0 0.0 [8,] 0. 0.0 0.0 > > convertColor(red.lab, from = "Lab", to = "sRGB") [,1] [,2] [,3] [1,]1 0.1 [2,]1 0.1 [3,]1 0.1 [4,]1 0.1 [5,]0 0.54720 [6,]0 0.54720 [7,]0 0.54720 [8,]0 0.54720 # red.in <- rep("red", 7) red.rgb <- t(col2rgb(red.in, alpha = 0)/255) red.rgb red.lab <- convertColor(red.rgb, from = "sRGB", to = "Lab") red.lab convertColor(red.lab, from = "Lab", to = "sRGB") > red.in <- rep("red", 7) > > red.rgb <- t(col2rgb(red.in, alpha = 0)/255) > red.rgb red green blue [1,] 1 00 [2,] 1 00 [3,] 1 00 [4,] 1 00 [5,] 1 00 [6,] 1 00 [7,] 1 00 > > red.lab <- convertColor(red.rgb, from = "sRGB", to = "Lab") > red.lab Lab [1,] 53.48418 80.01027 67.38407 [2,] 53.48418 80.01027 67.38407 [3,] 53.48418 80.01027 67.38407 [4,] 53.48418 80.01027 67.38407 [5,] 53.48418 80.01027 67.38407 [6,] 53.48418 80.01027 67.38407 [7,] 53.48418 80.01027 67.38407 > > convertColor(red.lab, from = "Lab", to = "sRGB") [,1] [,2] [,3] [1,]100 [2,]100 [3,]100 [4,]100 [5,]100 [6,]100 [7,]100 On Thu, Jul 18, 2019 at 11:02 AM Ivan Krylov wrote: > > This is, indeed, bizzare! > > On Thu, 18 Jul 2019 10:35:57 -0400 > Sarah Goslee wrote: > > > I've gotten as far as locating the problem in this line from > > grDevices::convertColor() > > > > xyz <- from$toXYZ(color, from.ref.white) > > So if you manually feed the arguments: > > Lab <- structure(c(53.484183785248, 53.484183785248, 53.484183785248, > 53.484183785248, 53.484183785248, 53.484183785248, 53.484183785248, > 53.484183785248, 53.484183785248, 53.484183785248, 53.484183785248, > 53.484183785248, 53.484183785248, 53.484183785248, 53.484183785248, > 53.484183785248, 53.484183785248, 53.484183785248, 53.484183785248, > 53.484183785248, 80.0102716478952, 80.0102716478952, 80.0102716478952, > 80.0102716478952, 80.0102716478952, 80.0102716478952, 80.0102716478952, > 80.0102716478952, 80.0102716478952, 80.0102716478952, 80.0102716478952, > 80.0102716478952, 80.0102716478952, 80.0102716478952, 80.0102716478952, > 80.0102716478952, 80.0102716478952, 80.0102716478952, 80.0102716478952, > 80.0102716478952, 67.3840746825475, 67.3840746825475, 67.3840746825475, > 67.3840746825475, 67.3840746825475, 67.3840746825475, 67.3840746825475, > 67.3840746825475, 67.3840746825475, 67.3840746825475, 67.3840746825475, > 67.3840746825475, 67.3840746825475, 67.3840746825475, 67.3840746825475, > 67.3840746825475, 67.3840746825475, 67.3840746825475, 67.3840746825475, > 67.3840746825475), .Dim = c(20L, 3L), .Dimnames = list(NULL, c("L", >
Re: [R] Dataframe columns are accessible by incomplete column names, is this a bug?
Hello Yannick, That behavior is documented in the help for subsetting ( ?'$' ): Both ‘[[’ and ‘$’ select a single element of the list. The main difference is that ‘$’ does not allow computed indices, whereas ‘[[’ does. ‘x$name’ is equivalent to ‘x[["name", exact = FALSE]]’. Also, the partial matching behavior of ‘[[’ can be controlled using the ‘exact’ argument. You can avoid it by using [[]] instead: > swiss[['Ex']] NULL > head(swiss[['Examination']]) [1] 15 6 5 12 17 9 That's one of the major reasons using $ is sometimes discouraged. Sarah On Thu, Jul 18, 2019 at 11:38 AM wrote: > > Hello all > I noticed today that you can access dataframe columns by using incomplete > names. This is a really unexpected behavior which led to some unexpected > errors and I was wondering whether it's a bug or not and whether it should be > changed in the future. > Here's a working example using the preinstalled "swiss" dataset: > > > head(swiss) > Fertility Agriculture Examination Education Catholic > Courtelary80.217.0 1512 9.96 > Delemont 83.145.1 6 984.84 > Franches-Mnt 92.539.7 5 593.40 > Moutier 85.836.5 12 733.77 > Neuveville76.943.5 1715 5.16 > Porrentruy76.135.3 9 790.57 > Infant.Mortality > Courtelary 22.2 > Delemont 22.2 > Franches-Mnt 20.2 > Moutier 20.3 > Neuveville 20.6 > Porrentruy 26.6 > > swiss$E > NULL > > swiss$Ex > [1] 15 6 5 12 17 9 16 14 12 16 14 21 14 19 22 18 17 26 31 19 22 14 22 20 12 > [26] 14 6 16 25 15 3 7 5 12 7 9 3 13 26 29 22 35 15 25 37 16 22 > > swiss$Ed > [1] 12 9 5 7 15 7 7 8 7 13 6 12 7 12 5 2 8 28 20 9 10 3 12 6 1 > [26] 8 3 10 19 8 2 6 2 6 3 9 3 13 12 11 13 32 7 7 53 29 29 > > So in order to access the column "Examination", I can type any substring from > "Ex" to "Examination" and will always get the column swiss$Examination. > > Thanks for reading and Greetings > Yannick Suter > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] bizarre color space conversion problem
I am getting unexpected results when converting from RGB to Lab. This is clearly some kind of configuration problem, but I cannot find it. I have three linux workstations, both fully updated (except all are running R 3.6.0 instead of 3.6.1, because that's the latest Fedora 30 binary). I'm running R --vanilla from the command line. On one workstation, it functions correctly; on the other two the conversion malfunctions as below. I found it when my scico color palettes were wildly wrong, but it isn't a scico package problem. https://twitter.com/numberwright/status/1151601407436439554 After spending far too much time poking at it, I'm still curious as to what might be going on. It's got to be my computer rather than R, but I do want to figure out what, in case it has consequences for other calculations. Here's my sample code: red.in <- rep("red", 20) red.rgb <- t(col2rgb(red.in, alpha = 0)/255) red.lab <- convertColor(red.rgb, from = "sRGB", to = "Lab") convertColor(red.lab, from = "Lab", to = "sRGB") #-#-# Output on computer A, as expected: > sessionInfo() R version 3.6.0 (2019-04-26) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: Fedora 30 (Workstation Edition) Matrix products: default BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_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] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.6.0 > > red.in <- rep("red", 20) > > red.rgb <- t(col2rgb(red.in, alpha = 0)/255) > red.lab <- convertColor(red.rgb, from = "sRGB", to = "Lab") > convertColor(red.lab, from = "Lab", to = "sRGB") [,1] [,2] [,3] [1,]100 [2,]100 [3,]100 [4,]100 [5,]100 [6,]100 [7,]100 [8,]100 [9,]100 [10,]100 [11,]100 [12,]100 [13,]100 [14,]100 [15,]100 [16,]100 [17,]100 [18,]100 [19,]100 [20,]100 #-#-# Output on computer B (and also computer C!) > sessionInfo() R version 3.6.0 (2019-04-26) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: Fedora 30 (Workstation Edition) Matrix products: default BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_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] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.6.0 > > red.in <- rep("red", 20) > > red.rgb <- t(col2rgb(red.in, alpha = 0)/255) > red.lab <- convertColor(red.rgb, from = "sRGB", to = "Lab") > convertColor(red.lab, from = "Lab", to = "sRGB") [,1] [,2] [,3] [1,]1 0.1 [2,]1 0.1 [3,]1 0.1 [4,]1 0.1 [5,]0 0.54720 [6,]0 0.54720 [7,]0 0.54720 [8,]0 0.54720 [9,]1 0.1 [10,]1 0.1 [11,]1 0.1 [12,]1 0.1 [13,]0 0.54720 [14,]0 0.54720 [15,]0 0.54720 [16,]0 0.54720 [17,]1 0.0 [18,]1 0.0 [19,]1 0.0 [20,]1 0.0 #-#-# I've gotten as far as locating the problem in this line from grDevices::convertColor() xyz <- from$toXYZ(color, from.ref.white) Packages are up to date on all computers, although this doesn't involve any contributed packages. Thoughts? -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Subsetting Data from a Dataframe
2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, > 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0", > "NULL"), class = "factor"), Var7 = c(0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 509986L, 457334L, 423431L, 491864L, 291347L, > 348557L, 415865L, 392211L, 335553L, 298921L, 383274L, 316046L, > 373400L, 346341L, 389709L, 401434L, 409913L, 374109L, 412340L, > 351334L, 318191L, 371280L, 362450L, 326204L, 365452L, 359126L, > 353572L, 432630L, 308945L, 298529L, 314237L, 397880L, 339472L, > 294810L, 328184L, 399537L, 400889L, 442645L, 407200L, 411296L, > 367262L, 407430L, 417298L, 422888L, 453429L, 344743L, 408298L, > 422106L, 363156L, 387085L, 536751L, 458335L, 478253L, 371372L, > 355103L, 351371L, 396376L, 295519L, 447933L, 478155L, 486481L, > 413681L, 467253L, 327260L, 386971L, 467136L, 411711L, 426864L, > 369899L, 355287L, 365007L, 397091L, 561952L, 477049L, 513256L, > 357575L, 470663L, 505672L, 340253L, 418327L, 582188L, 326354L, > 427588L, 517728L, 485881L, 453163L, 463697L, 357187L, 449418L, > 365614L, 372260L, 431281L, 390126L, 347262L, 472019L, 374950L, > 440093L, 428659L, 494099L, 507023L, 395678L, 366396L, 358862L, > 469883L, 369744L, 341466L, 461598L, 466752L, 381354L, 407277L, > 527482L, 317936L, 314390L, 351180L, 351920L, 315951L, 354029L, > 267565L, 399528L, 377080L, 310084L, 294011L, 385220L, 406141L, > 412094L, 444809L, 321582L, 399966L, 326061L, 315964L, 323720L, > 297622L, 244843L, 247743L, 306002L, 318435L, 266651L, 277154L, > 314510L, 297403L, 319653L, 222712L, 301423L, 240825L, 244846L, > 282070L, 241318L, 252998L, 310381L, 221844L, 159100L, 261463L, > 256824L, 214117L, 263015L, 253039L, 289615L, 272659L, 279316L, > 267969L, 262087L, 304361L, 258202L, 262335L, 221760L, 139884L, > 260220L), Var8 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, > 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, > 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, > 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, > 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, > 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 169L, > 1L, 1L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, > 169L, 169L, 169L, 169L, 169L, 169L, 169L, 1L, 169L, 1L, 169L, > 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, 169L, > 169L, 169L, 169L, 169L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 162L, 143L, 130L, 158L, 30L, 68L, 125L, 104L, 61L, 37L, > 98L, 49L, 93L, 66L, 102L, 113L, 119L, 94L, 123L, 70L, 51L, 90L, > 81L, 57L, 84L, 80L, 73L, 135L, 41L, 36L, 44L, 108L, 62L, 32L, > 60L, 110L, 112L, 137L, 115L, 120L, 87L, 117L, 126L, 129L, 142L, > 65L, 118L, 128L, 82L, 101L, 166L, 144L, 155L, 91L, 75L, 71L, > 106L, 33L, 139L, 154L, 157L, 124L, 149L, 59L, 100L, 148L, 121L, > 131L, 89L, 76L, 83L, 107L, 167L, 153L, 163L, 78L, 151L, 160L, > 63L, 127L, 168L, 58L, 132L, 164L, 156L, 141L, 146L, 77L, 140L, > 85L, 92L, 134L, 103L, 67L, 152L, 95L, 136L, 133L, 159L, 161L, > 105L, 86L, 79L, 150L, 88L, 64L, 145L, 147L, 97L, 116L, 165L, > 50L, 45L, 69L, 72L, 47L, 74L, 23L, 109L, 96L, 42L, 31L, 99L, > 114L, 122L, 138L, 54L, 111L, 56L, 48L, 55L, 35L, 10L, 12L, 40L, > 52L, 22L, 26L, 46L, 34L, 53L, 7L, 38L, 8L, 11L, 28L, 9L, 13L, > 43L, 6L, 3L, 18L, 15L, 4L, 21L, 14L, 29L, 25L, 27L, 24L, 19L, > 39L, 16L, 20L, 5L, 2L, 17L), .Label = c("0", "139884", "159100", > "214117", "221760", "221844", "222712", "240825", "241318", "244843", > "244846", "247743", "252998", "253039", "256824", "258202", "260220", > "261463", "262087", "262335", "263015", "266651", "267565", "267969", > "272659", "277154", "279316", "282070", "289615", "291347", "294011", > "294810", "295519", "297403", "297622", "298529", "298921", "301423", > "304361", "306002", "308945", "310084", "310381", "314237", "314390", > "314510", "315951", "315964", "316046", "317936", "318191", "318435", > "319653", "321582", "323720", "326061", "326204", "326354", "327260", > "328184", "335553", "339472", "340253", "341466", "344743", "346341", > "347262", "348557", "351180", "351334", "351371", "351920", "353572", > "354029", "355103", "355287", "357187", "357575", "358862", "359126", > "362450", "363156", "365007", "365452", "365614", "366396", "367262", > "369744", "369899", "371280", "371372", "372260", "373400", "374109", > "374950", "377080", "381354", "383274", "385220", "386971", "387085", > "389709", "390126", "392211", "395678", "396376", "397091", "397880", > "399528", "399537", "399966", "400889", "401434", "406141", "407200", > "407277", "407430", "408298", "409913", "411296", "411711", "412094", > "412340", "413681", "415865", "417298", "418327", "422106", "422888", > "423431", "426864", "427588", "428659", "431281", "432630", "440093", > "442645", "444809", "447933", "449418", "453163", "453429", "457334", > "458335", "461598", "463697", "466752", "467136", "467253", "469883", > "470663", "472019", "477049", "478155", "478253", "485881", "486481", > "491864", "494099", "505672", "507023", "509986", "513256", "517728", > "527482", "536751", "561952", "582188", "NULL"), class = "factor")), class > = "data.frame", row.names = c(NA, > -402L)) > > > Any help and/or guidance will be greatly appreciated, > > Cheers, > > Paul > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] install R
Hi, If you don't want to install the binary for your version of linux, then you must install the prerequisites first. Notably, you have to have a compiler if you want to compile R from source! Here's a list: https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Essential-and-useful-other-programs-under-a-Unix_002dalike But your standard package installation method (like apt or dnf) probably can install a pre-built binary for you. If you aren't familiar with compiling software, that's the way to go. Sarah On Wed, May 8, 2019 at 9:37 AM yueli wrote: > > Hello, > > > I am trying to install R. > > > Thanks in advance for any help! > > > Yue > > > > > li@li-HP-Pavilion-Desktop-590-p0xxx:~/R-3.6.0$ ./configure > checking build system type... x86_64-pc-linux-gnu > checking host system type... x86_64-pc-linux-gnu > loading site script './config.site' > loading build-specific script './config.site' > checking for pwd... /bin/pwd > checking whether builddir is srcdir... yes > checking whether ln -s works... yes > checking for ar... ar > checking for a BSD-compatible install... /usr/bin/install -c > checking for sed... /bin/sed > checking for which... /usr/bin/which > checking for less... /usr/bin/less > checking for gtar... no > checking for gnutar... no > checking for tar... /bin/tar > checking for tex... no > checking for pdftex... no > configure: WARNING: you cannot build PDF versions of the R manuals > checking for pdflatex... no > configure: WARNING: you cannot build PDF versions of vignettes and help pages > checking for makeindex... no > checking for texi2any... no > configure: WARNING: you cannot build info or HTML versions of the R manuals > checking for texi2dvi... no > checking for kpsewhich... no > checking for latex inconsolata package... checking for unzip... /usr/bin/unzip > checking for zip... /usr/bin/zip > checking for gzip... /bin/gzip > checking for bzip2... /bin/bzip2 > checking for firefox... /usr/bin/firefox > using default browser ... /usr/bin/firefox > checking for acroread... no > checking for acroread4... no > checking for xdg-open... /usr/bin/xdg-open > checking for working aclocal... missing > checking for working autoconf... missing > checking for working autoheader... missing > checking for bison... no > checking for byacc... no > checking for yacc... no > checking for notangle... false > checking for realpath... /usr/bin/realpath > checking for pkg-config... no > checking for gcc... gcc > checking whether the C compiler works... yes > checking for C compiler default output file name... a.out > checking for suffix of executables... > checking whether we are cross compiling... no > checking for suffix of object files... o > checking whether we are using the GNU C compiler... yes > checking whether gcc accepts -g... yes > checking for gcc option to accept ISO C89... none needed > checking how to run the C preprocessor... gcc -E > checking for grep that handles long lines and -e... /bin/grep > checking for egrep... /bin/grep -E > checking whether gcc needs -traditional... no > checking for ANSI C header files... yes > checking for sys/types.h... yes > checking for sys/stat.h... yes > checking for stdlib.h... yes > checking for string.h... yes > checking for memory.h... yes > checking for strings.h... yes > checking for inttypes.h... yes > checking for stdint.h... yes > checking for unistd.h... yes > checking minix/config.h usability... no > checking minix/config.h presence... no > checking for minix/config.h... no > checking whether it is safe to define __EXTENSIONS__... yes > checking how to run the C preprocessor... gcc -E > looking for a modern Fortran compiler > checking for gfortran... no > checking for g95... no > checking for xlf95... no > checking for f95... no > checking for fort... no > checking for ifort... no > checking for ifc... no > checking for efc... no > checking for pgfortran... no > checking for pgf95... no > checking for lf95... no > checking for ftn... no > checking for nagfor... no > checking for xlf90... no > checking for f90... no > checking for pgf90... no > checking for pghpf... no > checking for epcf90... no > checking for g77... no > checking for xlf... no > checking for f77... no > checking for frt... no > checking for pgf77... no > checking for cf77... no > checking for fort77... no > checking for fl32... no > checking for af77... no > checking whether we are using the GNU Fortran compiler... no > checking whether accepts -g... no > configure: error: No Fortran compiler found > > > [[alternative HTML version deleted]] > >
Re: [R] Read_fwf in package readr, double vs. numeric
And just for thoroughness, I meant that it works in readr 1.3.1, as my sessionInfo (but not what I typed myself) said. Sorry for the typo, but I'm glad it solved your problem nonetheless. Sarah On Wed, Apr 24, 2019 at 11:38 AM Doran, Harold wrote: > > Thank you, Sarah. Seems that updating to a newer version does indeed solve > that problem. For completeness, below is the version in which it seems to > work properly and below is the version in which I observe the problem I > described. > > > sessionInfo() > R version 3.5.3 (2019-03-11) > Platform: x86_64-w64-mingw32/x64 (64-bit) > Running under: Windows 7 x64 (build 7601) Service Pack 1 > > 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] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] readr_1.3.1 > > loaded via a namespace (and not attached): > [1] compiler_3.5.3 assertthat_0.2.1 R6_2.4.0 cli_1.1.0 > hms_0.4.2 > [6] tools_3.5.3 pillar_1.3.1 tibble_2.1.1 Rcpp_1.0.1 > crayon_1.3.4 > [11] utf8_1.1.4 fansi_0.4.0 pkgconfig_2.0.2 rlang_0.3.4 > > > sessionInfo() > R version 3.4.2 (2017-09-28) > Platform: x86_64-w64-mingw32/x64 (64-bit) > Running under: Windows 7 x64 (build 7601) Service Pack 1 > > 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] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] readr_1.1.1 > > loaded via a namespace (and not attached): > [1] compiler_3.4.2 assertthat_0.2.0 R6_2.2.2 cli_1.0.0 > hms_0.3 tools_3.4.2 > [7] pillar_1.3.0 tibble_1.4.2 Rcpp_1.0.0 crayon_1.3.4 > utf8_1.1.4 fansi_0.2.3 > [13] rlang_0.3.0.1 > > -Original Message- > From: Sarah Goslee > Sent: Wednesday, April 24, 2019 11:12 AM > To: Doran, Harold > Cc: r-help@r-project.org > Subject: Re: [R] Read_fwf in package readr, double vs. numeric > > Hi, > > I can't reproduce your problem: with readr 1.1.1 on linux, it works as > expected. Letting read_fwf guess the types also works fine. (See > below.) > > If you aren't running the current version of readr, update and retry. > If you are, then we probably need more info, at least sessionInfo(). > > Sarah > > > > library(readr) > myFile <- "foo.txt" > pos <- fwf_positions(c(1,2,7), c(1,6,10)) > > > type <- c('N','D','N') > types <- paste0(type, collapse = '') > types <- chartr('NCD', 'ncd', types) > read_fwf(file = myFile, col_positions = pos, col_types = types) > > # A tibble: 3 x 3 > X1 X2X3 > > 1 1 1.00e-20 1043 > 2 1 7.12e+ 4 1043 > 3 1 9.12e+ 4 1055 > > > type <- c('N','N','N') > types <- paste0(type, collapse = '') > types <- chartr('NCD', 'ncd', types) > read_fwf(file = myFile, col_positions = pos, col_types = types) > > # A tibble: 3 x 3 > X1 X2X3 > > 1 1 1.00e-20 1043 > 2 1 7.12e+ 4 1043 > 3 1 9.12e+ 4 1055 > > > > > read_fwf(file = myFile, col_positions = pos, col_types = NULL) > Parsed with column specification: > cols( > X1 = col_double(), > X2 = col_double(), > X3 = col_double() > ) > # A tibble: 3 x 3 > X1 X2X3 > > 1 1 1.00e-20 1043 > 2 1 7.12e+ 4 1043 > 3 1 9.12e+ 4 1055 > > > > > > sessionInfo() > R version 3.5.3 (2019-03-11) > Platform: x86_64-redhat-linux-gnu (64-bit) Running under: Fedora 28 > (Workstation Edition) > > Matrix products: default > BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=en_US.UTF-8LC_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] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] readr_1.3.1colorout_1.2-
Re: [R] Read_fwf in package readr, double vs. numeric
Hi, I can't reproduce your problem: with readr 1.1.1 on linux, it works as expected. Letting read_fwf guess the types also works fine. (See below.) If you aren't running the current version of readr, update and retry. If you are, then we probably need more info, at least sessionInfo(). Sarah library(readr) myFile <- "foo.txt" pos <- fwf_positions(c(1,2,7), c(1,6,10)) type <- c('N','D','N') types <- paste0(type, collapse = '') types <- chartr('NCD', 'ncd', types) read_fwf(file = myFile, col_positions = pos, col_types = types) # A tibble: 3 x 3 X1 X2X3 1 1 1.00e-20 1043 2 1 7.12e+ 4 1043 3 1 9.12e+ 4 1055 type <- c('N','N','N') types <- paste0(type, collapse = '') types <- chartr('NCD', 'ncd', types) read_fwf(file = myFile, col_positions = pos, col_types = types) # A tibble: 3 x 3 X1 X2X3 1 1 1.00e-20 1043 2 1 7.12e+ 4 1043 3 1 9.12e+ 4 1055 > read_fwf(file = myFile, col_positions = pos, col_types = NULL) Parsed with column specification: cols( X1 = col_double(), X2 = col_double(), X3 = col_double() ) # A tibble: 3 x 3 X1 X2X3 1 1 1.00e-20 1043 2 1 7.12e+ 4 1043 3 1 9.12e+ 4 1055 > sessionInfo() R version 3.5.3 (2019-03-11) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: Fedora 28 (Workstation Edition) Matrix products: default BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_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] stats graphics grDevices utils datasets methods base other attached packages: [1] readr_1.3.1colorout_1.2-0 loaded via a namespace (and not attached): [1] compiler_3.5.3 assertthat_0.2.0 R6_2.4.0 cli_1.0.1 [5] hms_0.4.2tools_3.5.3 pillar_1.3.1 tibble_2.0.1 [9] Rcpp_1.0.0 crayon_1.3.4 utf8_1.1.4 fansi_0.4.0 [13] pkgconfig_2.0.2 rlang_0.3.1 On Wed, Apr 24, 2019 at 10:56 AM Doran, Harold wrote: > > Suppose I have the following data sitting in a fwf file 'foo.txt'. The point > of this email is to ask the group how to properly read in the value in this > pseudo-data "1e-20" using the read_fwf function in the package readr. > > 11e-201043 > 1712201043 > 1912201055 > > First, suppose I do it this way, where in this case "D" is used for double > precision. > > library(readr) > pos <- fwf_positions(c(1,2,7), c(1,6,10)) > type <- c('N','D','N') > types <- paste0(type, collapse = '') > types <- chartr('NCD', 'ncd', types) > > read_fwf(file = myFile, col_positions = pos, col_types = types) > > # A tibble: 3 x 3 > X1 X2X3 > > 1 1 1.00e-20 1043 > 2 1 7.12e+ 4 1043 > 3 1 9.12e+ 4 1055 > > This seemingly works well and properly captures the value. However, if I > instead were to indicate to the function that *all* of my columns were > numeric (just insert this one line in lieu of the other above) > > type <- c('N','N','N') > > # A tibble: 3 x 3 > X1X2X3 > > 1 1 1 1043 > 2 1 71220 1043 > 3 1 91220 1055 > > The read in is not correct. Here is the pragmatic issue. I have a legacy > program that spits out the layout structure of the fwf file (start, end > positions) and also indicates what the column types are. This layout file we > receive always uses a column type of numeric (N) for any numeric types > (including the column holding values such as 1e-20). > > This layout file will not change so I need to figure out how to solve the > problem within my read in program. I suppose one option is that I could > manually change any values of "N" to "D" in my R code. That seems to work. > But not sure if that is the "right" way to solve this issue. > > Thanks > Harold > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot (cox)
Well, you don't provide a reproducible example, so there's only so much we can do. The help for par is a lot, but I told you which option to use. Did you try reading the examples for ?axis at all? plot (cox, col=1:2, xscale=1, xlab="OS", ylab="Probability", xaxt="n") axis(1, at=seq(0, 48, by=12)) Or whatever axis values you actually want. Sarah On Mon, Apr 15, 2019 at 3:02 PM Medic wrote: > > Thanks, but too hard for me > > Sarah Goslee : > > You can presumably use xaxt="n" in your plot() statement (see ?par for > > details), and then use axis() to make anything you'd like (see ?axis > > for details). > -- > >> Medic wrote: > >> In this code: > >> plot (cox, col=1:2, xscale=1, xlab="OS", ylab="Probability") > >> the X scale is divided (by default) as: > >> 0 ... 50 ... 100 ... 150 ... 200 > >> And I would like so: > >> 0 ... 12 ... 24 ... 36 ... 48. > >> I looked ?plot(cox), but did not understand what argument is > >> responsible for this. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot (cox)
You can presumably use xaxt="n" in your plot() statement (see ?par for details), and then use axis() to make anything you'd like (see ?axis for details). Sarah On Mon, Apr 15, 2019 at 12:51 PM Medic wrote: > > In this code: > > plot (cox, col=1:2, xscale=1, xlab="OS", ylab="Probability") > > the X scale is divided (by default) as: > > 0 ... 50 ... 100 ... 150 ... 200 > > And I would like so: > > 0 ... 12 ... 24 ... 36 ... 48. > > I looked ?plot(cox), but did not understand what argument is > responsible for this. > > Pls, help me! > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Run time error with afex package
Presumably you mean R versions by the 3.whatevers. The current version of afex no longer requires stringi, but earlier versions did. The best course is to update afex, but you could also just install the stringi, as the error message you're getting suggests. Sarah On Sun, Apr 14, 2019 at 1:14 PM Ricard, Mark D wrote: > > Dear R Users: > > When I attempt the run the package afex I get the following error: > > require(afex) > Loading required package: afex > Error: package or namespace load failed for 'afex' in library.dynam(lib, > package, package.lib): > DLL 'stringi' not found: maybe not installed for this architecture? > > I have tried version 3.3, 3.4 and 3.53 > > Mark D. Ricard > Biomechanics > Laboratory<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwweb.uta.edu%2Ffaculty%2Fricard%2FBiomechLab.html&data=02%7C01%7C%7Ceed3acbb15514be30bf108d6222b0941%7C5cdc5b43d7be4caa8173729e3b0a62d9%7C0%7C0%7C636733965559996367&sdata=Zne3UpVvzhB61%2FovgxVlzDPE%2BDjbbfAc2%2BhQcWeSFFw%3D&reserved=0> > Graduate Program Advisor > Department of Kinesiology Box 19259 > 500 W Nedderman Dr > The University of Texas at Arlington > Arlington , TX 76019-0259 > Email: ric...@uta.edu<mailto:ric...@uta.edu> > Phone (817) 272-0764 > Fax: (817) 272-3233 > Website: > http://wweb.uta.edu/faculty/ricard<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwweb.uta.edu%2Ffaculty%2Fricard&data=02%7C01%7C%7Ceed3acbb15514be30bf108d6222b0941%7C5cdc5b43d7be4caa8173729e3b0a62d9%7C0%7C0%7C636733965560006380&sdata=u7BPOp2cTfcsfl3J13ot1SL4O%2BteJHPtjsMT73OanLQ%3D&reserved=0> > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] String replace
Try reversing the order, or extending the to-replace bit. "M_1" is finding and replacing "M_10", "M_11", etc. "M_2" is finding and replacing "M_20", "M_21", etc. So M_14 becomes "01-03-20174" In the future, a toy dataset would help with the reproducible example aspect, and make your question easier to answer. Sarah On Wed, Apr 3, 2019 at 1:24 PM Graham Leask via R-help wrote: > > > I’m attempting to replace a string variable that normally works fine. However > when trying to > do this with a string in the form of a date the output becomes corrupted. > > See below: > > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_1" , > "01-03-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_2" , > "01-04-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_3" , > "01-05-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_4" , > "01-06-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_5" , > "01-07-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_6" , > "01-08-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_7" , > "01-09-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_8" , > "01-10-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_9" , > "01-11-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_10" , > "01-12-2017")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_11" , > "01-01-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_12" , > "01-02-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_13" , > "01-03-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_14" , > "01-04-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_15" , > "01-05-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_16" , > "01-06-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_17" , > "01-07-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_18" , > "01-08-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_19" , > "01-09-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_20" , > "01-10-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_21" , > "01-11-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_22" , > "01-12-2018")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_23" , > "01-01-2019")) > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_24" , > "01-02-2019")) > > The first line works fine but by the end the output is corrupted to > > "01-03-20174" > > > Any thoughts what I’m doing wrong here? > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cluster analysis
Hi, R has a vast array of tools for cluster analysis. There's even a task view: https://cran.r-project.org/web/views/Cluster.html Which method is best for your needs is going to require you spending some time working to understand the pros and cons, and possibly consulting with a local statistician. Sarah On Sun, Mar 31, 2019 at 4:20 PM bienvenidoz...@gmail.com wrote: > > Hi, > I have data from farmers with different variables. I would like to classify > them according to some variables. Can you help me with "R" to find the best > variables to classify them and how to classify them with "R". Some variables > are numerical others are ordinal. > > Best regards, > Bienvenue > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Coding help for data frame.
I'm glad you figured it out. You do still need to reply to the R-help list, not me, but because you did reply just to me I discovered that your orignal question had an image in it of your desired result, which was stripped by the pliant-text R-help server. So your original email ended with: "Is there anyway of coding if I could arrange like this?" with absolutely no way to know what that was referring to. Please take a look at the posting guide for this list to better understand how to frame good questions, so people can help you. Sarah On Thu, Mar 21, 2019 at 11:42 AM Anaanthan Pillai wrote: > > > Hi, > > I’ve managed to sort out the problem. Yes you are correct, one of the coding > method is using reshape2 > > The coding is as below: > > > library(tidyr) > > comdrug2 <- gather(comdrug, key = DrugType, value = Reduction, DrugX, DrugY) > > head(comdrug2) > ID DrugType Reduction > 1 1DrugX 0.10037492 > 2 2DrugX 0.09631495 > 3 3DrugX 0.07257339 > 4 4DrugX 0.08801665 > 5 5DrugX 0.10589090 > 6 6DrugX 0.10779589 > > tail(comdrug2) > ID DrugType Reduction > 95 45DrugY 0.17670152 > 96 46DrugY 0.13968377 > 97 47DrugY 0.08439656 > 98 48DrugY 0.17640175 > 99 49DrugY 0.17171570 > 100 50DrugY 0.15659558 > > > Alternatively could be done as: > > ## option 2 to combine drug effects into single columnn (Drugtype) > ## (will provide same result) > > comdrug_long <- reshape2::melt(comdrug, id.vars = "ID", >value.name = "HbA1c Reduction", >variable.name = "Types of Drug”) > > > Regards, > > Anaanthan > > > > Begin forwarded message: > > From: Anaanthan Pillai > Subject: Coding help for data frame. > Date: 21 March 2019 at 8:01:27 PM MYT > To: r-help@r-project.org > > Good day, > > #I’ve created hypothetical data for drug X and drug Y whereby both drug have > the ability to have HbA1c reduction. > > set.seed(10) > drugx= rnorm(50, mean = 0.1, sd=0.02) > > set.seed(11) > drugy= rnorm(50, mean=0.15, sd=0.03) > > #And created a data frame, compare drugs (comdrug) of 50 patients for each > drug. > > comdrug= data.frame("ID"=c(1:50), "DrugX"=drugx, "DrugY"=drugy) > > # whereby the data would look like this > > head(comdrug) > > > head(comdrug) > ID DrugX DrugY > 1 1 0.10037492 0.1322691 > 2 2 0.09631495 0.1507978 > 3 3 0.07257339 0.1045034 > 4 4 0.08801665 0.1091204 > 5 5 0.10589090 0.1853547 > 6 6 0.10779589 0.1219755 > > Is there anyway of coding if I could arrange like this? > > > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Coding help for data frame.
Please also copy the R-help email list when you reply. On Thu, Mar 21, 2019 at 10:05 AM Anaanthan Pillai wrote: > > The hypothetical data is about drug x and drug y both we assume as diabetic > drug which can reduce hbaic level (sugar level) > > Currently I have a data frame of 3X50, whereby the columns is (ID, drug x’s > hba1c reduction, drug y’s hba1c reduction) > > I want to reaarrange the data into ID, type of drugs (x or y) and their > corresponding hba1c level. Probably you need the reshape2 package. Can you provide an example of what you expect the resulting data frame to look like? I'm assuming that your sample data is the starting point. Or do you simply need to rbind the two columns together? Sarah > Anand > > Begin forwarded message: > > From: Sarah Goslee > Subject: Re: [R] Coding help for data frame. > Date: 21 March 2019 at 9:56:43 PM MYT > To: Anaanthan Pillai > Cc: r-help > > I'm sorry, I don't understand what you're trying to do with your > hypothetical data. > > Can you expand on what your question is? > > Sarah > > On Thu, Mar 21, 2019 at 9:54 AM Anaanthan Pillai > wrote: > > > Good day, > > #I’ve created hypothetical data for drug X and drug Y whereby both drug have > the ability to have HbA1c reduction. > > set.seed(10) > drugx= rnorm(50, mean = 0.1, sd=0.02) > > set.seed(11) > drugy= rnorm(50, mean=0.15, sd=0.03) > > #And created a data frame, compare drugs (comdrug) of 50 patients for each > drug. > > comdrug= data.frame("ID"=c(1:50), "DrugX"=drugx, "DrugY"=drugy) > > # whereby the data would look like this > > head(comdrug) > > head(comdrug) > > ID DrugX DrugY > 1 1 0.10037492 0.1322691 > 2 2 0.09631495 0.1507978 > 3 3 0.07257339 0.1045034 > 4 4 0.08801665 0.1091204 > 5 5 0.10589090 0.1853547 > 6 6 0.10779589 0.1219755 > > Is there anyway of coding if I could arrange like this? > > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question regarding the dcast function
Hi, dcast() is a function, not a package, so R can't find it in the package archive. You need to install the package that contains it. Probably you want reshape2 install.packages("reshape2") Sarah On Thu, Mar 21, 2019 at 9:54 AM Marie-joe Kfoury wrote: > > Hi, > > > I am having a problem with installing the dcast function in R 3.5.3 > > Here is the message that I am getting when trying to install it: > > > install.packages("dcast") > Installing package into ‘C:/Users/marie/Documents/R/win-library/3.5’ > (as ‘lib’ is unspecified) > Warning message: > package ‘dcast’ is not available (for R version 3.5.3) > > > > Marie Joe Kfoury > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Coding help for data frame.
I'm sorry, I don't understand what you're trying to do with your hypothetical data. Can you expand on what your question is? Sarah On Thu, Mar 21, 2019 at 9:54 AM Anaanthan Pillai wrote: > > Good day, > > #I’ve created hypothetical data for drug X and drug Y whereby both drug have > the ability to have HbA1c reduction. > > set.seed(10) > drugx= rnorm(50, mean = 0.1, sd=0.02) > > set.seed(11) > drugy= rnorm(50, mean=0.15, sd=0.03) > > #And created a data frame, compare drugs (comdrug) of 50 patients for each > drug. > > comdrug= data.frame("ID"=c(1:50), "DrugX"=drugx, "DrugY"=drugy) > > # whereby the data would look like this > > head(comdrug) > > > head(comdrug) > ID DrugX DrugY > 1 1 0.10037492 0.1322691 > 2 2 0.09631495 0.1507978 > 3 3 0.07257339 0.1045034 > 4 4 0.08801665 0.1091204 > 5 5 0.10589090 0.1853547 > 6 6 0.10779589 0.1219755 > > Is there anyway of coding if I could arrange like this? > > > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Weather station data
The VFS package has tools to process GHCN data (https://www.ncdc.noaa.gov/data-access/land-based-station-data/land-based-datasets/global-historical-climatology-network-ghcn). Sarah On Sun, Feb 17, 2019 at 10:02 AM Bernard Comcast wrote: > > Is anyone aware of any R capability to access data at weather stations around > the globe? An R package perhaps? > > Thanks > > Bernard -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R help
There's a bibtex parser for R: you could adapt that for your use, rather than trying to reinvent the equivalent tool. https://cran.r-project.org/web/packages/bibtex/index.html Sarah On Thu, Feb 14, 2019 at 5:57 PM Gouresh Kamble via R-help wrote: > > Dear to whom it may concern on the R team, > > > > I am having an issue with creating a code in which i can hold information > such as the author of a paper, the year of publication, and the title. Also > would like to add into this data frame a logical variable which would show > some keywords I used to find the data. I keep getting stuck on how to create > specific characters for the table. > > > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] periodicity
Hi Nick, A quick look on rseek.org didn't turn anything up. It would help to know what websites you're referring to - they might be loading custom code. Sarah On Wed, Jan 30, 2019 at 2:17 PM Nick Wray via R-help wrote: > > I've found references on websites to an R function "periodicity", but there's > no such built-in function as far as I can see in R studio. I can't find > reference to it being part of any package either. Can anyone help with this? > > Thanks, Nick Wray > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R help: fviz_nbclust’ is not available (for R version 3.5.2)
Hi, fviz_nbclust is a function within the package factoextra. Once you have installed the package and loaded it, you do not need to explicitly install the function. You probably also don't need FunCluster - I think you may be confusing that package with the FUNcluster argument to the fviz_nbclust function. Do take a look at ?fviz_nbclust for help and a working example. library(factoextra) library(NbClust) # Standardize the data load("df4.rda") fviz_nbclust(df4, FUNcluster, method = c("silhouette", "wss", "gap_stat")) Sarah On Wed, Jan 16, 2019 at 2:00 PM N Meriam wrote: > > Hello, > I'm struggling to install a function called "fviz_nbclus". > > My code is the following: > pkgs <- c("factoextra", "NbClust") > install.packages(pkgs) > library(factoextra) > library(NbClust) > # Standardize the data > load("df4.rda") > library(FunCluster) > > install.packages("fviz_nbclust") > #fviz_nbclust(df4, FUNcluster, method = c("silhouette", "wss", "gap_stat")) > > Installing package into ‘C:/Users/DELL/Documents/R/win-library/3.5’ > (as ‘lib’ is unspecified) > Warning in install.packages : > package ‘fviz_nbclust’ is not available (for R version 3.5.2) > > Best, > Meriam > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question
xyplot is not a package, it is a function within the lattice package, which should already be installed. library(lattice) # load the package from the R library ?xyplot # look at the help for the function The others are also functions, not packages. Sarah On Tue, Jan 8, 2019 at 9:15 AM S. Mahmoud Nasrollahi wrote: > Dear colleague > I have got a problem during working with some package in R and in > spite of trying with R help, internet and any other resources I could > not succeed. Indeed when I what to install some function like bwplot, > boxplot, xyplot I receive this sort of messages: > Warning in install.packages : > package ‘xyplot’ is not available (for R version 3.5.2) > Do you know how I can solve that? > > > -- > S. M. Nasrollahi > Postdoctoral Researcher > French National Institute for Agricultural Research > Unite´ Mixte de Recherches sur les Herbivores, > 63122 St Gene`s Champanelle, France > sayyed-mahmoud.nasroll...@inra.fr > Tel: +9826132248082 > Fax: +9826132246752 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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.sarahgoslee.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] you are making it far too difficult
\t is the symbol for a tab. /t is two characters just as it seems. It's highly unlikely your file is delimited with /t, which would look like 1/t2/t3 The help for read.table mentions this tangentially as part of read.delim(), and you can find out more under ?regex - see the section about escaping non-metacharacters with a backslash. Sarah On Thu, Dec 27, 2018 at 4:09 PM Spencer Brackett wrote: > > What is the significance of using / or \ ? > > On Thu, Dec 27, 2018 at 4:02 PM Sarah Goslee wrote: >> >> On Thu, Dec 27, 2018 at 2:03 PM Spencer Brackett >> wrote: >> > >> > Thank you for the help! I tried using the read.table command in my RStudio >> > using the following argument, and managed to open the file. >> > >> > GBM_protein_expression<-read.table(file.choose(), header=TRUE, sep=“/t”) >> >> Note that sep="/t" is NOT the same thing as the sep="\t" you were >> advised to use. >> >> >> >> >> > >> > However, my data did not unpack as yours did. I again only received a table >> > of true and flase distinctions per column, and my environment tab says that >> > there is 0 observations upon 0 variables. >> > >> > I believe I should be getting data similar to what you got, as it would >> > appear that your’s actually contains relevant gene/protein expression info. >> > >> > On Thu, Dec 27, 2018 at 6:21 AM Federico Calboli < >> > federico.calb...@kuleuven.be> wrote: >> > >> > > Once you have your TSV files just use something as >> > > >> > > x = read.table('protein_expression.tsv', h = T, sep = '\t') >> > > >> > > Do not copy paste the code of this email because it is formatted and >> > > would >> > > not work in R. >> > > >> > > >> > > Best >> > > >> > > F >> > > >> > > PS the data looks like this to me >> > > >> > > head(x) >> > > icgc_donor_id project_code icgc_specimen_id icgc_sample_id >> > > submitted_sample_id analysis_idantibody_id gene_name >> > > 1 DO12370 GBM-US SP26475 SA131594 >> > > TCGA-19-5960-01A-13-1900-20 97765 14-3-3_epsilon-M-C YWHAE >> > > 2 DO12370 GBM-US SP26475 SA131594 >> > > TCGA-19-5960-01A-13-1900-20 97765 4E-BP1-R-V EIF4EBP1 >> > > 3 DO12370 GBM-US SP26475 SA131594 >> > > TCGA-19-5960-01A-13-1900-20 977654E-BP1_pS65-R-V EIF4EBP1 >> > > 4 DO12370 GBM-US SP26475 SA131594 >> > > TCGA-19-5960-01A-13-1900-20 977654E-BP1_pT37-R-V EIF4EBP1 >> > > 5 DO12370 GBM-US SP26475 SA131594 >> > > TCGA-19-5960-01A-13-1900-20 977654E-BP1_pT70-R-C EIF4EBP1 >> > > 6 DO12370 GBM-US SP26475 SA131594 >> > > TCGA-19-5960-01A-13-1900-20 97765 53BP1-R-C TP53BP1 >> > > gene_stable_id gene_build_version normalized_expression_level >> > > verification_status verification_platform >> > > 1 NA NA -1.1636330 >> > > not testedNA >> > > 2 NA NA -1.7969721 >> > > not testedNA >> > > 3 NA NA -0.7256390 >> > > not testedNA >> > > 4 NA NA 0.6498421 >> > > not testedNA >> > > 5 NA NA -1.0262844 >> > > not testedNA >> > > 6 NA NA 1.5186400 >> > > not testedNA >> > > platform >> > > 1 M.D. Anderson Reverse Phase Protein Array Core >> > > 2 M.D. Anderson Reverse Phase Protein Array Core >> > > 3 M.D. Anderson Reverse Phase Protein Array Core >> > > 4 M.D. Anderson Reverse Phase Protein Array Core >> > > 5 M.D. Anderson Reverse Phase Protein Array Core >> > > 6 M.D. Anderson Reverse Phase Protein Array Core >> > > >> > > >> > > >> > > experimental_protocol >> > > 1 MDA_RPPA_Core >> > > http://tcga-data.nci.ni
Re: [R] you are making it far too difficult
://tcga-data.nci.nih.gov/tcgafiles/ftp_auth/distro_ftpusers/anonymous/tumor/blca/cgcc/mdanderson.org/mda_rppa_core/protein_exp/mdanderson.org_BLCA.MDA_RPPA_Core.mage-tab.1.7.0/mdanderson.org_BLCA.MDA_RPPA_Core.idf.txt > > raw_data_repository raw_data_accession > > 1TCGA TCGA-19-5960-01A-13-1900-20 > > 2TCGA TCGA-19-5960-01A-13-1900-20 > > 3TCGA TCGA-19-5960-01A-13-1900-20 > > 4TCGA TCGA-19-5960-01A-13-1900-20 > > 5TCGA TCGA-19-5960-01A-13-1900-20 > > 6TCGA TCGA-19-5960-01A-13-1900-20 > > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Retrievable results in a procedure
I'm a bit confused about what you actually want, but I think invisible() might be the answer. Note that there's already a base function try() so that's not a great name for test functions. Sarah On Tue, Dec 25, 2018 at 8:47 AM Steven Yen wrote: > I would like to suppressed printing of retrievable results in a > procedure and to print only when retrieved. > > In line 10 below I call procedure "try" and get matrices A,B,C all > printed upon a call to the procedure. I get around this unwanted > printing by calling with v<-try(A,B) as in line 11. > > Any way to suppress printing of the retrievable results listed in the > structure command? Thank you, and Merry Christmas to all. > > > A<-matrix(rpois(16,lambda=5),nrow=4,byrow=T) > B<-diag(4) > > try<-function(A,B){ > C<-A+B > cat("\nC:\n"); print(C) > structure(list(A=A,B=B,C=C)) > } > > try(A,B)# line 10 > v<-try(A,B) # line 11 > > -- > st...@ntu.edu.tw (S.T. Yen) > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Sarah Goslee (she/her) http://www.sarahgoslee.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with system() and source on linux
Actually, here's another possibility: system('bash -c "source filename"') On Thu, Dec 20, 2018 at 10:13 AM Sarah Goslee wrote: > > Hi, > > I can tell you what the problem is: > > You're probably running bash at the terminal command line, as I am: > > [sarahg@localhost]$ echo $0 > bash > > but the R system function uses sh > > > system("echo $0") > sh > > The bash shell has a source command; the sh shell doesn't. See here > for a possible solution: > > https://stackoverflow.com/questions/4732200/replacement-for-source-in-sh > > > I don't know if there's a way to specify bash shell in system(); a > very cursory googling didn't find anything. If you find a way, please > report back. > > Sarah > > On Thu, Dec 20, 2018 at 10:00 AM Agustin Lobo wrote: > > > > Hi! > > I quite often use system() to run other programs from within R, but > > have just hitted > > a problem: > > > > For a given program, I need to set up its environment, which I normally do > > with > > source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile > > from the terminal. > > Now, when I try to do the same from within R, I get: > > > > > system("source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile", intern=TRUE) > > sh: 1: source: not found > > Error in system("source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile", : > > error in running command > > > > I need this command to set the environment before I actually run the > > program. My idea was saving a simple script from within R in which > > the first line would be > > source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile > > > > and then run the script with system(), but I get that odd error with > > source. I thought source was just > > a plain linux command, how can it be "not found" from within system()? > > > > Any help much appreciated, > > Thanks > > > > > > -- > > Agustin Lobo > > aloboa...@gmail.com > > > > ______ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > -- > Sarah Goslee (she/her) > http://www.numberwright.com -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with system() and source on linux
Hi, I can tell you what the problem is: You're probably running bash at the terminal command line, as I am: [sarahg@localhost]$ echo $0 bash but the R system function uses sh > system("echo $0") sh The bash shell has a source command; the sh shell doesn't. See here for a possible solution: https://stackoverflow.com/questions/4732200/replacement-for-source-in-sh I don't know if there's a way to specify bash shell in system(); a very cursory googling didn't find anything. If you find a way, please report back. Sarah On Thu, Dec 20, 2018 at 10:00 AM Agustin Lobo wrote: > > Hi! > I quite often use system() to run other programs from within R, but > have just hitted > a problem: > > For a given program, I need to set up its environment, which I normally do > with > source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile > from the terminal. > Now, when I try to do the same from within R, I get: > > > system("source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile", intern=TRUE) > sh: 1: source: not found > Error in system("source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile", : > error in running command > > I need this command to set the environment before I actually run the > program. My idea was saving a simple script from within R in which > the first line would be > source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile > > and then run the script with system(), but I get that odd error with > source. I thought source was just > a plain linux command, how can it be "not found" from within system()? > > Any help much appreciated, > Thanks > > > -- > Agustin Lobo > aloboa...@gmail.com > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] extract hyperplan from e1071 model
Hi, Please don't forget to copy R-help on your reply - other people are likely to have more insight. My understanding is that you want to replicate the shaded polygons produced by plot.svm on your own plot. That's why I suggested you first try add=TRUE, and if that doesn't work, then look at the code for plot.svm so you can see how the predicted values are calculated on a grid to be plotted. R is open source - you can extract the section from that function that does what you want, and make your own code to add it to another plot. I have no idea what "the tutorial" is; I suggested two things you could try based on the help and my understanding of R. Sarah On Thu, Dec 20, 2018 at 9:07 AM Luigi Marongiu wrote: > > Dear Sarah, > I have looked at the tutorial but I did not find what I was looking > for. Essentially, I would like to extract the data that make the > hyperplane (it should be a matrix of X,Y value, for a bidimensional > plane, I guess) so I can plot a line in another plot. I tried with > model$SV but it is not the right one. > Luigi > > On Thu, Dec 20, 2018 at 2:59 PM Sarah Goslee wrote: > > > > Hi, > > > > According to the help for svm, which you probably should have started > > with, SV contains the support vectors, and index contains the position > > of the support vectors in the data matrix. > > > > As for plotting, plot.svm lets you pass additional options to plot so > > that you can customize the plot to your tastes. I'm not sure if > > add=TRUE is a useful option there, but you should try it. If that > > doesn't meet your needs, R is open source - you can easily look at the > > code for plot.svm and see what you need (basically the predicted > > values on agrid, if I'm understanding your goal correctly). > > > > Sarah > > > > On Thu, Dec 20, 2018 at 5:16 AM Luigi Marongiu > > wrote: > > > > > > Dear all, > > > I am using the package e1071 for modeling SVM. I obtain a model from > > > the data and I can plot the results; the plot shows the support > > > vectors (as 'X's) and the shaded areas as it should be. > > > However, I don't like the plot generated from the model and I would > > > like instead to have more control upon the plotting; in particular, I > > > would like to draw the hyperplane on plots I have already made from > > > the data available. > > > Is there a way to extract the values that are used to draw the hyperplane? > > > That is: plot(model) -- where model is obtained from svm() -- draws an > > > area in blue and one in red based on some values provided by model; > > > can I get these values so I can plot a line in a pre-existing plot? > > > Also, it is possible to extract the positions of the support vectors? > > > The names of the model generated by svm() are: > > > > names(mod) > > > [1] "call""type""kernel" "cost" > > > [5] "degree" "gamma" "coef0" "nu" > > > [9] "epsilon" "sparse" "scaled" "x.scale" > > > [13] "y.scale" "nclasses""levels" "tot.nSV" > > > [17] "nSV" "labels" "SV" "index" > > > [21] "rho" "compprob""probA" "probB" > > > [25] "sigma" "coefs" "na.action" "fitted" > > > [29] "decision.values" "terms" > > > > > > Which one should I look at? > > > Thank you > > > -- > > > Best regards, > > > Luigi > > > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] extract hyperplan from e1071 model
Hi, According to the help for svm, which you probably should have started with, SV contains the support vectors, and index contains the position of the support vectors in the data matrix. As for plotting, plot.svm lets you pass additional options to plot so that you can customize the plot to your tastes. I'm not sure if add=TRUE is a useful option there, but you should try it. If that doesn't meet your needs, R is open source - you can easily look at the code for plot.svm and see what you need (basically the predicted values on agrid, if I'm understanding your goal correctly). Sarah On Thu, Dec 20, 2018 at 5:16 AM Luigi Marongiu wrote: > > Dear all, > I am using the package e1071 for modeling SVM. I obtain a model from > the data and I can plot the results; the plot shows the support > vectors (as 'X's) and the shaded areas as it should be. > However, I don't like the plot generated from the model and I would > like instead to have more control upon the plotting; in particular, I > would like to draw the hyperplane on plots I have already made from > the data available. > Is there a way to extract the values that are used to draw the hyperplane? > That is: plot(model) -- where model is obtained from svm() -- draws an > area in blue and one in red based on some values provided by model; > can I get these values so I can plot a line in a pre-existing plot? > Also, it is possible to extract the positions of the support vectors? > The names of the model generated by svm() are: > > names(mod) > [1] "call""type""kernel" "cost" > [5] "degree" "gamma" "coef0" "nu" > [9] "epsilon" "sparse" "scaled" "x.scale" > [13] "y.scale" "nclasses""levels" "tot.nSV" > [17] "nSV" "labels" "SV" "index" > [21] "rho" "compprob""probA" "probB" > [25] "sigma" "coefs" "na.action" "fitted" > [29] "decision.values" "terms" > > Which one should I look at? > Thank you > -- > Best regards, > Luigi > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Filtering data with dplyr or grep and losing data?
Hi, What does, "it almost seems like I am losing data mean? Are you losing data? If so, what rows are being excluded that you think should be included? There are 90 rows in the test file that meet your criterion, as far as I can tell, and 90 rows in my R output. So apparently "almost seems like I am losing data" means "I am not losing data but am confused." So we need to know more about what you are expecting but not getting. Sarah On Wed, Dec 19, 2018 at 3:21 PM Satish Vadlamani wrote: > > Hello Experts: > > I have this log file that has about 1200 characters (max) on a line. What I > want to do is read this first and then extract certain portions of the file > into new columns. I want to extract rows that contain the text “[DF_API: > input string]”. When I read it and then filter based on the rows that I am > interested, it almost seems like I am losing data. I tried this using the > dplyr filter and using standard grep with the same result. > > Not sure why this is the case. Appreciate your help with this. The code and > the data is there at the following link. Satish > > Code is given below > > library(dplyr) > setwd("C:/Users/satis/Documents/VF/df_issue_dec01") > > sec1 <- read.delim(file="secondary1_aa_small.log") > head(sec1) > names(sec1) <- c("V1") > sec1_test <- filter(sec1,str_detect(V1,"DF_API: input string")==TRUE) > head(sec1_test) > > sec1_test2 = sec1[grep("DF_API: input string",sec1$V1, perl = TRUE),] > head(sec1_test2) > > write.csv(sec1_test, file = "test_out.txt", row.names = F, quote = F) > write.csv(sec1_test2, file = "test2_out.txt", row.names = F, quote = F) > > Data (and code) is given at the link below. Sorry, I should have used dput. > > https://spaces.hightail.com/space/arJlYkgIev > > > Satish Vadlamani > -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.