[R] Create a function to number each repeated visit or measurements
Hi dear R list members, I am trying to create a numerical variable that tracks the visits/entries that a subject has had. For example having a database of repeated serial measurements that are ordered by subject and time. So I would get a variable that says 0 for baseline visit/measurement, 1 for the second etc. In my case the unique identifier for each subject is AreaID Will the following code I can number the visits as long as I create as many lines as visits. But there is probably a way of coding a function or maybe there is already a function. DUP-rep(0,length(AreaID))DUP[2:length(DUP)]-sapply(2:(length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x-1],1,DUP[x]))DUP[3:length(DUP)]-sapply(3:( length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x-2],2,DUP[x])) My Guess was: AddLag-function(x) { DUP-c(rep(0,length(x)))for (i in 1:(max(as.numeric(GraphArtDB$Measure))+2)){ DUP[(i+1):length(x)]-sapply(((i+1):length(x)),function(x) ifelse(x[i]==x[x-i],i,DUP[x])) } return(DUP) } But it didn´t work. Any suggestions? Thanks in advance J ToledoUPennUSA [[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] get only little part of html with htmlParse
Here is my code. there are three method to get text to be parded by htmlParse function. 1.file on mycomputer options(encoding=gbk) library(XML) xmltext1 - htmlParse(/home/tiger/Desktop/27174.htm ) #/home/tiger/Desktop/27174.htm is the file of http://www.jb51.net/article/27174.htm downloaded on my computer. 2.url options(encoding=gbk) library(XML) xmltext2 - htmlParse(http://www.jb51.net/article/27174.htm; ) 3.readLines options(encoding=gbk) library(XML) txt=readLines(http://www.jb51.net/article/27174.htm;) xmltext3 - htmlParse(txt,asText=TRUE) method1,and method2 are ok,they can get right content to be parsed. when i run method 3 ,to my surprise ,xmltext3 can get some contents,but many are gone,they are not the same as method1,and method2,why? you can get only little part of html. xmltext3 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=zh-cnhead meta http-equiv=Content-Type content=text/html; charset=gb2312 titlePYTHONæ£å/title /head/html [[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] boxplot - bclust
These are warnings and I think that you can safely ignore them. It looks like the code should replace the line if (x$datamean) with something like if (!is.null(x$datamean)) Yes, I think so too - thanks for reporting this. David __ 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] binary data
Dear list, Hello to everybody, I´m interested in finding a package for statistical analysis of binary data, I have a matrix with the following structure: Case1 Case2 Case 3 ... CaseX Control1 Control2 Control3 ... ControlY Pep1 1 0 1 1 0 0 0 1 Pep2 1 1 1 1 1 0 0 1 Pep3 0 1 1 1 1 0 0 1 ... Pepz 1 1 1 1 1 0 0 1 I would like to know some R package to calculte similarity matrix or to make some statistical diferences between cases and controls Any help it would be very appreciated BW Juan --- Juan Fernandez Tajes, ph. D Grupo XENOMAR Departamento de BiologÃa Celular y Molecular Facultad de Ciencias-Universidade da Coruña Tlf. +34 981 167000 ext 2030 e-mail: jfernand...@udc.es [[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] [newbie] scripting remote check for R package
You might try: R --slave -e 'as.numeric(suppressWarnings(suppressPackageStartupMessages(require(ggplot2' Best, Gergely On Tue, Sep 4, 2012 at 3:30 AM, Tom Roche tom_ro...@pobox.com wrote: https://stat.ethz.ch/pipermail/r-help/2012-September/322985.html for RSERVER in 'foo' 'bar' 'baz' ; do ssh ${RSERVER} 'query R for package=package_name' done or is there a better way to script checking for an R package? https://stat.ethz.ch/pipermail/r-help/2012-September/323000.html I would call something like this via ssh [...] Rscript -e 'as.numeric(suppressWarnings(suppressPackageStartupMessages(require(ggplot2' https://stat.ethz.ch/pipermail/r-help/2012-September/323024.html Thanks! but [the] cluster where I need to run this (where I do *not* have root) [lacks Rscript.] So I'm wondering: 1 Is there a way to do `Rscript -e` with plain, commandline R? I learned how to use `R CMD BATCH`. It's definitely more painful than `Rscript -e`, but at least the following works: EXEC_DIR='/share/linux86_64/bin' # on foo, at least # EXEC_NAME='Rscript' EXEC_NAME='R' EXEC_PATH=${EXEC_DIR}/${EXEC_NAME} BATCH_INPUT_PATH=./junk.r # presumably in home dir BATCH_OUTPUT_PATH=./junk.r.out # ditto for RSERVER in 'foo' 'bar' 'baz' ; do echo -e ${RSERVER}: # The following 3 commands attempted to debug a # separate but related problem; about which, see # http://serverfault.com/questions/424027/ssh-foo-command-not-loading-remote-aliases # ssh ${RSERVER} ${EXEC_NAME} --version | head -n 1 # ssh ${RSERVER} grep -nHe 'bashrc' ~/.bash_profile # ssh ${RSERVER} grep -nHe '\W${EXEC_NAME}\W' ~/.bashrc ssh ${RSERVER} ${EXEC_PATH} --version | head -n 1 ssh ${RSERVER} echo -e 'as.numeric(suppressWarnings(suppressPackageStartupMessages(require(M3\n' ${BATCH_INPUT_PATH} ssh ${RSERVER} rm ${BATCH_OUTPUT_PATH} ssh ${RSERVER} ls -al ${BATCH_INPUT_PATH} ssh ${RSERVER} cat ${BATCH_INPUT_PATH} ssh ${RSERVER} ${EXEC_PATH} CMD BATCH --slave --no-timing ${BATCH_INPUT_PATH} ${BATCH_OUTPUT_PATH} ssh ${RSERVER} ls -al ${BATCH_OUTPUT_PATH} ssh ${RSERVER} head -n 1 ${BATCH_OUTPUT_PATH} echo # newline done Given the pain, I'd still like to know: 2 What should my admin have done to install both Rscript and R? (Alternatively, what should I tell my admin to do in order to make both Rscript and R available?) 3 Is there any reason to install R without Rscript? (Alternatively, when I ask my admin to install Rscript, is there any objection I should anticipate?) your assistance is appreciated, Tom Roche tom_ro...@pobox.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. [[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] boxplot of hierachical cluster
Hello everybody, I would like to make boxplots for my hierachical cluster, but only i found a package that not works with the current version. http://acccn.net/cr569/Rstuff/Minka/mining/html/boxplot.hclust.html I hope you can help me. Thank you. Best regards, Dominic library(cluster) cluster.Invierno - daisy(datos.corre[,-3],metric=gower,stand=TRUE) plot(hclust(cluster.Invierno),labels=datos.corre[,1]) str(datos.corre[,-3]) 'data.frame': 56 obs. of 6 variables: $ Estacion: Factor w/ 56 levels Abradelo,AltoDoRodicio,..: 1 2 3 4 5 6 7 8 9 10 ... $ Invierno: num 36 53.9 37.1 63.6 12.5 ... $ X : int 643449 616292 562796 669916 625025 631194 511201 524431 641809 590324 ... $ X.1 : int 4734442 4684126 4696309 4743224 4723028 4833932 4649389 4701030 4706108 4765782 ... $ X.2 : int 826 981 553 1364 432 421 473 424 697 731 ... $ X.3 : num 87961 82902 30608 84260 94169 ... [[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] R suitability for development project
On 09/03/2012 11:18 PM, Eric Langley wrote: chomp I note: Is it possible to have the output as an integer where 99 is the highest score? It certainly is. The mean ranks are: Item2Item3Item4 Totals 1.571429 1.642857 2.857143 3.928571 To make the highest score 99 (meaning the score for the highest ranked item) and the lowest score -99 as on your examples: # first convert high ranks to high numeric scores revmeanranks-4-meanranks revmeanranks Item1Item2Item3Item4 2.428571 2.357143 1.142857 0.071429 # scale the score to the desired range library(plotrix) rescale(revmeanranks,c(-99,99)) Item1 Item2 Item3 Item4 99.00 93.46 -9.15 -99.00 # then just round or truncate your values to get integers chomp I note: The look I am aiming to achieve (as shown here: http://community.abeo.us/sample-graphs/ ) is a relative position within the middle zero based horizontal axis. The mean is not required. Since all bars are 14 units long the upper and lower values note where the end of each bar should align, either to the right for Highest or to the left for Lowest. The third graph shows both. ~eric I think you may be doing something here that you don't intend. The point of plots like this is to transform numeric values into lengths or areas. If you don't maintain the same metric throughout the plot, the relationship between the two is lost. If you were using vertical lines to indicate the transformed mean ranks of the items, they could be placed at the appropriate positions. As you use different edges of the bars to place them, let's see, your bars are about 90 units wide so there would be about a 180 unit offset between positive and negative transformed mean ranks. Are you sure that you want to do this? Jim __ 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] Horizontal grid in background of barplot
On 09/04/2012 05:12 AM, David Arnold wrote: All, I have: x- matrix(c(22,3,6,69,9,4,7,81,23,4,22,50),nrow=3,byrow=TRUE) rownames(x)- c(Cold or flu,Headache,Backache); colnames(x)- c(Went to doctor,No response,Did nothing,Self-medicated) x- t(x) print(x) barplot(x,beside=TRUE, ylim=c(0,90), xlab=Ailment, ylab=Percent, legend.text=TRUE, args.legend=list(topright,title=Treatment)) abline(h=c(seq(10,90,10))) box() I'd like to get the horizontal lines in the background. Any suggestions? Hi David, Try this: library(plotrix) barp(x,col=gray(c(0.2,0.4,0.6,0.8)),names.arg=colnames(x), xlab=Ailment,ylab=Percent,ylim=c(0,90), do.first=expression(abline(h=seq(10,80,10 legend(2.5,85,rownames(x),fill=gray(c(0.2,0.4,0.6,0.8)), bg=white) Jim __ 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] Adding summary title to table
On Mon, 03-Sep-2012 at 03:25PM -0700, David Arnold wrote: | All, | | I have: | | x - matrix(c(22,3,6,69,9,4,7,81,23,4,22,50),nrow=3,byrow=TRUE) | rownames(x) - c(Cold or flu,Headache,Backache); | colnames(x) - c(Went to doctor,No response,Did | nothing,Self-medicated) | x - t(x) | print(x) | | 1. I'd like to add the title Nutritional Status above the column names | when displayed with print(x). | | 2. I'd like to add the title Academic Performance to the left of the row | names when displayed with print(x). | | Any thoughts? You'll get fairly close to what you want using print.char.matrix in the Hmisc package. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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] Create a function to number each repeated visit or measurements
Hi You did not provided any suitable data. x-sort(sample(letters[1:5], 50, rep=T)) unlist(lapply(split(x,x), function(x) (1:length(x))-1)) gives you a vector of indices from 0 to n for sorted vector x. Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jon Toledo Sent: Tuesday, September 04, 2012 7:59 AM To: r-help@r-project.org Subject: [R] Create a function to number each repeated visit or measurements Hi dear R list members, I am trying to create a numerical variable that tracks the visits/entries that a subject has had. For example having a database of repeated serial measurements that are ordered by subject and time. So I would get a variable that says 0 for baseline visit/measurement, 1 for the second etc. In my case the unique identifier for each subject is AreaID Will the following code I can number the visits as long as I create as many lines as visits. But there is probably a way of coding a function or maybe there is already a function. DUP-rep(0,length(AreaID))DUP[2:length(DUP)]- sapply(2:(length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x- 1],1,DUP[x]))DUP[3:length(DUP)]-sapply(3:( length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x-2],2,DUP[x])) My Guess was: AddLag-function(x) { DUP-c(rep(0,length(x)))for (i in 1:(max(as.numeric(GraphArtDB$Measure))+2)){ DUP[(i+1):length(x)]-sapply(((i+1):length(x)),function(x) ifelse(x[i]==x[x-i],i,DUP[x]))} return(DUP) } But it didn´t work. Any suggestions? Thanks in advance J ToledoUPennUSA [[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] unexpected (?) behavior of sort=TRUE in merge function
All, I realize from the archive that the sort argument in merge has been subject to discussion before, though I couldn't find an explanation for this behavior. I tried to simplify this to (kind of) minimal code from a real example to the following (and I have no doubts that there are smart people around achieving the same with smarter code :-)). I'm running R 2.15.1 64bit under MS Windows 7, full session info below. I do have a list with two dataframes: test - list(structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 11, 11, 11, 11, 11, 11), x = c(5.85714285714286, 5.9, 7.3, 5.85714285714286, 7.27272727272727, 4.375, 3.875, 2.5, 4.8, 3.625, 6.25, 4.71428571428571, 3.53571428571429, 4.638889, 4.42424242424242, 4.78260869565217, 4.875, 3.80434782608696, 5.73170731707317, 5.41935483870968, 5.78125, 6.30188679245283, 6.87755102040816, 5.56603773584906)), .Names = c(product, cong, x), row.names = c(NA, -24L), class = data.frame), structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0), x = c(3.04347826086957, 4.18181818181818, 3.75, 4.31578947368421, 4.5, 3.73913043478261, 4.8876404494382, 5.20792079207921, 5.68, 5.70526315789474, 6.38636363636364, 4.96703296703297)), .Names = c(product, cong, x), row.names = c(NA, -12L), class = data.frame)) The dataframes are pretty much the same but for the values in the x-column and the fact that the second one has only half as many observations, missing the second half of the expand.grid if you like. Now if I run lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=TRUE)) # sort=TRUE is the default, so could be omitted sorts the first dataframe according to the labels of factor product, while for the second one the order is maintained from the first dataframes (x) to merge (which is the difference that I could not find being documented). Now I run the same code with sort=FALSE instead: lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=FALSE)) The results are at least consistent and fulfill my needs (this is, btw, not unexpected from the documentation). Note that I get exactly the same behavior if I apply merge subsequently to test[[1]] and test[[2]], so it is not an issue from lapply. (I realize that my dataframes are ordered by levels of product, but using test[[2]] - test[[2]][sample(12),] and applying the same code as above reveals that indeed no sorting is done but the order is maintained from the first dataframe.) I have a working solution for myself, so I'm not after any advice on how to achieve the sorting -- I'd just like to better understand what's going on here and/or what I might have missed in the documentation or in the list archives. Thanks in advance, Michael Session info: R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.1 __ 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] unexpected (?) behavior of sort=TRUE in merge function
Hello, Inline. Em 04-09-2012 12:24, Meyners, Michael escreveu: All, I realize from the archive that the sort argument in merge has been subject to discussion before, though I couldn't find an explanation for this behavior. I tried to simplify this to (kind of) minimal code from a real example to the following (and I have no doubts that there are smart people around achieving the same with smarter code :-)). I'm running R 2.15.1 64bit under MS Windows 7, full session info below. I do have a list with two dataframes: test - list(structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 11, 11, 11, 11, 11, 11), x = c(5.85714285714286, 5.9, 7.3, 5.85714285714286, 7.27272727272727, 4.375, 3.875, 2.5, 4.8, 3.625, 6.25, 4.71428571428571, 3.53571428571429, 4.638889, 4.42424242424242, 4.78260869565217, 4.875, 3.80434782608696, 5.73170731707317, 5.41935483870968, 5.78125, 6.30188679245283, 6.87755102040816, 5.56603773584906)), .Names = c(product, cong, x), row.names = c(NA, -24L), class = data.frame), structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0), x = c(3.04347826086957, 4.18181818181818, 3.75, 4.31578947368421, 4.5, 3.73913043478261, 4.8876404494382, 5.20792079207921, 5.68, 5.70526315789474, 6.38636363636364, 4.96703296703297)), .Names = c(product, cong, x), row.names = c(NA, -12L), class = data.frame)) The dataframes are pretty much the same but for the values in the x-column and the fact that the second one has only half as many observations, missing the second half of the expand.grid if you like. Now if I run lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=TRUE)) # sort=TRUE is the default, so could be omitted sorts the first dataframe according to the labels of factor product No, it doesn't. It sorts according to the columns, i.e., the values, not according to the labels. The help page clearly states that the argument 'sort' is logical. Should the results be sorted on the |by| columns? And Y1 is coded as 1, Y2 as 2, etc. The output is right. Try the following. test2 - test test2[[1]]$product - as.character(test[[1]]$product) test2[[2]]$product - as.character(test[[2]]$product) # To make it more readable. grd - expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)) lapply(test2, function(x) merge(x, grd, all=T, sort=TRUE)) And now 'product' sorts from F to Y2, even if grd$product is still a factor with the same coding as in 'test'. Hope this helps, Rui Barradas , while for the second one the order is maintained from the first dataframes (x) to merge (which is the difference that I could not find being documented). Now I run the same code with sort=FALSE instead: lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=FALSE)) The results are at least consistent and fulfill my needs (this is, btw, not unexpected from the documentation). Note that I get exactly the same behavior if I apply merge subsequently to test[[1]] and test[[2]], so it is not an issue from lapply. (I realize that my dataframes are ordered by levels of product, but using test[[2]] - test[[2]][sample(12),] and applying the same code as above reveals that indeed no sorting is done but the order is maintained from the first dataframe.) I have a working solution for myself, so I'm not after any advice on how to achieve the sorting -- I'd just like to better understand what's going on here and/or what I might have missed in the documentation or in the list archives. Thanks in advance, Michael Session info: R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.1 __ 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
Re: [R] Scatter plot from tapply output, labels of data
Try this: # I created some example data mydf - data.frame( Species=sample(paste0(Species, 1:3), 50, TRUE), d13C=15+rnorm(50), d15N=15+rnorm(50), Year=sample(2009:2012, 50, TRUE)) attach(mydf) Nmean - tapply(d15N, list(Year,Species), mean) Cmean - tapply(d13C, list(Year,Species), mean) detach(mydf) # create an empty plot first with the correct x and y limits on the axes plot(1, 1, xlim=range(Cmean), ylim=range(Nmean), type=n, xlab=Cmean, ylab=Nmean, main=Color indicates year, symbol indicates species) # then add text for species, coloring by year # convert the matrices to vectors before plotting # use the col() and row() functions to get column (species) # and row (year) indicators text(as.vector(Cmean), as.vector(Nmean), dimnames(Cmean)[[2]][col(Cmean)], col=c(green, black, red, blue)[row(Cmean)]) Jean monaR mfu...@uit.no wrote on 09/03/2012 12:33:20 PM: Hei, i am trying to plot the means of two variables (d13C and d15N), by 2 grouping factors (Species and Year) that i obtained by the function tapply. I would like to plot with different colours according to the Year and show the Species as data labels. My data looks like this: Species d13Cd13NYear Species114,4 11.5 2009 Species2 ...... Nmean-tapply(d15N,list(Year,Species),mean) Cmean-tapply(d13C,list(Year,Species),mean) ##works fine, returns something like this Species1 Species2 Species3 2009 20.3 13.4 13,5 2011 NA 23.5 14.5 2012 11.3 NA23.4 plot(Cmean,Nmean,col=c(green,red,blue),) #works fine, gives a plot with data points coloured by Year text(Cmean,Nmean,labels=levels(Species),cex=.7,adj=c(-.1,-.6)) #does not work, mixes up the labels, have tried Species-as.factor(Species) and switched tapply(d15N,list(Year,Species),mean) to--tapply(d15N,list(Species,Year),mean) which gives the Years as column names but does not produce a better plot. The I cannot find the error, any idea what i am doing wrong Thanks sooo much [[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] Tendonitis and R users
Hello This request asks something beyond the technicalities of the R language, I would like to ask you wonderful people if you have ever suffered as programmers ( or de facto programmers like myself though I am a 'research assistant') from tendonitis and how you coped with it, i have golfer's elbow on both sides. Any resources? Pancho Mulongeni Namibia __ 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] Create a function to number each repeated visit or measurements
Thanks Petr then using unlist(x1[,2]) I am able to create the vector I need to add to the dataframe. Didn´t think of this approach. Best, JT Date: Tue, 4 Sep 2012 04:47:11 -0700 From: smartpink...@yahoo.com Subject: Re: [R] Create a function to number each repeated visit or measurements To: tintin...@hotmail.com CC: petr.pi...@precheza.cz; r-help@r-project.org Hi, May be you can also use ?aggregate(): x1-aggregate(x,list(x),function(x) seq_along(x)-1) # Group.1x #1 a 0, 1, 2, 3, 4, 5, 6 #2 b 0, 1, 2, 3, 4, 5 #3 c0, 1, 2, 3, 4, 5, 6, 7, 8 #4 d 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 #5 e 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 A.K. - Original Message - From: PIKAL Petr petr.pi...@precheza.cz To: Jon Toledo tintin...@hotmail.com; r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, September 4, 2012 7:07 AM Subject: Re: [R] Create a function to number each repeated visit or measurements Hi You did not provided any suitable data. x-sort(sample(letters[1:5], 50, rep=T)) unlist(lapply(split(x,x), function(x) (1:length(x))-1)) gives you a vector of indices from 0 to n for sorted vector x. Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jon Toledo Sent: Tuesday, September 04, 2012 7:59 AM To: r-help@r-project.org Subject: [R] Create a function to number each repeated visit or measurements Hi dear R list members, I am trying to create a numerical variable that tracks the visits/entries that a subject has had. For example having a database of repeated serial measurements that are ordered by subject and time. So I would get a variable that says 0 for baseline visit/measurement, 1 for the second etc. In my case the unique identifier for each subject is AreaID Will the following code I can number the visits as long as I create as many lines as visits. But there is probably a way of coding a function or maybe there is already a function. DUP-rep(0,length(AreaID))DUP[2:length(DUP)]- sapply(2:(length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x- 1],1,DUP[x]))DUP[3:length(DUP)]-sapply(3:( length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x-2],2,DUP[x])) My Guess was: AddLag-function(x) {DUP-c(rep(0,length(x)))for (i in 1:(max(as.numeric(GraphArtDB$Measure))+2)){ DUP[(i+1):length(x)]-sapply(((i+1):length(x)),function(x) ifelse(x[i]==x[x-i],i,DUP[x]))}return(DUP)} But it didn´t work. Any suggestions? Thanks in advance J ToledoUPennUSA [[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] Adding summary title to table
names(dimnames(x)) - list(, Nutritional Status) x Nutritional Status Cold or flu Headache Backache Went to doctor 229 23 No response 344 Did\nnothing 67 22 Self-medicated 69 81 50 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Patrick Connolly Sent: Tuesday, September 04, 2012 5:25 AM To: David Arnold Cc: r-help@r-project.org Subject: Re: [R] Adding summary title to table On Mon, 03-Sep-2012 at 03:25PM -0700, David Arnold wrote: | All, | | I have: | | x - matrix(c(22,3,6,69,9,4,7,81,23,4,22,50),nrow=3,byrow=TRUE) | rownames(x) - c(Cold or flu,Headache,Backache); | colnames(x) - c(Went to doctor,No response,Did | nothing,Self-medicated) | x - t(x) | print(x) | | 1. I'd like to add the title Nutritional Status above the column names | when displayed with print(x). | | 2. I'd like to add the title Academic Performance to the left of the row | names when displayed with print(x). | | Any thoughts? You'll get fairly close to what you want using print.char.matrix in the Hmisc package. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ . ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_). Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ . __ 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] predict rpart newdata - introduce only values variables used in the tree
Dear community, I've a tree which included at first 23 variables. Then I've pruned this tree, and there are only 8 variables involved. I'd like to predict and only introduce in newdata the values of these 8 variables involved. However, as the tree was built with the 23, it asked me for 15 values, even if it doesn't need them. Is there a way to introduce only this 8 values? Thanks in advance, show crossp...@hotmail.com as u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/predict-rpart-newdata-introduce-only-values-variables-used-in-the-tree-tp4642145.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] Adding summary title to table
Hello, Ty the following. names(dimnames(x)) - c(Academic Performance, Nutritional Status) x Awkward names, by the way. Hope this helps, Rui Barradas Em 03-09-2012 23:25, David Arnold escreveu: All, I have: x - matrix(c(22,3,6,69,9,4,7,81,23,4,22,50),nrow=3,byrow=TRUE) rownames(x) - c(Cold or flu,Headache,Backache); colnames(x) - c(Went to doctor,No response,Did nothing,Self-medicated) x - t(x) print(x) 1. I'd like to add the title Nutritional Status above the column names when displayed with print(x). 2. I'd like to add the title Academic Performance to the left of the row names when displayed with print(x). Any thoughts? David. -- View this message in context: http://r.789695.n4.nabble.com/Adding-summary-title-to-table-tp4642094.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@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] R suitability for development project
Jim, Thank you again for your response. The integer conversion looks good. You wrote: I think you may be doing something here that you don't intend. The point of plots like this is to transform numeric values into lengths or areas. If you don't maintain the same metric throughout the plot, the relationship between the two is lost. If you were using vertical lines to indicate the transformed mean ranks of the items, they could be placed at the appropriate positions. As you use different edges of the bars to place them, let's see, your bars are about 90 units wide so there would be about a 180 unit offset between positive and negative transformed mean ranks. Are you sure that you want to do this? I note: Yes, the bars are half the width of the axis. In this model there are 14 questions to determine the ranking. My concept is the all of the Items are ranked. Even though some Items may not be ranked in some positions, 1,2,4 or 4, they still receive a rank. Therefore with 14 ranks all of the bars are the same width. There position along the horizontal axis is determined by the right edge of the bar for highest rank. ~eric On Tue, Sep 4, 2012 at 5:31 AM, Jim Lemon j...@bitwrit.com.au wrote: On 09/03/2012 11:18 PM, Eric Langley wrote: chomp I note: Is it possible to have the output as an integer where 99 is the highest score? It certainly is. The mean ranks are: Item2Item3Item4 Totals 1.571429 1.642857 2.857143 3.928571 To make the highest score 99 (meaning the score for the highest ranked item) and the lowest score -99 as on your examples: # first convert high ranks to high numeric scores revmeanranks-4-meanranks revmeanranks Item1Item2Item3Item4 2.428571 2.357143 1.142857 0.071429 # scale the score to the desired range library(plotrix) rescale(revmeanranks,c(-99,99)) Item1 Item2 Item3 Item4 99.00 93.46 -9.15 -99.00 # then just round or truncate your values to get integers chomp I note: The look I am aiming to achieve (as shown here: http://community.abeo.us/sample-graphs/ ) is a relative position within the middle zero based horizontal axis. The mean is not required. Since all bars are 14 units long the upper and lower values note where the end of each bar should align, either to the right for Highest or to the left for Lowest. The third graph shows both. ~eric I think you may be doing something here that you don't intend. The point of plots like this is to transform numeric values into lengths or areas. If you don't maintain the same metric throughout the plot, the relationship between the two is lost. If you were using vertical lines to indicate the transformed mean ranks of the items, they could be placed at the appropriate positions. As you use different edges of the bars to place them, let's see, your bars are about 90 units wide so there would be about a 180 unit offset between positive and negative transformed mean ranks. Are you sure that you want to do this? Jim -- Eric Langley Founder e...@abeo.us 404-326-5382 __ 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] unexpected (?) behavior of sort=TRUE in merge function
Hi, Try this: convert.type1 - function(obj,types){ for (i in 1:length(obj)){ FUN - switch(types[i],character = as.character, numeric = as.numeric, factor = as.factor) obj[,i] - FUN(obj[,i]) } obj } test1-test test1[[1]]-convert.type1(test1[[1]],c(character,numeric,numeric)) test1[[2]]-convert.type1(test1[[2]],c(character,numeric,numeric)) lapply(test1, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=TRUE)) -- -- [[2]] product cong x 1 F -1 4.315789 2 F 0 5.705263 3 F 1 NA 4 F 11 NA 5 G -1 3.75 6 G 0 5.68 7 G 1 NA 8 G 11 NA 9 K -1 3.739130 10 K 0 4.967033 11 K 1 NA 12 K 11 NA 13 L -1 4.50 14 L 0 6.386364 15 L 1 NA 16 L 11 NA 17 Y1 -1 3.043478 18 Y1 0 4.887640 19 Y1 1 NA 20 Y1 11 NA 21 Y2 -1 4.181818 22 Y2 0 5.207921 23 Y2 1 NA 24 Y2 11 NA A.K. - Original Message - From: Meyners, Michael meyner...@pg.com To: r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, September 4, 2012 7:24 AM Subject: [R] unexpected (?) behavior of sort=TRUE in merge function All, I realize from the archive that the sort argument in merge has been subject to discussion before, though I couldn't find an explanation for this behavior. I tried to simplify this to (kind of) minimal code from a real example to the following (and I have no doubts that there are smart people around achieving the same with smarter code :-)). I'm running R 2.15.1 64bit under MS Windows 7, full session info below. I do have a list with two dataframes: test - list(structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 11, 11, 11, 11, 11, 11), x = c(5.85714285714286, 5.9, 7.3, 5.85714285714286, 7.27272727272727, 4.375, 3.875, 2.5, 4.8, 3.625, 6.25, 4.71428571428571, 3.53571428571429, 4.638889, 4.42424242424242, 4.78260869565217, 4.875, 3.80434782608696, 5.73170731707317, 5.41935483870968, 5.78125, 6.30188679245283, 6.87755102040816, 5.56603773584906)), .Names = c(product, cong, x), row.names = c(NA, -24L), class = data.frame), structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0), x = c(3.04347826086957, 4.18181818181818, 3.75, 4.31578947368421, 4.5, 3.73913043478261, 4.8876404494382, 5.20792079207921, 5.68, 5.70526315789474, 6.38636363636364, 4.96703296703297)), .Names = c(product, cong, x), row.names = c(NA, -12L), class = data.frame)) The dataframes are pretty much the same but for the values in the x-column and the fact that the second one has only half as many observations, missing the second half of the expand.grid if you like. Now if I run lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=TRUE)) # sort=TRUE is the default, so could be omitted sorts the first dataframe according to the labels of factor product, while for the second one the order is maintained from the first dataframes (x) to merge (which is the difference that I could not find being documented). Now I run the same code with sort=FALSE instead: lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=FALSE)) The results are at least consistent and fulfill my needs (this is, btw, not unexpected from the documentation). Note that I get exactly the same behavior if I apply merge subsequently to test[[1]] and test[[2]], so it is not an issue from lapply. (I realize that my dataframes are ordered by levels of product, but using test[[2]] - test[[2]][sample(12),] and applying the same code as above reveals that indeed no sorting is done but the order is maintained from the first dataframe.) I have a working solution for myself, so I'm not after any advice on how to achieve the sorting -- I'd just like to better understand what's going on here and/or what I might have missed in the documentation or in the list archives. Thanks in advance, Michael Session info: R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics
[R] prune rpart - select option with less splits when 2 cp's are the same
Dear community, I want to prune a rpart object and select the one that has 13 splits: object.rpart$cptable CP nsplit rel errorxerror xstd 1 0.09489173 0 1.000 1.0006465 0.05641905 2 0.05053897 1 0.9051083 0.9234187 0.05427033 . . . 10 0.01279452 12 0.6435679 0.8415860 0.05140204 11 *0.01188184* 13 0.6307733 0.8325764 0.05164638 12 *0.01188184* 14 0.6188915 0.8253215 0.05062095 However, when I try: object.rpartv2 - prune(object.rpart, cp=0.01188184, nsplit=13) I always obtain the one with nsplit = 14, is there a way to choose the nsplit=13 one? Thanks in advance, show crossp...@host.com as u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/prune-rpart-select-option-with-less-splits-when-2-cp-s-are-the-same-tp4642152.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] binary data
This is a pretty vague question. Ecologists work quite a bit with distance matrices and binary data. You will find some options in packages vegan and ecodist for example. I'm sure there are many others -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Juan Fernández Tajes Sent: Tuesday, September 04, 2012 3:19 AM To: r-help@r-project.org Subject: [R] binary data Dear list, Hello to everybody, IB4m interested in finding a package for statistical analysis of binary data, I have a matrix with the following structure: Case1 Case2 Case 3 ... CaseX Control1 Control2 Control3 ... ControlY Pep1 1 0 1 1 0 0 0 1 Pep2 1 1 1 1 1 0 0 1 Pep3 0 1 1 1 1 0 0 1 ... Pepz 1 1 1 1 1 0 0 1 I would like to know some R package to calculte similarity matrix or to make some statistical diferences between cases and controls Any help it would be very appreciated BW Juan --- Juan Fernandez Tajes, ph. D Grupo XENOMAR Departamento de BiologC-a Celular y Molecular Facultad de Ciencias-Universidade da CoruC1a Tlf. +34 981 167000 ext 2030 e-mail: jfernand...@udc.es [[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] Create a function to number each repeated visit or measurements
Hi, May be you can also use ?aggregate(): x1-aggregate(x,list(x),function(x) seq_along(x)-1) # Group.1 x #1 a 0, 1, 2, 3, 4, 5, 6 #2 b 0, 1, 2, 3, 4, 5 #3 c 0, 1, 2, 3, 4, 5, 6, 7, 8 #4 d 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 #5 e 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 A.K. - Original Message - From: PIKAL Petr petr.pi...@precheza.cz To: Jon Toledo tintin...@hotmail.com; r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, September 4, 2012 7:07 AM Subject: Re: [R] Create a function to number each repeated visit or measurements Hi You did not provided any suitable data. x-sort(sample(letters[1:5], 50, rep=T)) unlist(lapply(split(x,x), function(x) (1:length(x))-1)) gives you a vector of indices from 0 to n for sorted vector x. Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jon Toledo Sent: Tuesday, September 04, 2012 7:59 AM To: r-help@r-project.org Subject: [R] Create a function to number each repeated visit or measurements Hi dear R list members, I am trying to create a numerical variable that tracks the visits/entries that a subject has had. For example having a database of repeated serial measurements that are ordered by subject and time. So I would get a variable that says 0 for baseline visit/measurement, 1 for the second etc. In my case the unique identifier for each subject is AreaID Will the following code I can number the visits as long as I create as many lines as visits. But there is probably a way of coding a function or maybe there is already a function. DUP-rep(0,length(AreaID))DUP[2:length(DUP)]- sapply(2:(length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x- 1],1,DUP[x]))DUP[3:length(DUP)]-sapply(3:( length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x-2],2,DUP[x])) My Guess was: AddLag-function(x) { DUP-c(rep(0,length(x))) for (i in 1:(max(as.numeric(GraphArtDB$Measure))+2)){ DUP[(i+1):length(x)]-sapply(((i+1):length(x)),function(x) ifelse(x[i]==x[x-i],i,DUP[x])) } return(DUP) } But it didn´t work. Any suggestions? Thanks in advance J ToledoUPennUSA [[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] unexpected (?) behavior of sort=TRUE in merge function
Rui, Thanks for looking into this. I apologize, I should've added my output, maybe it looks differently on my machine than on others. I also should have made my question more explicit: I'm not looking for a solution to get the sorting one way or another, I have that already. I rather want to understand why the same code behaves differently on two very similar datasets (one just having less rows, see below). The first call gives the following for me: lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=TRUE)) [[1]] product congx 1F -1 5.857143 2F0 3.625000 3F1 4.782609 4F 11 6.301887 5G -1 7.30 6G0 4.80 7G1 4.424242 8G 11 5.781250 9K -1 4.375000 10 K0 4.714286 11 K1 3.804348 12 K 11 5.566038 13 L -1 7.272727 14 L0 6.25 15 L1 4.875000 16 L 11 6.877551 17 Y1 -1 5.857143 18 Y10 3.875000 19 Y11 3.535714 20 Y1 11 5.731707 21 Y2 -1 5.90 22 Y20 2.50 23 Y21 4.638889 24 Y2 11 5.419355 [[2]] product congx 1 Y1 -1 3.043478 2 Y10 4.887640 3 Y11 NA 4 Y1 11 NA 5 Y2 -1 4.181818 6 Y20 5.207921 7 Y21 NA 8 Y2 11 NA 9G -1 3.75 10 G0 5.68 11 G1 NA 12 G 11 NA 13 F -1 4.315789 14 F0 5.705263 15 F1 NA 16 F 11 NA 17 L -1 4.50 18 L0 6.386364 19 L1 NA 20 L 11 NA 21 K -1 3.739130 22 K0 4.967033 23 K1 NA 24 K 11 NA So different from what you may have observed, here the first data set [[1]] is sorted by label of product, not by value. As you correctly stated, Y1 is coded as 1, Y2 as 2, etc., but the first rows are for F, followed by G etc. The second [[2]] is sorted by level (value). So I have different behavior on very similar looking data sets, and hence to me at least one of those cannot be right according to documentation (but I agree with you that the second is correct according to the help). In my larger example, it seems as if data sets which do not originally have all combinations of product and cong anyway are sorted like [[2]], and those that are complete (all 24 combinations occur) are sorted like [[1]] is, which to me is still unexpected. Hope this clarifies my question. Any thoughts appreciated. Michael -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: Dienstag, 4. September 2012 14:01 To: Meyners, Michael Cc: r-help Subject: Re: [R] unexpected (?) behavior of sort=TRUE in merge function Hello, Inline. Em 04-09-2012 12:24, Meyners, Michael escreveu: All, I realize from the archive that the sort argument in merge has been subject to discussion before, though I couldn't find an explanation for this behavior. I tried to simplify this to (kind of) minimal code from a real example to the following (and I have no doubts that there are smart people around achieving the same with smarter code :-)). I'm running R 2.15.1 64bit under MS Windows 7, full session info below. I do have a list with two dataframes: test - list(structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 11, 11, 11, 11, 11, 11), x = c(5.85714285714286, 5.9, 7.3, 5.85714285714286, 7.27272727272727, 4.375, 3.875, 2.5, 4.8, 3.625, 6.25, 4.71428571428571, 3.53571428571429, 4.638889, 4.42424242424242, 4.78260869565217, 4.875, 3.80434782608696, 5.73170731707317, 5.41935483870968, 5.78125, 6.30188679245283, 6.87755102040816, 5.56603773584906)), .Names = c(product, cong, x), row.names = c(NA, -24L), class = data.frame), structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0), x = c(3.04347826086957, 4.18181818181818, 3.75, 4.31578947368421, 4.5, 3.73913043478261, 4.8876404494382, 5.20792079207921, 5.68, 5.70526315789474, 6.38636363636364, 4.96703296703297)), .Names = c(product, cong, x), row.names = c(NA, -12L), class = data.frame)) The dataframes are pretty much the same but for the values in the x- column and the fact that the second one has only half as many observations, missing the second half of the expand.grid if you like. Now if I run lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T,
Re: [R] Tendonitis and R users
I've vome close a couple of times. Solutions: don't use computer-not alway practical. Carefully watch posture and arm/hand actions to reduce strain. If do a lot of keyboarding not just R type look into using a Dvoark keyboard. Something I have not done but which is likely to help is consult your institutions health and safety people about solutions such as ergonomic keyboards etc. John Kane Kingston ON Canada -Original Message- From: resea...@namibia.pharmaccess.org Sent: Tue, 4 Sep 2012 12:55:36 + To: r-help@r-project.org Subject: [R] Tendonitis and R users Hello This request asks something beyond the technicalities of the R language, I would like to ask you wonderful people if you have ever suffered as programmers ( or de facto programmers like myself though I am a 'research assistant') from tendonitis and how you coped with it, i have golfer's elbow on both sides. Any resources? Pancho Mulongeni Namibia __ 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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ 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] unexpected (?) behavior of sort=TRUE in merge function
Hello, You're right I had missed the point, sorry. I can't see a reason why that behavior, but it seems to have to do with all = T, remove it and the problem is gone. But that's probably not what you want. NA's issue? Rui Barradas Em 04-09-2012 15:17, Meyners, Michael escreveu: Rui, Thanks for looking into this. I apologize, I should've added my output, maybe it looks differently on my machine than on others. I also should have made my question more explicit: I'm not looking for a solution to get the sorting one way or another, I have that already. I rather want to understand why the same code behaves differently on two very similar datasets (one just having less rows, see below). The first call gives the following for me: lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=TRUE)) [[1]] product congx 1F -1 5.857143 2F0 3.625000 3F1 4.782609 4F 11 6.301887 5G -1 7.30 6G0 4.80 7G1 4.424242 8G 11 5.781250 9K -1 4.375000 10 K0 4.714286 11 K1 3.804348 12 K 11 5.566038 13 L -1 7.272727 14 L0 6.25 15 L1 4.875000 16 L 11 6.877551 17 Y1 -1 5.857143 18 Y10 3.875000 19 Y11 3.535714 20 Y1 11 5.731707 21 Y2 -1 5.90 22 Y20 2.50 23 Y21 4.638889 24 Y2 11 5.419355 [[2]] product congx 1 Y1 -1 3.043478 2 Y10 4.887640 3 Y11 NA 4 Y1 11 NA 5 Y2 -1 4.181818 6 Y20 5.207921 7 Y21 NA 8 Y2 11 NA 9G -1 3.75 10 G0 5.68 11 G1 NA 12 G 11 NA 13 F -1 4.315789 14 F0 5.705263 15 F1 NA 16 F 11 NA 17 L -1 4.50 18 L0 6.386364 19 L1 NA 20 L 11 NA 21 K -1 3.739130 22 K0 4.967033 23 K1 NA 24 K 11 NA So different from what you may have observed, here the first data set [[1]] is sorted by label of product, not by value. As you correctly stated, Y1 is coded as 1, Y2 as 2, etc., but the first rows are for F, followed by G etc. The second [[2]] is sorted by level (value). So I have different behavior on very similar looking data sets, and hence to me at least one of those cannot be right according to documentation (but I agree with you that the second is correct according to the help). In my larger example, it seems as if data sets which do not originally have all combinations of product and cong anyway are sorted like [[2]], and those that are complete (all 24 combinations occur) are sorted like [[1]] is, which to me is still unexpected. Hope this clarifies my question. Any thoughts appreciated. Michael -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: Dienstag, 4. September 2012 14:01 To: Meyners, Michael Cc: r-help Subject: Re: [R] unexpected (?) behavior of sort=TRUE in merge function Hello, Inline. Em 04-09-2012 12:24, Meyners, Michael escreveu: All, I realize from the archive that the sort argument in merge has been subject to discussion before, though I couldn't find an explanation for this behavior. I tried to simplify this to (kind of) minimal code from a real example to the following (and I have no doubts that there are smart people around achieving the same with smarter code :-)). I'm running R 2.15.1 64bit under MS Windows 7, full session info below. I do have a list with two dataframes: test - list(structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 11, 11, 11, 11, 11, 11), x = c(5.85714285714286, 5.9, 7.3, 5.85714285714286, 7.27272727272727, 4.375, 3.875, 2.5, 4.8, 3.625, 6.25, 4.71428571428571, 3.53571428571429, 4.638889, 4.42424242424242, 4.78260869565217, 4.875, 3.80434782608696, 5.73170731707317, 5.41935483870968, 5.78125, 6.30188679245283, 6.87755102040816, 5.56603773584906)), .Names = c(product, cong, x), row.names = c(NA, -24L), class = data.frame), structure(list(product = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c(Y1, Y2, G, F, L, K), class = factor), cong = c(-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0), x = c(3.04347826086957, 4.18181818181818, 3.75, 4.31578947368421, 4.5, 3.73913043478261, 4.8876404494382, 5.20792079207921, 5.68, 5.70526315789474, 6.38636363636364, 4.96703296703297)), .Names = c(product, cong, x), row.names = c(NA, -12L), class = data.frame)) The dataframes are pretty much the same but for the values in the x-
[R] Help about rugarch
Hi everyone, I use the rugarch package in order tu run a rolling windows estimation using the function ugarchroll. I want to set the windows moving. For example, I want to do n.ahead=1, refit.every=1, refit.windows=moving, .. But I don't know how to set the length of the rolling windows (say for eg. 250). Thank you in advance for your help Giles [[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] Coxph not converging with continuous variable
Dear Terry, I agree that this example is highly atypical. Having said that, my experience with optimization algorithms is that scaling (a.k.a. standardizing) the continuous covariates is greatly helpful in terms of convergence. Have you considered automatically standardizing the continuous covariates, and then converting the scaled coefficients back to the original scale? Of course, the end user could do this just as easily! Best, Ravi Ravi Varadhan, Ph.D. Assistant Professor The Center on Aging and Health Division of Geriatric Medicine Gerontology Johns Hopkins University rvarad...@jhmi.edumailto:rvarad...@jhmi.edu 410-502-2619 [[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] tapply to data.frame or matrix
Dear R users, imagine i have a dataframe and an indexing vector with the length of the amount of columns of the dataframe. Is there any convenient way to combine the colums of the dataframe into vectors (or straight away apply fundtions to these subsets) according to the indexing vector in a similar manner to the tapply function? For example, in the follwoing case, I would like to combine columns 1 and two into one vector, and columns 3-4 into another: test = as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind =c(1,1,2,2,2) Thanks a lot! Jannis __ 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] unexpected (?) behavior of sort=TRUE in merge function
Rui, yes, without all=T it works fine, but of course there is no point in the whole exercise if I'd drop that, as print(test) would do the same, unless I have other values of product or cong in any dataset, which I haven't. :-) The purpose of the merge is to have all combinations of the levels of product and cong in each dataframe in my list -- there might be smarter ways, but it does the trick, and I need a unified setup (layout, size and sorting of the data) to ease the following steps in my code. Of course, I could achieve that easily by sorting the data subsequently, so there are multiple ways to get what I want to have. However, the purpose being a bit beyond this post, it's really about the behavior here on data sets that look so similar, and about the fact that one of those is not treated like it should be according to documentation). Thanks again for taking the time to reply. Cheers, Michael -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: Dienstag, 4. September 2012 16:58 To: Meyners, Michael Cc: r-help Subject: Re: [R] unexpected (?) behavior of sort=TRUE in merge function Hello, You're right I had missed the point, sorry. I can't see a reason why that behavior, but it seems to have to do with all = T, remove it and the problem is gone. But that's probably not what you want. NA's issue? Rui Barradas Em 04-09-2012 15:17, Meyners, Michael escreveu: Rui, Thanks for looking into this. I apologize, I should've added my output, maybe it looks differently on my machine than on others. I also should have made my question more explicit: I'm not looking for a solution to get the sorting one way or another, I have that already. I rather want to understand why the same code behaves differently on two very similar datasets (one just having less rows, see below). The first call gives the following for me: lapply(test, function(x) merge(x, expand.grid(product=c(Y1, Y2, G, F, L, K), cong=c(-1,0,1,11)), all=T, sort=TRUE)) [[1]] product congx 1F -1 5.857143 2F0 3.625000 3F1 4.782609 4F 11 6.301887 5G -1 7.30 6G0 4.80 7G1 4.424242 8G 11 5.781250 9K -1 4.375000 10 K0 4.714286 11 K1 3.804348 12 K 11 5.566038 13 L -1 7.272727 14 L0 6.25 15 L1 4.875000 16 L 11 6.877551 17 Y1 -1 5.857143 18 Y10 3.875000 19 Y11 3.535714 20 Y1 11 5.731707 21 Y2 -1 5.90 22 Y20 2.50 23 Y21 4.638889 24 Y2 11 5.419355 [[2]] product congx 1 Y1 -1 3.043478 2 Y10 4.887640 3 Y11 NA 4 Y1 11 NA 5 Y2 -1 4.181818 6 Y20 5.207921 7 Y21 NA 8 Y2 11 NA 9G -1 3.75 10 G0 5.68 11 G1 NA 12 G 11 NA 13 F -1 4.315789 14 F0 5.705263 15 F1 NA 16 F 11 NA 17 L -1 4.50 18 L0 6.386364 19 L1 NA 20 L 11 NA 21 K -1 3.739130 22 K0 4.967033 23 K1 NA 24 K 11 NA So different from what you may have observed, here the first data set [[1]] is sorted by label of product, not by value. As you correctly stated, Y1 is coded as 1, Y2 as 2, etc., but the first rows are for F, followed by G etc. The second [[2]] is sorted by level (value). So I have different behavior on very similar looking data sets, and hence to me at least one of those cannot be right according to documentation (but I agree with you that the second is correct according to the help). In my larger example, it seems as if data sets which do not originally have all combinations of product and cong anyway are sorted like [[2]], and those that are complete (all 24 combinations occur) are sorted like [[1]] is, which to me is still unexpected. Hope this clarifies my question. Any thoughts appreciated. Michael -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: Dienstag, 4. September 2012 14:01 To: Meyners, Michael Cc: r-help Subject: Re: [R] unexpected (?) behavior of sort=TRUE in merge function Hello, Inline. Em 04-09-2012 12:24, Meyners, Michael escreveu: All, I realize from the archive that the sort argument in merge has been subject to discussion before, though I couldn't find an explanation for this behavior. I tried to simplify this to (kind of) minimal code from a real example to the following (and I have no doubts that there are smart people around achieving the same with smarter code :-)). I'm running R 2.15.1 64bit under MS Windows 7, full session info
Re: [R] tapply to data.frame or matrix
Hello, Here's a way. test - as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind - c(1,1,2,2,2) lapply(split(colnames(test), test.ind), function(x) unlist(test[, x])) Hope this helps, Rui Barradas Em 04-09-2012 15:40, Jannis escreveu: Dear R users, imagine i have a dataframe and an indexing vector with the length of the amount of columns of the dataframe. Is there any convenient way to combine the colums of the dataframe into vectors (or straight away apply fundtions to these subsets) according to the indexing vector in a similar manner to the tapply function? For example, in the follwoing case, I would like to combine columns 1 and two into one vector, and columns 3-4 into another: test = as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind =c(1,1,2,2,2) Thanks a lot! Jannis __ 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] Create a function to number each repeated visit or measurements
For unsorted x, or for a factor x with unused levels, ave(integer(length(x)), x, FUN=seq_along) - 1 works. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of PIKAL Petr Sent: Tuesday, September 04, 2012 4:08 AM To: Jon Toledo; r-help@r-project.org Subject: Re: [R] Create a function to number each repeated visit or measurements Hi You did not provided any suitable data. x-sort(sample(letters[1:5], 50, rep=T)) unlist(lapply(split(x,x), function(x) (1:length(x))-1)) gives you a vector of indices from 0 to n for sorted vector x. Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jon Toledo Sent: Tuesday, September 04, 2012 7:59 AM To: r-help@r-project.org Subject: [R] Create a function to number each repeated visit or measurements Hi dear R list members, I am trying to create a numerical variable that tracks the visits/entries that a subject has had. For example having a database of repeated serial measurements that are ordered by subject and time. So I would get a variable that says 0 for baseline visit/measurement, 1 for the second etc. In my case the unique identifier for each subject is AreaID Will the following code I can number the visits as long as I create as many lines as visits. But there is probably a way of coding a function or maybe there is already a function. DUP-rep(0,length(AreaID))DUP[2:length(DUP)]- sapply(2:(length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x- 1],1,DUP[x]))DUP[3:length(DUP)]-sapply(3:( length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x-2],2,DUP[x])) My Guess was: AddLag-function(x) { DUP-c(rep(0,length(x)))for (i in 1:(max(as.numeric(GraphArtDB$Measure))+2)){ DUP[(i+1):length(x)]-sapply(((i+1):length(x)),function(x) ifelse(x[i]==x[x-i],i,DUP[x])) } return(DUP) } But it didn´t work. Any suggestions? Thanks in advance J ToledoUPennUSA [[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] Tendonitis and R users
I think I've avoided tendonitis by carefully stretching the affected area when I begin to feel discomfort and, as John suggests, Carefully watch posture and arm/hand actions to reduce strain. Clint BowmanINTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600FAX:(360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels:300 Desmond Drive, Lacey, WA 98503-1274 On Tue, 4 Sep 2012, John Kane wrote: I've come close a couple of times. Solutions: don't use computer-not always practical. Carefully watch posture and arm/hand actions to reduce strain. If do a lot of keyboarding not just R type look into using a Dvoark keyboard. Something I have not done but which is likely to help is consult your institutions health and safety people about solutions such as ergonomic keyboards etc. John Kane Kingston ON Canada -Original Message- From: resea...@namibia.pharmaccess.org Sent: Tue, 4 Sep 2012 12:55:36 + To: r-help@r-project.org Subject: [R] Tendonitis and R users Hello This request asks something beyond the technicalities of the R language, I would like to ask you wonderful people if you have ever suffered as programmers ( or de facto programmers like myself though I am a 'research assistant') from tendonitis and how you coped with it, i have golfer's elbow on both sides. Any resources? Pancho Mulongeni Namibia __ 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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ 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] Tendonitis and R users
When I suffered from wrist pain I found changing from a standard mouse to a cordless trackball gave rapid and complete relief. Your mileage may vary. Keith J I think I've avoided tendonitis by carefully stretching the affected area when I begin to feel discomfort and, as John suggests, Carefully watch posture and arm/hand actions to reduce strain. Clint Bowman INTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX: (360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 On Tue, 4 Sep 2012, John Kane wrote: I've come close a couple of times. Solutions: don't use computer-not always practical. Carefully watch posture and arm/hand actions to reduce strain. If do a lot of keyboarding not just R type look into using a Dvoark keyboard. Something I have not done but which is likely to help is consult your institutions health and safety people about solutions such as ergonomic keyboards etc. John Kane Kingston ON Canada -Original Message- From: resea...@namibia.pharmaccess.org Sent: Tue, 4 Sep 2012 12:55:36 + To: r-help@r-project.org Subject: [R] Tendonitis and R users Hello This request asks something beyond the technicalities of the R language, I would like to ask you wonderful people if you have ever suffered as programmers ( or de facto programmers like myself though I am a 'research assistant') from tendonitis and how you coped with it, i have golfer's elbow on both sides. Any resources? Pancho Mulongeni Namibia __ 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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ 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] Tendonitis and R users
Keith Jewell k.jew...@campden.co.uk escreveu: When I suffered from wrist pain I found changing from a standard mouse to a cordless trackball gave rapid and complete relief. A mousepad with a jelly support for the wrist cured my pain. One can find several tenths of websites with plenty of useful information on prevention and treatment of wrist pains of computer users. Googling around a little will surely be more effective and efficient getting information. However, the best website will never provide tailored solutions and medical counseling may be advisable, very especially in the case of an athlete as it seems to be the case of the original poster. Best wishes. -- Alexandre Aguiar, MD SCT SPS Consultoria -- Sent from my tablet. Please, excuse my brevity. Enviado do tablet. Por favor, perdoe a brevidade. Publié de le tablet. S'il vous plaît pardonnez la brièveté. Veröffentlicht aus dem Tablet. Bitte verzeihen Sie die Kürze. Enviado desde mi tablet. Por favor, disculpen mi brevedad. Inviato dal mio tablet. Per favore, scusate la mia brevità. __ 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] Tendonitis and R users
I may be out of line here, but I fail to see what on earth this has to do with R and why this thread should be continued here. I appreciate the fact that there is no maliciousness involved, but the danger of such off topic discussions (imho, of course) is that it dilutes the purpose and value of R-help and wastes time and energy. So may I plea to keep discussions here on topic and move this to private or one of the innumerable ergonomics sites on the web. Thank you. -- Bert On Tue, Sep 4, 2012 at 9:16 AM, Keith Jewell k.jew...@campden.co.uk wrote: When I suffered from wrist pain I found changing from a standard mouse to a cordless trackball gave rapid and complete relief. Your mileage may vary. Keith J I think I've avoided tendonitis by carefully stretching the affected area when I begin to feel discomfort and, as John suggests, Carefully watch posture and arm/hand actions to reduce strain. Clint Bowman INTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX: (360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 On Tue, 4 Sep 2012, John Kane wrote: I've come close a couple of times. Solutions: don't use computer-not always practical. Carefully watch posture and arm/hand actions to reduce strain. If do a lot of keyboarding not just R type look into using a Dvoark keyboard. Something I have not done but which is likely to help is consult your institutions health and safety people about solutions such as ergonomic keyboards etc. John Kane Kingston ON Canada -Original Message- From: research@namibia.pharmaccess.**orgresea...@namibia.pharmaccess.org Sent: Tue, 4 Sep 2012 12:55:36 + To: r-help@r-project.org Subject: [R] Tendonitis and R users Hello This request asks something beyond the technicalities of the R language, I would like to ask you wonderful people if you have ever suffered as programmers ( or de facto programmers like myself though I am a 'research assistant') from tendonitis and how you coped with it, i have golfer's elbow on both sides. Any resources? Pancho Mulongeni Namibia __** 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.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __**__ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/**photosharinghttp://www.inbox.com/photosharingto find out more! __** 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.htmlhttp://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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[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] Tendonitis and R users
HI, I tried wrist exercises for carpal tunnel syndrome. It's not 100% effective, but it helps. A.K. - Original Message - From: research email resea...@namibia.pharmaccess.org To: r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, September 4, 2012 8:55 AM Subject: [R] Tendonitis and R users Hello This request asks something beyond the technicalities of the R language, I would like to ask you wonderful people if you have ever suffered as programmers ( or de facto programmers like myself though I am a 'research assistant') from tendonitis and how you coped with it, i have golfer's elbow on both sides. Any resources? Pancho Mulongeni Namibia __ 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] ADMB error- function maximizer failed (couldnt find STD file)
Greetings glmmADMB function users, I am trying to run a series of models using the glmmADMB function with several different distribution families (e.g., poisson, negbinom). I am using a Optiplex 790 PC with Windows 7, 16.0 GB of RAM and a 64-bit operating system. I am running R version 2.15.0 and started out using the most recent version of glmmADMB (I believe version 7.2.15). My data is zero inflated count data that is overdispersed. When I ran the following code for either a zero inflated poisson (family=poisson) or a neg binomial (i.e., family=nbinom): fit_zipoiss1 - glmmadmb(LOCS~D_ROADS + (1|YEAR) , data=FAWNS, zeroInflation=TRUE, family=poisson, mcmc=TRUE) I get the error: Error in glmmadmb(LOCS ~ D_ROADS + (1 | YEAR), data = FAWNS, zeroInflation = TRUE, : The function maximizer failed (couldn't find STD file) I tried setting the number of mcmc iterations by running the following code: fit_zipoiss - glmmadmb(LOCS~D_ROADS + (1|YEAR) , data=FAWNS, zeroInflation=TRUE, family=poisson, mcmc=TRUE, mcmc.opts=mcmcControl(mcmc=5)) but again received the same Function maximizer error. As suggested by previous users (specifically Ben Bolker) I downloaded an earlier version of glmmADMB (glmmADMB_0.7.tar.gz) and re-ran the same models (e.g., poisson and neg. binomial) and received the same error. As suggested by Mr. Bolker and others I also tried running both a poisson and neg. binomial model with admb.opts=admbControl(shess=FALSE,noinit=FALSE) and received the same error. I am not sure if an even older version of glmmADMB (i.e., glmmADMB v. 0.6.5) would work as it seems to have worked for others but I am unsure of where I can find this version? Any suggestions would be very much appreciated. Thank you for your time. Nate Svoboda Nathan Svoboda Graduate Research Assistant Mississippi State University [[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] tapply to data.frame or matrix
Hi, Here's another way: testagg-aggregate(colnames(test),list(test.ind),function(x) test[,x]) list(unlist(testagg[,2][1]),unlist(testagg[,2][2])) #[[1]] #0.V11 0.V12 0.V13 0.V14 0.V21 0.V22 0.V23 0.V24 1 2 3 4 5 6 7 8 #[[2]] #1.V31 1.V32 1.V33 1.V34 1.V41 1.V42 1.V43 1.V44 1.V51 1.V52 1.V53 1.V54 # 9 10 11 12 13 14 15 16 17 18 19 20 A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Jannis bt_jan...@yahoo.de Cc: r-help r-help@r-project.org Sent: Tuesday, September 4, 2012 11:30 AM Subject: Re: [R] tapply to data.frame or matrix Hello, Here's a way. test - as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind - c(1,1,2,2,2) lapply(split(colnames(test), test.ind), function(x) unlist(test[, x])) Hope this helps, Rui Barradas Em 04-09-2012 15:40, Jannis escreveu: Dear R users, imagine i have a dataframe and an indexing vector with the length of the amount of columns of the dataframe. Is there any convenient way to combine the colums of the dataframe into vectors (or straight away apply fundtions to these subsets) according to the indexing vector in a similar manner to the tapply function? For example, in the follwoing case, I would like to combine columns 1 and two into one vector, and columns 3-4 into another: test = as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind =c(1,1,2,2,2) Thanks a lot! Jannis __ 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.
[R] Calculate a minimum-variance portfolio with fPortfolio
Hello everybody, I'm running into an issue with the fPortfolio package. 1. What I want: Calculate the minimum-variance portfolio on 20 assets with respect to the following constraints: - min weight per asset = 0% (i.e. no short-selling) - max weight per asset = 10% - min sum of asset weights = 100% (i.e. fully invested) - max sum of asset weights = 100% (i.e. no leverage) 2. What I get: Execution stopped: The minimum risk portfolio could not be computed. Possible Reason: Your portfolio constraints may be too restrictive. Status Information: status=1 from solver solveRquadprog. Error: returned from Rmetrics 3. Why I don't understand this error: Well, I don't know. The constraints seem good since I would be able to construct an equal-weighted portfolio that satisfies all of them (e.g. with 5% in each asset). 4. Reproducible example: library(fPortfolio) # Data data - SMALLCAP[, 1:20] # Constraints box.1 - paste0(minW[1:nAssets] = , 0) box.2 - paste0(maxW[1:nAssets] = , 0.10) box.3 - maxsumW[1:nAssets] = 1 box.4 - minsumW[1:nAssets] = 1 boxConstraints - c(box.1, box.2, box.3, box.4) # Portfolio Specs Spec - portfolioSpec() # Calculate MinVar Portfolio minvar - minvariancePortfolio( data = data, spec = Spec, constraints = boxConstraints) 5. Thanks a lot for your help! Markus Douglas, Jr. -- View this message in context: http://r.789695.n4.nabble.com/Calculate-a-minimum-variance-portfolio-with-fPortfolio-tp4642188.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] using apply with sparse matrix from package Matrix
Jennifer Lyon jennifer.s.l...@gmail.com on Fri, 31 Aug 2012 17:22:57 -0600 writes: Hi: I was trying to use apply on a sparse matrix from package Matrix, and I get the error: Error in asMethod(object) : Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 106 Is there a way to apply a function to all the rows without bumping into this problem? Here is a simplified example: dim(sm) [1] 72913 43052 class(sm) [1] dgCMatrix attr(,package) [1] Matrix str(sm) Formal class 'dgCMatrix' [package Matrix] with 6 slots ..@ i : int [1:6590004] 789 801 802 1231 1236 11739 17817 17943 18148 18676 ... ..@ p : int [1:43053] 0 147 303 450 596 751 908 1053 1188 1347 ... ..@ Dim : int [1:2] 72913 43052 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL ..@ x : num [1:6590004] 0.601 0.527 0.562 0.641 0.684 ... ..@ factors : list() my.sum-apply(sm, 1, sum) Error in asMethod(object) : Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 106 So, actually it would have worked (though not efficiently) if your sm matrix would have been much smaller. However, we provide rowSums(), rowMeans(), colSums(), colMeans() for all of our matrices, including the sparse ones. So your present problem can be solved using my.sum - rowSums(sm) Best regards, Martin Maechler, ETH Zurich __ 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] Ryacas
I am having issues with Ryacas errors. I searched and found this error was reported in 2006, but nothing since. library(Ryacas) Loading required package: XML yacas(expression(Factor(x^2-1))) [1] Starting Yacas! CommandLine(1) : Expecting ) closing bracket for sub-expression, but got ^ instead yacas(D(x)Sin(x)) CommandLine(1) : Expecting ) closing bracket for sub-expression, but got Sin instead x - Sym('x') (x+1) * (x-1) CommandLine(1) : Error parsing expression, near token + os:WindowsXP Rversion: R version 2.15.1 (2012-06-22) -- Roasted Marshmallows Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit)R-2.15.1 Yacas version:1.0.63 Any suggestions appreciated, Jason -- View this message in context: http://r.789695.n4.nabble.com/Ryacas-tp4642204.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] Comparing Von Bertalanffy Growth Curves
I am trying to compare Vbert growth curves from several years of fish data. I am following the code provided by: http://www.ncfaculty.net/dogle/fishR/gnrlex/VonBertalanffy/VonBertalanffy.pdf. Specifically the section on VBGM Comparisons between groups. This code is pretty cut and dry. I am able to run it perfectly with the fake data that is provided. But when I run it with my own data I get stuck with this line: fitGen - nls(vbGen,data=LMB,start=svGen) I get this error code: Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model. Does anyone know how to fix it? I have no missing values and do not know how to fix the infinity produced. Here is my data set: structure(list(Age = c(1L, 2L, 3L, 5L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), MM = c(155.79, 296.37, 325.77, 374.65, 181.46, 258.31, 321.88, 355.6, 139.75, 230.72, 319.61, 344.84, 130.92, 236.34, 290.53, 360.33, 400.61, 155.33, 240.87, 315.46, 345.05, 378.2, 134.71, 256.66, 333.71, 362.99, 381.46, 153.91, 217.21, 287.8, 357.28, 385.62, 222.25, 288.93, 294.05, 332.79, 367.39), Year = c(2005L, 2005L, 2005L, 2005L, 2006L, 2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 2007L, 2008L, 2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L, 2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L, 2012L)), .Names = c(Age, MM, Year), class = data.frame, row.names = c(NA, -37L)) In case it's helpful here is all my code before this point: str(LMB) MMi=as.integer(MM) Yearf=as.factor(Year) Agei=as.integer(Age) ( svCom - vbStarts(MMi~Agei,data=LMB)) ( svGen - lapply(svCom,rep,2) ) vbGen - MMi~Linf[Yearf]*(1-exp(-K[Yearf]*(Age-t0[Yearf]))+error) fitGen - nls(vbGen,data=LMB,start=svGen) Thank you, April __ 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] Ryacas
On Tue, Sep 4, 2012 at 2:34 PM, Jason Romine jrom...@usgs.gov wrote: I am having issues with Ryacas errors. I searched and found this error was reported in 2006, but nothing since. It works for me on my Windows Vista laptop. Suggest you review the toubleshooting section on the home page http://ryacas.googlecode.com/#TROUBLESHOOTING library(Ryacas) Loading required package: XML library(Ryacas) yacas(expression(Factor(x^2-1))) [1] Starting Yacas! expression((x + 1) * (x - 1)) yacas(D(x)Sin(x)) expression(cos(x)) x - Sym('x') (x+1) * (x-1) expression((x + 1) * (x - 1)) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] [newbie] scripting remote check for R package
https://stat.ethz.ch/pipermail/r-help/2012-September/322985.html [how] to script [remote] checking for an R package? https://stat.ethz.ch/pipermail/r-help/2012-September/323000.html I would call something like this via ssh [...] Rscript -e 'as.numeric(suppressWarnings(suppressPackageStartupMessages(require(ggplot2' https://stat.ethz.ch/pipermail/r-help/2012-September/323024.html Thanks! but [the] cluster where I need to run this (where I do *not* have root) [lacks Rscript.] So I'm wondering: 1 Is there a way to do `Rscript -e` with plain, commandline R? Incorporating Gergely Daróczi's last suggestion (köszönöm!) I get # the package for which to check that has the most dependencies APEX_PKG='M3' # substitute yours for RSERVER in 'foo' 'bar' 'baz' ; do echo -e ${RSERVER} has: ssh ${RSERVER} R --version | head -n 1 ssh ${RSERVER} echo -e ${RSERVER} has ${APEX_PKG}: ssh ${RSERVER} R --slave -e 'as.logical(suppressWarnings(suppressPackageStartupMessages(require(${APEX_PKG}' echo # newline done which works. I'd still like to know: 2 What should my admin have done to install both Rscript and R? (Alternatively, what should I tell my admin to do in order to make both Rscript and R available?) 3 Is there any reason to install R without Rscript? (Alternatively, when I ask my admin to install Rscript, is there any objection I should anticipate?) your assistance is appreciated, Tom Roche tom_ro...@pobox.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] how to get Rscript, and is there any reason not to?
As described in the thread beginning @ https://stat.ethz.ch/pipermail/r-help/2012-September/322985.html I work (as a user, without root) on a cluster that has several servers on which R is installed but not Rscript. I'd like to know 1 What should I tell my admin to do in order to make both Rscript and R available? (FWIW I believe the boxes are running CentOS, though possibly RHEL 5 or 6.) 2 Is there any reason to install R without Rscript? Alternatively, when I ask my admin to install Rscript, is there any objection I should anticipate? TIA, Tom Roche tom_ro...@pobox.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] what package does the mesh function need
Hello, I tried to plot some 3d-plots with the 'mesh' function, but I allways get the message 'Fehler: konnte Funktion mash nicht finden' in english this means 'error: can't find the function mesh'. Do I need another package? I didn't found anything in the web this afternoon, only descriptions how to use the function. I looked up a lot of function-lists in the documentation, but there I didn't found the function. Greets Paka -- View this message in context: http://r.789695.n4.nabble.com/what-package-does-the-mesh-function-need-tp4642209.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] Adding summary title to table
On Tue, 04-Sep-2012 at 08:18AM -0500, David L Carlson wrote: | names(dimnames(x)) - list(, Nutritional Status) | x | Nutritional Status | Cold or flu Headache Backache | Went to doctor 229 23 | No response 344 | Did\nnothing 67 22 | Self-medicated 69 81 50 Very neat but it doesn't put the line break in the cell Did nothing I guessed that was an important aspect of what was wanted, but if it isn't, the names(dimnames()) ideas is very elegant. | | -- | David L Carlson | Associate Professor of Anthropology | Texas AM University | College Station, TX 77843-4352 | | | -Original Message- | From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- | project.org] On Behalf Of Patrick Connolly | Sent: Tuesday, September 04, 2012 5:25 AM | To: David Arnold | Cc: r-help@r-project.org | Subject: Re: [R] Adding summary title to table | | On Mon, 03-Sep-2012 at 03:25PM -0700, David Arnold wrote: | | | All, | | | | I have: | | | | x - matrix(c(22,3,6,69,9,4,7,81,23,4,22,50),nrow=3,byrow=TRUE) | | rownames(x) - c(Cold or flu,Headache,Backache); | | colnames(x) - c(Went to doctor,No response,Did | | nothing,Self-medicated) | | x - t(x) | | print(x) | | | | 1. I'd like to add the title Nutritional Status above the column | names | | when displayed with print(x). | | | | 2. I'd like to add the title Academic Performance to the left of | the row | | names when displayed with print(x). | | | | Any thoughts? | | You'll get fairly close to what you want using print.char.matrix in | the Hmisc package. | | HTH | | | -- | ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ | . | ___Patrick Connolly | {~._.~} Great minds discuss ideas | _( Y )_Average minds discuss events | (:_~*~_:) Small minds discuss people | (_)-(_) . Eleanor Roosevelt | | ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ | . | | __ | 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. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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] AFTREG weights
On Wed, Aug 1, 2012 at 3:08 PM, fra.meu...@hotmail.it wrote: Dear Göran Broström, I am trying to use AFTREG function for R to estimate a loglogistic survival function, including time dependent covariates. Actually, my Subset includes some partial events; the idea is to model this kind of events using something similar to âweightsâ in the SURVREG function. In particular I would like to manage this kind of Dataset: IdRow StartTime EndTime Event IdObs Cov Weight 1 0 1 0 1a 0.1284 0.3 2 1 2 1 1a 0.4896 0.3 3 2 3 0 1b 0.7017 0.7 4 3 4 1 1b 0.8564 0.7 5 0 1 0 2 0.7964 1 6 1 2 0 2 0.8466 1 7 2 3 0 2 0.2234 1 8 3 4 1 2 0.8437421 9 0 1 0 3 0.6433821 10 1 2 0 3 0.3004331 11 2 3 0 3 0.6669641 with this function AftRegTD-aftreg(Surv(StartTime,EndTime,Event)~Cov,dist=loglogistic,id=dfTest$IdObs,data=dfTest) Any suggestion to introduce weights as argument in aftreg function? No, not for the moment, although it would be straightforward to add. However, I am not sure that case weights is what you are seeking. Göran Thanks, Francesca -- Göran Broström [[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] Create a function to number each repeated visit or measurements
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jon Toledo Sent: Monday, September 03, 2012 10:59 PM To: r-help@r-project.org Subject: [R] Create a function to number each repeated visit or measurements Hi dear R list members, I am trying to create a numerical variable that tracks the visits/entries that a subject has had. For example having a database of repeated serial measurements that are ordered by subject and time. So I would get a variable that says 0 for baseline visit/measurement, 1 for the second etc. In my case the unique identifier for each subject is AreaID Will the following code I can number the visits as long as I create as many lines as visits. But there is probably a way of coding a function or maybe there is already a function. DUP-rep(0,length(AreaID))DUP[2:length(DUP)]- sapply(2:(length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x- 1],1,DUP[x]))DUP[3:length(DUP)]-sapply(3:( length(AreaID),function(x) ifelse(AreaID[x]==AreaID[x-2],2,DUP[x])) My Guess was: AddLag-function(x) { DUP-c(rep(0,length(x)))for (i in 1:(max(as.numeric(GraphArtDB$Measure))+2)){ DUP[(i+1):length(x)]-sapply(((i+1):length(x)),function(x) ifelse(x[i]==x[x-i],i,DUP[x]))} return(DUP) } But it didn´t work. Any suggestions? Thanks in advance Your email was scrambled and therefore difficult to decipher. However, using the plyr package, you could do something like library(plyr) ddply(your_data_frame,AreaID,transform,visit=0:(length(AreaID)-1)) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Tendonitis and R users
On Tue, 4 Sep 2012, Clint Bowman wrote: I think I've avoided tendinitis ... In the early 1990s I got tendinitis when I had to switch from strictly text-based screens to GUIs and the mouse. A few accupunture sessions cured it, and I've avoided it ever since by using a track ball rather than a mouse. Has worked for me for about 20 years. Rich -- Richard B. Shepard, Ph.D. | Integrity - Credibility - Innovation Applied Ecosystem Services, Inc. |Helping Ensure Our Clients' Futures http://www.appl-ecosys.com Voice: 503-667-4517 Fax: 503-667-8863 __ 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 can I export a big data.frame to excel 2010 - file.xlsx?
Hi, I need some help to export a data frame with 83 rows and 1411 colums. I have used the package RODBC until now. But now, I have 1411 colums that I can't send to the old excel. If anybody knows a package to convert my data frame in xlsx tell me! Thanks for help in advance! Pamela Botrel -- View this message in context: http://r.789695.n4.nabble.com/How-can-I-export-a-big-data-frame-to-excel-2010-file-xlsx-tp4642223.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] How can I export a big data.frame to excel 2010 - file.xlsx?
Ms. Botrel, On 4 September 2012 13:52, PamelaBotrel pamela.bot...@hotmail.com wrote: I need some help to export a data frame with 83 rows and 1411 colums. I have used the package RODBC until now. But now, I have 1411 colums that I can't send to the old excel. If anybody knows a package to convert my data frame in xlsx tell me! Several options... 1. write.csv import into Excel and save to an XLSX 2. there is an xlsx package on cran that also, theoretically works. I say, theoretically, because I have no use for Excel on my systems. Let me know how you get on... -- H -- Sent from my mobile device Envoyait de mon portable [[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] what package does the mesh function need
On 2012-09-04 12:10, paka wrote: Hello, I tried to plot some 3d-plots with the 'mesh' function, but I allways get the message 'Fehler: konnte Funktion mash nicht finden' in english this means 'error: can't find the function mesh'. Do I need another package? I didn't found anything in the web this afternoon, only descriptions how to use the function. I looked up a lot of function-lists in the documentation, but there I didn't found the function. Greets Paka You need to offer some code to demonstrate the problem. It may be as simple as typing mash instead of mesh (note the second letter) as you have done in your post. And what makes you think that there _should_ be a function mesh()? The answer to that question may well provide a sufficient clue to its whereabouts. Finally, searching for functions is relatively simple with the findFn() function in the sos package. Peter Ehlers __ 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 can I export a big data.frame to excel 2010 - file.xlsx?
Hello, Try package XLConnect. The vignette has several examples, and so do the help pages, for instance, ?XLConnect You should also get rid of excel and use R for serious work. And even not so serious. Hope this helps, Rui Barradas Em 04-09-2012 21:52, PamelaBotrel escreveu: Hi, I need some help to export a data frame with 83 rows and 1411 colums. I have used the package RODBC until now. But now, I have 1411 colums that I can't send to the old excel. If anybody knows a package to convert my data frame in xlsx tell me! Thanks for help in advance! Pamela Botrel -- View this message in context: http://r.789695.n4.nabble.com/How-can-I-export-a-big-data-frame-to-excel-2010-file-xlsx-tp4642223.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@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] Ryacas
Thank you Gabor. I tried to exhaust all troubleshooting solutions listed on the site you suggested prior to posting my question. Perhaps you could share what this error is stemming from. Interestingly, on another machine I have no issue with it when I run R 2.10, whereas when I try Ryacas with R 2.15.1 on the same machine the error shows up. Thanks, Jason -- View this message in context: http://r.789695.n4.nabble.com/Ryacas-tp4642204p4642229.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] ADMB error- function maximizer failed (couldnt find STD file)
gNathan Svoboda nsvoboda at CFR.MsState.Edu writes: Greetings glmmADMB function users, I am trying to run a series of models using the glmmADMB function with several different distribution families (e.g., poisson, negbinom). I am using a Optiplex 790 PC with Windows 7, 16.0 GB of RAM and a 64-bit operating system. I am running R version 2.15.0 and started out using the most recent version of glmmADMB (I believe version 7.2.15). My data is zero inflated count data that is overdispersed. When I ran the following code for either a zero inflated poisson (family=poisson) or a neg binomial (i.e., family=nbinom): fit_zipoiss1 - glmmadmb(LOCS~D_ROADS + (1|YEAR) , data=FAWNS, zeroInflation=TRUE, family=poisson, mcmc=TRUE) I get the error: Error in glmmadmb(LOCS ~ D_ROADS + (1 | YEAR), data = FAWNS, zeroInflation = TRUE, : The function maximizer failed (couldn't find STD file) I tried setting the number of mcmc iterations by running the following code: fit_zipoiss - glmmadmb(LOCS~D_ROADS + (1|YEAR) , data=FAWNS, zeroInflation=TRUE, family=poisson, mcmc=TRUE, mcmc.opts=mcmcControl(mcmc=5)) but again received the same Function maximizer error. # As suggested by previous users (specifically Ben Bolker) I # downloaded an earlier version of glmmADMB (glmmADMB_0.7.tar.gz) # and re-ran the same models (e.g., poisson and neg. binomial) and # received the same error. As suggested by Mr. Bolker and others I # also tried running both a poisson and neg. binomial model with # admb.opts=admbControl(shess=FALSE,noinit=FALSE) and received the # same error. I am not sure if an even older version of glmmADMB # (i.e., glmmADMB v. 0.6.5) would work as it seems to have worked for # others but I am unsure of where I can find this version? A couple of points: * http://www.math.mcmaster.ca/~bolker/R/src/contrib/ has earlier versions of the glmmADMB package, although not version 0.6.5 (nothing between 0.5-2 and 0.7) ... * how many years do you have? Especially if you have a giant data set, you might try exploring the effects of treating YEAR as fixed. This will have a couple of advantages -- may get you around the problem, and will also allow you to fit your model using the pscl package. Treating YEAR as fixed will work well if you (1) have lots of data per year and/or (2) have a small number of years. * have you done exploratory plots of LOCS vs D_ROADS by year? Are your data very unbalanced, either in terms of observations or in terms of numbers of zero counts? (i.e. do you have a very small number of observations, or a very small number of non-zero observations, for some combinations of D_ROADS and year? in principle random-effects models are supposed to handle these issues, but they can't always ...) * it's probably not worth bothering with mcmc at all while you are still in the debugging stage -- it is an add-on, not an integral part of the model fitting process. (Just leave out the mcmc argument entirely: the default value is FALSE) * I think the current convention is that glmmADMB questions belong on the r-sig-mixed-mod...@r-project.org list (not here in the general R help, and not on the ADMB mailing list). stuff to make gmane happy ... it doesn't like too much quoted __ 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] Comparing Von Bertalanffy Growth Curves
April Lindeman aprillindeman at yahoo.com writes: I am trying to compare Vbert growth curves from several years of fish data. I am following the code provided by: http://www.ncfaculty.net/dogle/fishR/gnrlex/VonBertalanffy/VonBertalanffy.pdf. Specifically the section on VBGM Comparisons between groups. This code is pretty cut and dry. I am able to run it perfectly with the fake data that is provided. But when I run it with my own data I get stuck with this line: fitGen - nls(vbGen,data=LMB,start=svGen) I get this error code: Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model. Does anyone know how to fix it? I have no missing values and do not know how to fix the infinity produced. Here is my data set: structure(list(Age = c(1L, 2L, 3L, 5L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), MM = c(155.79, 296.37, 325.77, 374.65, 181.46, 258.31, 321.88, 355.6, 139.75, 230.72, 319.61, 344.84, 130.92, 236.34, 290.53, 360.33, 400.61, 155.33, 240.87, 315.46, 345.05, 378.2, 134.71, 256.66, 333.71, 362.99, 381.46, 153.91, 217.21, 287.8, 357.28, 385.62, 222.25, 288.93, 294.05, 332.79, 367.39), Year = c(2005L, 2005L, 2005L, 2005L, 2006L, 2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 2007L, 2008L, 2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L, 2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L, 2012L)), .Names = c(Age, MM, Year), class = data.frame, row.names = c(NA, -37L)) In case it's helpful here is all my code before this point: str(LMB) MMi=as.integer(MM) Yearf=as.factor(Year) Agei=as.integer(Age) ( svCom - vbStarts(MMi~Agei,data=LMB)) ( svGen - lapply(svCom,rep,2) ) vbGen - MMi~Linf[Yearf]*(1-exp(-K[Yearf]*(Age-t0[Yearf]))+error) fitGen - nls(vbGen,data=LMB,start=svGen) I believe that the reason you're running into trouble is that you have a very small number of data points per year. You're trying to fit a three-parameter model to at *most* 5 data points per year, and at least 4 (2005-2007 have only 4 ages, 2008-2012 have 5 ages). In principle this should be possible, but nls is a little bit fragile and so it gets in trouble. I wasn't able to run all your code because some of the packages you use seem to be unavailable for the development version of R I'm using ... The following solution works for me. You may be better off fitting a nonlinear mixed model, but I don't have time to work out that example at the moment ... LMB - structure(list(Age = c(1L, 2L, 3L, 5L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), MM = c(155.79, 296.37, 325.77, 374.65, 181.46, 258.31, 321.88, 355.6, 139.75, 230.72, 319.61, 344.84, 130.92, 236.34, 290.53, 360.33, 400.61, 155.33, 240.87, 315.46, 345.05, 378.2, 134.71, 256.66, 333.71, 362.99, 381.46, 153.91, 217.21, 287.8, 357.28, 385.62, 222.25, 288.93, 294.05, 332.79, 367.39), Year = c(2005L, 2005L, 2005L, 2005L, 2006L, 2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 2007L, 2008L, 2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L, 2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L, 2012L)), .Names = c(Age, MM, Year), class = data.frame, row.names = c(NA, -37L)) library(ggplot2) LMB$Yearf - factor(LMB$Year) (g0 - ggplot(LMB,aes(Age,MM))+geom_point(aes(colour=factor(Year (g2 - g0 + geom_smooth(aes(colour=factor(Year)),se=FALSE,method=auto,span=2)) n1 - nls(MM~SSasympOff(Age,Asym,lrc,c0),data=LMB) pframe - data.frame(Age=seq(1,5,length.out=50)) pframe$MM - predict(n1,newdata=pframe) (g1 - g0+geom_line(data=pframe)) library(nlme) nyear - length(unique(LMB$Year)) svec - c(rbind(coef(n1), matrix(0,nrow=nyear-1,ncol=length(coef(n1) fit2 - gnls(MM~SSasympOff(Age,Asym,lrc,c0),data=LMB, params=Asym+lrc+c0~Yearf, start=svec) printCoefmat(summary(fit2)$tTable) pframe2 - expand.grid(Age=seq(1,5,length.out=50), Year=unique(LMB$Year)) pframe2$Yearf - factor(pframe2$Year) pframe2$MM - predict(fit2,newdata=pframe2) g0 + geom_line(data=pframe2, aes(colour=factor(Year))) __ 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] Comparing Von Bertalanffy Growth Curves
Pretty hard to say since you did not give us all of your code: str(LMB) 'data.frame': 37 obs. of 3 variables: $ Age : int 1 2 3 5 1 2 3 4 1 2 ... $ MM : num 156 296 326 375 181 ... $ Year: int 2005 2005 2005 2005 2006 2006 2006 2006 2007 2007 ... MMi=as.integer(MM) Error: object 'MM' not found Yearf=as.factor(Year) Error in is.factor(x) : object 'Year' not found Agei=as.integer(Age) Error: object 'Age' not found So you left out an attach(LMB) at least. Then attach(LMB) MMi=as.integer(MM) Yearf=as.factor(Year) Agei=as.integer(Age) ( svCom - vbStarts(MMi~Agei,data=LMB)) Error: could not find function vbStarts Now you've left out loading one or more packages with library() commands. I'll stop here. If you want help, provide minimal, self-contained, reproducible code. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of April Lindeman Sent: Tuesday, September 04, 2012 1:43 PM To: r-help@r-project.org Subject: [R] Comparing Von Bertalanffy Growth Curves I am trying to compare Vbert growth curves from several years of fish data. I am following the code provided by: http://www.ncfaculty.net/dogle/fishR/gnrlex/VonBertalanffy/VonBertalanf fy.pdf. Specifically the section on VBGM Comparisons between groups. This code is pretty cut and dry. I am able to run it perfectly with the fake data that is provided. But when I run it with my own data I get stuck with this line: fitGen - nls(vbGen,data=LMB,start=svGen) I get this error code: Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model. Does anyone know how to fix it? I have no missing values and do not know how to fix the infinity produced. Here is my data set: structure(list(Age = c(1L, 2L, 3L, 5L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), MM = c(155.79, 296.37, 325.77, 374.65, 181.46, 258.31, 321.88, 355.6, 139.75, 230.72, 319.61, 344.84, 130.92, 236.34, 290.53, 360.33, 400.61, 155.33, 240.87, 315.46, 345.05, 378.2, 134.71, 256.66, 333.71, 362.99, 381.46, 153.91, 217.21, 287.8, 357.28, 385.62, 222.25, 288.93, 294.05, 332.79, 367.39), Year = c(2005L, 2005L, 2005L, 2005L, 2006L, 2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 2007L, 2008L, 2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L, 2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L, 2012L)), .Names = c(Age, MM, Year), class = data.frame, row.names = c(NA, -37L)) In case it's helpful here is all my code before this point: str(LMB) MMi=as.integer(MM) Yearf=as.factor(Year) Agei=as.integer(Age) ( svCom - vbStarts(MMi~Agei,data=LMB)) ( svGen - lapply(svCom,rep,2) ) vbGen - MMi~Linf[Yearf]*(1-exp(-K[Yearf]*(Age-t0[Yearf]))+error) fitGen - nls(vbGen,data=LMB,start=svGen) Thank you, April __ 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] Ryacas
On Tue, Sep 4, 2012 at 5:19 PM, Jason Romine jrom...@usgs.gov wrote: Thank you Gabor. I tried to exhaust all troubleshooting solutions listed on the site you suggested prior to posting my question. Perhaps you could share what this error is stemming from. Interestingly, on another machine I have no issue with it when I run R 2.10, whereas when I try Ryacas with R 2.15.1 on the same machine the error shows up. Its not related to R 2.15.1 since I used that on Windows to produce the answers in my post. The error message you got does not indicate the source of the problem. You could try using verbose=TRUE to get more feedback and go over the troubleshooting section again. Look at the whole section and not just the Windows part. yacas(expression(Factor(x^2-1)), verbose = TRUE) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] cenboxplot(): Reporting Limit Twice Correct Concentration
I've gone over the data and do not see my error; the dput() output of the data frame and the pdf output of cenboxplot() are attached. The command used: cenboxplot(sb.t$quant, sb.t$ceneq1, range=1.5, main='Total Recoverable Antimony', xlab='Pre-Mining Era', ylab='Concentration (log mg/L)') (on a single line in emacs). The RL on the plot is drawn at 0.01 rather than at 0.005 and I'd like to learn why. Richstructure(list(site = structure(c(12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 16L, 16L, 17L, 17L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L), .Label = c(D-1, D-2, D-3, D-4, D-5, D-6, D-7, D-8, D-9, Effluent, GB-ES1, GW-2, Gold Bowl Sump, Influent, JJ-16, JJ-18, JJ-20, JJ-22, MC-1, MC-2, MC-3, MW-1, MW-10, MW-11, MW-12, MW-13, MW-14, MW-15, MW-16, MW-2R, MW-3, MW-4, MW-5, MW-6R, MW-7, MW-8, MW-9, Mine Domestic Well, P-10, P-5, P-6, P-8, P-9, RAS-001, SN-22, SW Zone Sump, SW-1, SW-10, SW-11, SW-12, SW-13, SW-14, SW-15, SW-16, SW-17, SW-18, SW-2, SW-3, SW-4, SW-5, SW-6, SW-7, SW-8, SW-9), class = factor), sampdate = structure(c(8421, 8442, 8477, 8503, 8537, 8567, 8595, 8596, 8636, 8666, 8686, 8713, 8741, 8782, 8810, 8833, 8861, 8889, 8924, 8957, 8988, 9022, 9049, 9114, 9142, 9246, 9274, 9295, 9407, 8573, 8693, 8573, 8693, 8363, 8390, 8421, 8442, 8476, 8505, 8532, 8567, 8604, 8638, 8665, 8686, 8717, 8741, 8778, 8805, 8833, 8860, 8887, 8924, 8959, 8987, 9022, 9050, 9113, 9141, 9169, 9205, 9244, 9274, 9296, 9408, 8364, 8391, 8421, 8441, 8476, 8505, 8531, 8566, 8594, 8636, 8665, 8686, 8714, 8741, 8777, 8805, 8832, 8861, , 8923, 8959, 8987, 9022, 9050, 9112, 9141, 9168, 9205, 9244, 9274, 9293, 9408, 8367, 8392, 8420, 8441, 8475, 8504, 8531, 8566, 8594, 8637, 8664, 8687, 8715, 8742, 8777, 8806, 8832, 8861, , 8923, 8958, 8987, 9021, 9140, 9168, 9204, 9246, 9274, 9295, 9406, 8364, 8392, 8421, 8441, 8476, 8504, 8531, 8566, 8594, 8637, 8664, 8687, 8715, 8747, 8777, 8806, 8832, 8861, , 8923, 8958, 8987, 9021, 9049, 9112, 9140, 9168, 9204, 9246, 9274, 9296, 9406, 8364, 8397, 8419, 8441, 8474, 8505, 8531, 8565, 8594, 8638, 8664, 8686, 8714, 8741, 8777, 8805, 8832, 8861, , 8923, 8959, 8987, 9022, 9050, 9112, 9141, 9168, 9204, 9246,
[R] repace values in raster based on values in another raster
Hi, I am attempting to create a new raster based on values of another raster. In the Arc world, this is called a conditional statement or con statement. I am having quite a bit of difficulty figuring this out in R. Here is some pseudo-code: if (fire.did.not.occurr == 1) then (new. raster = landuse.raster) Here is some real code and the associated error: landuse.raster - raster(C:/temp/landuse.raster.tif) new.raster - landuse.raster new.raster[new.raster 0] - NA new.raster[fire.did.not.occurr == 1] - landuse.raster Error in x@data@values[i] - value : incompatible types (from S4 to integer) in subassignment type fix If I replace the landuse.raster with a specific number in the final command, then the operation works, but I would like to replace with the values in the landuse.raster. Please help. FYI: Please know that I have searched the forums and have not found anything helpful. Perhaps I am using incorrect search criteria. Thanks, Sean -- View this message in context: http://r.789695.n4.nabble.com/repace-values-in-raster-based-on-values-in-another-raster-tp4642245.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] using apply with sparse matrix from package Matrix
On Tue, Sep 4, 2012 at 10:58 AM, Martin Maechler maech...@stat.math.ethz.ch wrote: Jennifer Lyon jennifer.s.l...@gmail.com on Fri, 31 Aug 2012 17:22:57 -0600 writes: Hi: I was trying to use apply on a sparse matrix from package Matrix, and I get the error: Error in asMethod(object) : Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 106 Is there a way to apply a function to all the rows without bumping into this problem? Here is a simplified example: dim(sm) [1] 72913 43052 class(sm) [1] dgCMatrix attr(,package) [1] Matrix str(sm) Formal class 'dgCMatrix' [package Matrix] with 6 slots ..@ i : int [1:6590004] 789 801 802 1231 1236 11739 17817 17943 18148 18676 ... ..@ p : int [1:43053] 0 147 303 450 596 751 908 1053 1188 1347 ... ..@ Dim : int [1:2] 72913 43052 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL ..@ x : num [1:6590004] 0.601 0.527 0.562 0.641 0.684 ... ..@ factors : list() my.sum-apply(sm, 1, sum) Error in asMethod(object) : Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 106 So, actually it would have worked (though not efficiently) if your sm matrix would have been much smaller. However, we provide rowSums(), rowMeans(), colSums(), colMeans() for all of our matrices, including the sparse ones. So your present problem can be solved using my.sum - rowSums(sm) Best regards, Martin Maechler, ETH Zurich Thank you for letting me know about rowSums(). Two points. First, sadly, I was unclear in my posting, and using sum was just an example. In the real case I am using my own function on each row. I guess the answer for this problem is that iteration is my friend. Good to know. Second, since I'm embarrassed to say I hadn't remembered rowSums(), for cases when I needed the sum of the rows, I had just been postmultiplying by a vector of 1's. Just FYI, I thought I should try rowSums(), so did a small timing trial, and it appears postmultiplying is faster than rowSums. Run is as follows: str(sm) Formal class 'dgCMatrix' [package Matrix] with 6 slots ..@ i : int [1:6590004] 721 926 1275 1791 2370 2755 3393 4638 5363 5566 ... ..@ p : int [1:43053] 0 147 303 450 596 751 908 1053 1188 1347 ... ..@ Dim : int [1:2] 72913 43052 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL ..@ x : num [1:6590004] 0.0735 0.3206 0.1861 0.1604 0.197 ... ..@ factors : list() library(rbenchmark) #Just checking how expensive building a vector of 1's is - not very #at least for matrix of the size I'm interested in benchmark(i1-rep(1, ncol(sm))) test replications elapsed relative user.self sys.self 1 i1 - rep(1, ncol(sm)) 100 0.1191 0.120 user.child sys.child 1 0 0 #Postmultiplying by 1's timing benchmark(la-sm %*% i1) test replications elapsed relative user.self sys.self user.child 1 la - sm %*% i1 100 5.9931 5.9930 0 sys.child 1 0 #rowSums timing benchmark(la1-rowSums(sm)) test replications elapsed relative user.self sys.self 1 la1 - rowSums(sm) 100 28.117128.1140.004 user.child sys.child 1 0 0 #Make sure the results are the same all(la==la1) [1] TRUE The Matrix package is awesome, and I appreciate you taking the time to answer my questions. Jen sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rbenchmark_0.3.1 Matrix_1.0-6 lattice_0.20-6 loaded via a namespace (and not attached): [1] grid_2.15.1 __ 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] cenboxplot(): Reporting Limit Twice Correct Concentration
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Tuesday, September 04, 2012 4:15 PM To: r-help@r-project.org Subject: [R] cenboxplot(): Reporting Limit Twice Correct Concentration I've gone over the data and do not see my error; the dput() output of the data frame and the pdf output of cenboxplot() are attached. The command used: cenboxplot(sb.t$quant, sb.t$ceneq1, range=1.5, main='Total Recoverable Antimony', xlab='Pre-Mining Era', ylab='Concentration (log mg/L)') (on a single line in emacs). The RL on the plot is drawn at 0.01 rather than at 0.005 and I'd like to learn why. Rich Rich, The line is drawn at the maximum censored value. max(sb.t$quant[sb.t$ceneq1==TRUE]) [1] 0.01 The line is drawn at 0.01 because there is a censored record where quant=0.01, i.e. sb.t[which(sb.t$quant==0.01 sb.t$ceneq1==TRUE),] site sampdateera param quant ceneq1 floor ceiling 34169 MW-5 1995-01-10 Pre-mining SbTot 0.01 TRUE 00.01 Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] POSIXlt and daylight savings time
I have a data frame that contains dates, but when I use as.POSIXlt() I lose the hours on all records. I traced this down to a particuar hour which causes the issue... as.POSIXlt('2004-10-31 02:00:00') [1] 2004-10-31 as.POSIXlt('2004-10-31 03:00:00') [1] 2004-10-31 03:00:00 How do I tell as.POSIXlt() to ignore daylight savings and just convert to a time as is? I've read about the 'isdst' but it is still unclear what to do. This is a cleaned up date field that I received so adjusting the date itself is not possible. Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/POSIXlt-and-daylight-savings-time-tp4642253.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] Sweave encoding option
Hi list, I was running Sweave on one of my .rnw file. Everything was fine, until I came back from the vacation. Nothing changed (at least to my knowledge), but now I have this problem: Sweave(myfile.rnw) Error: ‘COLO001final.rnw’ is not ASCII and does not declare an encoding After snooping around on the web, I found this solution: Sweave(myfile.rnw, encoding=utf8) Now everything works fine. Could somebody explain to me what happened? Why I need to specify the encoding now for it to work? What has changed (beyond my knowledge) in my computer that is causing this error? I'm running R 2.15.1 on WinXP. Thanks! Tao __ 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] Revolution Analytics
Has anyone every used Revolution Analytics? It claims to be faster than R, but when I ran a for loop of linear regression that requires a couple of minutes to process in RStudio. Revolution Analytics has a run time that was exactly the same. I was just wondering if anyone has experience with the two and what your thoughts are. Thanks, William -- View this message in context: http://r.789695.n4.nabble.com/Revolution-Analytics-tp4642248.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 data from .csv file as a matrix and compare the different between two matrix
Hi, I have two table matrix, and I would like to compare the different between two matrix. For example: Matrix 1: A B C A 0 1 0 B 0 0 1 C 0 0 0 Matrix 2: A B C A 0 1 0 B 0 0 0 C 0 0 0 Each column which have value 1, should also return value 1. As in this case/example, the result should appear like this (as below). The result of this differentiation should also be in matrix table and should be write in . csv file. Result of the differences: A B C A 0 1 0 B 0 0 0 C 0 0 0 At the mean time, I'm able to load the .csv file and convert it to matrix matrix1 -read.table(matrix1.csv, header=T, sep=,) matrix1 - as.matrix(matrix1) matrix2 - read.table(matrix2.csv, header=T, sep=,) matrix2 - as.matrix(matrix2) But, I can't find a suitable script to compare the differences between the matrix and write it to file. Appreciate any help from the expert [[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] Sweave encoding option
What happened might be that your vacation took too long. The encoding argument was introduced in R 2.13.1 (July last year). Nothing has changed in your Rnw document, but things have always been changing in R, so the best thing to do is to check out help(Sweave). Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Tue, Sep 4, 2012 at 7:02 PM, Shi, Tao shida...@yahoo.com wrote: Hi list, I was running Sweave on one of my .rnw file. Everything was fine, until I came back from the vacation. Nothing changed (at least to my knowledge), but now I have this problem: Sweave(myfile.rnw) Error: ‘COLO001final.rnw’ is not ASCII and does not declare an encoding After snooping around on the web, I found this solution: Sweave(myfile.rnw, encoding=utf8) Now everything works fine. Could somebody explain to me what happened? Why I need to specify the encoding now for it to work? What has changed (beyond my knowledge) in my computer that is causing this error? I'm running R 2.15.1 on WinXP. Thanks! Tao __ 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] Producing a SMA signal when closing price is above the moving average for 3 days
You could think of your problem as one of combining a signal that tells when the state of the system should change to (or remain at) on and a signal that tells when it should change to off to come up with a series giving the state at each time point. E.g., OnOrOff - function(toOn, toOff, wasOn){ # toOn and toOff are logical vectors (indexed implicitly by time). # toOn[t] is TRUE means that the state should change to (or continue to # be) on (1) from time t until a later toOff value turns it off. # If both toOn[t] and toOff[t] are FALSE, then state[t] is copied from # state[t-1]. # wasOn=TRUE means that the state was on at time 0. stopifnot(length(toOn)==length(toOff), !any(toOn toOff)) tmp - integer(length(toOn)) tmp[1] - if (wasOn) 1 else -1 tmp[toOn] - 1 tmp[toOff] - -1 s - tmp != 0 zeroDups - function(x) { x[-1][x[-1]==x[-length(x)]] - 0 ; x } tmp[s] - zeroDups(tmp[s]) cumsum(tmp) + (tmp[1] == -1) } In your example you have a series of 1s and 0s saying whether the price is currently above or below the 50-day runing average. E.g., x - c(1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1) (TRUE and FALSE instead of 1 and 0 would be more convenient, but I'll follow your lead.) You can use filter to to find where there were 3 aboves (TRUEs) or 3 belows (FALSEs) in a row and pass those into OnOrOff. The following does this but assumes the previous state was off (an exercise for the reader): SwitchAtThree - function (x, init = c(0, 0)) { count - function(x) filter(c(init, x), rep(1, 3), side = 1)[-seq_along(init)] OnOrOff(count3(x == 1) == 3, count3(x == 0) == 3, FALSE) } With the above x we get: data.frame(x, fx=SwitchAtThree(x)) x fx 1 1 0 2 1 0 3 0 0 4 1 0 5 1 0 6 1 1 7 0 1 8 1 1 9 0 1 10 0 1 11 0 0 12 1 0 An advantage of this technique is that you can fiddle with the filter coefficients and the '==3' to change the start-on/start-off conditions from 3 in a row to 3 out of the last 4 or the last two plus at least one of the two prior to them or make the on/off signals assymetric (e.g., 3 in a row TRUE to turn on, 2 in a row FALSE to turn off). It is pretty quick for long series. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Douglas Karabasz Sent: Monday, September 03, 2012 8:24 PM To: r-help@r-project.org Subject: [R] Producing a SMA signal when closing price is above the moving average for 3 days I have loaded price data for GE and then calculated a 50 day simple moving average. Then I have a created a ifelse statement that produce a 1 when GE's closing price is above the simple moving average and a 0 when GE Closing price is below the 50 day simple moving average. However, what I really want to do is to produce a 1 for when the price is above the simple moving average for 3 days and I want it to keep the 1 until the price moves back below the 50 day simple moving average for 3 days then I want to return a 0 until the Price closes above the SMA for 3 days. Thank you, Douglas library(quantmod) getSymbols(GE) # Get Price Data GEsma - SMA(GE$GE.Close, n=50) # Simple Moving Average of the closing price GEsma[is.na(GEsma)] - 50 # Make NA's to 50 so ifelse statement works correctly aboveSMA - ifelse(GE$GE.Close GEsma, 1, 0) # 1 when price is above 50 day moving average # 0 When below moving average chartSeries(GE) # Shows Price chart addSMA(n=50) # adds 50 day moving average to chart __ 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] POSIXlt and daylight savings time
a) Don't use POSIXlt in data frames... use POSIXct. POSIXlt is like a data frame of its own, and data frames within data frames lead to surprising results, to say the least. b) I have had best luck using Sys.setenv( TZ=Etc/GMT+8 ) for US Pacific Standard Time as local time for the duration of analysis. c) Use the format argument if you want consistent results. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. pdb ph...@philbrierley.com wrote: I have a data frame that contains dates, but when I use as.POSIXlt() I lose the hours on all records. I traced this down to a particuar hour which causes the issue... as.POSIXlt('2004-10-31 02:00:00') [1] 2004-10-31 as.POSIXlt('2004-10-31 03:00:00') [1] 2004-10-31 03:00:00 How do I tell as.POSIXlt() to ignore daylight savings and just convert to a time as is? I've read about the 'isdst' but it is still unclear what to do. This is a cleaned up date field that I received so adjusting the date itself is not possible. Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/POSIXlt-and-daylight-savings-time-tp4642253.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@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 data from .csv file as a matrix and compare the different between two matrix
Hi, Not quite understand your question. Suppose the columns of one matrix (matrix1) have multiple 1's while matrix 2 have only 0's, do you mean that the difference should be 0 for that column? Anyway, the result that you wanted for this example can be got from: mat1-read.table(text= A B C 0 1 0 0 0 1 0 0 0 ,sep=,header=TRUE) mat2-read.table(text= A B C 0 1 0 0 0 0 0 0 0 ,sep=,header=TRUE) library(plyr) join(mat1,mat2,type=inner) # A B C #1 0 1 0 #2 0 0 0 #3 0 0 0 #This solution may not work in situations like the one I mentioned above. A.K. - Original Message - From: s.s.m. fauzi ssmf...@gmail.com To: r-help@r-project.org Cc: Sent: Tuesday, September 4, 2012 7:39 PM Subject: [R] Read data from .csv file as a matrix and compare the different between two matrix Hi, I have two table matrix, and I would like to compare the different between two matrix. For example: Matrix 1: A B C A 0 1 0 B 0 0 1 C 0 0 0 Matrix 2: A B C A 0 1 0 B 0 0 0 C 0 0 0 Each column which have value 1, should also return value 1. As in this case/example, the result should appear like this (as below). The result of this differentiation should also be in matrix table and should be write in . csv file. Result of the differences: A B C A 0 1 0 B 0 0 0 C 0 0 0 At the mean time, I'm able to load the .csv file and convert it to matrix matrix1 -read.table(matrix1.csv, header=T, sep=,) matrix1 - as.matrix(matrix1) matrix2 - read.table(matrix2.csv, header=T, sep=,) matrix2 - as.matrix(matrix2) But, I can't find a suitable script to compare the differences between the matrix and write it to file. Appreciate any help from the expert [[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] Revolution Analytics
RA is R, with some special modifications. You may not be exercising those enhancements with your code. This is not a support forum for RA, so you should ask your question in an RA-specific forum. You should also provide example code when you do, so it will be clear what features you are using. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. wwreith reith_will...@bah.com wrote: Has anyone every used Revolution Analytics? It claims to be faster than R, but when I ran a for loop of linear regression that requires a couple of minutes to process in RStudio. Revolution Analytics has a run time that was exactly the same. I was just wondering if anyone has experience with the two and what your thoughts are. Thanks, William -- View this message in context: http://r.789695.n4.nabble.com/Revolution-Analytics-tp4642248.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@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.