Re: [R] Transformations in Tidyverse (renaming and ordering columns)
I am impressed. Upon playing with factor, I took it a step further to commonize (and this could very well be simpified): > > testset$Observation <- factor(testset$Order, levels=testset$Order, labels=testset$Observation) > testset$Label <- factor(testset$Seq, levels=testset$Seq, labels=testset$Label) > > testset %>% select(Observation, Label, Value) %>% spread(key=Observation, value=Value) # A tibble: 4 x 4 Label One Two Three 1 Western163 147 119 2 Northern 105 10082 3 Eastern121 10690 4 Southern747065 > All I see left now is to replace "Label" heading value with the appropriate testset$Section value provided for the situation. In this case... # A tibble: 4 x 4 For Reporting Quarter One Two Three ... FWIW, before sending this I cleared all formatting and dismissed the formatting toolbar (been doing only the latter before) in the Gmail client, which I presume will finally strip HTML from the message. -- Cheers, Joel Maxuel On Mon, Oct 22, 2018 at 10:48 PM John Laing wrote: > I don't know much about the Tidyverse, but more generally the way to > represent ordered categorical data is with a factor. This seems to work: > > > testset$Observation <- factor(testset$Observation, levels=c("One", > "Two", "Three")) > > testset$Label <- factor(testset$Label, levels=c("Western", "Northern", > "Eastern", "Southern")) > > testset %>% select(Observation, Label, Value) %>% > spread(key=Observation, value=Value) > # A tibble: 4 x 4 > Label One Two Three > > 1 Western163 147 119 > 2 Northern 105 10082 > 3 Eastern121 10690 > 4 Southern747065 > >> >> [[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] Transformations in Tidyverse (renaming and ordering columns)
For clarity sake. More show (with example closer to reality), less tell. :^) ## Current: > library(knitr) > library(tidyverse) ── Conflicts ─ tidyverse_conflicts() ── x dplyr::filter() masks stats::filter() x dplyr::lag()masks stats::lag() > library(tibble) > library(dplyr) > > testset <- as_tibble(tribble(~SN, ~Section, ~Order, ~Observation, ~Seq, ~Label, ~Value, + 2, "For Reporting Quarter", 1, "One", 1, "Western", 163, + 2, "For Reporting Quarter", 1, "One", 2, "Northern", 105, + 2, "For Reporting Quarter", 1, "One", 3, "Eastern", 121, + 2, "For Reporting Quarter", 1, "One", 4, "Southern", 74, + 2, "For Reporting Quarter", 2, "Two", 1, "Western", 147, + 2, "For Reporting Quarter", 2, "Two", 2, "Northern", 100, + 2, "For Reporting Quarter", 2, "Two", 3, "Eastern", 106, + 2, "For Reporting Quarter", 2, "Two", 4, "Southern", 70, + 2, "For Reporting Quarter", 3, "Three", 1, "Western", 119, + 2, "For Reporting Quarter", 3, "Three", 2, "Northern", 82, + 2, "For Reporting Quarter", 3, "Three", 3, "Eastern", 90, + 2, "For Reporting Quarter", 3, "Three", 4, "Southern", 65)) > testset %>% select(Observation, Label, Value) %>% spread(key=Observation, value=Value) # A tibble: 4 x 4 Label One Three Two 1 Eastern12190 106 2 Northern 10582 100 3 Southern746570 4 Western163 119 147 > ## Intended: # A tibble: 4 x 4 For Reporting Quarter One Two Three 1 Western 163 147 119 2 Northern 105 10082 3 Eastern121 10690 4 Southern 74 70 65 > ## Unfortunately I don't know how to get there from here. Section, Order and Seq are there to assist with getting the data to the right output programmatically, however I don't know how to make use of them. Hope this helps. -- Cheers, Joel Maxuel On Mon, Oct 22, 2018 at 6:18 PM Jeff Newmiller wrote: > If you are willing to work in the context of LaTeX output then perhaps you > will find the "tables" package useful. However, while you think you have > communicated clearly enough regarding what you want to accomplish, I do > not, so either someone else will intuit what you want or you will create a > mock-up of what you want your output to look like to remove the guesswork. > > [[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] Transformations in Tidyverse (renaming and ordering columns)
Hi Jeff, Thanks for the input, however it does not seem we are on the same wavelength. Maybe I should have distilled my example down even further to solidify context, although given what I was trying to accomplish I believe it is all in context. At this point I am not concerned about presenting multiple sections (agreed, looping will be important) - my emphasis right now is to present just one piece in a manner that makes sense. As a result, I am finding that using `spread` to convert the flat data into a "crosstab" does not. The flat data has (IMO - at least the wider version I have locally) all the info needed to allow a sort to be enforced, and any miscellaneous data for that section, without having to customize each section individually (in essence, allow for looping). With regard to sorting, in the past hour or so I have tried the `seq` parameter (after changing `key` to the `Order` column) in `spread`, as well as the `arrange` function after `spread` but neither are helpful. I have considered a leading character in the headings to force a sort, with something to trim it from the final output, but I am not fond of that solution. Also, having the section heading outside the table to me feels like a waste of space. With 13 proposed sections in the end (120 to 140 observations), having that all in only two pages may already be a challenge. -- Cheers, Joel Maxuel [[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] Transformations in Tidyverse (renaming and ordering columns)
Hello all, I am slowly picking away at a factsheet that will include several result sets from a single tibble (there is a column identifying the section title) and would like to have that value in the top left corner of each resulting table. When using the `spread` function, I see that any remaining columns not identified by `key` nor `value` will be placed to the far left. Like the example below, I would like the column label Fiscal be renamed to the data value "A", so the top-left of the result is "A". However, if I try to progmatically set the column name, I run into issues: library(knitr) library(tidyverse) library(tibble) library(dplyr) library(magrittr) testset <- as_tibble(tribble(~Section, ~Observation, ~Order, ~Fiscal, ~Value, "A", "One", 1, "2016-17", 419, "A", "One", 1, "2017-18", 499, "A", "One", 1, "2018-19", 463, "A", "Two", 2, "2016-17", 391, "A", "Two", 2, "2017-18", 445, "A", "Two", 2, "2018-19", 423, "A", "Three", 3, "2016-17", 348, "A", "Three", 3, "2017-18", 353, "A", "Three", 3, "2018-19", 357)) sectionA <- as_tibble(filter(testset, Section == "A")) # Mind you for this example, does very little spread(select(sectionA, Observation, "A" = Fiscal, Value), key=Observation, value=Value) # Works, with reservations spread(select(sectionA, Observation, slice(sectionA,1) %>% magrittr::extract2("Section") = Fiscal, Value), key=Observation, value=Value) # Produces error: # Error: unexpected '=' in "spread(select(sectionA, Observation, slice(sectionA,1) %>% magrittr::extract2("Section") =" I presume my premise is very wrong. Also, I am curious how to sort columns (and rows) with extra columns (/rows) not meant for display. In this case, the columns One, Two, and Three (in real life won't be linguistic representations of numbers), are out of order - however I do have the Order column to fix that (if I knew how to include it for sorting purposes, without displaying it). A few hints here would help. (Perhaps there is column/row hiding in kableExtra - which I will be using later on?) -- Cheers, Joel Maxuel [[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-es] Workspace en Rstudio
Estimado Javier, Estoy utilizando R version 3.3.2 para correr el modelos. En el manual de ASReml indica que por defecto vienen determinados bytes, pero no indica como codificarlo y en otras pagina no encontré nada sobre este tema en R. Al parecer en R se limita el ASReml. Gracias por la respuesta y comentarme que es posible en la versión estándar!!! Acabo de descargar la versión ASReml v3.0 standard, te comentare como me va!! Joel Ibanez El 8 de junio de 2017, 16:38, Javier Marcuzzi < javier.ruben.marcu...@gmail.com> escribió: > Estimado Joel Ibañez Flores > > > > ¿Qué versión esta utilizando? En R no recuerdo, si supe usar la versión > standard donde se puede agregar espacio, aunque el escribir los comando es > algo complicado, nada que ver con R, pero la versión de R hasta donde se no > tiene todo. > > > > El problema no es RStudio, es ASReml. > > > > Javier Rubén Marcuzzi > > > > *De: *joel ibañez flores <j.ibanezflo...@gmail.com> > *Enviado: *jueves, 8 de junio de 2017 17:13 > *Para: *R-help-es@r-project.org > *Asunto: *[R-es] Workspace en Rstudio > > > > Estimados, > > Les tengo una pequeña consulta. > > > > Estoy trabajando con ASReml en Rstudio, me encuentro corriendo un modelo > > (CHL) para obtener el ANOVA de la interacción de los factores gen x env > > > > CHL<- asreml(fixed= MS~geno:env, random = ~rep, data = index) (interacción) > > > > Sin embargo, cuando ejecuto el modelo, R indica que siguiente mensaje: > > > > Current workspace: 128.00Mb > > Warning message: > > Abnormal termination > > Insufficient workspace - (reset workspace argument) > > Results may be erroneous > > > > Revise el workspace en R y este indica; S4=128Mb. Por lo que la solución > > seria aumentar el valor (a S6=512Mb), pero no lo logro aumentar. > > > > Alguien ha tenido un problema similar o sabe como aumentar el workspace en > > Rstudio? > > > > Saludos! > > > > Joel Ibanez > > > > [[alternative HTML version deleted]] > > > > ___ > > R-help-es mailing list > > R-help-es@r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-help-es > > > [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
[R-es] Workspace en Rstudio
Estimados, Les tengo una pequeña consulta. Estoy trabajando con ASReml en Rstudio, me encuentro corriendo un modelo (CHL) para obtener el ANOVA de la interacción de los factores gen x env CHL<- asreml(fixed= MS~geno:env, random = ~rep, data = index) (interacción) Sin embargo, cuando ejecuto el modelo, R indica que siguiente mensaje: Current workspace: 128.00Mb Warning message: Abnormal termination Insufficient workspace - (reset workspace argument) Results may be erroneous Revise el workspace en R y este indica; S4=128Mb. Por lo que la solución seria aumentar el valor (a S6=512Mb), pero no lo logro aumentar. Alguien ha tenido un problema similar o sabe como aumentar el workspace en Rstudio? Saludos! Joel Ibanez [[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] Paired sample t-test with mi.t.test
Dear Dr. Eichner and Dr. Kohl, First, thank you for your response. I tried your code and R it worked perfectly I just had to add: mi.t.test(implist*$imputation,* "pre_test", "post_test", alternative = "greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95) for the code to run. Thank you very much again for taking the time. Best, Joel On Fri, Apr 7, 2017 at 3:26 PM, Prof. Dr. Matthias Kohl < matthias.k...@stamats.de> wrote: > Dear Joel, > > are you trying to apply function mi.t.test from my package MKmisc? > > Could you please try: > mi.t.test(implist, "pre_test", "post_test", alternative = > "greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95) > > x and y are the names of the variables, not the variables themselves. > > Best > Matthias > > Am 06.04.2017 um 18:32 schrieb Joel Gagnon: > >> Dear all, >> >> It is my first time posting on this list so forgive me for any rookie >> mistakes I could make. >> >> I want to conduct t-tests on a dataset that has been imputed using the >> mice >> package: >> imput_pps <- mice(pps, m=20, maxit=20, meth='pmm') # pps is my dataset. It >> contains items from an 11-item questionnaire gather at pre and post test. >> So the data set has 22 columns. >> >> I then proceed to compute the total scores for the pre and post test on my >> imputed datasets: >> >> long_pps <- complete(imput_pps, action ="long", include = TRUE) >> long_pps$pre_test <- rowSums(long_pps[ ,c(3:13)]) >> long_pps$post_test <- rowSums(long_pps[ , c(14:24)]) >> >> I then used as.mids to convert back to mids object: >> mids_pps <- as.mids(long_pps) >> >> Next, I created an imputation list object using mitools: >> implist <- lapply(seq(mids_pps$m), function(im) complete(mids_pps, im)) >> implist <- imputationList(implist) >> >> Now, I want to conduct t-tests using the mi.t.test package. I tried the >> following code: >> mi.t.test(implist, implist$pre_test, implist$post_test, alternative = >> "greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95) >> >> When I run this code, R tells me that Y is missing. I know this may sound >> stupid, but I thought that I specified Y with this line: implist$pre_test, >> implist$post_test - with implist$pre_test being X and implist$post_test >> being Y - like I usually do for a normal t-test using the t.test function. >> >> It seems I don't quite understand what the Y variable is supposed to >> represent. Could someone help me figure out what I am doing wrong? You >> help would be very much appreciated. >> >> Best regards, >> >> Joel Gagnon, Ph.D(c), >> Department of Psychology, >> Université du Québec à Trois-Rivières >> Québec, Canada >> >> [[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/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > -- > Prof. Dr. Matthias Kohl > www.stamats.de > [[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] Paired sample t-test with mi.t.test
Dear all, It is my first time posting on this list so forgive me for any rookie mistakes I could make. I want to conduct t-tests on a dataset that has been imputed using the mice package: imput_pps <- mice(pps, m=20, maxit=20, meth='pmm') # pps is my dataset. It contains items from an 11-item questionnaire gather at pre and post test. So the data set has 22 columns. I then proceed to compute the total scores for the pre and post test on my imputed datasets: long_pps <- complete(imput_pps, action ="long", include = TRUE) long_pps$pre_test <- rowSums(long_pps[ ,c(3:13)]) long_pps$post_test <- rowSums(long_pps[ , c(14:24)]) I then used as.mids to convert back to mids object: mids_pps <- as.mids(long_pps) Next, I created an imputation list object using mitools: implist <- lapply(seq(mids_pps$m), function(im) complete(mids_pps, im)) implist <- imputationList(implist) Now, I want to conduct t-tests using the mi.t.test package. I tried the following code: mi.t.test(implist, implist$pre_test, implist$post_test, alternative = "greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95) When I run this code, R tells me that Y is missing. I know this may sound stupid, but I thought that I specified Y with this line: implist$pre_test, implist$post_test - with implist$pre_test being X and implist$post_test being Y - like I usually do for a normal t-test using the t.test function. It seems I don't quite understand what the Y variable is supposed to represent. Could someone help me figure out what I am doing wrong? You help would be very much appreciated. Best regards, Joel Gagnon, Ph.D(c), Department of Psychology, Université du Québec à Trois-Rivières Québec, Canada [[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] R freezing issue when checking to see if variable belongs to two different vectors
I often find myself trying to get a quick assessment of how much of one vector is inside of another vector. I almost always try this with variables that are some sort of identifier, like a client id number or an SSN. I typically do this: table( DF1$Identifier %in% DF2$Identifier) This will return a count of True and False logical responses. However, sometimes when I try to do this my computer will freeze and I am unable to stop or escape the process, requiring me to shutdown R via the task manager. I was wondering if anybody else experiences this and, if so, why this might be happening. Thanks in advance, Joel [[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] [R-pkgs] New Package "radiomics": First and Second Order Matrix Statistics
Dear R Users, I am pleased to inform you that my package, 'radiomics' is now available on CRAN: https://cran.r-project.org/web/packages/radiomics/ <http://cran.r-project.org/web/packages/clifro/> The radiomics package offers 4 classes of texture matrices, and associated feature sets. These matrices can be used for image classification, or for extraction of meaningful information from the input image (as in the case of the research field of radiomics). The texture matrices are: - Gray level co-occurrence matrix (GLCM) - Gray level run-length matrix (GLRLM) - Gray level size-zone matrix (GLSZM) - Multiple gray level size-zone matrix (MGLSZM) Each of these matrices are calculated from an input grayscale matrix, and return objects of class 'glcm', 'glrlm', 'glszm' or 'mglszm'. Features of the matrices can be calculated using the calc_features() function. calc_features() can also be called on an image matrix, and will return first-order summary statistics. The github page can be viewed here:https://github.com/joelcarlson/radiomics <https://github.com/ropensci/clifro#enhancing-the-national-climate-database-with-clifro> Lists of features, and an introduction to the package can be found in the package vignette. In-depth explanation of texture analysis matrices can be found here: http://joelcarlson.me/2015/07/10/radiomics-package/ Any comments, contributions, and feedback are always welcome. I hope you find this helpful! Regards --- Joel Carlson [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] Windows Installation Without Third-Party Packages
I am trying to install R for Windows, but when I use the installer provided on CRAN, a number of third-party packages are installed by default (i.e. lattice, Matrix, codetools, etc.). If R is installed with administrator privileges, so it's available for all users, non-administrators can't update those packages. Is there any way to just install R without any third-party packages, and let individual users install the packages they want? Thanks. - Elliot [[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] grep(pattern = each element of a vector) ?
Jake, You can use the plyr library or some form of apply. If you are on a 64bit system you can multithread and it goes much faster. something like this(for 32bit): require(plyr) df1 - data.frame(Taxa = c('blue', 'red', NA,'blue', 'red', NA,'blue', 'red', NA)) df2 - data.frame(Taxa = c( 'blue', 'red', NA), Class = c('Z', 'HI', 'A')) #function to do the lookup find.class-function(x)df2[grep(x, df2$Taxa),'Class'] ddply(.data=df1, .variables='Taxa', .fun=transform, Class=find.class(Taxa)) Joel From: Beaulieu, Jake Sent: Thursday, September 12, 2013 12:06 PM To: r-help@r-project.org Cc: Wahman, David; Farrar, David; Allen, Joel; Green, Hyatt; McManus, Michael Subject: grep(pattern = each element of a vector) ? Hi, I have a large dataframe that contains species names. I have a second dataframe that contains species names and some additional info, called 'Class', about each species. I would like match the species name is the first data frame with the 'Class' information contained in the second. Since the species names are often formatted differently between the data sets, merge doesn't work well. grep does the trick, but the function needs to be called separately for each observation in the first data frame. I put grep into a loop, but this is too slow. Is there a way to run grep repeatedly without resorting to a loop? Possibly something in the apply family? df1 - data.frame(Taxa = c('blue', 'red', NA)) df2 - data.frame(Taxa = c( 'blue', 'red', NA), Class = c('Z', 'HI', 'A')) index - NULL for (i in 1:length(df1$Taxa)) { index[i] - grep(df1$Taxa[1], df2$Taxa) } index sessionInfo() R version 3.0.1 (2013-05-16) Platform: i386-w64-mingw32/i386 (32-bit) == Jake J. Beaulieu, PhD US Environmental Protection Agency National Risk Management Research Lab 26 W. Martin Luther King Drive Cincinnati, OH 45268 USA 513-569-7842 (desk) 513-487-2511 (fax) beaulieu.j...@epa.govmailto:beaulieu.j...@epa.gov [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting several columns/rows of a dataframe?
Sorry, the use of rows/columns I found so far was rather contradictive, both refering to what can be gotten via subset() instead of what I'm looking for. Is there a way to get multiple colums/rows? Something like corpus.df${mph,mgl,eng} Thanks in advance for any answers. -- Joel Prokopchuk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting several columns/rows of a dataframe?
Thanks everyone. I had looked in the documentation (just in the wrong places,apparently) and googled, but I couldn't find this. 2013/5/1 Rui Barradas ruipbarra...@sapo.pt: Hello, Try corpus.df[, c(mph, mgl, eng)] Hope this helps, Rui Barradas Em 01-05-2013 21:04, Joel Prokopchuk escreveu: Sorry, the use of rows/columns I found so far was rather contradictive, both refering to what can be gotten via subset() instead of what I'm looking for. Is there a way to get multiple colums/rows? Something like corpus.df${mph,mgl,eng} Thanks in advance for any answers. -- Joel Prokopchuk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joel Prokopchuk Zeltweg 18 8032 Zürich +41 76/45'100'46 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I'm trying to parse 1 column of a dataframe into 3 seperate columns
I have a factor called 'utm_medium' in the dataframe 'data' str(data$utm_medium) Factor w/ 396925 levels ,affiliateID=sessionID=821850667323ec6ae6cffd28f380etag=,..: 366183 355880 357141 20908 357513 365348 368088 360827 31704 364767 ... The data in this factor is delimited with ''. I basically want the affiliateID, sessionID and etag data separated. Ex. data$utm_medium[1:10] [1] affiliateID=4f3ac4b695e7dsessionID=993f4c447e68dfc36ed692223349f2e3eta g= [2] affiliateID=4f3ac4b695e7dsessionID=209dd9986ace55d50a450afeba62b78feta g= [3] affiliateID=4f3ac4b695e7dsessionID=2efdb8e1e1f5ac9c0d5baec355c78f85eta g= [4] affiliateID=sessionID=5a6ca9d41148f30ce694628427af7991etag= [5] affiliateID=4f3ac4b695e7dsessionID=331fbcdf1f3d5e7bac0d92c12e19f63deta g= [6] affiliateID=4f3ac4b695e7dsessionID=8fc27c8478e9bd30043ea4d3c7ddb29ceta g= [7] affiliateID=4f3ac4b695e7dsessionID=af467d480addffca43ffbdbce1edfdb4eta g= [8] affiliateID=4f3ac4b695e7dsessionID=598645e05a187ee63ff922a36360f021eta g= [9] affiliateID=sessionID=8895e21d0842ed45063ba8328dc3bc61etag= [10] affiliateID=4f3ac4b695e7dsessionID=88ca2998c5a91b6efbece0c4f79caeb7eta g= 396925 Levels: ... affiliateID=50bfbbbeed918sessionID=5c49c142cbf1b149c6a4647d1a4fc97beta g= I've parsed it via: test -as.character(data$utm_medium) test - strsplit(test, ) which results in a list, which I 'unlisted': test2 - unlist(test) and then attempted to extract into separate vectors: a - vector(mode = character, length = length(test2)) s - vector(mode = character, length = length(test2)) e - vector(mode = character, length = length(test2)) i - 1 j - 1 for (i in 1:length(test2)) { a[j] - test2[i] s[j] - test2[i+1] e[j] - test2[i+2] i - i + 3 j - j + 1 } This code runs, but I'm indexing it incorrectly and I can't figure out why. I'll sleep on it tonight and probably figure it out, but I can't help thinking that there's a much easier way to parse this data. Help! Please! joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Repeated Aggregation with data.table
I still haven't come up with a solution to the question below, and I have another one. I frequently find myself in a situation where I have the list of columns I want to aggregate over in the form of a vector of strings, and I have to do something like the following: dat[, list(mean.z = mean(z)), by = eval(parse(text = sprintf(list(%s), paste(x, collapse=,] I think that's a pretty ugly solution (although it does work), but I haven't come up with anything better. Any suggestions? Thanks. - Elliot On Tue, Sep 11, 2012 at 11:33 AM, Elliot Joel Bernstein elliot.bernst...@fdopartners.com wrote: I've been using this setup: flist - expression( list(mean.z = mean(z), sd.z = sd(z)) ) dat[ , eval(flist), list(x)] It works great, but there's one small catch. If I do something like flist - expression(list(x.per.y = sum(x) / sum(y))) dat[, eval(flist), list(y)] it does the wrong thing, because sum(y) in each group is just the common value, rather than that value times the length. Is there any way around this? Obviously I could rewrite the expression if I know I'm going to by grouping by y, but I'd like it to be generic. Thanks. - Elliot On Wed, Aug 8, 2012 at 9:17 AM, David Winsemius dwinsem...@comcast.netwrote: On Aug 7, 2012, at 9:28 PM, arun wrote: HI, Try this: fun1-function(x,.expr){ .expr-expression(list(mean.z=**mean(z),sd.z=sd(z))) z1-eval(.expr) } #or fun1-function(x,.expr){ .expr-expression(list(mean.z=**mean(z),sd.z=sd(z))) z1-.expr } dat[,eval(z1),list(x)] dat[,eval(z1),list(y)] dat[,eval(z1),list(x,y)] I'm not seeing the connection between those functions and the data.table call. (Running that code produces an error on my machine.) If the goal is to have an expression result then just create it with expression(). In the example: flist - expression( list(mean.z = mean(z), sd.z = sd(z)) ) dat[ , eval(flist), list(x)] x mean.z sd.z 1: 2 0.04436034 1.039615 2: 3 -0.06354504 1.077686 3: 1 -0.08879671 1.066916 -- David. A.K. - Original Message - From: Elliot Joel Bernstein elliot.bernstein@fdopartners.**comelliot.bernst...@fdopartners.com To: r-help@r-project.org Cc: Sent: Tuesday, August 7, 2012 5:36 PM Subject: [R] Repeated Aggregation with data.table I have been using ddply to do aggregation, and I frequently define a single aggregation function that I use to aggregate over different groups. For example, require(plyr) dat - data.frame(x = sample(3, 100, replace=TRUE), y = sample(3, 100, replace = TRUE), z = rnorm(100)) f - function(x) { data.frame(mean.z = mean(x$z), sd.z = sd(x$z)) } ddply(dat, x, f) ddply(dat, y, f) ddply(dat, c(x, y), f) I recently discovered the data.table package, which dramatically speeds up the aggregation: require(data.table) dat - data.table(dat) dat[, list(mean.z = mean(z), sd.z = sd(z)), list(x)] dat[, list(mean.z = mean(z), sd.z = sd(z)), list(y)] dat[, list(mean.z = mean(z), sd.z = sd(z)), list(x,y)] But I can't figure out how to save the aggregation function list(mean.z = mean(z), sd.z = sd(z)) as a variable that I can reuse, similar to the function f above. Can someone please explain how to do that? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernstein@fdopartners.**comelliot.bernst...@fdopartners.com __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Repeated Aggregation with data.table
I've been using this setup: flist - expression( list(mean.z = mean(z), sd.z = sd(z)) ) dat[ , eval(flist), list(x)] It works great, but there's one small catch. If I do something like flist - expression(list(x.per.y = sum(x) / sum(y))) dat[, eval(flist), list(y)] it does the wrong thing, because sum(y) in each group is just the common value, rather than that value times the length. Is there any way around this? Obviously I could rewrite the expression if I know I'm going to by grouping by y, but I'd like it to be generic. Thanks. - Elliot On Wed, Aug 8, 2012 at 9:17 AM, David Winsemius dwinsem...@comcast.netwrote: On Aug 7, 2012, at 9:28 PM, arun wrote: HI, Try this: fun1-function(x,.expr){ .expr-expression(list(mean.z=**mean(z),sd.z=sd(z))) z1-eval(.expr) } #or fun1-function(x,.expr){ .expr-expression(list(mean.z=**mean(z),sd.z=sd(z))) z1-.expr } dat[,eval(z1),list(x)] dat[,eval(z1),list(y)] dat[,eval(z1),list(x,y)] I'm not seeing the connection between those functions and the data.table call. (Running that code produces an error on my machine.) If the goal is to have an expression result then just create it with expression(). In the example: flist - expression( list(mean.z = mean(z), sd.z = sd(z)) ) dat[ , eval(flist), list(x)] x mean.z sd.z 1: 2 0.04436034 1.039615 2: 3 -0.06354504 1.077686 3: 1 -0.08879671 1.066916 -- David. A.K. - Original Message - From: Elliot Joel Bernstein elliot.bernstein@fdopartners.**comelliot.bernst...@fdopartners.com To: r-help@r-project.org Cc: Sent: Tuesday, August 7, 2012 5:36 PM Subject: [R] Repeated Aggregation with data.table I have been using ddply to do aggregation, and I frequently define a single aggregation function that I use to aggregate over different groups. For example, require(plyr) dat - data.frame(x = sample(3, 100, replace=TRUE), y = sample(3, 100, replace = TRUE), z = rnorm(100)) f - function(x) { data.frame(mean.z = mean(x$z), sd.z = sd(x$z)) } ddply(dat, x, f) ddply(dat, y, f) ddply(dat, c(x, y), f) I recently discovered the data.table package, which dramatically speeds up the aggregation: require(data.table) dat - data.table(dat) dat[, list(mean.z = mean(z), sd.z = sd(z)), list(x)] dat[, list(mean.z = mean(z), sd.z = sd(z)), list(y)] dat[, list(mean.z = mean(z), sd.z = sd(z)), list(x,y)] But I can't figure out how to save the aggregation function list(mean.z = mean(z), sd.z = sd(z)) as a variable that I can reuse, similar to the function f above. Can someone please explain how to do that? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernstein@fdopartners.**comelliot.bernst...@fdopartners.com __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Repeated Aggregation with data.table
I have been using ddply to do aggregation, and I frequently define a single aggregation function that I use to aggregate over different groups. For example, require(plyr) dat - data.frame(x = sample(3, 100, replace=TRUE), y = sample(3, 100, replace = TRUE), z = rnorm(100)) f - function(x) { data.frame(mean.z = mean(x$z), sd.z = sd(x$z)) } ddply(dat, x, f) ddply(dat, y, f) ddply(dat, c(x, y), f) I recently discovered the data.table package, which dramatically speeds up the aggregation: require(data.table) dat - data.table(dat) dat[, list(mean.z = mean(z), sd.z = sd(z)), list(x)] dat[, list(mean.z = mean(z), sd.z = sd(z)), list(y)] dat[, list(mean.z = mean(z), sd.z = sd(z)), list(x,y)] But I can't figure out how to save the aggregation function list(mean.z = mean(z), sd.z = sd(z)) as a variable that I can reuse, similar to the function f above. Can someone please explain how to do that? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Thinning Lattice Plot
Thanks everyone for your replies. I didn't know about the ecdfplot function, so I'll start using that instead of Ecdf. Why is Ecdf not a lattice plot? The result certainly looks like other lattice plots, the arguments are similar to other lattice plots. In fact, internally it seems to just call the histogram function with a different prepanel and panel function. Is it not considered a lattice plot only because it isn't part of the lattice package? Thanks. - Elliot On Tue, Jul 31, 2012 at 2:32 AM, Deepayan Sarkar deepayan.sar...@gmail.comwrote: On Tue, Jul 31, 2012 at 2:43 AM, Elliot Joel Bernstein elliot.bernst...@fdopartners.com wrote: Is there an easy way to thin a lattice plot? I often create plots from large data sets, and use the pdf command to save them to a file, but the resulting files can be huge, because every point in the underlying dataset is rendered in the plot, even though it isn't possible to see that much detail. For example: require(Hmisc) x - rnorm(1e6) pdf(test.pdf) Ecdf(x) dev.off() (This is not a lattice plot, BTW.) The resulting pdf files is 31MB. Hmm, for me it's 192K. Perhaps you have not bothered to update R recently. Is there any easy way to get a smaller pdf file without having to manually prune the dataset? In general, as David noted, you need to do some sort of data summarization; great if tools are available to that, otherwise yourself. In this case, for example, it seems reasonable to do Ecdf(quantile(x, probs = ppoints(500, a=1))) If you don't like to do this yourself, ecdfplot() in latticeExtra will allow library(latticeExtra) ecdfplot(x, f.value = ppoints(500, a=1)) -Deepayan -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Installing Package with Dependency on Matrix
I'm attempting to update to R 2.15.1, and I'm having trouble with a package that depends on the Matrix package. I've created a dummy package consisting only of a DESCRIPTION file that specifies the dependence on Matrix, a NAMESPACE file, and an R directory, containing a single function, square - function(x) { return (x*x) }. When I try to install, I get the following error: [ebernstein@coolio R]$ R CMD INSTALL temp -l /home/ebernstein/Rlib_2.15.1/ * installing *source* package temp ... ** R ** preparing package for lazy loading Error : .onLoad failed in loadNamespace() for 'Matrix', details: call: assignInNamespace(..Old..as.matrix, base::as.matrix, ns = base) error: locked binding of ..Old..as.matrix cannot be changed Error : package Matrix could not be loaded ERROR: lazy loading failed for package temp * removing /home/ebernstein/Rlib_2.15.1/temp If I remove the dependency on Matrix, it installs fine. I'm using R 2.15.1 on linux, and version 1.0-6 of the Matrix package. Can anyone explain what's going on here? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Installing Package with Dependency on Matrix
A follow up on this issue...if I first build the package using R CMD build temp, I can install the resulting .tar.gz file from within R using the install.packages command, but I still can't install it from the command line using R CMD INSTALL. - Elliot On Tue, Jul 31, 2012 at 11:33 AM, Elliot Joel Bernstein elliot.bernst...@fdopartners.com wrote: I'm attempting to update to R 2.15.1, and I'm having trouble with a package that depends on the Matrix package. I've created a dummy package consisting only of a DESCRIPTION file that specifies the dependence on Matrix, a NAMESPACE file, and an R directory, containing a single function, square - function(x) { return (x*x) }. When I try to install, I get the following error: [ebernstein@coolio R]$ R CMD INSTALL temp -l /home/ebernstein/Rlib_2.15.1/ * installing *source* package temp ... ** R ** preparing package for lazy loading Error : .onLoad failed in loadNamespace() for 'Matrix', details: call: assignInNamespace(..Old..as.matrix, base::as.matrix, ns = base) error: locked binding of ..Old..as.matrix cannot be changed Error : package Matrix could not be loaded ERROR: lazy loading failed for package temp * removing /home/ebernstein/Rlib_2.15.1/temp If I remove the dependency on Matrix, it installs fine. I'm using R 2.15.1 on linux, and version 1.0-6 of the Matrix package. Can anyone explain what's going on here? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Thinning Lattice Plot
I see. I typically use a (one-sided) formula as the first argument to Ecdf, but didn't even think about that distinction in putting together this example. Thanks again for your help. - Elliot On Tue, Jul 31, 2012 at 12:46 PM, Deepayan Sarkar deepayan.sar...@gmail.com wrote: On Tue, Jul 31, 2012 at 6:43 PM, Elliot Joel Bernstein elliot.bernst...@fdopartners.com wrote: Thanks everyone for your replies. I didn't know about the ecdfplot function, so I'll start using that instead of Ecdf. Why is Ecdf not a lattice plot? The result certainly looks like other lattice plots, the arguments are similar to other lattice plots. In fact, internally it seems to just call the histogram function with a different prepanel and panel function. Is it not considered a lattice plot only because it isn't part of the lattice package? Of course not. What you are saying is a valid description of the Ecdf.formula() method, which definitely produces a lattice plot (or trellis plot if you prefer). However, the example you gave, namely, x - rnorm(1e6) Ecdf(x) ends up calling Ecdf.default(), which is very much a traditional graphics function. I should add that this is for Hmisc 3.9-2, and don't know if the behaviour is different with other versions. Note that Ecdf() has more features than ecdfplot(), in particular it allows weights. -Deepayan -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Thinning Lattice Plot
Is there an easy way to thin a lattice plot? I often create plots from large data sets, and use the pdf command to save them to a file, but the resulting files can be huge, because every point in the underlying dataset is rendered in the plot, even though it isn't possible to see that much detail. For example: require(Hmisc) x - rnorm(1e6) pdf(test.pdf) Ecdf(x) dev.off() The resulting pdf files is 31MB. Is there any easy way to get a smaller pdf file without having to manually prune the dataset? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] QUADRATIC PROGRAMMING
hi, what code in R would I use to solve the problem below? An apartment complex has 250 apartments to rent.If they rent x apartments then their monthly profit is given by: p(x)= -8^x^2 + 3200x -8 Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] QUADRATIC PROGRAMMING
hi, what code in R would I use to solve the problem below? An apartment complex has 250 apartments to rent.If they rent x apartments then their monthly profit is given by: p(x)= -8^x^2 + 3200x -8 Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tight Axes in Prepanel Function
How do I specify a tight y-axis, where the plot completely fills the y-axis range, inside the prepanel function? For example, consider the following code: require(lattice) set.seed(12345) x - 1:1000 y - cumsum(rnorm(length(x))) prepanel.test - function(x, y, groups = NULL, subscripts = NULL, ...) { if (is.null(groups)) { result - list(ylim = range(y)) } else { result - list(ylim = range(y, finite = TRUE)) } return (result) } print(xyplot(y~x, prepanel = prepanel.test, type = 'l', grid = TRUE), split = c(1,1,1,2), more = TRUE) print(xyplot(y~x, ylim = range(y, finite = TRUE), type = 'l', grid = TRUE), split = c(1,2,1,2)) The top plot has extra whitespace at the top and bottom. Is there any way to eliminate this without having to specify 'ylim' directly in the call the 'xyplot'? (The reason I want to include this in the prepanel function is that I want to add conditioning and use the combineLimits function in the latticeExtra package.) Thanks. - Elliot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] combineLimits and Dates
I'm having some trouble using the latticeExtra 'combineLimits' function with a Date x-variable: require(lattice) set.seed(12345) dates - seq(as.Date(2011-01-01), as.Date(2011-12-31), days) dat - data.frame(d = rep(dates, 4), g = factor(rep(rep(c(1,2), each = length(dates)), 2)), h = factor(rep(c(a, b), each = length(dates)*2)), x = rnorm(4 * length(dates)), y = rnorm(4 * length(dates))) plt1 - xyplot(x + y ~ d | g, groups = h, data = dat, type = 'l', scales = list(relation = free), auto.key = TRUE) plt1 - useOuterStrips(plt1) plt1 - combineLimits(plt1) The x-axis labels are right after the call to 'useOuterStrips' but they get converted to numeric after the call to 'combineLimits'. How do I keep them as date labels? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] How to change the order of columns in a data frame?
Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 change the order of columns in a data frame?
It does not work when using more variables, and my data frames usually contains about thousand columns... Best, Joel fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8), X5=c(5,5,5)) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 X5 1 0 1 6 7 3 4 9 2 8 5 2 0 1 6 7 3 4 9 2 8 5 3 0 1 6 7 3 4 9 2 8 5 pos - colnames(fakedata)[2:ncol(fakedata)] pos [1] X1 X6 X7 X3 X4 X9 X2 X8 X5 pos - c(1, 1+as.numeric(gsub(X, , pos))) pos [1] 1 2 7 8 4 5 10 3 9 6 fakedata[, pos] A X1 X9 X2 X7 X3 X5 X6 X8 X4 1 0 1 9 2 7 3 5 6 8 4 2 0 1 9 2 7 3 5 6 8 4 3 0 1 9 2 7 3 5 6 8 4 Sarah Goslee sarah.gos...@gmail.com 17-02-2012 14:36 fakedata - data.frame(A=c(0,0,0), X2=c(2,2,2), X1=c(1,1,1), X3=c(3,3,3)) fakedata A X2 X1 X3 1 0 2 1 3 2 0 2 1 3 3 0 2 1 3 pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata[, pos] A X1 X2 X3 1 0 1 2 3 2 0 1 2 3 3 0 1 2 3 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel -- Sarah Goslee http://www.functionaldiversity.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 change the order of columns in a data frame?
@Alfredo The X is removed, but the reordering does not work: colnames(df)[1] - Mass columnNames - colnames(df) colnames(df) [1] Mass X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 colnames(df) - gsub(X,,colnames(df)) colnames(df) [1] Mass 110 11 12 13 14 15 16 17 18 19 220 34567 89 df - df[,colnames(df)] colnames(df) [1] Mass 110 11 12 13 14 15 16 17 18 19 220 34567 89 Best, Joel Alfredo Alessandrini caveneb...@gmail.com 17-02-2012 14:40 Hi Joel, to replace the colnames: colnames(dataframe - )gsub(X,,colnames(dataframe)) to order by colnames: dataframe - dataframe[,colnames(dataframe)] Alfredo 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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 change the order of columns in a data frame?
@ Jim That would work for just a few columns, but I will have around 1000 of them so I need something more generic. best, Joel jim holtman jholt...@gmail.com 17-02-2012 14:44 pos2 - pos1[, c(X, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20)] 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 change the order of columns in a data frame?
Thank you Sarah, now it works!! Sarah Goslee sarah.gos...@gmail.com 17-02-2012 15:13 Sorry, it should be: fakedata[, order(pos)] A X1 X2 X3 X4 X5 X6 X7 X8 X9 1 0 1 2 3 4 5 6 7 8 9 2 0 1 2 3 4 5 6 7 8 9 3 0 1 2 3 4 5 6 7 8 9 Using order also ensures that non-sequential column ids will work: fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8)) pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 1 0 1 6 7 3 4 9 2 8 2 0 1 6 7 3 4 9 2 8 3 0 1 6 7 3 4 9 2 8 fakedata[, order(pos)] A X1 X2 X3 X4 X6 X7 X8 X9 1 0 1 2 3 4 6 7 8 9 2 0 1 2 3 4 6 7 8 9 3 0 1 2 3 4 6 7 8 9 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: It does not work when using more variables, and my data frames usually contains about thousand columns... Best, Joel fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8), X5=c(5,5,5)) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 X5 1 0 1 6 7 3 4 9 2 8 5 2 0 1 6 7 3 4 9 2 8 5 3 0 1 6 7 3 4 9 2 8 5 pos - colnames(fakedata)[2:ncol(fakedata)] pos [1] X1 X6 X7 X3 X4 X9 X2 X8 X5 pos - c(1, 1+as.numeric(gsub(X, , pos))) pos [1] 1 2 7 8 4 5 10 3 9 6 fakedata[, pos] A X1 X9 X2 X7 X3 X5 X6 X8 X4 1 0 1 9 2 7 3 5 6 8 4 2 0 1 9 2 7 3 5 6 8 4 3 0 1 9 2 7 3 5 6 8 4 Sarah Goslee sarah.gos...@gmail.com 17-02-2012 14:36 fakedata - data.frame(A=c(0,0,0), X2=c(2,2,2), X1=c(1,1,1), X3=c(3,3,3)) fakedata A X2 X1 X3 1 0 2 1 3 2 0 2 1 3 3 0 2 1 3 pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata[, pos] A X1 X2 X3 1 0 1 2 3 2 0 1 2 3 3 0 1 2 3 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel -- Sarah Goslee http://www.functionaldiversity.org -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 names on dataset
Hi fellow R users. I have a problem when i try to change the Names of the columns on a dataset: The names of the names dataset looks like this: toPlot names(toPlot) [1] REPORT_20 REPORT_21 REPORT_22 REPORT_23 [5] REPORT_24 REPORT_25 REPORT_QREP001 REPORT_RS010 [9] REPORT_RS011 REPORT_RS030 REPORT_RS090 REPORT_RS110 [13] REPORT_RS120 REPORT_RS121 REPORT_RS122 REPORT_RS130 [17] REPORT_RS131 REPORT_RS140 REPORT_RS141 Then I got an dataset with correspondent texts text ID TEXT 1 REPORT_RS010_D Statusrapport 2 REPORT_RS011_D Ifyllnad 3 REPORT_RS030_D Export 4 REPORT_RS090_D Uppföljning 5 REPORT_RS110_D Guidelines 6 REPORT_RS120_DKorstabulering - en gruppvariabel 7 REPORT_RS121_D Korstabulering - jämförelse med andra enheter 8 REPORT_RS122_D Korstabulering- två klassvariabler och jämförelse med andra 9 REPORT_RS130_D Sjukdomar 10 REPORT_RS131_D Sjukdomar och en gruppvariabel 11 REPORT_RS140_D Operationer 12 REPORT_RS141_D Operationer och en gruppvariabel I what i want is to change the names of toPlot with the real texts so I tried this: names(toPlot)[names(toPlot)==REPORT_RS140]-text[text$ID==paste(REPORT_RS140,_D,sep=),2]; that gave me this strange result names(toPlot) [1] REPORT_20 REPORT_21 REPORT_22 REPORT_23 [5] REPORT_24 REPORT_25 REPORT_QREP001 REPORT_RS010 [9] REPORT_RS011 REPORT_RS030 REPORT_RS090 REPORT_RS110 [13] REPORT_RS120 REPORT_RS121 REPORT_RS122 REPORT_RS130 [17] REPORT_RS131 7 REPORT_RS141 As you can see I got the number 7 instead of the text and I dont know why. Can anyone spot the error? //joel -- View this message in context: http://r.789695.n4.nabble.com/Change-names-on-dataset-tp4091154p4091154.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Normality tests on groups of rows in a data frame, grouped based on content in other columns
Hi Dennis, Thanks for your prompt response. Best, Joel Dennis Murphy djmu...@gmail.com 30-10-2011 21:11 Hi: Here are a few ways (untested, so caveat emptor): # plyr package library('plyr') ddply(df, .(Plant, Tissue, Gene), summarise, ntest = shapiro.test(ExpressionLevel)) # data.table package library('data.table') dt - data.table(df, key = 'Plant, Tissue, Gene') dt[, list(ntest = shapiro.test(ExpressionLevel)), by = key(dt)] # aggregate() function aggregate(ExpressionLevel ~ Plant + Tissue + Gene, data = df, FUN = shapiro.test) # doBy package: summaryBy(ExpressionLevel ~ Plant + Tissue + Gene, data = df, FUN = shapiro.test) There are others, too... HTH, Dennis 2011/10/30 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear R users, I have a data frame in the form below, on which I would like to make normality tests on the values in the ExpressionLevel column. head(df) ID Plant Tissue Gene ExpressionLevel 1 1 p1 t1 g1 366.53 2 2 p1 t1 g2 0.57 3 3 p1 t1 g311.81 4 4 p1 t2 g1 498.43 5 5 p1 t2 g2 2.14 6 6 p1 t2 g3 7.85 I would like to make the tests on every group according to the content of the Plant, Tissue and Gene columns. My first problem is how to run a function for all these sub groups. I first thought of making subsets: group1 - subset(df, Plant==p1 Tissue==t1 Gene==g1) group2 - subset(df, Plant==p1 Tissue==t1 Gene==g2) group3 - subset(df, Plant==p1 Tissue==t1 Gene==g3) group4 - subset(df, Plant==p1 Tissue==t2 Gene==g1) group5 - subset(df, Plant==p1 Tissue==t2 Gene==g2) group6 - subset(df, Plant==p1 Tissue==t2 Gene==g3) etc... But that would be very time consuming and I would like to be able to use the code for other data frames... I have also tried to store these in a list, which I am looping through, running the tests, something like this: alist=list(group1, group2, group3, group4, group5, group6) for(i in alist) { print(shapiro.test(i$ExpressionLevel)) print(pearson.test(i$ExpressionLevel)) print(pearson.test(i$ExpressionLevel, adjust=FALSE)) } But, there must be an easier and more elegant way of doing this... I found the example below at http://stackoverflow.com/questions/4716152/why-do-r-objects-not-print-in-a-function-or-a-for-loop. I think might be used for the printing of the results, but I do not know how to adjust for my data frame, since the functions are applied on several columns instead of certain rows in one column. DF - data.frame(A = rnorm(100), B = rlnorm(100)) obj2 - lapply(DF, shapiro.test) tab2 - lapply(obj, function(x) c(W = unname(x$statistic), p.value = x$p.value)) tab2 - data.frame(do.call(rbind, tab2)) printCoefmat(tab2, has.Pvalue = TRUE) Finally, I have found several different functions for testing for normality, but which one(s) should I choose? As far as I can see in the help files they only differ in the minimum number of samples required. Thanks in advance! Kind regards, Joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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] Normality tests on groups of rows in a data frame, grouped based on content in other columns
Dear R users, I have a data frame in the form below, on which I would like to make normality tests on the values in the ExpressionLevel column. head(df) ID Plant Tissue Gene ExpressionLevel 1 1 p1 t1 g1 366.53 2 2 p1 t1 g2 0.57 3 3 p1 t1 g311.81 4 4 p1 t2 g1 498.43 5 5 p1 t2 g2 2.14 6 6 p1 t2 g3 7.85 I would like to make the tests on every group according to the content of the Plant, Tissue and Gene columns. My first problem is how to run a function for all these sub groups. I first thought of making subsets: group1 - subset(df, Plant==p1 Tissue==t1 Gene==g1) group2 - subset(df, Plant==p1 Tissue==t1 Gene==g2) group3 - subset(df, Plant==p1 Tissue==t1 Gene==g3) group4 - subset(df, Plant==p1 Tissue==t2 Gene==g1) group5 - subset(df, Plant==p1 Tissue==t2 Gene==g2) group6 - subset(df, Plant==p1 Tissue==t2 Gene==g3) etc... But that would be very time consuming and I would like to be able to use the code for other data frames... I have also tried to store these in a list, which I am looping through, running the tests, something like this: alist=list(group1, group2, group3, group4, group5, group6) for(i in alist) { print(shapiro.test(i$ExpressionLevel)) print(pearson.test(i$ExpressionLevel)) print(pearson.test(i$ExpressionLevel, adjust=FALSE)) } But, there must be an easier and more elegant way of doing this... I found the example below at http://stackoverflow.com/questions/4716152/why-do-r-objects-not-print-in-a-function-or-a-for-loop. I think might be used for the printing of the results, but I do not know how to adjust for my data frame, since the functions are applied on several columns instead of certain rows in one column. DF - data.frame(A = rnorm(100), B = rlnorm(100)) obj2 - lapply(DF, shapiro.test) tab2 - lapply(obj, function(x) c(W = unname(x$statistic), p.value = x$p.value)) tab2 - data.frame(do.call(rbind, tab2)) printCoefmat(tab2, has.Pvalue = TRUE) Finally, I have found several different functions for testing for normality, but which one(s) should I choose? As far as I can see in the help files they only differ in the minimum number of samples required. Thanks in advance! Kind regards, Joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Not saving plot
Hi I got a strange problem. I got this code: poc-function(USER=nana,REGISTRY=nana,...){ require(RMySQL) require(R2HTML) require(lattice) ... (removed the dataprocessing) toReturn=capture.output(HTML(as.title(En liten rapport!),file=,align=center)) fileDir-paste(/home/joel/tmpR/rikssvikt/,USER,sep=); fileName-tempfile(pattern=UTT1, tmpdir=); try(png(paste(fileDir,fileName,.png,sep=))); barchart(toPlot,xlab=Antal körningar); dev.off(); gfn -paste(filemanager?USERID=,USER,file=,fileName,.png,sep=); tmp-capture.output(HTMLInsertGraph(file=,GraphFileName=gfn)); toReturn-paste(toReturn,substr(tmp,1,nchar(tmp)-8)); return(paste(div,toReturn[2],/div,sep=)) } When I just run the code without its being in the function in works and saves the plot at the designated location. But when I instead try to run the code when its inside the function it dossent save the plot at all. Anyone know why that is? //joel -- View this message in context: http://r.789695.n4.nabble.com/Not-saving-plot-tp3850981p3850981.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Not saving plot
Seems to have something todo with barchart. Cuz if I just change it to plot it works. But I want to use barchart due to the graphical advantages so do anyone have an ide. -- View this message in context: http://r.789695.n4.nabble.com/Not-saving-plot-tp3850981p3851255.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Not saving plot
You sir are a hero! It works now thanks to your fast and accurate answer. Thanks for the help. //joel -- View this message in context: http://r.789695.n4.nabble.com/Not-saving-plot-tp3850981p3851331.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Auto size of plots.
Hi I'm wondering if there is anyway to auto set the margin of a plot. Right now I'm setting it with par(mar=...) so that all the text for a bar shows up inside the plot. But I don't want to change par(mar=) for every new plot I make. So is there any way to tell R to increase the margin automatic as long as something is outside its borders? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Auto-size-of-plots-tp3846560p3846560.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R cmd build error -- running 'zip' failed
Hi All, My attempts to build an R package on my Windows 7 computer using R V13.0 ir R V13.1 using R CMD build --binary filename have been failing at the penultimate step with the error message running 'zip' failed coming after the procedure has completed the MD5 sums step.The same build command on the same package completes successfully on my older Vista computer. Since I would prefer to do the builds on the Windows 7 computer I would appreciate any thoughts on why this maybe happening and what I can do to fix the problem. Thanks and best regards, Joel Pitt [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Read file line by line
Hi I got a file that looks like this: (i have shorten it alot the real file is over 200k rows long) chr10 rs7909677 101955 A G 0 1 0 1 0 0... chr10 rs2436025 238506 C G 1 0 0 1 0 0... chr10 rs11253562 148946 C T 0 1 0 0 1 ... chr10 rs1105116 230788 G T 0 0 1 0 0 1... chr10 rs4881551 149076 A G 0 1 0 0 1 0 0 1... What I want it to go trough the file and get the highest value in the third column so to say. And because the file is so big I don't want to read it all into the memory so reading in chunks and then traverse it line by line and get the biggest number. What I've experiment with is something like this inFile - file('gwas_data_chr10.gen') output - 0 while(length(input - readLines(inFile, n=1000)) 0){ for (i in seq_along(input)){ temp-as.numeric(strsplit(input[i], +)[[1]][3]) if(outputtemp){ output-temp } } } close(inFile) The problem is that it seems to get stuck on an infinity loop of the 1000 first rows of the file, it dossent continue with the next 1000 from the first loop so to say. Can someone see the error in my code or dose anyone have an other solution to the problem? -- View this message in context: http://r.789695.n4.nabble.com/Read-file-line-by-line-tp3602349p3602349.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Read file line by line
Found what was wrong with my code changed: inFile - file('gwas_data_chr10.gen') to: inFile - file('gwas_data_chr10.gen','r') Dunno why its important but it is :P -- View this message in context: http://r.789695.n4.nabble.com/Read-file-line-by-line-tp3602349p3602399.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] splom Tick Location
When using the 'splom' function of the 'lattice' packge, is it possible to get all the tick marks in the outer margins of the plot? X - as.data.frame(matrix(rnorm(1000), 100, 10)) plot(X) ## Tick marks are in the outer margin splom(X) ## Tick marks are inside the on-diagonal panels Thanks. - Elliot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Errors and line numbers in scripts?
Is it possible to get R to report the line number of an error when a script is called with source()? I found the following post from 2009, but it's not clear to me if this ever made it into the release version: ws wrote: * Is there a way to have R return the line number in a script when it errors out? ** ** I call my script like: ** ** $ R --vanilla script.R output.txt ** ** I seem to remember a long discussion about this at some point, but I can't ** remember the outcome. ** ** * The current development version returns much more information about error locations. I don't know if it will handle this case (R doesn't get told the filename in case of input redirection, for example). Generally the goal is to report error lines during interactive use, batch use is assumed to already be debugged. Duncan Murdoch Thanks. - Elliot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop over a split string
Hi I got a string that looks like this: string-a b c d e f And what I wanna do is loop trough all the letters. like for(i in string){ print(i) } would render the result: a b c d e f Ive tried using strsplit but without result, dose anyone know how I could make this happen? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Loop-over-a-split-string-tp3514204p3514204.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop over a split string
This is no homework, Im just trying to learn R but sorry for wasting your time you all mighty God of R Uwe Ligges. And if this is not a forum to ask simple questions can you please redirect me to where I might get help? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Loop-over-a-split-string-tp3514204p3514225.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop over a split string
Thx Paul My string aint that simple its just that if it works for this simple example it will work for my string therefor I just used the a b c d e f syntax. -- View this message in context: http://r.789695.n4.nabble.com/Loop-over-a-split-string-tp3514204p3514252.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Cumsum in Lattice Panel Function
That worked perfectly. Thanks! - Elliot On Mon, May 09, 2011 at 12:20:36AM +0530, Deepayan Sarkar wrote: On Fri, May 6, 2011 at 9:24 PM, Elliot Joel Bernstein elliot.bernst...@fdopartners.com wrote: I'm trying to create an xyplot with a groups argument where the y-variable is the cumsum of the values stored in the input data frame. I almost have it, but I can't get it to automatically adjust the y-axis scale. How do I get the y-axis to automatically scale as it would have if the cumsum values had been stored in the data frame? Here is the code I have so far: require(lattice) dates - seq(as.Date(2011-01-01), as.Date(2011-04-30), days) g - 1:3 dat - data.frame(date = rep(dates, length(g)), group = rep(g, each = length(dates)), value = rnorm(length(dates)*length(g)) + 0.05) xyplot(value ~ date, data = dat, group = group, type = 'l', grid = TRUE, panel = panel.superpose, panel.groups = function(x, y, ...) { panel.xyplot(x, cumsum(y), ...) }) I want the result to look the same as if I had done dat$cumvalue - with(dat, unsplit(lapply(split(value, group), cumsum), group)) xyplot(cumvalue ~ date, data = dat, group = group, type = 'l', grid = TRUE) You need something along the lines of xyplot(value ~ date, data = dat, group = group, type = 'l', grid = TRUE, panel = panel.superpose, panel.groups = function(x, y, ...) { panel.xyplot(x, cumsum(y), ...) }, prepanel = function(x, y, groups, ...) { yy - unlist(tapply(y, groups, cumsum)) list(ylim = range(yy, finite = TRUE)) }) -Deepayan -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Cumsum in Lattice Panel Function
I'm trying to create an xyplot with a groups argument where the y-variable is the cumsum of the values stored in the input data frame. I almost have it, but I can't get it to automatically adjust the y-axis scale. How do I get the y-axis to automatically scale as it would have if the cumsum values had been stored in the data frame? Here is the code I have so far: require(lattice) dates - seq(as.Date(2011-01-01), as.Date(2011-04-30), days) g - 1:3 dat - data.frame(date = rep(dates, length(g)), group = rep(g, each = length(dates)), value = rnorm(length(dates)*length(g)) + 0.05) xyplot(value ~ date, data = dat, group = group, type = 'l', grid = TRUE, panel = panel.superpose, panel.groups = function(x, y, ...) { panel.xyplot(x, cumsum(y), ...) }) I want the result to look the same as if I had done dat$cumvalue - with(dat, unsplit(lapply(split(value, group), cumsum), group)) xyplot(cumvalue ~ date, data = dat, group = group, type = 'l', grid = TRUE) Thanks for your help. - Elliot Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Remove all whitespaces
Hi I got a string that looks something like this 1 2 3 4 5 6 7 8 9 ... and I want it to be 123456789... So I want to remove all spaces (or whitespaces) from my string. Anyone know a good way of doing this? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Remove-all-whitespaces-tp3497867p3497867.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Alter a line in a file.
Hi all R users Ive got a file that contains diffrent settings in the manor of: setting1=value1 setting2=value2 setting3=value3 setting4=value4 . . . What I want to do is open the file and change the value of a specific setting like wanna change setting4=value4 - setting4=value5 and then save the file again. setting1=value1 setting2=value2 setting3=value3 setting4=value5 . . . -- View this message in context: http://r.789695.n4.nabble.com/Alter-a-line-in-a-file-tp3498187p3498187.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Alter a line in a file.
jholtman wrote: a - readLines(textConnection('setting1=value1 setting2=value2 setting3=value3 setting4=value4')) closeAllConnections() # change values ac - sub('setting4=value4', 'setting4=value5', a) writeLines(ac, con='myFile.txt') Problem is that I dont know the value on all the settings that I wanna change otherwise that looks like something to continue on. Petr Pikal wrote: What file, what is its structure, is it some R object or separate file? What did you try and what went wrong? Regards Petr Just a normal textfile nothing fancy Ive tried diffrent kind of ways of useing my OS witch is linux by the system command to do it for me but Im not good enought on regexp to get it to work properly. -- View this message in context: http://r.789695.n4.nabble.com/Alter-a-line-in-a-file-tp3498187p3498316.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Read last line of a file
Hi dear R users. I got a file that I need to extract the third column (or word) of the last line of files that has a diffrent amounts of rows. It works with x-read.tables(file) x[1,3] This returns the proper result but as the files is large this takes time and uses memory that is just unneccery. p-read.table(textConnection(system(tail -1 file,intern=TRUE))) p[1,3] This also returns the proper result but then requires the system to be unix based witch is quite silly if you ask me. Would rather just use R commands. So Im wondering if anyone of you got a better way of reading the last line of a file and extracting the third column (or word) of that line. Best regards //Joel Damberg -- View this message in context: http://r.789695.n4.nabble.com/Read-last-line-of-a-file-tp3494963p3494963.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 and filtering time series data
My current code looks like this. Anything that can be improved? #! /usr/bin/rscript # install.packages(c('zoo','xts')) library(zoo) library(xts) req_stats - function(data, type = NA) { if (is.na(type)) csv - data else # subset of data matching our request type csv - subset(data, Kind == type) # import into a time series x - xts(csv$Duration, as.POSIXct(csv$Time)) # requests per second rps - period.apply(x, endpoints(x, 'seconds'), length) # stats c(length(x), mean(x), var(x), quantile(x, c(.05, .95)), mean(rps)) # indexFormat(x) - %Y-%m-%d %H:%M:%OS # options(digits.secs=6) } # assumes column headers data - read.csv(benchie.csv) # take out the rows with N all - subset(data, Include == Y) # Kind: R = sidebar request, C = sidebar click, U = upload doc, A = create ad sidebar_req - req_stats(all, R) # sidebar_click - req_stats(all, C) doc_upload - req_stats(all, U) ad_create - req_stats(all, A) all - req_stats(all) # mdat - rbind(all, sidebar_req, sidebar_click, doc_upload, ad_create) # rownames(mdat) - c(all, sidebar req, sidebar click, doc upload, ad create) mdat - rbind(all, sidebar_req, doc_upload, ad_create) rownames(mdat) - c(all, sidebar req, doc upload, ad create) colnames(mdat) - c(count, mean, var, 5%, 95%, rps) print(round(mdat, digits = 3)) -- - for hire: mac osx device driver ninja, kernel extensions and usb drivers -++--- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont -++--- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] microsecond timestamp support
Does R have support for microseconds in timestamps, e.g. when reading this in Time,Include,Kind,Duration 2011-04-01 14:20:36.368324,Y,U,1.03238296509 2011-04-01 14:20:35.342732,Y,C,0.0252721309662 2011-04-01 14:20:34.337209,Y,R,0.00522899627686 Thanks, Joel -- - for hire: mac osx device driver ninja, kernel extensions and usb drivers -++--- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont -++--- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 and filtering time series data
Folks, I'm new to R and would like to use it to analyze web server performance data. I collect the data in this CSV format: 1304083104.41,Y,668.856249809 1304083104.41,Y,348.143193007 First column is a seconds.microseconds timestamp, rows with N instead of Y need to be skipped and the last column has the same format as the first column, except it's request duration (latency). I would like to calculate average number of requests per second, mean latency, variance, 5 and 95 percentiles. What is the best way to accomplish this, starting with importing of time series? Thanks, Joel -- - for hire: mac osx device driver ninja, kernel extensions and usb drivers -++--- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont -++--- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Scaling Lattice Graphics for tikzDevice
On Feb 18, 2011 11:02 PM, Deepayan Sarkar deepayan.sar...@gmail.com wrote: On Fri, Feb 18, 2011 at 11:04 PM, Elliot Joel Bernstein elliot.bernst...@fdopartners.com wrote: I'm trying to use lattice graphics to produce some small plots for inclusion in a LaTeX file. I want the LaTeX fonts to be used in the plots, but to be scaled down to match the size of the plot. I have written the following code to apply a scaling factor to all the cex and padding entries in the trellis parameters, but there is still a large white space between the key and the top of the plot area. Does anyone know how I can get rid of that (or if I'm going about this all wrong and there's a much cleaner way)? ## -- ## ## test.R ## ## -- ## require(tikzDevice) I have not (yet) used tikzDevice, so don't know what impact it will have, but in my experience with pdf(), it's usually more effective to create a larger file and then scale it when including it in the .tex file. -Deepayan require(lattice) rescale.pars - function(cex.factor = 0.5, padding.factor = 0.25, pars = trellis.par.get()) { result - NULL for (i in seq_along(pars)) { if (names(pars)[[i]] == cex) { if (is.null(result)) { result - list() } result - c(result, cex=cex.factor*pars[[i]]) } else if (grepl(padding$, names(pars)[[i]])) { if (is.null(result)) { result - list() } eval(parse(text=sprintf(result - c(result, %s=padding.factor*pars[[i]]), names(pars)[[i]]))) } else if (inherits(pars[[i]], list)) { temp - rescale.pars(cex.factor, padding.factor, pars[[i]]) if (!is.null(temp)) { result[[names(pars)[[i - temp } } } return (result) } x - 1:100 y - cumsum(rnorm(length(x), 1, 10)) z - cumsum(rnorm(length(x), 1, 20)) tikz(test-plot.tex, width=2, height=2) xyplot(y + z ~ x, main = My Plot, xlab = x, auto.key=list(text=c(Line 1, Line 2), points=FALSE, lines=TRUE), grid = TRUE, par.settings = rescale.pars()) dev.off() ## -- ## ## END R CODE ## ## -- ## Thanks. - Elliot - Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Deepayan - Thank you for your reply. In the past I've generally done what you suggest, but I'm trying to use tikz so the graphics can inherit the fonts used in the LaTeX document. Is there a way to do that with the pdf device? Thanks. - Elliot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Scaling Lattice Graphics for tikzDevice
)) { temp - rescale.pars(cex.factor, padding.factor, pars[[i]]) if (!is.null(temp)) { result[[names(pars)[[i - temp } } } return (result) } x - 1:100 y - cumsum(rnorm(length(x), 1, 10)) z - cumsum(rnorm(length(x), 1, 20)) tikz(test-plot.tex, width=2, height=2) xyplot(y + z ~ x, main = My Plot, xlab = x, auto.key=list(text=c(Line 1, Line 2), points=FALSE, lines=TRUE), grid = TRUE, par.settings = rescale.pars()) dev.off() ## -- ## ## END R CODE ## ## -- ## Thanks. - Elliot - Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst
Re: [R] saving plots
look at ?savePlot It will save the current plot you are viewing. -- View this message in context: http://r.789695.n4.nabble.com/saving-plots-tp3304540p3304548.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Confused
Hi Im confused by one thing, and if someone can explain it I would be a happy rev(strsplit(hej,NULL)) [[1]] [1] h e j lapply(strsplit(hej,NULL),rev) [[1]] [1] j e h Why dossent the first one work? What is it in R that fails so to say that you need to use lapply for it to get the correct output. -- View this message in context: http://r.789695.n4.nabble.com/Confused-tp3263700p3263700.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL, cant find MySQL
Hi I'm having some trouble with getting RMySQL installed on my Ubuntu system. As the apt-get install version of R is 2.10.x I've reinstalled 2.12 the old fashion way by ./conf and make. But now when I shall install RMySQL I get Configuration error: could not find the MySQL installation include and/or library directories. Manually specify the location of the MySQL libraries and the header files and re-run R CMD INSTALL. And in truth I cant find the headers or libraries anywhere on my comp, but I have MySQL up and running. I did install MySQL via apt-get so if anyone know where it put the different files I would love to know :). Thx for the help Joel -- View this message in context: http://r.789695.n4.nabble.com/RMySQL-cant-find-MySQL-tp3253689p3253689.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rserve
Hi Im just wondering if anyone knows if Rserve is parallel programed? and if so how, do it send every new connection to a new node or? Thx for the help Joel -- View this message in context: http://r.789695.n4.nabble.com/Rserve-tp3251032p3251032.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rserve
Can add that if it dossent split up the processes by default is there anyway I can do it by myself? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Rserve-tp3251032p3251138.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hidden variables
Hi Im trying to make a package in R just to learn how it works. One thing I dont manage to do is to make a hidden environment or variable so to say. I want a hash list that I create my useing: TestEnv-new.env() assign(Key1,Ans1,envir=TestEnv) assign(Key2,Ans2,envir=TestEnv) Then I just have this function to try it: TestFunc- function(Key, ...) UseMethod(TestFunc) TestFunc.default - function(Key,...){ Ans-get(Key, envir=TestEnv) print(Ans) } But when I load this package I can access the TestEnv by just typing TestEnv, but I want this one hidden so that you only can get the Ans from the Key via the TestFunc. Thx for the help Joel -- View this message in context: http://r.789695.n4.nabble.com/Hidden-variables-tp3251588p3251588.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hidden environment
Hi I wondering if its possible to make a hidden environment for a package, so the user cant see whats in it but the diffrent functions inside the package can use the variables in the environment. Hope you can understand what Im after. Joel -- View this message in context: http://r.789695.n4.nabble.com/Hidden-environment-tp3253502p3253502.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Generic Functions and Dates
I'm trying to write a generic function that calls different methods depending on the structure of the argument, but not the exact type of its contents. For example, the function 'nan2last' below works for a numeric vector but not for a vector of Date objects. Is there any way to make it work on any vector? setGeneric(nan2last, function(x) { standardGeneric(nan2last) }) setMethod(nan2last, vector, function(x) { naLocs - (1:length(x))[is.na(x)] if (length(naLocs) == 0) return (x) naLocs - naLocs[naLocs1] for (i in 1:length(naLocs)) { x[naLocs[i]] - x[naLocs[i]-1] } return(x) }) ## Works x - 1:10; x[sample(10,3)] - NA print(cbind(x, nan2last(x))) ## Doesn't work x - seq(as.Date(2011-01-01), as.Date(2011-01-31), days)
Re: [R] Accessing MySQL Database in R
You could try useing '127.0.0.1' instead of 'localhost' and see if that works. -- View this message in context: http://r.789695.n4.nabble.com/Accessing-MySQL-Database-in-R-tp3221264p3221291.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Waaaayy off topic...Statistical methods, pub bias, scientific validity
The issue Spencer brings up is a problem whether the funding is private or public. Just as businesses fund studies that support their goals, government agencies fund studies that justify the need for their services and expansion of their powers and budgets. In fact, there's a whole field of study variously called public choice economics and the new institutional economics that study these and related issues. On a related note, there is certainly a lot of self-selection bias in what fields of study people choose to enter. For just one example, it isn't too difficult to believe that of the pool of people talented and interested in statistics, those who choose to enter public health or epidemiology might be more likely to want research that justifies expansion of public health and environmental agencies' regulatory powers and this might affect the research questions they ask, the ways they design and select their statistical models, and what results they choose to include and exclude from publications. AFAIK, there is substantial evidence that researchers, espeically in non-experimental studies, tend to get results they expect or hope to find, even if they feel no conscious bias. This is likely one of the reasons observational studies are so frequently overturned by randomized controlled trials. RCT's provide less room for confirmation bias to rear its ugly head. Joel -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves Sent: Thursday, January 06, 2011 9:13 PM To: Carl Witthoft Cc: r-help@r-project.org Subject: Re: [R] Wyy off topic...Statistical methods, pub bias, scientific validity A more insidious problem, that may not affect the work of Jonah Lehrer, is political corruption in the way research is funded, with less public and more private funding of research (http://portal.unesco.org/education/en/ev.php-URL_ID=21052URL_DO=DO_TOPICU RL_SECTION=201.html). ...as private funding replaces tax money for basic science, we must expect an increase in research results that match the needs of the funding agency while degrading the quality of published research. This produces more research that can not be replicated -- effects that get smaller upon replication. (My wife and I routinely avoid certain therapies recommended by physicians, because the physicians get much of their information on recent drugs from the pharmaceuticals, who have a vested interest in presenting their products in the most positive light.) Spencer On 1/6/2011 2:39 PM, Carl Witthoft wrote: The next week's New Yorker has some decent rebuttal letters. The case is hardly as clear-cut as the author would like to believe. Carl __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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] pdf package help files
I think that should have been help.start() Joel -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves Sent: Saturday, December 18, 2010 1:35 PM To: Duncan Murdoch Cc: r-help@r-project.org; eric Subject: Re: [R] pdf package help files Hi, Duncan: I'm confused: help_start() Error: could not find function help_start Thanks, Spencer sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base On 12/18/2010 1:19 PM, Duncan Murdoch wrote: On 18/12/2010 2:20 PM, eric wrote: Newbie here...just learning Do most packages come with pdf versions of the help files ? If yes, how to I access the entire pdf file to be able to print it ? Is there a standard command for that ? No, the pdf version is not normally installed. If you want to see the same content on a locally installed package, run help_start() then browse to the package. The pdf files are just concatenated versions of all the help pages shown in that index. You can produce the pdf using R CMD Rd2dvi --pdf foo where foo is a directory holding the source code to the package. Alternatively, as others have suggested, just look at the PDF on CRAN. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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] package survey
and does anyone know if it is possible to find the codes for functions in survey package? Yes, you can find the code by doing the following: 1) Go to the CRAN R package list (http://cran.r-project.org/web/packages/), scroll down to the survey package link and click on it. 2) Scroll down to the Downloads section and download the package source file. The R folder in this file contains the code for the functions in the package. You can of course follow an analogous procedure to get the code for other packages. There might be an easier or quicker way to do it from within R but ,if there is, I haven't learned it yet. Joel -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of andrija djurovic Sent: Saturday, December 18, 2010 4:23 PM To: r-help@r-project.org Subject: [R] package survey Hi R users, could someone help me to find out which formulas, for standard error calculation, are used in following example: a=data.frame(weights=rep(c(10,1),c(4,1)),fpc=rep(41,5),uk=rep(1,5)) srs-svydesign(id=~1, weights=~weights, data=a) srs1-svydesign(id=~1, weights=~weights,fpc=~fpc, data=a) svytotal(~uk,srs) total SE uk41 9 svytotal(~uk,srs1) total SE uk41 8.4334 and does anyone know if it is possible to find the codes for functions in survey package? thanks in advance Andrija [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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] package survey
-Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Saturday, December 18, 2010 5:54 PM To: Joel Schwartz Cc: r-help@r-project.org Subject: Re: [R] package survey On Dec 18, 2010, at 8:11 PM, Joel Schwartz wrote: and does anyone know if it is possible to find the codes for functions in survey package? Yes, you can find the code by doing the following: 1) Go to the CRAN R package list (http://cran.r-project.org/web/packages/ ), scroll down to the survey package link and click on it. 2) Scroll down to the Downloads section and download the package source file. The R folder in this file contains the code for the functions in the package. You can of course follow an analogous procedure to get the code for other packages. There might be an easier or quicker way to do it from within R but ,if there is, I haven't learned it yet. (I suspect Joel knows this.) If the package is loaded, you can just type the name of the function at the console. svyhist # produces about a half-page of code. Yes, I should have suggested that option as well. It's probably the quickest way if you just want the code for one or a few functions. But if you want the code for most or all functions in a package (including ones for which you might not know the name off the top of your head) is there some way of sending the code for all functions in particular package to a .r file from the command line with one or two lines of code? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Dont print plot on screen
Hi is there any command or setting that allows you to do the plot command but it dose not print the plot on screen? So when you are saveing an plot in a function you dont want it to display the plot just save it. -- View this message in context: http://r.789695.n4.nabble.com/Dont-print-plot-on-screen-tp3078167p3078167.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 with capture.output
Hi Im trying to capture the output of HTML but dont really get what I want As an example: y-data.frame(a=c(1,2,3),b=c(1,2,3),c=c(1,2,3)) toReturn-capture.output(HTML(y,file=)); This gives me the output of toReturn as an vector: toReturn [1] [2] [3] p align= center [4] table cellspacing=0 border=1 [5] caption align=bottom class=captiondataframe/caption [6] trtd [7] \ttable border=0 class=dataframe [8] \ttbody [9] \ttr class= firstline [10] \t\tthnbsp; /th [11] \t\ttha /th [12] \t\tthb /th [13] \t\tthc/th [14] \t/tr . . . But what I want is a continues string of the code on just one row: [1] p align= center table cellspacing=0 border=1 caption align=bottom class=captiondataframe/caption ... Anyone know a way I can accomplish this? /Joel -- View this message in context: http://r.789695.n4.nabble.com/Help-with-capture-output-tp3074192p3074192.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 capture.output
Why to you always find the answer as soon as you have posted the Q here :P paste(toReturn, collapse=) But if anyone have a better solution plz share. //Joel -- View this message in context: http://r.789695.n4.nabble.com/Help-with-capture-output-tp3074192p3074199.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 with Rserv
Hi I get this error with Rserve: eval failedeval failed, request status: R parser: syntax erroreval failed, request status: R parser: input incompleteorg.rosuda.REngine.Rserve.RserveException: eval failed at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:233) at se.ucr.qrep.RGenerator.generateReport(RGenerator.java:45) Anyone know what it could mean? -- View this message in context: http://r.789695.n4.nabble.com/Error-with-Rserv-tp3074458p3074458.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Save R2HTML as an object instead of file
Or is there any kind of File buffer that dossent save a file on the harddrive? coz this gives me the thing I want but it still saves the file on the HD .HTML.file=(temp-file(era.html,w+)) HTML(NANALALA) HTML(diag(3)) Then I can just use readLines(temp) to get the result but as I said I dont want it to save the HTML on the HD just in an object. -- View this message in context: http://r.789695.n4.nabble.com/Save-R2HTML-as-an-object-instead-of-file-tp3066776p3066845.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Save R2HTML as an object instead of file
Hi Is it possible to instead of getting the HTML code written to a file, get it saved as a string in an object instead? Or is there any kind of package that can do this? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Save-R2HTML-as-an-object-instead-of-file-tp3066776p3066776.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Print to the cmd line in a script
Hi Ive written a script that loopes throu some data, but what I want to do is to print to the cmd line how many times it has looped to the cmd line. And as it is just a counter from 1 this should be quite easy :P but ive tried things like print(counter) and so on but it dossent print anything to the cmd prompt, so what is the command to print from inside a script? -- View this message in context: http://r.789695.n4.nabble.com/Print-to-the-cmd-line-in-a-script-tp3057009p3057009.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Print to the cmd line in a function
I do mean function not script, edit it in the forum but for the mailinglist here you have it. -- View this message in context: http://r.789695.n4.nabble.com/Print-to-the-cmd-line-in-a-function-tp3057009p3057025.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Aligning Grid Lines with Date Ticks in Trellis Plot
I know this issue has been discussed before, but I hoped the advent of pretty.Date would resolve it. In the following code, the first plot produces misaligned vertical grid lines, while in the second plot they are properly aligned. Is there any way to get something along the lines of the first call to produce properly aligned grid lines? X - data.frame(date=seq(as.Date(1990/01/01), as.Date(2010/11/24), by=1)) X$value - rnorm(length(X$date)) ## This produces grid lines not aligned with the date ticks xyplot(value ~ date, data=X, panel = function(...) { panel.grid(v=-1,h=-1,col=black) panel.xyplot(...) }) ## This produces grid lines aligned with the date ticks xyplot(value ~ date, data=X, panel = function(...) { panel.abline(v=pretty(X$date, 5)) panel.grid(v=0,h=-1,col=black) panel.xyplot(...) }) Thanks. - Elliot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] the first. from SAS in R
Is there any similar function in R to the first. in SAS? What it dose is: Lets say we have this table: a b c 1 1 5 1 0 2 2 0 2 2 0 NA 2 9 2 3 1 3 and then I want do to do one thing the first time the number 1 appers in a and something else the secund time 1 appers in a and so on. so something similar to: if first.a { a$d-1 }else{ a$d-0 } This would give me a b c b 1 1 5 1 1 0 2 0 2 0 2 1 2 0 NA 0 2 9 2 0 3 1 3 1 Is there such a function in R or anything similar? thx //Joel -- View this message in context: http://r.789695.n4.nabble.com/the-first-from-SAS-in-R-tp3055417p3055417.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Three-way ANOVA shows me two-way results
Marius think you wanted to do a new post and not reply to mine :P -- View this message in context: http://r.789695.n4.nabble.com/the-first-from-SAS-in-R-tp3055417p3055459.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Slow update(insert) on Data.frame
Hi When I try to update an number in a large data.frame by its pos It's really slow it take almost a sec to do this and I wonder why and if where is any faster way to update a number in a data.frame ive tried DF$col[POS]-number DF[xPOS,yPOS]-number Thx //Joel -- View this message in context: http://r.789695.n4.nabble.com/Slow-update-insert-on-Data-frame-tp3055707p3055707.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Prob with merge
Hi Im trying to merge 2 data frames using merge but I dont get the result i want Lets make this a small test as my data set is to big to put in here :). t1-data.frame(a=c(1,2,3,4,5,6),b=c(11,11,NA,11,11,11)) t1-data.frame(a=c(1,2,3,4,5,8),b=c(12,12,12,12,12,32)) this gives me: t1 a b 1 1 12 2 2 12 3 3 12 4 4 12 5 5 12 6 8 32 t2 a b 1 1 11 2 2 11 3 3 NA 4 4 11 5 5 11 6 6 11 now when i merge i get: merge(t1,t2, by=a) a b.x b.y 1 1 12 11 2 2 12 11 3 3 12 NA 4 4 12 11 5 5 12 11 But what I want is it to look like: a b.x b.y 1 1 12 11 2 2 12 11 3 3 12 NA 4 4 12 11 5 5 12 11 6 8 32 NA So I keep all of the rows from t1 and get an NA in dose slots at the t2 part of the merge. Anyone know how to accomplice this? Thx //Joel -- View this message in context: http://r.789695.n4.nabble.com/Prob-with-merge-tp3053652p3053652.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Prob with merge
Thx alot mate. -- View this message in context: http://r.789695.n4.nabble.com/Prob-with-merge-tp3053652p3053675.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extract elements that starts with...
Hi I got an table that contains this colum and i wonder if there is any nice way to extract all rows that contains all dose that start with A02, so all the rows that have A020 and A021 etc etc... | A010 | | A010 | | A010 | | A020 | | A020 | | A020 | | A020 | | A020 | | A021 | | A021 | Thx for your help //Joel -- View this message in context: http://r.789695.n4.nabble.com/Extract-elements-that-starts-with-tp3046332p3046332.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 elements that starts with...
Thx alot works perfect! //Joel -- View this message in context: http://r.789695.n4.nabble.com/Extract-elements-that-starts-with-tp3046332p3046420.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Multiple Line Plots with xyplot
I'm trying to make multiple line plots, each with a different color, using the xyplot command. Specifically, I have an NxK matrix Y and an Nx1 matrix x. I would like the plot to contain a line for each (x, Y[,i]), i=1:K. I know something like xyplot(Y[,1] + Y[,2] + Y[,3] ~ x, type='l') will work, but if Y is large, this notation can get very awkward. Is there a way to do something simpler, along the lines of xyplot(Y ~ x, type='l') Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Number above the bar?
Hi I got an barplot, and I would like to have the exact number of the bars just above the bars anyone know how to do this? Sorry for bad English, and I do hope that you understand what im after. //Joel -- View this message in context: http://r.789695.n4.nabble.com/Number-above-the-bar-tp3037438p3037438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] check RAM usage
Maybe should have said that Im working on a Linux unit :) and that command is for Windows only. But thx anyway If you got any other ideas please share. /Joel -- View this message in context: http://r.789695.n4.nabble.com/check-RAM-usage-tp3018753p3021938.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] check RAM usage
Hi Is there any way to check an certain command or procedure's RAM usage? Im after something similar to system.time(bla) that gives me the time the command took to preform but for RAM usage. Hope you understand what i mean. Best regards Joel -- View this message in context: http://r.789695.n4.nabble.com/check-RAM-usage-tp3018753p3018753.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Set value if else...
Hi I want to set a variable to either 1 or 0 depending on an value of a dataframe and then add this as a colum to the dataframe. This could be done with a loop but as we are able to do questions on a complete row or colum without a loop it would be sweet if it could be done. for example: table: Name Age Joel 24 agust 17 maja40 and so on... And what I want to do is a command that gives me VoteRight-1 if table$age18 else set VoteRight to 0 Then use cbind or something to add it to the table. so i get Name Age VoteRight Joel 241 agust 170 maja401 And as I said before im guessing this can be done without a loop... //Joel -- View this message in context: http://r.789695.n4.nabble.com/Set-value-if-else-tp2996667p2996667.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Set value if else...
Indeed I was close :) Thx for the fast respond! Have a good day //Joel -- View this message in context: http://r.789695.n4.nabble.com/Set-value-if-else-tp2996667p2996682.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plot table as table
The subject says it all :). So I have a table and I want it do be ploted like a table so to say and cant find any function/package that dose it for me. Anyone know of one? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Plot-table-as-table-tp2993270p2993270.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 table as table
It should look something like this (not at all relevant except the look) http://r.789695.n4.nabble.com/file/n2993297/tableR19.jpg -- View this message in context: http://r.789695.n4.nabble.com/Plot-table-as-table-tp2993270p2993297.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 table as table
Thx for the ideas will try them out. Have a wonderful day //Joel -- View this message in context: http://r.789695.n4.nabble.com/Plot-table-as-table-tp2993270p2993344.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rpart query
Dont know if it will work but you can try ctree from the party package require(party) bla - ctree(Class ~ Outlook + Temp + Humidity + Windy, data=dataframe) plot(bla) //Joel -- View this message in context: http://r.789695.n4.nabble.com/Rpart-query-tp2991198p2991417.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rpart query
My guess is that you have two few observations is your dataset for rpart to determin a safe dissision. -- View this message in context: http://r.789695.n4.nabble.com/Rpart-query-tp2991198p2991461.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rpart query
Or now Im pretty sure of it as when I took your dataset and used the magic way of ctrl-c ctrl-v to make some more observations I get a decision tree. -- View this message in context: http://r.789695.n4.nabble.com/Rpart-query-tp2991198p2991469.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rserve config
Dont know if this is the right forum for this but here we go. Trying to figure out where I should put the Rserv.conf file in windows, anyone have any idea? //Joel -- View this message in context: http://r.789695.n4.nabble.com/Rserve-config-tp2966394p2966394.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.