Re: [R-es] Tiempo de vida
Pero como har�a el data frame?? Porque las cuchillas son de la misma referencia. En realidad es para ver cada cuanto se gstan las cuchillas y ver que pedidos hay que hacer de las mismas. La tabla que tengo es: 25 enero-> 1 cuchilla gastada 30 enero -> 1 cuchilla gastada 3 de febrero -> 2 cuchillas gastadas 5 de febrero -> 1 cuchilla gastada Y as� No tiene necesariamente que ser gastada en la misma afeitadora, ya que hay 3 cortadoras y los datos de a que cortadora se cambian no son proporcionados y son imposibles de conseguir (ya que esa informaci�n es de un externo). Gracias. Jes�s > Date: Mon, 7 Dec 2015 17:47:45 +0100 > From: gri...@yandex.com > To: j.para.fernan...@hotmail.com; r-help-es@r-project.org > Subject: Re: [R-es] Tiempo de vida > > Hola: > > On Mon, 7 Dec 2015 16:34:14 +0100 > Jes�s Para Fern�ndezwrote: > > > Los datos no son de desgaste de cuchilla, sino de consumo de las mismas. > > > > Por ello tengo los datos de la siguiente forma: > > > > Unidades cambiadasFecha > > > > > > En unidades cambiadas, suele ser una y en fecha el dia que se hizo el > > cmabio. > > No seria: > > TIEMPO: Fecha que se coloca una cuchilla nueva hasta que se cambia. > ESTADO: Siempre 1 (siempre se cambia): no existen censuras. > > y un registro para cada cuchilla. > > Servir�a? > > Saludos. > > > > > Con eso no se muy bien como estructurar los datos para hacer el an�lisis. > > > > Gracias > > Jes�s > > > > > > > > > Date: Mon, 7 Dec 2015 16:27:18 +0100 > > > From: gri...@yandex.com > > > To: j.para.fernan...@hotmail.com > > > CC: r-help-es@r-project.org > > > Subject: Re: [R-es] Tiempo de vida > > > > > > Hola: > > > > > > On Mon, 7 Dec 2015 15:12:24 +0100 > > > Jes__s Para Fern__ndez wrote: > > > > > > > Buenas, > > > > > > > > Como pudeo calcular el tiempo de vida? Os cuento, tengo una serie de > > > > cuchillas y quiero ver el consumo de las mismas y he pensado en hacer > > > > un estudio por tiempo de vida. No se como hacerlo con R > > > > > > Has una tabla de datos con 4 columnas: > > > > > > 1. Fecha que se empieza a utilizar la cuchilla > > > 2. Fecha de la �ltima revisi�n de la cuchilla > > > 3. TIEMPO: el tiempo transcurrido entre las dos fechas anteriores > > > 4. ESTADO: estado de la cuchilla cuando se revis� la �ltima vez: > > > 0 = Buen estado > > > 1 = Para tirar > > > > > > Y utiliza el m�todo kaplan-meier: > > > > > > library(survival) > > > KM <- survfit(Surv(DATO$TIEMPO, DATOS$ESTADO) ~ 1) > > > summary(KM) > > > plot(KM) > > > > > > Un ejemplo: > > > > > > > library(survival) > > > > AML.KM <- survfit(Surv(aml$time, aml$status) ~ 1) > > > > summary(AML.KM) > > > Call: survfit(formula = Surv(aml$time, aml$status) ~ 1) > > > > > > time n.risk n.event survival std.err lower 95% CI upper 95% CI > > > 5 23 2 0,9130 0,0588 0,80491,000 > > > 8 21 2 0,8261 0,0790 0,68480,996 > > > 9 19 1 0,7826 0,0860 0,63100,971 > > >12 18 1 0,7391 0,0916 0,57980,942 > > >13 17 1 0,6957 0,0959 0,53090,912 > > >18 14 1 0,6460 0,1011 0,47530,878 > > >23 13 2 0,5466 0,1073 0,37210,803 > > >27 11 1 0,4969 0,1084 0,32400,762 > > >30 9 1 0,4417 0,1095 0,27170,718 > > >31 8 1 0,3865 0,1089 0,22250,671 > > >33 7 1 0,3313 0,1064 0,17650,622 > > >34 6 1 0,2761 0,1020 0,13380,569 > > >43 5 1 0,2208 0,0954 0,09470,515 > > >45 4 1 0,1656 0,0860 0,05980,458 > > >48 2 1 0,0828 0,0727 0,01480,462 > > > > plot(AML.KM) > > > > > > Dibuja la curva de supervivencia con el intervalo de confianza. > > > > > > Espero que te sea �til. > > > > > > Saludos. > > > > > > > > > > > > > > > > > > > > Gracias > > > > Jes_s > > > > > > > > [[alternative HTML version deleted]] > > > > > > [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
Re: [R] metafor package
Hi John, Please keep r-help copied on the reply. What's the 'previous model'? How do you get estimates within subgroups that 'includes the overall effect'? I really cannot follow you here. Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com > -Original Message- > From: John Peterson [mailto:john.peterson@gmail.com] > Sent: Monday, December 07, 2015 22:14 > To: Viechtbauer Wolfgang (STAT) > Subject: Re: [R] metafor package > > Hi Dr. Viechtbauer, > Thank you very much for your reply. I tried your advice and was able to > make a forest plot with only the estimates for each subgroup.For the > estiamte for each subgroup, similar to the previous model, I random > effects model within each subgroup. However, I now find the result for > the estiamte within subgroup to be different thant the result for the > previous model. I have tried analyzing this in STATA and I get the same > result as the model which includes the overall effect. Any advice on what > may be wrong here? Thanks greatly, > John > > On 7 December 2015 at 04:02, Viechtbauer Wolfgang (STAT) >wrote: > The code you posted is totally mangled up, but it's just what can be > found here: > > http://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups > > If you don't want an overall estimate, just pass the estimates and > corresponding sampling variances to the forest() function (and not the > model object). Use the 'rows' argument to specify where the estimates > will be placed and adjust 'ylim' so give you enough space to leave gaps > for headings and the subgroup estimates. Then fit models within the > subgroups (the 'subset' argument is useful here) and use addpoly() to add > the subgroup estimates in the appropriate rows. With text(), you can add > headings as needed. > > If you use weights() on each subgroup model object, you can get the > subgroup weights (that add up to 100% within each subgroup). It's > probably easiest to just add those values with text() in an appropriate > place to the plot. > > Best, > Wolfgang > > -- > Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and > Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD > Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com > > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of John > > Peterson > > Sent: Monday, December 07, 2015 01:39 > > To: r-help@r-project.org > > Subject: [R] metafor package > > > > Hi Everyone, > > > > I am conducting a meta-analysis using the metafor package. I am > > interested > > in obtaining an estimate by subgroup only without showing an overall > > effect. This is directly from the metafor website. How would i modify > > this > > code to only show subgroup effects? Further, I want to show weights by > > subgroup. The option showweights=TRUE does not display weights by > > subgroup > > but by the weight of each study in comparison to all studies (and not > the > > subgroup). You help would be appreciated. [snip garbled code] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing data by targeting in filenames inside a nested list
Hi Mario, It is at the limit of my skills so I'm not sure this will be a real solution. But it might help you anyway (and there will be more competent people anyway). What does not make sense to me is why you set the names of your files and then use them to list them with list.files() What don't you just do electrical_meas_files <- list.files(path, pattern) and define a pattern if you don't want to read all of them? For the next step, I don't think you need to lapply() at all; it is already in the loop. I usually prefer loops to lapply() because I find it more intuitive. But your lapply() solution would work as well. So I think that your code is somewhat redundant (but I might have missed something). This should do it: #first define your output data list that will be iteratively filled, this will increase speed electrical_meas_raw_data <- vector(mode="list", length=length(electrical_meas_files)) #then read the files (seq_along() is great) for(i in seq_along(measurement_filenames)){ electrical_meas_raw_data[[i]] <- read.xlsx(file=electrical_meas_files[[i]], sheetName="Data", header=TRUE, as.data.frame =TRUE, stringsAsFactors = F) } HTH, Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/12/15 12:29, BARLAS Marios 247554 a écrit : Hello everyone, So, rookie me is trying to write a smart code, so here's what I'm doing: I have a list of a couple of hundrend files, some of which refer to different experiments. The naming of the file refers to the experiment and the serial number to the topological reference on my sample. Performing my data analysis in 1 file class at a time looks OK, so I'm trying to generalize my code. I figured out I could group them together by performing a pattern read on a nested list, which works for getting the file names and grouping them but then I'm getting some problems when I try to perform the import from the nested list. My code looks like this: # Vector containing file name patterns to be read and grouped together measurement_filenames <- c("*Q_Read_prist*", "*Quasi_Forming*", "*read_set#1*","*Q_Reset_pForm#1*","*read_reset#2*","*quasistatic_set*", "*read_set#2*", "*quasistatic_reset#2*" ) # Create a list of the files to be read in sorted in a natural fashion electrical_meas_files <- lapply(measurement_filenames, function(x) naturalsort(list.files(path, pattern=x))) names(electrical_meas_files) <- measurement_filenames # Perform data import for each element for(i in 1:length(measurement_filenames)) { electrical_meas_raw_data[[i]] <- lapply(electrical_meas_files[[i]], function(x) read.xlsx(file=x, sheetName="Data", header=TRUE, as.data.frame =TRUE, stringsAsFactors = F) ) } My idea is to come up with a nested list of the structure {list of different experiments} {list of all sites where the experiment was run} {set of dataframes with all data for each site} Do I make sense or am I over-complicating the situation ? Any ideas how I could write this piece of code or improve it ? Thanks in advance, Mario __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Importing data by targeting in filenames inside a nested list
Hello everyone, So, rookie me is trying to write a smart code, so here's what I'm doing: I have a list of a couple of hundrend files, some of which refer to different experiments. The naming of the file refers to the experiment and the serial number to the topological reference on my sample. Performing my data analysis in 1 file class at a time looks OK, so I'm trying to generalize my code. I figured out I could group them together by performing a pattern read on a nested list, which works for getting the file names and grouping them but then I'm getting some problems when I try to perform the import from the nested list. My code looks like this: # Vector containing file name patterns to be read and grouped together measurement_filenames <- c("*Q_Read_prist*", "*Quasi_Forming*", "*read_set#1*","*Q_Reset_pForm#1*","*read_reset#2*","*quasistatic_set*", "*read_set#2*", "*quasistatic_reset#2*" ) # Create a list of the files to be read in sorted in a natural fashion electrical_meas_files <- lapply(measurement_filenames, function(x) naturalsort(list.files(path, pattern=x))) names(electrical_meas_files) <- measurement_filenames # Perform data import for each element for(i in 1:length(measurement_filenames)) { electrical_meas_raw_data[[i]] <- lapply(electrical_meas_files[[i]], function(x) read.xlsx(file=x, sheetName="Data", header=TRUE, as.data.frame =TRUE, stringsAsFactors = F) ) } My idea is to come up with a nested list of the structure {list of different experiments} {list of all sites where the experiment was run} {set of dataframes with all data for each site} Do I make sense or am I over-complicating the situation ? Any ideas how I could write this piece of code or improve it ? Thanks in advance, Mario __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] metafor package
Hi Dr. Viechtbauer, The code provided in the metafor projects website for subgroup includes fitting a random effects model on the entire dataset and fitting a random effects model within subgroups. When I exactly follow this code, my estimates and confidence intervals for estimate within each subgroup matches with what I get in STATA so it seems to be the correct estimate (and CI). However, I don't want to present an overall effect and I want to present only the effect within each subgroup. In my second attempt, I did not run a random effects model within the entire dataset and only ran the models within each subgroup. I generated a variable corresponding to the estimate(risk ratio) and standard error which I plugged in the forest() function (i.e. forest(rr, se, .). When I run this code, the estimate I get for each subgroup is slightly different than the estimate I get for each subgroup in comparison to when I also included the random effects model for the overall effect. (i.e. my first attempt). Is this the right approach? I was not clear when you said passing the estimates and sampling variances to the forest() function. I created a variable corresponding to the estimate and standard error and plugged those in the forest() function. I am not sure if this is the right approach. Thanks, John On 8 December 2015 at 03:47, Viechtbauer Wolfgang (STAT) < wolfgang.viechtba...@maastrichtuniversity.nl> wrote: > Hi John, > > Please keep r-help copied on the reply. > > What's the 'previous model'? How do you get estimates within subgroups > that 'includes the overall effect'? I really cannot follow you here. > > Best, > Wolfgang > > -- > Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and > Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD > Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com > > > -Original Message- > > From: John Peterson [mailto:john.peterson@gmail.com] > > Sent: Monday, December 07, 2015 22:14 > > To: Viechtbauer Wolfgang (STAT) > > Subject: Re: [R] metafor package > > > > Hi Dr. Viechtbauer, > > Thank you very much for your reply. I tried your advice and was able to > > make a forest plot with only the estimates for each subgroup.For the > > estiamte for each subgroup, similar to the previous model, I random > > effects model within each subgroup. However, I now find the result for > > the estiamte within subgroup to be different thant the result for the > > previous model. I have tried analyzing this in STATA and I get the same > > result as the model which includes the overall effect. Any advice on what > > may be wrong here? Thanks greatly, > > John > > > > On 7 December 2015 at 04:02, Viechtbauer Wolfgang (STAT) > >wrote: > > The code you posted is totally mangled up, but it's just what can be > > found here: > > > > http://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups > > > > If you don't want an overall estimate, just pass the estimates and > > corresponding sampling variances to the forest() function (and not the > > model object). Use the 'rows' argument to specify where the estimates > > will be placed and adjust 'ylim' so give you enough space to leave gaps > > for headings and the subgroup estimates. Then fit models within the > > subgroups (the 'subset' argument is useful here) and use addpoly() to add > > the subgroup estimates in the appropriate rows. With text(), you can add > > headings as needed. > > > > If you use weights() on each subgroup model object, you can get the > > subgroup weights (that add up to 100% within each subgroup). It's > > probably easiest to just add those values with text() in an appropriate > > place to the plot. > > > > Best, > > Wolfgang > > > > -- > > Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and > > Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD > > Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com > > > > > -Original Message- > > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of John > > > Peterson > > > Sent: Monday, December 07, 2015 01:39 > > > To: r-help@r-project.org > > > Subject: [R] metafor package > > > > > > Hi Everyone, > > > > > > I am conducting a meta-analysis using the metafor package. I am > > > interested > > > in obtaining an estimate by subgroup only without showing an overall > > > effect. This is directly from the metafor website. How would i modify > > > this > > > code to only show subgroup effects? Further, I want to show weights by > > > subgroup. The option showweights=TRUE does not display weights by > > > subgroup > > > but by the weight of each study in comparison to all studies (and not > > the > > > subgroup). You help would be appreciated. > > [snip garbled code] > > [[alternative HTML version deleted]] __
[R] Error while using e1071 package
I am using R 3.2.2 on win-7 while using predict function with e1071 (naive bayes classifier) I am getting the following error "Error in object$tables[[v]][, nd] : subscript out of bounds" pl help. regards Parth __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] metafor package
The first and second argument of forest() (or more precisely, forest.default()) are for the estimates and the corresponding sampling variances, respectively. So, if you do forest(rr, se, ...), then the function will interpret the standard errors as if they are variances. So, you should do forest(rr, sei=se, ...). And just in case: In all likelihood, those SEs are for the *log-transformed* risk ratios, so you should also pass log-transformed risk ratios to the function (and then use 'atransf=exp' so results are shown with back-transformed x-axis labels and annotations). Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com > -Original Message- > From: John Peterson [mailto:john.peterson@gmail.com] > Sent: Tuesday, December 08, 2015 14:25 > To: Viechtbauer Wolfgang (STAT) > Cc: R-help@r-project.org > Subject: Re: [R] metafor package > > Hi Dr. Viechtbauer, > > The code provided in the metafor projects website for subgroup includes > fitting a random effects model on the entire dataset and fitting a random > effects model within subgroups. When I exactly follow this code, my > estimates and confidence intervals for estimate within each subgroup > matches with what I get in STATA so it seems to be the correct estimate > (and CI). However, I don't want to present an overall effect and I want > to present only the effect within each subgroup. In my second attempt, I > did not run a random effects model within the entire dataset and only ran > the models within each subgroup. I generated a variable corresponding to > the estimate(risk ratio) and standard error which I plugged in the > forest() function (i.e. forest(rr, se, .). When I run this code, the > estimate I get for each subgroup is slightly different than the estimate > I get for each subgroup in comparison to when I also included the random > effects model for the overall effect. (i.e. my first attempt). Is this > the right approach? I was not clear when you said passing the estimates > and sampling variances to the forest() function. I created a variable > corresponding to the estimate and standard error and plugged those in the > forest() function. I am not sure if this is the right approach. Thanks, > > John > > On 8 December 2015 at 03:47, Viechtbauer Wolfgang (STAT) >wrote: > Hi John, > > Please keep r-help copied on the reply. > > What's the 'previous model'? How do you get estimates within subgroups > that 'includes the overall effect'? I really cannot follow you here. > > Best, > Wolfgang > > -- > Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and > Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD > Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com > > > -Original Message- > > From: John Peterson [mailto:john.peterson@gmail.com] > > Sent: Monday, December 07, 2015 22:14 > > To: Viechtbauer Wolfgang (STAT) > > Subject: Re: [R] metafor package > > > > Hi Dr. Viechtbauer, > > Thank you very much for your reply. I tried your advice and was able to > > make a forest plot with only the estimates for each subgroup.For the > > estiamte for each subgroup, similar to the previous model, I random > > effects model within each subgroup. However, I now find the result for > > the estiamte within subgroup to be different thant the result for the > > previous model. I have tried analyzing this in STATA and I get the same > > result as the model which includes the overall effect. Any advice on > what > > may be wrong here? Thanks greatly, > > John > > > > On 7 December 2015 at 04:02, Viechtbauer Wolfgang (STAT) > > wrote: > > The code you posted is totally mangled up, but it's just what can be > > found here: > > > > http://www.metafor- > project.org/doku.php/plots:forest_plot_with_subgroups > > > > If you don't want an overall estimate, just pass the estimates and > > corresponding sampling variances to the forest() function (and not the > > model object). Use the 'rows' argument to specify where the estimates > > will be placed and adjust 'ylim' so give you enough space to leave gaps > > for headings and the subgroup estimates. Then fit models within the > > subgroups (the 'subset' argument is useful here) and use addpoly() to > add > > the subgroup estimates in the appropriate rows. With text(), you can > add > > headings as needed. > > > > If you use weights() on each subgroup model object, you can get the > > subgroup weights (that add up to 100% within each subgroup). It's > > probably easiest to just add those values with text() in an appropriate > > place to the plot. > > > > Best, > > Wolfgang > > > > -- > > Wolfgang Viechtbauer, Ph.D., Statistician
[R] column means dropping column minimum
Suppose I have something like the following dataframe: samp1 <- c(60,50,20,90) samp2 <- c(60,60,90,58) samp3 <- c(25,65,65,90) test <- data.frame(samp1,samp2,samp3) I want to calculate column means. Easy enough, if I want to use all the data within each column: print(colMeans(test),na.rm = TRUE) However, I'm danged if I can figure out how to do the same thing after dropping the minimum value for each column. For example, column 1 in the dataframe test consists of 60, 50,20,90. I want to calculate the mean over (60,50,90), dropping the minimum value (20). Figuring out what the minimum value is in a single column is easy, but I can't figure out how to arm-twist colMeans into 'applying itself' to the elements of a column greater than the minimum, for each column in turn. I've tried permutations of select, subset etc., to no avail. Only thing I can think of is to (i) find the minimum in a column, (ii) change it to NA, and then (iii) tell colMeans to na.rm = TRUE): test2 <- test for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]==NA} print(test2) print(colMeans(test2),na.rm = TRUE) While this works, seems awfully 'clunky' -- is there a better way? Thanks in advance... __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] column means dropping column minimum
There is a bug in your code: it is not > for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]==NA} but for (i in 1:ncos(test)) { test2[which.min(test[, i]), i] <- NA } Otherwise, a solution would be to create your own function to compute the mean of a vector without the smallest value: meanNoMin <- function (x, na.rm = FALSE) mean(sort(x)[-1], na.rm = na.rm) … and then, to apply it to all columns of your data frame: sapply(test, meanNoMin, na.rm = TRUE) If you need faster code, you may want to look at Rcpp and a C++ version of the previous code, but it is much more work. Best, Philippe Grosjean > On 08 Dec 2015, at 15:29, Evan Coochwrote: > > Suppose I have something like the following dataframe: > > samp1 <- c(60,50,20,90) > samp2 <- c(60,60,90,58) > samp3 <- c(25,65,65,90) > > test <- data.frame(samp1,samp2,samp3) > > I want to calculate column means. Easy enough, if I want to use all the data > within each column: > > > print(colMeans(test),na.rm = TRUE) > > > However, I'm danged if I can figure out how to do the same thing after > dropping the minimum value for each column. For example, column 1 in the > dataframe test consists of 60, 50,20,90. I want to calculate the mean over > (60,50,90), dropping the minimum value (20). Figuring out what the minimum > value is in a single column is easy, but I can't figure out how to arm-twist > colMeans into 'applying itself' to the elements of a column greater than the > minimum, for each column in turn. I've tried permutations of select, subset > etc., to no avail. Only thing I can think of is to (i) find the minimum in a > column, (ii) change it to NA, and then (iii) tell colMeans to na.rm = TRUE): > > test2 <- test > > for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]==NA} > > print(test2) > > print(colMeans(test2),na.rm = TRUE) > > > While this works, seems awfully 'clunky' -- is there a better way? > > Thanks in advance... > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] column means dropping column minimum
First, your code has flaws in the assignment of NA and in passing na.rm=TRUE to colMeans(). It should be: test2 <- test for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]=NA} print(test2) samp1 samp2 samp3 16060NA 2506065 3NA9065 490NA90 print(colMeans(test2,na.rm = TRUE)) samp1samp2samp3 66.7 70.0 73.3 For your purpose, I suggest the following: apply(test, 2, function(x) { mean(x[-which.min(x)])}) GG [[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] column means dropping column minimum
The which.min() only gets the first minimum value. If two or more values are tied for the minimum, it will delete only the first one. This would get them all: > apply(test, 2, function(x) mean(x[-which(x == min(x))])) samp1samp2samp3 66.7 70.0 73.3 - David L Carlson Department of Anthropology Texas A University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Giorgio Garziano Sent: Tuesday, December 8, 2015 12:58 PM To: r-help@r-project.org Subject: Re: [R] column means dropping column minimum First, your code has flaws in the assignment of NA and in passing na.rm=TRUE to colMeans(). It should be: test2 <- test for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]=NA} print(test2) samp1 samp2 samp3 16060NA 2506065 3NA9065 490NA90 print(colMeans(test2,na.rm = TRUE)) samp1samp2samp3 66.7 70.0 73.3 For your purpose, I suggest the following: apply(test, 2, function(x) { mean(x[-which.min(x)])}) GG [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in loading the drc package
Hi all, When trying to load the drc package. I got the following error. Any suggestions? Thanks. Hanna > install.packages("drc", dependencies=TRUE) --- Please select a CRAN mirror for use in this session --- trying URL 'https://cran.fhcrc.org/bin/windows/contrib/3.1/drc_2.5-12.zip' Content type 'application/zip' length 502776 bytes (490 Kb) opened URL downloaded 490 Kb package ‘drc’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\Temp\Rtmpysroid\downloaded_packages > library(drc) Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘Matrix’ 1.1-3 is already loaded, but >= 1.1.5 is required In addition: Warning message: package ‘drc’ was built under R version 3.1.3 Error: package or namespace load failed for ‘drc’ > [[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] [FORGED] Error in loading the drc package
On 09/12/15 08:32, li li wrote: Hi all, When trying to load the drc package. I got the following error. Any suggestions? Yes. Read the error message cheers, Rolf Turner Thanks. Hanna install.packages("drc", dependencies=TRUE) --- Please select a CRAN mirror for use in this session --- trying URL 'https://cran.fhcrc.org/bin/windows/contrib/3.1/drc_2.5-12.zip' Content type 'application/zip' length 502776 bytes (490 Kb) opened URL downloaded 490 Kb package ‘drc’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\Temp\Rtmpysroid\downloaded_packages library(drc) Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘Matrix’ 1.1-3 is already loaded, but >= 1.1.5 is required In addition: Warning message: package ‘drc’ was built under R version 3.1.3 Error: package or namespace load failed for ‘drc’ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [FORGED] Error in loading the drc package
Thanks. 2015-12-08 15:20 GMT-05:00 Rolf Turner: > > Please keep communications on-list. Others may have relevant comments and > suggestions to make. > > > On 09/12/15 09:00, li li wrote: > >> Thanks for the reply. So a newer version of R can solve the problem? But >> I was able to successfully load the package yesterday. >> Thanks. >> > > I have no access to your system so I cannot advise. Apparently > *something* changed with your system between sometime yesterday and > whenever you got the error. Only you are in a position to know what > changed. > > However that is probably irrelevant. Just > > * update R > * update (re-install) the drc package > > and things should work without errors or warnings. > > cheers, > > Rolf Turner > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > [[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] [FORGED] Error in loading the drc package
Please keep communications on-list. Others may have relevant comments and suggestions to make. On 09/12/15 09:00, li li wrote: Thanks for the reply. So a newer version of R can solve the problem? But I was able to successfully load the package yesterday. Thanks. I have no access to your system so I cannot advise. Apparently *something* changed with your system between sometime yesterday and whenever you got the error. Only you are in a position to know what changed. However that is probably irrelevant. Just * update R * update (re-install) the drc package and things should work without errors or warnings. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why mean is not working in by?
Sarah: Note that (as I read them) aggregate() and by() work differently on data frames. aggregate() computes FUN column by column while by() feeds the whole (subset) data frame to FUN. If I am wrong about this, I would greatly appreciate being corrected. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Dec 8, 2015 at 3:09 PM, Bert Gunterwrote: > Because you are using by() incorrectly. > > "A data frame is split by row into **data frames** subsetted by the > values of one or more factors, and function FUN is applied to each > subset in turn." > > So your FUN is applied to a subset of the data frame (which is also a > list). Note that sum, min, and max have "..." as their initial > arguments and so use all the columns in the data frame of each subset > for var() takes the covariance matrix of the several columns and > summary.data.frame summarizes each column. mean() and sd() must be fed > a numeric vector as their first argument, which a data frame is not -- > ergo the error. > > Cheers, > Bert > > > Bert Gunter > > "Data is not information. Information is not knowledge. And knowledge > is certainly not wisdom." >-- Clifford Stoll > > > On Tue, Dec 8, 2015 at 2:30 PM, Dimitri Liakhovitski > wrote: >> Hello! >> Could you please explain why the first 5 lines work but the last 2 lines >> don't? >> Thank you! >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = var) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = max) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = min) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) >> >> -- >> Dimitri Liakhovitski >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why mean is not working in by?
by() calls FUN with a data.frame as the argument. summary(), sum(), etc. have methods that work on data.frames but sd() and mean() do not. aggregate() calls its FUN with each column of a data.frame as the argument. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 8, 2015 at 3:08 PM, Dimitri Liakhovitski < dimitri.liakhovit...@gmail.com> wrote: > Sorry, I omitted the first line: > > myvars <- c("Sepal.Length", "Sepal.Width") > by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) > by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) > by(data = iris[myvars], INDICES = iris["Species"], FUN = var) > by(data = iris[myvars], INDICES = iris["Species"], FUN = max) > by(data = iris[myvars], INDICES = iris["Species"], FUN = min) > > by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) > by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) > > The first lines are doing what I expected them to do: for each level > of the factor "Species" they gave me a summary, a sum, a variance, a > max, a min for each of the 2 variables in question (myvars). > I expected by to generate the sd and the mean for the 2 variables in > question for each level of "Species". > > On Tue, Dec 8, 2015 at 5:50 PM, Sarah Goslee> wrote: > > Hi Dimitri, > > > > I changed this into a reproducible example (we don't know what myvars > > is). Assuming length(myvars) > 1, I'm not convinced that your first > > five lines "work" either: what do you expect? > > > > I get: > > > >> by(data = iris[, -5], INDICES = iris["Species"], FUN = min) > > Species: setosa > > [1] 0.1 > > -- > > Species: versicolor > > [1] 1 > > -- > > Species: virginica > > [1] 1.4 > > > > But was expecting: > > > >> aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=min) > > Species Sepal.Length Sepal.Width Petal.Length Petal.Width > > 1 setosa 4.3 2.3 1.0 0.1 > > 2 versicolor 4.9 2.0 3.0 1.0 > > 3 virginica 4.9 2.2 4.5 1.4 > > > > > > > > aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=sd) > > aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=mean) > > > > provide the answers I would expect. If you want clearer advice, you > > need to provide an actually reproducible example, and tell us more > > about what you expect to get. > > > > Sarah > > > > > > On Tue, Dec 8, 2015 at 5:30 PM, Dimitri Liakhovitski > > wrote: > >> Hello! > >> Could you please explain why the first 5 lines work but the last 2 > lines don't? > >> Thank you! > >> > >> by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) > >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) > >> by(data = iris[myvars], INDICES = iris["Species"], FUN = var) > >> by(data = iris[myvars], INDICES = iris["Species"], FUN = max) > >> by(data = iris[myvars], INDICES = iris["Species"], FUN = min) > >> > >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) > >> by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) > >> > >> -- > >> Dimitri Liakhovitski > >> > > > > -- > Dimitri Liakhovitski > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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.
[R] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
hello all, I intend transfer a big data.frame, more than 1e4 rows, more than 100 columns... I found solutions (in internet and help pages) for small data.frame like the showed bellow. Big data.frames is very expensive in computation time in my approach I would like to optimize this transfer anyway ... I saw a function named "as.tclObj" that seems to me a promising form but hard to code... Somebody know a way more clever to do it? thanks for tips cleber ## library( tcltk ) nrow <- 10 ; ncol <- 100 # simulated data: data is originally a data frame DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) ## # DF_tcl <- as.tclObj( as.matrix( DF ) ) tableDataTclArray <- tclArray() for( i in 1:nrow( DF ) ) tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) for( i in 1:ncol( DF ) ) tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) for( i in 1:nrow( DF ) ) for( j in 1:ncol( DF ) ) tableDataTclArray[[ i, j ]] <- DF[i,j] ## ## ## ## # my full code: ### library( tcltk ); tclRequire("Tktable") wDataOrg <- tktoplevel() tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, 15 ) ) height <- -1; width <- -1 nrowDefault <- 1e4+1; ncolDefault <- 100+1 tableDataTclArray <- tclArray() tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, cols=ncolDefault, height=height+1,width=width+1, xscrollcommand=function(...) tkset( scrX, ... ), yscrollcommand=function(...) tkset( scrY, ... ), rowstretchmode='unset', colstretchmode='unset', multiline=0, cache=1, background="white", selectmode="extended", selecttitle=0, font='{Arial} 10', ipadx=5, ipady=5, anchor='e', borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', variable=tableDataTclArray ) tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) tcl( tableData, "tag", "coltag", "coltitle", "0" ) tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', relief="raised", state='disabled' ) tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) tcl( tableData, "width", "0", "20" ) scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) tkxview( tableData, ... ) ) scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) tkyview( tableData, ... ) ) scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, scrYwidth + 2) ) tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" ) tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) ## expensive time computation [[elided Yahoo spam]] DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) simulated data for( i in 1:nrow( DF ) ){ tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) } for( i in 1:ncol( DF ) ){ tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) } for( i in 1:nrow( DF ) ) { for( j in 1:ncol( DF ) ){ tableDataTclArray[[ i, j ]] <- DF[i,j] } } # --- Este email foi escaneado pelo Avast antivírus. https://www.avast.com/antivirus __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
Are you sure this is the right way to go for your use case? Even if you got a quick solution to display an 1e4 x 100 table in TkTable, what is the purpose of it? Will the user browse the whole dataset that way? Even if the answer is yes, you would probably need to implement sorting and filtering features to ease access to the data… and you will end up reinventing a database. Have you considered to put your data in, say SQLite, using RSQLite? Then, you could feed your data page by page (10, 20, 50, or 100 items per page) into your TkTable widget. You still you will got a bunch of programming in tcltk. But it may be a necessity if you have to integrate the table display in a larger Tk GUI. Another approach, still with the database backend, is to use HTML + Javascript and the numerous solutions that exist to display the content of your database. If you need close interaction with R, you may like the Shiny reactive programming approach. Look at the DT package, although I have not tested it with very large tables. Best, Philippe Grosjean > On 09 Dec 2015, at 01:37, Cleber N.Borgeswrote: > > hello all, > I intend transfer a big data.frame, more than 1e4 rows, more than 100 > columns... > I found solutions (in internet and help pages) for small data.frame like the > showed bellow. > Big data.frames is very expensive in computation time in my approach > I would like to optimize this transfer anyway ... > I saw a function named "as.tclObj" that seems to me a promising form but hard > to code... > Somebody know a way more clever to do it? > > thanks for tips > cleber > > ## > library( tcltk ) > nrow <- 10 ; ncol <- 100 > # simulated data: data is originally a data frame > DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) > ## > # DF_tcl <- as.tclObj( as.matrix( DF ) ) > > tableDataTclArray <- tclArray() > for( i in 1:nrow( DF ) ) >tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( > DF )[ i ] , '"') ) ) > > for( i in 1:ncol( DF ) ) >tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( > DF )[ i ] , '"') ) ) > > > for( i in 1:nrow( DF ) ) >for( j in 1:ncol( DF ) ) >tableDataTclArray[[ i, j ]] <- DF[i,j] > ## > > > > > > ## > ## > ## > # my full code: > ### > library( tcltk ); tclRequire("Tktable") > wDataOrg <- tktoplevel() > tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) > fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, > 15 ) ) > height <- -1; width <- -1 > nrowDefault <- 1e4+1; ncolDefault <- 100+1 > tableDataTclArray <- tclArray() > tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, > cols=ncolDefault, > height=height+1,width=width+1, > xscrollcommand=function(...) tkset( scrX, ... ), > yscrollcommand=function(...) tkset( scrY, ... ), > rowstretchmode='unset', colstretchmode='unset', > multiline=0, cache=1, > background="white", selectmode="extended", selecttitle=0, > font='{Arial} 10', ipadx=5, ipady=5, anchor='e', > borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', > variable=tableDataTclArray ) > tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) > tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) > tcl( tableData, "tag", "coltag", "coltitle", "0" ) > tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', > relief="raised", state='disabled' ) > tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', > relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) > tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', > relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) > tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) > tcl( tableData, "width", "0", "20" ) > scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) > tkxview( tableData, ... ) ) > scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) > tkyview( tableData, ... ) ) > scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) > tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, > scrYwidth + 2) ) > tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) > tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" ) > tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) > ## expensive time computation > [[elided Yahoo spam]] > DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) > simulated data > for( i in 1:nrow( DF ) ){ >tableDataTclArray[[ i, 0 ]] <- .Tcl(
Re: [R] Why mean is not working in by?
Got it - thank you, everybody! by splits it into data frames. Lesson: use aggregate. On Tue, Dec 8, 2015 at 6:17 PM, William Dunlapwrote: > by() calls FUN with a data.frame as the argument. summary(), sum(), etc. > have methods that work on data.frames but sd() and mean() do not. > > aggregate() calls its FUN with each column of a data.frame as the argument. > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Tue, Dec 8, 2015 at 3:08 PM, Dimitri Liakhovitski > wrote: >> >> Sorry, I omitted the first line: >> >> myvars <- c("Sepal.Length", "Sepal.Width") >> by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = var) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = max) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = min) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) >> >> The first lines are doing what I expected them to do: for each level >> of the factor "Species" they gave me a summary, a sum, a variance, a >> max, a min for each of the 2 variables in question (myvars). >> I expected by to generate the sd and the mean for the 2 variables in >> question for each level of "Species". >> >> On Tue, Dec 8, 2015 at 5:50 PM, Sarah Goslee >> wrote: >> > Hi Dimitri, >> > >> > I changed this into a reproducible example (we don't know what myvars >> > is). Assuming length(myvars) > 1, I'm not convinced that your first >> > five lines "work" either: what do you expect? >> > >> > I get: >> > >> >> by(data = iris[, -5], INDICES = iris["Species"], FUN = min) >> > Species: setosa >> > [1] 0.1 >> > -- >> > Species: versicolor >> > [1] 1 >> > -- >> > Species: virginica >> > [1] 1.4 >> > >> > But was expecting: >> > >> >> aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=min) >> > Species Sepal.Length Sepal.Width Petal.Length Petal.Width >> > 1 setosa 4.3 2.3 1.0 0.1 >> > 2 versicolor 4.9 2.0 3.0 1.0 >> > 3 virginica 4.9 2.2 4.5 1.4 >> > >> > >> > >> > aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=sd) >> > aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=mean) >> > >> > provide the answers I would expect. If you want clearer advice, you >> > need to provide an actually reproducible example, and tell us more >> > about what you expect to get. >> > >> > Sarah >> > >> > >> > On Tue, Dec 8, 2015 at 5:30 PM, Dimitri Liakhovitski >> > wrote: >> >> Hello! >> >> Could you please explain why the first 5 lines work but the last 2 >> >> lines don't? >> >> Thank you! >> >> >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = var) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = max) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = min) >> >> >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) >> >> >> >> -- >> >> Dimitri Liakhovitski >> >> >> >> >> >> -- >> Dimitri Liakhovitski >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- Dimitri Liakhovitski __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
Hi Cleber, have you tried: edit(mtcars) Jim On Wed, Dec 9, 2015 at 1:04 PM, Cleber N.Borgeswrote: > my objective is to show data in screen inside a tktable... > for that, the data must be in a TCL variable and not only in a R variable > like that: > > library( tcltk ) >> mtcars_in_TCL <- tclArray() >> for( i in 1:5 ) for( j in 1:5 ) mtcars_in_TCL[[ i,j ]] <- >> > as.matrix(mtcars)[ i,j ] > > i thank by attention > cleber > > > Em 08/12/2015 22:51, Bert Gunter escreveu: > >> Define: "transfer" >> >> ( save/load should be efficient and fast within R, but you appear to >> have something else in mind. What?) >> >> Apologies if it's obvious and I just don't get it. >> >> Cheers, >> >> Bert >> >> >> Bert Gunter >> >> "Data is not information. Information is not knowledge. And knowledge >> is certainly not wisdom." >> -- Clifford Stoll >> >> >> On Tue, Dec 8, 2015 at 4:37 PM, Cleber N.Borges >> wrote: >> >>> hello all, >>> I intend transfer a big data.frame, more than 1e4 rows, more than 100 >>> columns... >>> I found solutions (in internet and help pages) for small data.frame like >>> the >>> showed bellow. >>> Big data.frames is very expensive in computation time in my approach >>> I would like to optimize this transfer anyway ... >>> I saw a function named "as.tclObj" that seems to me a promising form but >>> hard to code... >>> Somebody know a way more clever to do it? >>> >>> thanks for tips >>> cleber >>> >>> ## >>> library( tcltk ) >>> nrow <- 10 ; ncol <- 100 >>> # simulated data: data is originally a data frame >>> DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) >>> ## >>> # DF_tcl <- as.tclObj( as.matrix( DF ) ) >>> >>> tableDataTclArray <- tclArray() >>> for( i in 1:nrow( DF ) ) >>> tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', >>> rownames( DF )[ i ] , '"') ) ) >>> >>> for( i in 1:ncol( DF ) ) >>> tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', >>> colnames( DF )[ i ] , '"') ) ) >>> >>> >>> for( i in 1:nrow( DF ) ) >>> for( j in 1:ncol( DF ) ) >>> tableDataTclArray[[ i, j ]] <- DF[i,j] >>> ## >>> >>> >>> >>> >>> >>> ## >>> ## >>> ## >>> # my full code: >>> ### >>> library( tcltk ); tclRequire("Tktable") >>> wDataOrg <- tktoplevel() >>> tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) >>> fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, >>> 5, 8, >>> 15 ) ) >>> height <- -1; width <- -1 >>> nrowDefault <- 1e4+1; ncolDefault <- 100+1 >>> tableDataTclArray <- tclArray() >>> tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, >>> cols=ncolDefault, >>> height=height+1,width=width+1, >>> xscrollcommand=function(...) tkset( scrX, ... ), >>> yscrollcommand=function(...) tkset( scrY, ... ), >>> rowstretchmode='unset', colstretchmode='unset', >>> multiline=0, cache=1, >>> background="white", selectmode="extended", >>> selecttitle=0, >>> font='{Arial} 10', ipadx=5, ipady=5, anchor='e', >>> borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', >>> variable=tableDataTclArray ) >>> tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) >>> tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) >>> tcl( tableData, "tag", "coltag", "coltitle", "0" ) >>> tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', >>> relief="raised", state='disabled' ) >>> tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', >>> relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) >>> tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', >>> relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) >>> tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) >>> tcl( tableData, "width", "0", "20" ) >>> scrX <- tkscrollbar( fmTableData, orient="horizontal", >>> command=function(...) >>> tkxview( tableData, ... ) ) >>> scrY <- tkscrollbar( fmTableData, orient="vertical", >>> command=function(...) >>> tkyview( tableData, ... ) ) >>> scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) >>> tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = >>> c(0, >>> scrYwidth + 2) ) >>> tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) >>> tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, >>> fill="both" >>> ) >>> tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) >>> ## expensive time computation >>> [[elided Yahoo spam]] >>> DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) >>> ) >>> simulated data >>> for( i in 1:nrow( DF ) ){ >>>
[R] Why mean is not working in by?
Hello! Could you please explain why the first 5 lines work but the last 2 lines don't? Thank you! by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) by(data = iris[myvars], INDICES = iris["Species"], FUN = var) by(data = iris[myvars], INDICES = iris["Species"], FUN = max) by(data = iris[myvars], INDICES = iris["Species"], FUN = min) by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) -- Dimitri Liakhovitski __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
Define: "transfer" ( save/load should be efficient and fast within R, but you appear to have something else in mind. What?) Apologies if it's obvious and I just don't get it. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Dec 8, 2015 at 4:37 PM, Cleber N.Borgeswrote: > hello all, > I intend transfer a big data.frame, more than 1e4 rows, more than 100 > columns... > I found solutions (in internet and help pages) for small data.frame like the > showed bellow. > Big data.frames is very expensive in computation time in my approach > I would like to optimize this transfer anyway ... > I saw a function named "as.tclObj" that seems to me a promising form but > hard to code... > Somebody know a way more clever to do it? > > thanks for tips > cleber > > ## > library( tcltk ) > nrow <- 10 ; ncol <- 100 > # simulated data: data is originally a data frame > DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) > ## > # DF_tcl <- as.tclObj( as.matrix( DF ) ) > > tableDataTclArray <- tclArray() > for( i in 1:nrow( DF ) ) > tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', > rownames( DF )[ i ] , '"') ) ) > > for( i in 1:ncol( DF ) ) > tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', > colnames( DF )[ i ] , '"') ) ) > > > for( i in 1:nrow( DF ) ) > for( j in 1:ncol( DF ) ) > tableDataTclArray[[ i, j ]] <- DF[i,j] > ## > > > > > > ## > ## > ## > # my full code: > ### > library( tcltk ); tclRequire("Tktable") > wDataOrg <- tktoplevel() > tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) > fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, > 15 ) ) > height <- -1; width <- -1 > nrowDefault <- 1e4+1; ncolDefault <- 100+1 > tableDataTclArray <- tclArray() > tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, > cols=ncolDefault, > height=height+1,width=width+1, > xscrollcommand=function(...) tkset( scrX, ... ), > yscrollcommand=function(...) tkset( scrY, ... ), > rowstretchmode='unset', colstretchmode='unset', > multiline=0, cache=1, > background="white", selectmode="extended", > selecttitle=0, > font='{Arial} 10', ipadx=5, ipady=5, anchor='e', > borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', > variable=tableDataTclArray ) > tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) > tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) > tcl( tableData, "tag", "coltag", "coltitle", "0" ) > tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', > relief="raised", state='disabled' ) > tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', > relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) > tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', > relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) > tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) > tcl( tableData, "width", "0", "20" ) > scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) > tkxview( tableData, ... ) ) > scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) > tkyview( tableData, ... ) ) > scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) > tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, > scrYwidth + 2) ) > tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) > tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" > ) > tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) > ## expensive time computation > [[elided Yahoo spam]] > DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) > simulated data > for( i in 1:nrow( DF ) ){ > tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', > rownames( DF )[ i ] , '"') ) ) > } > for( i in 1:ncol( DF ) ){ > tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', > colnames( DF )[ i ] , '"') ) ) > } > for( i in 1:nrow( DF ) ) { > for( j in 1:ncol( DF ) ){ > tableDataTclArray[[ i, j ]] <- DF[i,j] > } > } > # > > > --- > Este email foi escaneado pelo Avast antivírus. > https://www.avast.com/antivirus > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why mean is not working in by?
Hi Dimitri, I changed this into a reproducible example (we don't know what myvars is). Assuming length(myvars) > 1, I'm not convinced that your first five lines "work" either: what do you expect? I get: > by(data = iris[, -5], INDICES = iris["Species"], FUN = min) Species: setosa [1] 0.1 -- Species: versicolor [1] 1 -- Species: virginica [1] 1.4 But was expecting: > aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=min) Species Sepal.Length Sepal.Width Petal.Length Petal.Width 1 setosa 4.3 2.3 1.0 0.1 2 versicolor 4.9 2.0 3.0 1.0 3 virginica 4.9 2.2 4.5 1.4 aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=sd) aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=mean) provide the answers I would expect. If you want clearer advice, you need to provide an actually reproducible example, and tell us more about what you expect to get. Sarah On Tue, Dec 8, 2015 at 5:30 PM, Dimitri Liakhovitskiwrote: > Hello! > Could you please explain why the first 5 lines work but the last 2 lines > don't? > Thank you! > > by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) > by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) > by(data = iris[myvars], INDICES = iris["Species"], FUN = var) > by(data = iris[myvars], INDICES = iris["Species"], FUN = max) > by(data = iris[myvars], INDICES = iris["Species"], FUN = min) > > by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) > by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) > > -- > Dimitri Liakhovitski > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why mean is not working in by?
Sorry, I omitted the first line: myvars <- c("Sepal.Length", "Sepal.Width") by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) by(data = iris[myvars], INDICES = iris["Species"], FUN = var) by(data = iris[myvars], INDICES = iris["Species"], FUN = max) by(data = iris[myvars], INDICES = iris["Species"], FUN = min) by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) The first lines are doing what I expected them to do: for each level of the factor "Species" they gave me a summary, a sum, a variance, a max, a min for each of the 2 variables in question (myvars). I expected by to generate the sd and the mean for the 2 variables in question for each level of "Species". On Tue, Dec 8, 2015 at 5:50 PM, Sarah Gosleewrote: > Hi Dimitri, > > I changed this into a reproducible example (we don't know what myvars > is). Assuming length(myvars) > 1, I'm not convinced that your first > five lines "work" either: what do you expect? > > I get: > >> by(data = iris[, -5], INDICES = iris["Species"], FUN = min) > Species: setosa > [1] 0.1 > -- > Species: versicolor > [1] 1 > -- > Species: virginica > [1] 1.4 > > But was expecting: > >> aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=min) > Species Sepal.Length Sepal.Width Petal.Length Petal.Width > 1 setosa 4.3 2.3 1.0 0.1 > 2 versicolor 4.9 2.0 3.0 1.0 > 3 virginica 4.9 2.2 4.5 1.4 > > > > aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=sd) > aggregate(iris[,-5], by=iris[,"Species", drop=FALSE], FUN=mean) > > provide the answers I would expect. If you want clearer advice, you > need to provide an actually reproducible example, and tell us more > about what you expect to get. > > Sarah > > > On Tue, Dec 8, 2015 at 5:30 PM, Dimitri Liakhovitski > wrote: >> Hello! >> Could you please explain why the first 5 lines work but the last 2 lines >> don't? >> Thank you! >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = var) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = max) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = min) >> >> by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) >> by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) >> >> -- >> Dimitri Liakhovitski >> -- Dimitri Liakhovitski __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
my objective is to show data in screen inside a tktable... for that, the data must be in a TCL variable and not only in a R variable like that: library( tcltk ) mtcars_in_TCL <- tclArray() for( i in 1:5 ) for( j in 1:5 ) mtcars_in_TCL[[ i,j ]] <- as.matrix(mtcars)[ i,j ] i thank by attention cleber Em 08/12/2015 22:51, Bert Gunter escreveu: Define: "transfer" ( save/load should be efficient and fast within R, but you appear to have something else in mind. What?) Apologies if it's obvious and I just don't get it. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Dec 8, 2015 at 4:37 PM, Cleber N.Borgeswrote: hello all, I intend transfer a big data.frame, more than 1e4 rows, more than 100 columns... I found solutions (in internet and help pages) for small data.frame like the showed bellow. Big data.frames is very expensive in computation time in my approach I would like to optimize this transfer anyway ... I saw a function named "as.tclObj" that seems to me a promising form but hard to code... Somebody know a way more clever to do it? thanks for tips cleber ## library( tcltk ) nrow <- 10 ; ncol <- 100 # simulated data: data is originally a data frame DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) ## # DF_tcl <- as.tclObj( as.matrix( DF ) ) tableDataTclArray <- tclArray() for( i in 1:nrow( DF ) ) tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) for( i in 1:ncol( DF ) ) tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) for( i in 1:nrow( DF ) ) for( j in 1:ncol( DF ) ) tableDataTclArray[[ i, j ]] <- DF[i,j] ## ## ## ## # my full code: ### library( tcltk ); tclRequire("Tktable") wDataOrg <- tktoplevel() tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, 15 ) ) height <- -1; width <- -1 nrowDefault <- 1e4+1; ncolDefault <- 100+1 tableDataTclArray <- tclArray() tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, cols=ncolDefault, height=height+1,width=width+1, xscrollcommand=function(...) tkset( scrX, ... ), yscrollcommand=function(...) tkset( scrY, ... ), rowstretchmode='unset', colstretchmode='unset', multiline=0, cache=1, background="white", selectmode="extended", selecttitle=0, font='{Arial} 10', ipadx=5, ipady=5, anchor='e', borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', variable=tableDataTclArray ) tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) tcl( tableData, "tag", "coltag", "coltitle", "0" ) tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', relief="raised", state='disabled' ) tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) tcl( tableData, "width", "0", "20" ) scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) tkxview( tableData, ... ) ) scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) tkyview( tableData, ... ) ) scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, scrYwidth + 2) ) tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" ) tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) ## expensive time computation [[elided Yahoo spam]] DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) simulated data for( i in 1:nrow( DF ) ){ tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) } for( i in 1:ncol( DF ) ){ tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) } for( i in 1:nrow( DF ) ) { for( j in 1:ncol( DF ) ){ tableDataTclArray[[ i, j ]] <- DF[i,j] } } # --- Este email foi escaneado pelo Avast antivírus. https://www.avast.com/antivirus __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
Re: [R] tmap colour scale
Hi Freddy, Have you tried rev() on the palette? Jim On Wed, Dec 9, 2015 at 7:32 AM, Freddy Eggletonwrote: > Hi, > > I am trying to plot Conservative Vote % per borough for London using tmap > however the legend colours boroughs with a high Conservative % as light > blue and boroughs with a low % of conservative votes as dark blue. How do i > reverse this scale so that areas with the most Conservative votes are > darkest? > > my code is as follows; > > tm_shape(lndbor) + tm_polygons("CON", style = "kmeans", palette = > "-Blues", title = "Conservative Vote (%)") > > Thanks, > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[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] Why mean is not working in by?
Because you are using by() incorrectly. "A data frame is split by row into **data frames** subsetted by the values of one or more factors, and function FUN is applied to each subset in turn." So your FUN is applied to a subset of the data frame (which is also a list). Note that sum, min, and max have "..." as their initial arguments and so use all the columns in the data frame of each subset for var() takes the covariance matrix of the several columns and summary.data.frame summarizes each column. mean() and sd() must be fed a numeric vector as their first argument, which a data frame is not -- ergo the error. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Dec 8, 2015 at 2:30 PM, Dimitri Liakhovitskiwrote: > Hello! > Could you please explain why the first 5 lines work but the last 2 lines > don't? > Thank you! > > by(data = iris[myvars], INDICES = iris["Species"], FUN = summary) > by(data = iris[myvars], INDICES = iris["Species"], FUN = sum) > by(data = iris[myvars], INDICES = iris["Species"], FUN = var) > by(data = iris[myvars], INDICES = iris["Species"], FUN = max) > by(data = iris[myvars], INDICES = iris["Species"], FUN = min) > > by(data = iris[myvars], INDICES = iris["Species"], FUN = sd) > by(data = iris[myvars], INDICES = iris["Species"], FUN = mean) > > -- > Dimitri Liakhovitski > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] change the x axis tickmarks when using plot function in drc package
Hi all, When plotting the dose response curve using plot function as in the example codes below, the scale of the axis should really be on the log scale of the dose given the shape of the graph. But as you can see, the tickmarks of the returned graph represent the original scale. How can I change the tick marks to the scale that the correspond to log(dose)? Thanks much in advance. Hanna dose <- rep(50*2^(-(0:11)),3) dose d <- 100 c <- 1 b <- 1 e <- 1.6 y <- rnorm(length(dose))+ c+ (d-c)/(1+exp(b*(log(dose)-log(e library(drc) mod <- drm(y~dose, fct = LL.4()) summary(mod) plot(mod, type="all") [[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] change the x axis tickmarks when using plot function in drc package
Thanks for the reply but that does not seem to work. With that the plot is on log scale for both the response and the dose levels, but the tickmarks are still on the original scale. 2015-12-08 22:22 GMT-05:00 Jim Lemon: > Hi Hannah, > Try this: > > plot(mod, type="all",log="xy") > > Jim > > > On Wed, Dec 9, 2015 at 1:57 PM, li li wrote: > >> Hi all, >> When plotting the dose response curve using plot function as in the >> example codes below, the scale of the axis should really be on the log >> scale of the dose given the shape of the graph. But as you can see, the >> tickmarks of the returned graph represent the original scale. How can I >> change the tick marks to the scale that the correspond to log(dose)? >> Thanks much in advance. >> Hanna >> >> >> dose <- rep(50*2^(-(0:11)),3) >> dose >> d <- 100 >> c <- 1 >> b <- 1 >> e <- 1.6 >> y <- rnorm(length(dose))+ c+ (d-c)/(1+exp(b*(log(dose)-log(e >> library(drc) >> mod <- drm(y~dose, fct = LL.4()) >> summary(mod) >> plot(mod, type="all") >> >> [[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.
Re: [R] change the x axis tickmarks when using plot function in drc package
Hi Hannah, Try this: plot(mod, type="all",log="xy") Jim On Wed, Dec 9, 2015 at 1:57 PM, li liwrote: > Hi all, > When plotting the dose response curve using plot function as in the > example codes below, the scale of the axis should really be on the log > scale of the dose given the shape of the graph. But as you can see, the > tickmarks of the returned graph represent the original scale. How can I > change the tick marks to the scale that the correspond to log(dose)? > Thanks much in advance. > Hanna > > > dose <- rep(50*2^(-(0:11)),3) > dose > d <- 100 > c <- 1 > b <- 1 > e <- 1.6 > y <- rnorm(length(dose))+ c+ (d-c)/(1+exp(b*(log(dose)-log(e > library(drc) > mod <- drm(y~dose, fct = LL.4()) > summary(mod) > plot(mod, type="all") > > [[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.
Re: [R] Error while using e1071 package
Hi Partha, Probably the first thing to be done is to see what: object$tables really is. The error message tells you that either "v" has become larger than the number of elements in the list/data frame "tables" or that "nd" has become larger than the number of columns in the element "v" (or both). Perhaps displaying the successive values as the code is run: for(v in 1:) { cat("v =",v,"\n") for(nd in 1:) { cat("nd =",nd,"\n") ... } } will tell you where the error is occurring. Jim On Wed, Dec 9, 2015 at 1:16 AM, Partha Sinhawrote: > I am using R 3.2.2 on win-7 > > while using predict function with e1071 (naive bayes classifier) > I am getting the following error > "Error in object$tables[[v]][, nd] : subscript out of bounds" > > > pl help. > regards > Parth > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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.
[R] tmap colour scale
Hi, I am trying to plot Conservative Vote % per borough for London using tmap however the legend colours boroughs with a high Conservative % as light blue and boroughs with a low % of conservative votes as dark blue. How do i reverse this scale so that areas with the most Conservative votes are darkest? my code is as follows; tm_shape(lndbor) + tm_polygons("CON", style = "kmeans", palette = "-Blues", title = "Conservative Vote (%)") Thanks, __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.