Re: [R] plotting multiple variables in 1 bar graph
Hi see in line -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of David Carlson Sent: Tuesday, October 23, 2012 6:47 PM To: 'Macy Anonuevo'; r-help@r-project.org Subject: Re: [R] plotting multiple variables in 1 bar graph snip What I need now is to plot all the variables in 1 site as they change over time. Something like barplot(VADeaths, beside = TRUE, col = c(lightblue, mistyrose, lightcyan, lavender, cornsilk), legend = rownames(VADeaths), ylim = c(0, 100)) title(main = Death Rates in Virginia, font.main = 4) If I understand the code correctly, this means that only the variable VADeaths is plotted over time? I'm hoping to have multiple variables plotted over time, with the bars clustered by variable so that you can see how each variable changes over time. Not exactly. VADeaths is a matrix not a single variable. str(VADeaths) num [1:5, 1:4] 11.7 18.1 26.9 41 66 8.7 11.7 20.3 30.9 54.3 ... - attr(*, dimnames)=List of 2 ..$ : chr [1:5] 50-54 55-59 60-64 65-69 ... ..$ : chr [1:4] Rural Male Rural Female Urban Male Urban Female See ?barplot help page for details. Regards Petr or maybe you could try ggplot2 I tried looking through ggplot2 and I don't understand the code. I don't even know where to start. Regards Petr What Excel produced: http://r.789695.n4.nabble.com/file/n4647099/abdeens_benthic_cover.jpg (The image has mean %cover as the y-value instead of mean count but the example still applies) I've spent several hours looking for code to do this but didn't find anything. I'd use the Excel graph except that it doesn't have the sd or se bars. -- View this message in context: http://r.789695.n4.nabble.com/plotting- multiple-variables-in-1-bar-graph-tp4647099.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4647131i=2mailing 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. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4647131i=3mailing 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. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/plotting-multiple-variables-in-1-bar- graph -tp4647099p4647131.html To unsubscribe from plotting multiple variables in 1 bar graph, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsub s cribe_by_codenode=4647099code=cmFkaWFudC5zdGFyc0BnbWFpbC5jb218NDY0NzA 5 OXwtNDIxODQ0NzMx . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro _ viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespace s .BasicNamespace-nabble.view.web.template.NabbleNamespace- nabble.view.web .template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail . naml-instant_emails%21nabble%3Aemail.naml- send_instant_email%21nabble%3A email.naml -- Geekerie Shirts: shirts for the pop culture junkie - http://geekerie.multiply.com Sustainability in action: the official website of El Nido Resorts' Environment Department - http://elnidoenvironment.wordpress.com -- View this message in context: http://r.789695.n4.nabble.com/plotting-multiple-variables-in-1-bar- graph -tp4647099p4647134.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] repeat takes along time
Hi Hi I want help for repeat because it takes a long time repeat{ for (i in 1:n){ probb[i]=sum(Wc[z[,j]=yb[i]]) } deltab[,b]=rbinom(n,1,probb) if(length(which(is.na(deltab[,b])==T))==0){break} } This code works but takes much computation time. What is this code supposed to do? It gives an error (see below) repeat{ + for (i in 1:n){ + probb[i]=sum(Wc[z[,j]=yb[i]]) + } + deltab[,b]=rbinom(n,1,probb) + if(length(which(is.na(deltab[,b])==T))==0){break} + } Error: object 'n' not found PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. and some data to test the code. Anyway, this kind of code shall be implemented probably in other language like C+. Regards Petr Anyone could help me to find a solution to take a shor time. Thanks Jorge -- View this message in context: http://r.789695.n4.nabble.com/repeat- takes-along-time-tp4647160.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.
[R] List of multidimensional arrays
Dear all, I am trying to create a list, where each list element is a vector of different length arrays that contain 2by2 matrices. To be more specific there are 11 treatments that are compared with placebo (we have 11 comparisons) and each comparison is studied by a different number of trials and each trial has a different number of missing participants in both arms. The length of the list is equal to the number of comparisons. In each comparison the number of arrays is equal to the number of trials that study this comparison. For instance 4 trials compare PAR with placebo. So, for this comparison we have 4 arrays and each array has a length equal to the producy of the number of participants in each arm. These arrays contain 2x2 matrices. I have attached a document with the data and the code. I cannot create the list results the way I have described above. It creates only the matrices for the first array (that has length equal to 135) of the first comparison leaving the rest 10 comparisons NULL. Any suggestion would be really helpful Thank you in advance, Loukia __ 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] Understanding lattice barchart() display
On 2012-10-23 15:39, Rich Shepard wrote: On Tue, 23 Oct 2012, Bert Gunter wrote: I believe you are misunderstanding what a barchart is (or maybe I do, since I never use 'em). I believe that there should be one quant value for each tclass and stream, and you have several. Bert, My first attempt at using barchart() ?panel.barchart is the place to look for documentation for details of any lattice display. Note especially the horizontal argument details (also in ?barchart). I looked at the panel section in ?barchart but did not gain any insights into why there are segments in the bars. As Bert correctly points out, you have more than one quant value per tclass/stream combination. You need to summarize your 1987-case data.frame to a 56-case data.frame (8 levels of tclass and 7 levels of stream). The easy way to do that is: benthos2 - aggregate(quant ~ tclass + stream, data = benthos, FUN = sum) Then just use benthos2 as the data argument to barchart(). 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.
[R] Results not dispalying in R console
Hi I'm not getting any results in R console when i run commands. I reinstalled R but the results are same - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/Results-not-dispalying-in-R-console-tp4647271.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] Export summary from regression output
HI, May be this helps: ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group - gl(2,10,20, labels=c(Ctl,Trt)) weight - c(ctl, trt) lm.D9 - lm(weight ~ group) fun1-function(x){ res-c(paste(as.character(summary(x)$call),collapse= ), x$coefficients[1], x$coefficients[2], length(x$model), summary(x)$coefficients[2,2], summary(x)$r.squared, summary(x)$adj.r.squared, summary(x)$fstatistic, pf(summary(x)$fstatistic[1],summary(x)$fstatistic[2],summary(x)$fstatistic[3],lower.tail=FALSE)) names(res)-c(call,intercept,slope,n,slope.SE,r.squared,Adj. r.squared, F-statistic,numdf,dendf,p.value) return(res)} res2-fun1(lm.D9) write.csv(res2,newregsummary.csv) x call lm weight ~ group intercept 5.032 slope -0.371 n 2 slope.SE 0.3114348514 r.squared 0.073077599 Adj. r.squared 0.02158191 F-statistic 1.4191012974 numdf 1 dendf 18 p.value 0.249023166 A.K. - Original Message - From: fxen3k f.seha...@gmail.com To: r-help@r-project.org Cc: Sent: Tuesday, October 23, 2012 7:28 AM Subject: [R] Export summary from regression output Hi there, I tried it many times but didn't get it worked. I just want to export the summary of a OLS regression (lm() function) into a csv-file including the call-formula, coefficients, r-squared, adjusted r-squared and f statistic. I know I can export: write.csv2(Regression_60d_ann$coefficients, Regression_60d_ann.csv) But then I only get the coefficients, but not all the other output... I tried creating a matrix and I wanted to put in Regression_60d_ann$coefficients, Regression_60d_ann$adj.r.squared, Regression_60d_ann$r.squared, etc. but it didn't work due to different length of rows. Can anyone help or has a better solution? Thanks in advance Felix -- View this message in context: http://r.789695.n4.nabble.com/Export-summary-from-regression-output-tp4647109.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] incomplete final line found by readTableHeader
Thanks, JeffThis is from a course, but the course is just needed to take some slides for presentation. I just learn R by myself, and want this skill more practical. So I try to use the innovative way to perform a more professional presentation.hence, no worry about the homework support issue. However, I still got the problem, I think I did the right thing to make the excel, then change the extension to csv to make sure it has the appropriate comma in it.But the warning still be there. I will try other more. Thank you. Date: Tue, 23 Oct 2012 20:14:53 -0700 From: ml-node+s789695n4647264...@n4.nabble.com To: wenbo...@live.cn Subject: Re: incomplete final line found by readTableHeader Keep in mind that this is NOT a homework support list... you are supposed to use the support provided by your educational institution if you are in a course. Read the posting guide mentioned in the footer of every email. FWIW, as described your problem is with Excel, and this is not an Excel support list either. I suggest that you edit the csv file with a text editor (e.g. NotePad) to make sure the correct number of commas are on each line of the data file. --- Jeff NewmillerThe . . Go Live... DCN:[hidden email]Basics: ##.#. ##.#. 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. Shane2012 [hidden email] wrote: Hello, I am trying to read in an Excel file that I saved as a .csv so I can analyze my assignment data! I am getting really frustrated because this is what I keep getting: Warning message: In read.table(CityData.CSV, sep = /, header = T) : incomplete final line found by readTableHeader on 'CityData.CSV' I have open the file and make sure click return after the last line, then save the file. I try to use kinds of read data frame methods, such as read.table read.csv or my.files - list.files(path) for(i in my.files) { nam - paste(CityData, substr(i, 14, 15), sep ='') assign(nam, read.csv(i)) } - They all failed. Can anyone offer some help? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/incomplete-final-line-found-by-readTableHeader-tp4647259.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] 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. __ [hidden email] 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/incomplete-final-line-found-by-readTableHeader-tp4647259p4647264.html To unsubscribe from incomplete final line found by readTableHeader, click here. NAML -- View this message in context: http://r.789695.n4.nabble.com/incomplete-final-line-found-by-readTableHeader-tp4647259p4647265.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use tapply with more than one variables grouped
Hi, Just a modification of David's method: apply(dat1,2,function(x) names(which.max(x[!is.na(x)]))==Obama) # AL AR CA NY #FALSE FALSE TRUE TRUE names(dat1)[apply(dat1,2,function(x) names(which.max(x[!is.na(x)]))==Obama)] #[1] CA NY A.K. - Original Message - From: David Winsemius dwinsem...@comcast.net To: noobmin pseudov...@hotmail.com Cc: r-help@r-project.org Sent: Tuesday, October 23, 2012 8:45 PM Subject: Re: [R] How to use tapply with more than one variables grouped On Oct 23, 2012, at 1:25 PM, noobmin wrote: AL AR CA NY Doug 250 250 250 NA Jennifer 20 340 300 100 Michele 250 500 250 60 Obama 15 45 520 600 My English is not very good, I'll try again. I want to list ALL states in the country where Obama had greater contribution. The table above shows the total contribution received by each candidate in a given state. To AL state obama not received more than Doug. For the AR state he received no more than others candidates. For the CA state he received a total of $ 520, which is 520300250=250 and should be selected. In NY also had the largest contribution, $ 600, 60010060 and should therefore be selected. I want to make it to the N presidency candidates and M states of the country. The table above is only an example. Perhaps: apply(dat, 2, function(x) x[Obama] == max(x, na.rm=TRUE) ) AL AR CA NY FALSE FALSE TRUE TRUE Or perhaps: names(dat)[ apply(dat, 2, function(x) x[Obama] == max(x, na.rm=TRUE) ) ] [1] CA NY Sorry again, for me it was clear. = ( Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to-use-tapply-with-more-than-one-variables-grouped-tp4646948p4647220.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. David Winsemius, MD Alameda, CA, USA __ 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] Z score
Hi, I need to find the z-score of the data present in a speardsheet. The values needs to be calculated for each gene across the samples (refer the example). And, it should be a simple thing, but I am unable to do it right now ! The example re the structure of the spreadsheet is - # Example: MyFile - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77,88 Gene_2,98,22,34 Gene_3,33,43,33 Gene_4,78,,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) And, I think this formula that can be used for z score is - (x-mean(x))/sd(x) And, apply() function for rows should work. But bottomline - I am unable to do it correctly. Could you show me - using apply () or some other alternative function. Thank you. Cheers, Ved [[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] R untar error
Hi, When I use untar command and I got an error. untar(/public03/ara_gse_raw_data/GSE26679_RAW.tar,exdir=/public03/data/arabidopsis_data/GSE26679_RAW) sh: /tmp/RtmpzQGJvh/file5f09b232: No such file or directory I want to know how to solve this problem. Thanks very much for any tips. 2012-10-24 zhaohu44 [[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] ROC with more than one predictor
On Tue, Oct 23, 2012 at 11:52 PM, Luigi marongiu.lu...@gmail.com wrote: Any tip on how to proceed? You may want to do check rocplus package. Its vignette is pretty good. http://cran.r-project.org/web/packages/rocplus/vignettes/rocplus.pdf In your case, I think pairwise comparison would be one approach Best, Mehmet __ 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] Changing radii line type in radial plots
On 2012-10-23 15:22, bwone wrote: Hello all, Is it possible to change the radii line type in radial plots? I wasn't able to find anything online. Do please be more specific: which package's radial plot function are you using? Package plotrix has radial.plot() with an 'lty' argument. Peter Ehlers Thanks, Bern -- View this message in context: http://r.789695.n4.nabble.com/Changing-radii-line-type-in-radial-plots-tp4647238.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] List of multidimensional arrays
On Oct 23, 2012, at 11:36 PM, Loukia Spineli wrote: Dear all, I am trying to create a list, where each list element is a vector of different length arrays that contain 2by2 matrices. To be more specific there are 11 treatments that are compared with placebo (we have 11 comparisons) and each comparison is studied by a different number of trials and each trial has a different number of missing participants in both arms. The length of the list is equal to the number of comparisons. In each comparison the number of arrays is equal to the number of trials that study this comparison. For instance 4 trials compare PAR with placebo. So, for this comparison we have 4 arrays and each array has a length equal to the producy of the number of participants in each arm. These arrays contain 2x2 matrices. I have attached a document with the data and the code. Well, A for effort but somewhat lower grade for not reading the Posting Guide and attaching a MIME-text file. I cannot create the list results the way I have described above. It creates only the matrices for the first array (that has length equal to 135) of the first comparison leaving the rest 10 comparisons NULL. Any suggestion would be really helpful Thank you in advance, Loukia __ 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. David Winsemius, MD Alameda, CA, USA __ 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] Results not dispalying in R console
Hello, And what do you expect from us, without example? Regards, Pascal Le 12/10/24 15:44, arunkumar a écrit : Hi I'm not getting any results in R console when i run commands. I reinstalled R but the results are same - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/Results-not-dispalying-in-R-console-tp4647271.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 untar error
On Oct 23, 2012, at 7:43 PM, zhaohu44 wrote: Hi, When I use untar command and I got an error. untar(/public03/ara_gse_raw_data/GSE26679_RAW.tar,exdir=/public03/data/arabidopsis_data/GSE26679_RAW) sh: /tmp/RtmpzQGJvh/file5f09b232: No such file or directory I want to know how to solve this problem. This does not look like an R problem. -- David Winsemius, MD Alameda, CA, USA __ 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] Results not dispalying in R console
wow. That sounds like a problem. For a more constructive response, read the posting guide and post specific examples and explain how the output you get is not what you expect. Also, the output of sessionInfo() is likely to be helpful, and if you use a Mac, or Debian/other Linux, one of the platform-specific email lists might be a more appropriate forum. --- 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. arunkumar akpbond...@gmail.com wrote: Hi I'm not getting any results in R console when i run commands. I reinstalled R but the results are same - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/Results-not-dispalying-in-R-console-tp4647271.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] List of multidimensional arrays
You are absolutely right. I read the guidelines! Mistake to attach 'word' file! The comfort is that at least I got an A :). I revise my question approapriately! On Wed, Oct 24, 2012 at 10:36 AM, David Winsemius dwinsem...@comcast.netwrote: On Oct 23, 2012, at 11:36 PM, Loukia Spineli wrote: Dear all, I am trying to create a list, where each list element is a vector of different length arrays that contain 2by2 matrices. To be more specific there are 11 treatments that are compared with placebo (we have 11 comparisons) and each comparison is studied by a different number of trials and each trial has a different number of missing participants in both arms. The length of the list is equal to the number of comparisons. In each comparison the number of arrays is equal to the number of trials that study this comparison. For instance 4 trials compare PAR with placebo. So, for this comparison we have 4 arrays and each array has a length equal to the producy of the number of participants in each arm. These arrays contain 2x2 matrices. I have attached a document with the data and the code. Well, A for effort but somewhat lower grade for not reading the Posting Guide and attaching a MIME-text file. I cannot create the list results the way I have described above. It creates only the matrices for the first array (that has length equal to 135) of the first comparison leaving the rest 10 comparisons NULL. Any suggestion would be really helpful Thank you in advance, Loukia __ 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. David Winsemius, MD Alameda, CA, USA [[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] List of multidimensional arrays
Dear all, I am trying to create a list, where each list element is a vector of different length arrays that contain 2by2 matrices. To be more specific there are 11 treatments that are compared with placebo (we have 11 comparisons) and each comparison is studied by a different number of trials and each trial has a different number of missing participants in both arms. The length of the list is equal to the number of comparisons. In each comparison the number of arrays is equal to the number of trials that study this comparison. For instance 4 trials compare PAR with placebo. So, for this comparison we have 4 arrays and each array has a length equal to the producy of the number of participants in each arm. These arrays contain 2x2 matrices. I have attached a document with the data and the code. I cannot create the list results the way I have described above. It creates only the matrices for the first array (that has length equal to 135) of the first comparison leaving the rest 10 comparisons NULL. Any suggestion would be really helpful Thank you in advance, Loukia List of multidimensional arrays.pdf Description: Adobe PDF document __ 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] incomplete final line found by readTableHeader
Le mardi 23 octobre 2012 à 20:36 -0700, Shane2012 a écrit : Thanks, Jeff This is from a course, but the course is just needed to take some slides for presentation. I just learn R by myself, and want this skill more practical. So I try to use the innovative way to perform a more professional presentation.hence, no worry about the homework support issue. However, I still got the problem, I think I did the right thing to make the excel, then change the extension to csv to make sure it has the appropriate comma in it.But the warning still be there. I will try other more. Thank you. The warning is slightly ambiguous in this context. What it means is *not* the record/observation/individual is incomplete, i.e. needs one more comma but the last line of the file is incomplete, i.e. does not end with a line break. This warning is completely innocuous in this case as David stated: you can get rid of it by opening your CSV file with a text editor and adding an empty line at the end of the file, but if you don't do this, things will work as expected. To make it short: you don't have any problem. ;-) Regards __ 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] R5: Lock a class field from within a method?
Hello, testclass - setRefClass( testclass, fields = list(testfield = logical), methods = list(validate=function(){testfield-TRUE})) test - testclass$new() test$testfield logical(0) test$validate() test$testfield [1] TRUE Works just fine for me. I would love to be able to do something like testclass - setRefClass( testclass, fields = list(testfield = logical), methods = list(validate=function(){ testfield-TRUE .self$lock(testfield) })) but am unabel to achieve that. Can anyone point out how to go about rendering a field immutable after execution of a specific method? Sincerely, Joh __ 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] plotting multiple variables in 1 bar graph
On 10/23/2012 07:22 PM, Macy Anonuevo wrote: I'd greatly appreciate your help in making a bar graph with multiple variables plotted on it. All the help sites I've seen so far only plot 1 variable on the y-axis Data set: I have 6 sites, each measured 5 times over the past year. During each sampling time, I counted the occurrences of different benthic components (coral, dead coral, sand, etc.) over 5 transects in each site site time transect coral deadcoral sand rubble . S1 time1 trans110 15 10 4 S1 time1 trans2 5 410 6 S1 time1 trans3 10 2 5 7 . . . S5 time5trans5 63 1 6 I used aggregate to get the means of the individual variables (coral, dead coral, etc.) using the site and time as grouping factors. aggregate.plot(deadcoral, by=list(SITE=site, TIME=time), FUN=c(mean), error=c(sd), legend.site=topright, bar.col=rainbow(6)) What I need now is to plot all the variables in 1 site as they change over time. What Excel produced: http://r.789695.n4.nabble.com/file/n4647099/abdeens_benthic_cover.jpg (The image has mean %cover as the y-value instead of mean count but the example still applies) I've spent several hours looking for code to do this but didn't find anything. I'd use the Excel graph except that it doesn't have the sd or se bars. Hi Macy, This isn't exactly the same as the Excel plot, but it might help you out. If your data is in a data frame named abs: library(plotrix) barpos-barp(abs,names.arg=names(abs), do.first=grid(nx=NA,lty=1,ny=9),col=rainbow(5), ylim=c(0,100),staxx=TRUE,ylab=Percent, main=Abdeen Benthic Cover Through Time, height.at=seq(0,100,by=10)) dispersion(barpos$x,barpos$y,ulim=barpos$y/10) legend(5,80,paste(T,1:5,sep=),fill=rainbow(5), 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] SEM multigroup modeling
Dear Maya, You and I corresponded about this problem yesterday, so I'll respond on the r-help list only briefly: On Tue, 23 Oct 2012 23:12:23 +0300 Maya Abou Zeid ma...@aub.edu.lb wrote: Hello, I am using the SEM package in R to fit a multigroup latent variable model and ran into some difficulties. I have 2 questions: 1. First, I am getting the following error message and wondering what to do to fix it: Error in solve.default((N[g] - 1) * robustVcov(mod.g, adj.obj = adj.objects[[g]])) : system is computationally singular: reciprocal condition number = 4.52055e-23 It's not really possible to try to locate the source of the problem without the data. You could try several things to get a proper solution, as mentioned in ?sem, and you might try suppressing the computation of the robust coefficient covariance matrix, which is where the problem surfaces. 2. Second, I want to specify different models for two groups (Drivers vs. Nondrivers), but I want only 1 parameter to be different, while everything else remains the same. Should I just create two files with the model equations? But then how do I use these 2 files as an input to the multigroupModel or sem functions? I tried the following but got the error message {Error in model[, 2] : incorrect number of dimensions}. Here is a sample of the code: mod.QT.1 - specifyEquations(...) # model equations for category 1 mod.QT.2 - specifyEquations(...) # model equations for category 2 Lst.model - list(mod.QT.1, mod.QT.2) mod.mg - multigroupModel(Lst.model, groups=c(Driver, Nondriver)) sem.QT - sem(mod.mg, data=QTrav, group=Driver_Class1, formula = ~ ..., fixed.x=c(...)) multigroupModel() doesn't take a list of models as an argument but rather arbitrarily named iniital arguments, one for each group. See ?multigroupModel for (some) more information. Are there any sample codes for multigroup modeling using the SEM package that I can look at? There are a couple of examples in ?sem, but I know you've already seen them. These are given in a little more detail in http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-SEMs.pdf. Best, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ Thanks in advance, Maya [[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] Z score
Hello, Try the following. apply(MyFile, 1, scale) Hope this helps, Rui Barradas Em 24-10-2012 07:17, Vedant Sharma escreveu: Hi, I need to find the z-score of the data present in a speardsheet. The values needs to be calculated for each gene across the samples (refer the example). And, it should be a simple thing, but I am unable to do it right now ! The example re the structure of the spreadsheet is - # Example: MyFile - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77,88 Gene_2,98,22,34 Gene_3,33,43,33 Gene_4,78,,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) And, I think this formula that can be used for z score is - (x-mean(x))/sd(x) And, apply() function for rows should work. But bottomline - I am unable to do it correctly. Could you show me - using apply () or some other alternative function. Thank you. Cheers, Ved [[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] barplot
On 10/24/2012 03:21 AM, Thiho Jules wrote: Hi, I want to make a barplot with the following datasets: I have a file as following: name chr position A1 A2 pop1 pop1 pop2 pop2 I have calculated a measure using all the values in columns pops, the values are saved in a vector. Now I want to make a barplot using the values in this vector as the y axis and the values in the column position in the x-axis. Hi Thiho, You can do this with the barp function in the plotrix package. See the x argument for placing the bars at arbitrary positions. 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] Z score
Hi, Try this: res-do.call(rbind,lapply(lapply(apply(MyFile,1,function(x) x[!is.na(x)]),function(x) (x-mean(x))/sd(x)),function(x) x[c(Sample_1,Sample_2,Sample_3)])) res # Sample_1 Sample_2 Sample_3 #Gene_1 0.4931970 -1.1507929 0.6575959 #Gene_2 1.1421818 -0.7179429 -0.4242390 #Gene_3 -0.5773503 1.1547005 -0.5773503 #Gene_4 -0.7071068 NA 0.7071068 A.K. - Original Message - From: Vedant Sharma vedantg...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 2:17 AM Subject: [R] Z score Hi, I need to find the z-score of the data present in a speardsheet. The values needs to be calculated for each gene across the samples (refer the example). And, it should be a simple thing, but I am unable to do it right now ! The example re the structure of the spreadsheet is - # Example: MyFile - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77,88 Gene_2,98,22,34 Gene_3,33,43,33 Gene_4,78,,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) And, I think this formula that can be used for z score is - (x-mean(x))/sd(x) And, apply() function for rows should work. But bottomline - I am unable to do it correctly. Could you show me - using apply () or some other alternative function. Thank you. Cheers, Ved [[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] Z score
Hi, In cases, with more sample columns, you could also use this: res2-t(sapply(lapply(apply(MyFile,1,function(x) x[!is.na(x)]),function(x) (x-mean(x))/sd(x)),function(x) x[colnames(MyFile)] )) res2 # Sample_1 Sample_2 Sample_3 #Gene_1 0.4931970 -1.1507929 0.6575959 #Gene_2 1.1421818 -0.7179429 -0.4242390 #Gene_3 -0.5773503 1.1547005 -0.5773503 #Gene_4 -0.7071068 NA 0.7071068 A.K. - Original Message - From: Vedant Sharma vedantg...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 2:17 AM Subject: [R] Z score Hi, I need to find the z-score of the data present in a speardsheet. The values needs to be calculated for each gene across the samples (refer the example). And, it should be a simple thing, but I am unable to do it right now ! The example re the structure of the spreadsheet is - # Example: MyFile - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77,88 Gene_2,98,22,34 Gene_3,33,43,33 Gene_4,78,,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) And, I think this formula that can be used for z score is - (x-mean(x))/sd(x) And, apply() function for rows should work. But bottomline - I am unable to do it correctly. Could you show me - using apply () or some other alternative function. Thank you. Cheers, Ved [[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] factor or character
Hello, Sorry but, what doesn't work? What is the error message or result? As for stringsAsFactors not keeping character strings as character strings maybe this is from calling data.frame from within the environment used by with(), but you can use other ways of converting to character strings, such as mod5.sig$snps - as.character(mod5.sig$snps) before subsetting. And you can also check the result of colnames(todos) %in% mod5.sig$snp What does this give you? Hope this helps, Rui Barradas Em 24-10-2012 11:58, Silvano Cesar da Costa escreveu: Hi, still doesn't work. Hello, I've just seen the error, you are _not_ searching for colnames in mod5.sig$snps. Corrected: Selec = todos[ , colnames(todos) %in% mod5.sig$snps] Hope this helps, Rui Barradas Em 23-10-2012 21:17, Silvano Cesar da Costa escreveu: Hi Rui, it doesn't work: (mod5.sig = with(mod5, data.frame(snps = SNP[pvalor5e-8], stringsAsFactors=FALSE))) str(mod5.sig) 'data.frame': 76 obs. of 1 variable: $ snps: Factor w/ 220 levels rs10058955_A,..: 89 59 88 73 40 35 97 55 87 204 ... Selec = todos[ , colnames(todos) %in% mod5.sig] head(Selec) data frame com 0 colunas e 6 linhas the problem is the same. Thanks, Hello, When creating the data.frame of snps use the option stringsAsFactors = FALSE I believe your error comes from the fact that you are trying to find colnames in a variable coded as integers (a factor, like str shows). Hope this helps, Rui Barradas Em 23-10-2012 19:02, Silvano Cesar da Costa escreveu: Hi, The program below work very well. (snps = c('rs621782_G', 'rs8087639_G', 'rs8094221_T', 'rs7227515_A', 'rs537202_C')) Selec = todos[ , colnames(todos) %in% snps] head(Selec) But, I have a data set with 1.000 columns and I need extract 70 to use (like snps in command above). This 70 snps are in a file. So I create a file to extract them with (mod5.sig = with(mod5, data.frame(snps = SNP[pvalor 5e-8]))) str(mod5.sig) (snps = (mod5.sig)) The structure is: 'data.frame': 76 obs. of 1 variable: $ snps: Factor w/ 220 levels rs10058955_A,..: 89 59 88 73 40 35 97 55 87 204 ... But it doesn't work. The output is: Selec = todos[ , colnames(todos) %in% snps] head(Selec) data frame with 0 columns and 6 rows What's is wrong? Thanks a lot, - Silvano Cesar da Costa Universidade Estadual de Londrina Centro de Ciências Exatas Departamento de Estatística Fone: (43) 3371-4346 __ 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. - Silvano Cesar da Costa Universidade Estadual de Londrina Centro de Ciências Exatas Departamento de Estatística Fone: (43) 3371-4346 - - Silvano Cesar da Costa Universidade Estadual de Londrina Centro de Ciências Exatas Departamento de Estatística Fone: (43) 3371-4346 - __ 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] Five cases of the Multivariate VECM
Hello, I was studying several packages related to time series analysis (urca, vars, tseries). I understand that we can estimate a VECM and also test restrictions on alphas and betas. However, I couldn't find a function that allows me to specify the five cases of VECM (restricted constant, unrestricted constant, restricted and unrestricted trend and no constant). Is there any function that fulfills this aspect of VECM analysis in any package? Thanks a lot for your time and attention. Claudio D. Shikida http://www.shikida.net and http://works.bepress.com/claudio_shikida/ Esta mensagem pode conter informação confidencial e/ou privilegiada. Se você não for o destinatário ou a pessoa autorizada a receber esta mensagem, não poderá usar, copiar ou divulgar as informações nela contidas ou tomar qualquer ação baseada nessas informações. Se você recebeu esta mensagem por engano, por favor avise imediatamente o remetente, respondendo o presente e-mail e apague-o em seguida. This message may contain confidential and/or privileged ...{{dropped:9}} __ 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] recursive function on a structured list of lists (dendrogram)
Dear all, I have been trying the following without avail and would be very grateful for any help. From a dendrogram (recursive list of lists with some structure), I would like to obtain some information of the component lists and of the enclosing list at the same time. In dendrogram-speech I basically would like the label of the leaf and the height of the enclosing branch. A dendrogram example (from the help file of stats::dendrogram), and some functions showing how it is structured: hc - hclust(dist(USArrests), ave) dend1 - as.dendrogram(hc) plot(dend1) str(dend1) Similarly to dendrapply(), I tried o recursively obtain from the tree a list including, for each member (leaf) the height of the list containing it. However, I fail to fully grasp how the 'recursiveness' is made within the function saving both elements at the leaf and branch levels. For reference the dendrapply function is as follows: function (X, FUN, ...) { FUN - match.fun(FUN) if (!inherits(X, dendrogram)) stop('X' is not a dendrogram) Napply - function(d) { r - FUN(d, ...) if (!is.leaf(d)) { if (!is.list(r)) r - as.list(r) if (length(r) (n - length(d))) r[seq_len(n)] - vector(list, n) r[] - lapply(d, Napply) } r } Napply(X) } I essentially don't manage to 'save' the height of a branch (a list of lists) so that it can be used at the next iterations for adding to the leafs there. Many thanks for any guidance on how to recursively implement a function. Kind regards, Ivan [[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] After sorting a dataframe by date
Ai...I see, i didn't know I can sort rowname. more study to do :) cheers, martin -- View this message in context: http://r.789695.n4.nabble.com/After-sorting-a-dataframe-by-date-tp4647173p4647291.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] Results not dispalying in R console
On 24/10/12 19:44, arunkumar wrote: Hi I'm not getting any results in R console when i run commands. I reinstalled R but the results are same. I *suspect* that you are displaying the results inside some sort of function (e.g. a for loop, or source() ) whence the results are invisible unless explicitly print()-ed. However, given the award-winning vagueness of your question, it's hard to tell. Advice: (1) Learn something about R; don't just hammer and hope. Read the introductory manuals and scan the FAQ. (2) Learn to ask questions in such a manner that they can actually be answered. As fortune(182) has it, ``R is lacking a mind_read() function!'' cheers, Rolf Turner __ 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] equation solver
Hi, I'm Pina and I'm a student in geology. I'm working with spectral profile of sand and I have to find the similarity between one spectral profile selected by hyperspectral image anche one that I created to mix different percentage of 4 mineral component. I have to find the best mix of percentage of this 4 mineral in order to have the best likeness with the spectral profile chose by hyperspectral image. Untill now I worked with excel using the function equation solver to find the best fit but I 'd like to know if is possible do this operation working in R. Thanks for the attention. I'm looking forward to hearing from you. Regards. Pina. -- View this message in context: http://r.789695.n4.nabble.com/equation-solver-tp4647287.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] repeat takes along time
Hi Petr Thanks for reply. On 24 October 2012 07:26, PIKAL Petr [via R] ml-node+s789695n464726...@n4.nabble.com wrote: Hi It is a piece of my code. At this, i create a matrix(deltab) with each column is a binomial, but in there are several NAs, and i must restart the cycle the number of Nas is zero. So, the problem this process takes a very long time. Hi I want help for repeat because it takes a long time repeat{ for (i in 1:n){ probb[i]=sum(Wc[z[,j]=yb[i]]) } deltab[,b]=rbinom(n,1,probb) if(length(which(is.na(deltab[,b])==T))==0){break} } This code works but takes much computation time. What is this code supposed to do? It gives an error (see below) repeat{ + for (i in 1:n){ + probb[i]=sum(Wc[z[,j]=yb[i]]) + } + deltab[,b]=rbinom(n,1,probb) + if(length(which(is.na(deltab[,b])==T))==0){break} + } Error: object 'n' not found PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. and some data to test the code. Anyway, this kind of code shall be implemented probably in other language like C+. Regards Petr Anyone could help me to find a solution to take a shor time. Thanks Jorge -- View this message in context: http://r.789695.n4.nabble.com/repeat- takes-along-time-tp4647160.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4647269i=0mailing 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. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4647269i=1mailing 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. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/repeat-takes-along-time-tp4647160p4647269.html To unsubscribe from repeat takes along time, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4647160code=anBtbWVpc3RlckBnbWFpbC5jb218NDY0NzE2MHwxODQ1OTAyNw== . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- *Jorge Mendonça* -- View this message in context: http://r.789695.n4.nabble.com/repeat-takes-along-time-tp4647160p4647285.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Recode function car package erases previous values
Hi all, I am attempting to create a new variable based on values of other variables. The variable is called pharm. It basically takes the numeric code of 1 as yes and 0 to be No from the variable B20_C1 (a question on a survey). However, I would also like to have a level for non-respondents and these are captured in the variable nr.B20C, which is a 1 when there is a non-response on the whole group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will have three levels, Yes No and no resp. See below what happens pharm-as.factor(recode(B20_C1,1='Yes';0='No')) table(pharm) pharm No Yes 716 7 levels(pharm)-c('No','Yes','no resp') table(pharm) pharm No Yes no resp 716 7 0 pharm-as.factor(recode(nr.B20C,1='no resp')) table(pharm) pharm 0 no resp 723 6 The recode variable just cannot seem to 'remember' I had just recoded 7 values to 'Yes' and 716 to be 'No' and instead it assigns the level '0' which comes from nr.B20C (it has values 0 or 1). This inconvenient as I would like to have ultimately the following table pharm No Yes no resp 716 7 6 (FROM nr.B20C where row has value 1). Background. The variable pharm assess where you used the pharmacy to get your contraception. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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] factor or character
Hi, still doesn't work. Hello, I've just seen the error, you are _not_ searching for colnames in mod5.sig$snps. Corrected: Selec = todos[ , colnames(todos) %in% mod5.sig$snps] Hope this helps, Rui Barradas Em 23-10-2012 21:17, Silvano Cesar da Costa escreveu: Hi Rui, it doesn't work: (mod5.sig = with(mod5, data.frame(snps = SNP[pvalor5e-8], stringsAsFactors=FALSE))) str(mod5.sig) 'data.frame':76 obs. of 1 variable: $ snps: Factor w/ 220 levels rs10058955_A,..: 89 59 88 73 40 35 97 55 87 204 ... Selec = todos[ , colnames(todos) %in% mod5.sig] head(Selec) data frame com 0 colunas e 6 linhas the problem is the same. Thanks, Hello, When creating the data.frame of snps use the option stringsAsFactors = FALSE I believe your error comes from the fact that you are trying to find colnames in a variable coded as integers (a factor, like str shows). Hope this helps, Rui Barradas Em 23-10-2012 19:02, Silvano Cesar da Costa escreveu: Hi, The program below work very well. (snps = c('rs621782_G', 'rs8087639_G', 'rs8094221_T', 'rs7227515_A', 'rs537202_C')) Selec = todos[ , colnames(todos) %in% snps] head(Selec) But, I have a data set with 1.000 columns and I need extract 70 to use (like snps in command above). This 70 snps are in a file. So I create a file to extract them with (mod5.sig = with(mod5, data.frame(snps = SNP[pvalor 5e-8]))) str(mod5.sig) (snps = (mod5.sig)) The structure is: 'data.frame': 76 obs. of 1 variable: $ snps: Factor w/ 220 levels rs10058955_A,..: 89 59 88 73 40 35 97 55 87 204 ... But it doesn't work. The output is: Selec = todos[ , colnames(todos) %in% snps] head(Selec) data frame with 0 columns and 6 rows What's is wrong? Thanks a lot, - Silvano Cesar da Costa Universidade Estadual de Londrina Centro de Ciências Exatas Departamento de Estatística Fone: (43) 3371-4346 __ 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. - Silvano Cesar da Costa Universidade Estadual de Londrina Centro de Ciências Exatas Departamento de Estatística Fone: (43) 3371-4346 - - Silvano Cesar da Costa Universidade Estadual de Londrina Centro de Ciências Exatas Departamento de Estatística Fone: (43) 3371-4346 __ 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] bugs and misfeatures in polr(MASS).... fixed!
Sorry, I have been away. I'll have a look at this and get back to you tomorrow. Tim On Thu, Oct 18, 2012 at 10:35 PM, ahs [via R] ml-node+s789695n4646600...@n4.nabble.com wrote: Hello, I am trying to use this fix for the convergence problem in polr, but I don't seem to get the change of code right. I redefine the function polr by the lines tjb wrote if(missing(start)) { # try something that should always work -tjb u - as.integer(table(y)) u - (cumsum(u)/sum(u))[1:q] zetas - switch(method, logistic= qlogis(u), probit= qnorm(u), cauchit= qcauchy(u), cloglog= -log(-log(u)) ) s0 - c(rep(0,pc),zetas[1],log(diff(zetas))) but - which part should I erase? The whole old if(missing(start)) {...} or something else or nothing? I have tried all ways I could think of. I also can't see where the new object s0 is used in the old code? Any input on my problem would be very much appreciated! -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/bugs-and-misfeatures-in-polr-MASS-fixed-tp3024677p4646600.html To unsubscribe from bugs and misfeatures in polr(MASS) fixed!, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=3024677code=dGltb3RoeS5iZW5oYW1AdXFjb25uZWN0LmVkdS5hdXwzMDI0Njc3fDE5NTE2NDMxMjk= . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml - Tim J. Benham -- View this message in context: http://r.789695.n4.nabble.com/bugs-and-misfeatures-in-polr-MASS-fixed-tp3024677p4647307.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] equation solver
On 24-10-2012, at 10:04, pina pina@hotmail.it wrote: Hi, I'm Pina and I'm a student in geology. I'm working with spectral profile of sand and I have to find the similarity between one spectral profile selected by hyperspectral image anche one that I created to mix different percentage of 4 mineral component. I have to find the best mix of percentage of this 4 mineral in order to have the best likeness with the spectral profile chose by hyperspectral image. Untill now I worked with excel using the function equation solver to find the best fit but I 'd like to know if is possible do this operation working in R. It looks like you need something that can do optimization. R provides optim() and nlminb(). A similar question was posted several days ago. See http://r.789695.n4.nabble.com/Optimization-in-R-similar-to-MS-Excel-Solver-td4646759.html You might have some use for package limSolve and function lsei. Also see the CRAN Optimization Task View (http://cran.r-project.org/web/views/Optimization.html) Berend Thanks for the attention. I'm looking forward to hearing from you. Regards. Pina. -- View this message in context: http://r.789695.n4.nabble.com/equation-solver-tp4647287.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] multi-panel figure: overall title for each row
Hannes, A bit inelegant, but it works. Try this: mtext(Overall Title Row 2, outer=TRUE, line=-17) mtext(Overall Title Row 3, outer=TRUE, line=-34) Jean capy_bara hettl...@few.vu.nl wrote on 10/23/2012 09:08:39 AM: Dear all, I have a 3x2 plot and in addition to the title of the individual plots I would like to have an overall title for each row. I managed to get an overall title for the whole plot matrix with mtext: par(mfrow=(c(3,2)), mar=c(6.4,4.5,4.2, 1.8), oma=c(0,0,3,0)) for (i in 1:6) barplot(sample(1:10,5), main=paste(Plot #,i)) mtext(Overall Title Row 1, outer=TRUE) but I cannot put an overall title in the middle above the titles of the plots in the second or third row. If I use mtext within the loop, I can only add another title above an individual plot. I hope someone can help me, many thanks in advance Hannes [[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] Understanding lattice barchart() display
On Tue, 23 Oct 2012, Peter Ehlers wrote: As Bert correctly points out, you have more than one quant value per tclass/stream combination. You need to summarize your 1987-case data.frame to a 56-case data.frame (8 levels of tclass and 7 levels of stream). The easy way to do that is: benthos2 - aggregate(quant ~ tclass + stream, data = benthos, FUN = sum) Then just use benthos2 as the data argument to barchart(). Peter, Thank you. I'll learn the aggregate function and do as you suggest. Regards, Rich __ 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] Recode function car package erases previous values
Hi, May be this helps: set.seed(1) dat1-data.frame(B20_C1=c(NA,sample(0:1,4,replace=TRUE),NA),B20_C2=c(NA,sample(0:1,3,replace=TRUE),sample(0:1,2,replace=TRUE)),nrB20C=c(1,NA,NA,NA,NA,NA)) dat1 # B20_C1 B20_C2 nrB20C #1 NA NA 1 #2 0 0 NA #3 0 1 NA #4 0 0 NA #5 1 1 NA #6 NA 1 NA dat1$pharm-ifelse(apply(dat1,1,function(x) all(is.na(x[1:2]))),no response,ifelse(dat1[,1]==1,Yes,No)) dat2-within(dat1,{pharm-factor(pharm)}) levels(dat2$pharm) #[1] No no response Yes dat2 # B20_C1 B20_C2 nrB20C pharm #1 NA NA 1 no response #2 0 0 NA No #3 0 1 NA No #4 0 0 NA No #5 1 1 NA Yes #6 NA 1 NA NA table(dat2$pharm) # No no response Yes # 3 1 1 A.K. - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: r-help@r-project.org r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 5:17 AM Subject: [R] Recode function car package erases previous values Hi all, I am attempting to create a new variable based on values of other variables. The variable is called pharm. It basically takes the numeric code of 1 as yes and 0 to be No from the variable B20_C1 (a question on a survey). However, I would also like to have a level for non-respondents and these are captured in the variable nr.B20C, which is a 1 when there is a non-response on the whole group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will have three levels, Yes No and no resp. See below what happens pharm-as.factor(recode(B20_C1,1='Yes';0='No')) table(pharm) pharm No Yes 716 7 levels(pharm)-c('No','Yes','no resp') table(pharm) pharm No Yes no resp 716 7 0 pharm-as.factor(recode(nr.B20C,1='no resp')) table(pharm) pharm 0 no resp 723 6 The recode variable just cannot seem to 'remember' I had just recoded 7 values to 'Yes' and 716 to be 'No' and instead it assigns the level '0' which comes from nr.B20C (it has values 0 or 1). This inconvenient as I would like to have ultimately the following table pharm No Yes no resp 716 7 6 (FROM nr.B20C where row has value 1). Background. The variable pharm assess where you used the pharmacy to get your contraception. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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] Results not dispalying in R console
I **think** he is saying that he is not getting anything at all back on the console. If so, he needs to *follow the posting guide* and tell us what OS and setup he is using and **exactly** what is meant by the R console (GUI, command line, ...?) . Your last suggestion to post elsewhere may also be apropos. -- Bert On Wed, Oct 24, 2012 at 12:40 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: wow. That sounds like a problem. For a more constructive response, read the posting guide and post specific examples and explain how the output you get is not what you expect. Also, the output of sessionInfo() is likely to be helpful, and if you use a Mac, or Debian/other Linux, one of the platform-specific email lists might be a more appropriate forum. --- 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. arunkumar akpbond...@gmail.com wrote: Hi I'm not getting any results in R console when i run commands. I reinstalled R but the results are same - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/Results-not-dispalying-in-R-console-tp4647271.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. -- 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 __ 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] Recode function car package erases previous values
-Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Wednesday, October 24, 2012 3:31 PM To: Pancho Mulongeni Cc: R help Subject: Re: [R] Recode function car package erases previous values Hi, May be this helps: set.seed(1) dat1-data.frame(B20_C1=c(NA,sample(0:1,4,replace=TRUE),NA),B20_C2=c(NA,sample(0:1,3,replace=TRUE),sample(0:1,2,replace=TRUE)),nrB20C=c(1,NA,NA,NA,NA,NA)) dat1 # B20_C1 B20_C2 nrB20C #1 NA NA 1 #2 0 0 NA #3 0 1 NA #4 0 0 NA #5 1 1 NA #6 NA 1 NA dat1$pharm-ifelse(apply(dat1,1,function(x) all(is.na(x[1:2]))),no response,ifelse(dat1[,1]==1,Yes,No)) dat2-within(dat1,{pharm-factor(pharm)}) levels(dat2$pharm) #[1] No no response Yes dat2 # B20_C1 B20_C2 nrB20C pharm #1 NA NA 1 no response #2 0 0 NA No #3 0 1 NA No #4 0 0 NA No #5 1 1 NA Yes #6 NA 1 NA NA table(dat2$pharm) # No no response Yes # 3 1 1 A.K. Thank you, once I understand what you did I will use it, for now, I use a workaround 1. First I use the recode function pharm-as.factor(recode(B20_C1,1='Yes';0='No')) 2. Now I just subset pharm[nr.B20C==1]-'no resp' and this gives me the desired output No Yes no resp 716 7 6 - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: r-help@r-project.org r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 5:17 AM Subject: [R] Recode function car package erases previous values Hi all, I am attempting to create a new variable based on values of other variables. The variable is called pharm. It basically takes the numeric code of 1 as yes and 0 to be No from the variable B20_C1 (a question on a survey). However, I would also like to have a level for non-respondents and these are captured in the variable nr.B20C, which is a 1 when there is a non-response on the whole group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will have three levels, Yes No and no resp. See below what happens pharm-as.factor(recode(B20_C1,1='Yes';0='No')) table(pharm) pharm No Yes 716 7 levels(pharm)-c('No','Yes','no resp') table(pharm) pharm No Yes no resp 716 7 0 pharm-as.factor(recode(nr.B20C,1='no resp')) table(pharm) pharm 0 no resp 723 6 The recode variable just cannot seem to 'remember' I had just recoded 7 values to 'Yes' and 716 to be 'No' and instead it assigns the level '0' which comes from nr.B20C (it has values 0 or 1). This inconvenient as I would like to have ultimately the following table pharm No Yes no resp 716 7 6 (FROM nr.B20C where row has value 1). Background. The variable pharm assess where you used the pharmacy to get your contraception. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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] for ( i in 23:0 ) { V - vector [ 1 : i ] }
I'm used to run that on Matlab for indice=1:23, V=vector(1:indice) end that give me 23 vectors as output. Why the same command on R for ( i in 23:0 ) { V - vector [ 1 : i ] } returns one only vector? How can I obtain the 23 vectors that I need ? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/for-i-in-23-0-V-vector-1-i-tp4647306.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] bugs and misfeatures in polr(MASS).... fixed!
Great! You can skip my question about s0 though, I found where it is being used, but I still struggle with the code and convergence problem. I also found something here http://biostat.mc.vanderbilt.edu/wiki/pub/Main/CharlesDupontStuff/newPolr.R that seems like someone tried to fix it, but with this code I get mu starting values out of range, nor do I get it right when I try to force starting values. If you got your code to work fine, you might have the answer to my problem. If you want, maybe you could post your whole *fixed-polr.R*? :-) I also can't see where the new object s0 is used in the old code? -- View this message in context: http://r.789695.n4.nabble.com/bugs-and-misfeatures-in-polr-MASS-fixed-tp3024677p4647311.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] Interper output from cajorls and VECM
Hello Rmillan, I was looking for the same issue and I found that the variables ECT1, ECT2... are the loading matrix, as you can check in the example of the paper found at http://cran.r-project.org/web/packages/vars/vignettes/vars.pdf http://cran.r-project.org/web/packages/vars/vignettes/vars.pdf The example is on pages 24-25 Best, Laura -- View this message in context: http://r.789695.n4.nabble.com/Interper-output-from-cajorls-and-VECM-tp4639963p4647314.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] multi-panel figure: overall title for each row
A perhaps more elegant way to do it would be to use the ?layout function rather than the ancient mfrow() to create space for both titles and graphs. You could then e.g. draw your titles in the space you created for titles. -- Bert On Wed, Oct 24, 2012 at 5:33 AM, Jean V Adams jvad...@usgs.gov wrote: Hannes, A bit inelegant, but it works. Try this: mtext(Overall Title Row 2, outer=TRUE, line=-17) mtext(Overall Title Row 3, outer=TRUE, line=-34) Jean capy_bara hettl...@few.vu.nl wrote on 10/23/2012 09:08:39 AM: Dear all, I have a 3x2 plot and in addition to the title of the individual plots I would like to have an overall title for each row. I managed to get an overall title for the whole plot matrix with mtext: par(mfrow=(c(3,2)), mar=c(6.4,4.5,4.2, 1.8), oma=c(0,0,3,0)) for (i in 1:6) barplot(sample(1:10,5), main=paste(Plot #,i)) mtext(Overall Title Row 1, outer=TRUE) but I cannot put an overall title in the middle above the titles of the plots in the second or third row. If I use mtext within the loop, I can only add another title above an individual plot. I hope someone can help me, many thanks in advance Hannes [[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. -- 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 __ 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] for ( i in 23:0 ) { V - vector [ 1 : i ] }
Quoting Rolf Turner: (1) Learn something about R; don't just hammer and hope. Read the introductory manuals and scan the FAQ. -- Bert On Wed, Oct 24, 2012 at 5:25 AM, colaiutachambers gabriele.carrar...@gmail.com wrote: I'm used to run that on Matlab for indice=1:23, V=vector(1:indice) end that give me 23 vectors as output. Why the same command on R for ( i in 23:0 ) { V - vector [ 1 : i ] } returns one only vector? How can I obtain the 23 vectors that I need ? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/for-i-in-23-0-V-vector-1-i-tp4647306.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. -- 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 __ 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] List of multidimensional arrays
I am looking at your pdf file. it doesn't match your description. There are no missing values in the vectors x, y, t. Each vector has length 55 which is not a multiple of 4, so we don't know where the 2x2 matrices come from. The code doesn't run. There are are too many }. PDF files are formatted and are not ascii. Please send your code in ascii text in the body of the email. Please pick it up from your email and paste it into a fresh R session to be sure that it works. Perhaps consrtruct manually an example of what you want the answer to look like. Rich On Wed, Oct 24, 2012 at 3:51 AM, Loukia Spineli spinelilouki...@gmail.comwrote: Dear all, I am trying to create a list, where each list element is a vector of different length arrays that contain 2by2 matrices. To be more specific there are 11 treatments that are compared with placebo (we have 11 comparisons) and each comparison is studied by a different number of trials and each trial has a different number of missing participants in both arms. The length of the list is equal to the number of comparisons. In each comparison the number of arrays is equal to the number of trials that study this comparison. For instance 4 trials compare PAR with placebo. So, for this comparison we have 4 arrays and each array has a length equal to the producy of the number of participants in each arm. These arrays contain 2x2 matrices. I have attached a document with the data and the code. I cannot create the list results the way I have described above. It creates only the matrices for the first array (that has length equal to 135) of the first comparison leaving the rest 10 comparisons NULL. Any suggestion would be really helpful Thank you in advance, Loukia __ 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] Recode function car package erases previous values
Hi Pancho, I tried ur method: pharm-as.factor(recode(dat1$B20_C1,1='Yes';0='No')) pharm #[1] NA No No Yes Yes NA #Levels: No Yes pharm[dat1$nrB20C==1]-'no resp' #Warning message: #In `[-.factor`(`*tmp*`, dat1$nr.B20C == 1, value = no resp) : # invalid factor level, NAs generated pharm #[1] NA No No Yes Yes NA #Levels: No Yes Not sure how you got the result. A.K. - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Wednesday, October 24, 2012 9:51 AM Subject: RE: [R] Recode function car package erases previous values -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Wednesday, October 24, 2012 3:31 PM To: Pancho Mulongeni Cc: R help Subject: Re: [R] Recode function car package erases previous values Hi, May be this helps: set.seed(1) dat1-data.frame(B20_C1=c(NA,sample(0:1,4,replace=TRUE),NA),B20_C2=c(NA,sample(0:1,3,replace=TRUE),sample(0:1,2,replace=TRUE)),nrB20C=c(1,NA,NA,NA,NA,NA)) dat1 # B20_C1 B20_C2 nrB20C #1 NA NA 1 #2 0 0 NA #3 0 1 NA #4 0 0 NA #5 1 1 NA #6 NA 1 NA dat1$pharm-ifelse(apply(dat1,1,function(x) all(is.na(x[1:2]))),no response,ifelse(dat1[,1]==1,Yes,No)) dat2-within(dat1,{pharm-factor(pharm)}) levels(dat2$pharm) #[1] No no response Yes dat2 # B20_C1 B20_C2 nrB20C pharm #1 NA NA 1 no response #2 0 0 NA No #3 0 1 NA No #4 0 0 NA No #5 1 1 NA Yes #6 NA 1 NA NA table(dat2$pharm) # No no response Yes # 3 1 1 A.K. Thank you, once I understand what you did I will use it, for now, I use a workaround 1. First I use the recode function pharm-as.factor(recode(B20_C1,1='Yes';0='No')) 2. Now I just subset pharm[nr.B20C==1]-'no resp' and this gives me the desired output No Yes no resp 716 7 6 - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: r-help@r-project.org r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 5:17 AM Subject: [R] Recode function car package erases previous values Hi all, I am attempting to create a new variable based on values of other variables. The variable is called pharm. It basically takes the numeric code of 1 as yes and 0 to be No from the variable B20_C1 (a question on a survey). However, I would also like to have a level for non-respondents and these are captured in the variable nr.B20C, which is a 1 when there is a non-response on the whole group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will have three levels, Yes No and no resp. See below what happens pharm-as.factor(recode(B20_C1,1='Yes';0='No')) table(pharm) pharm No Yes 716 7 levels(pharm)-c('No','Yes','no resp') table(pharm) pharm No Yes no resp 716 7 0 pharm-as.factor(recode(nr.B20C,1='no resp')) table(pharm) pharm 0 no resp 723 6 The recode variable just cannot seem to 'remember' I had just recoded 7 values to 'Yes' and 716 to be 'No' and instead it assigns the level '0' which comes from nr.B20C (it has values 0 or 1). This inconvenient as I would like to have ultimately the following table pharm No Yes no resp 716 7 6 (FROM nr.B20C where row has value 1). Background. The variable pharm assess where you used the pharmacy to get your contraception. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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] find similarity between two spectral profile
If you provide some data we can work with (a reproducible example), then we can help you. Now we can only guess? -- View this message in context: http://r.789695.n4.nabble.com/find-similarity-between-two-spectral-profile-tp4647157p4647319.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] Recode function car package erases previous values
Hi Arun, I also used to get that error, but what class is your nr.B20C, mine is not a factor, it is numeric and perhaps that's why it works -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Wednesday, October 24, 2012 4:35 PM To: Pancho Mulongeni Cc: R help Subject: Re: [R] Recode function car package erases previous values Hi Pancho, I tried ur method: pharm-as.factor(recode(dat1$B20_C1,1='Yes';0='No')) pharm #[1] NA No No Yes Yes NA #Levels: No Yes pharm[dat1$nrB20C==1]-'no resp' #Warning message: #In `[-.factor`(`*tmp*`, dat1$nr.B20C == 1, value = no resp) : # invalid factor level, NAs generated pharm #[1] NA No No Yes Yes NA #Levels: No Yes Not sure how you got the result. A.K. - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Wednesday, October 24, 2012 9:51 AM Subject: RE: [R] Recode function car package erases previous values -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Wednesday, October 24, 2012 3:31 PM To: Pancho Mulongeni Cc: R help Subject: Re: [R] Recode function car package erases previous values Hi, May be this helps: set.seed(1) dat1-data.frame(B20_C1=c(NA,sample(0:1,4,replace=TRUE),NA),B20_C2=c(NA,sample(0:1,3,replace=TRUE),sample(0:1,2,replace=TRUE)),nrB20C=c(1,NA,NA,NA,NA,NA)) dat1 # B20_C1 B20_C2 nrB20C #1 NA NA 1 #2 0 0 NA #3 0 1 NA #4 0 0 NA #5 1 1 NA #6 NA 1 NA dat1$pharm-ifelse(apply(dat1,1,function(x) all(is.na(x[1:2]))),no response,ifelse(dat1[,1]==1,Yes,No)) dat2-within(dat1,{pharm-factor(pharm)}) levels(dat2$pharm) #[1] No no response Yes dat2 # B20_C1 B20_C2 nrB20C pharm #1 NA NA 1 no response #2 0 0 NA No #3 0 1 NA No #4 0 0 NA No #5 1 1 NA Yes #6 NA 1 NA NA table(dat2$pharm) # No no response Yes # 3 1 1 A.K. Thank you, once I understand what you did I will use it, for now, I use a workaround 1. First I use the recode function pharm-as.factor(recode(B20_C1,1='Yes';0='No')) 2. Now I just subset pharm[nr.B20C==1]-'no resp' and this gives me the desired output No Yes no resp 716 7 6 - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: r-help@r-project.org r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 5:17 AM Subject: [R] Recode function car package erases previous values Hi all, I am attempting to create a new variable based on values of other variables. The variable is called pharm. It basically takes the numeric code of 1 as yes and 0 to be No from the variable B20_C1 (a question on a survey). However, I would also like to have a level for non-respondents and these are captured in the variable nr.B20C, which is a 1 when there is a non-response on the whole group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will have three levels, Yes No and no resp. See below what happens pharm-as.factor(recode(B20_C1,1='Yes';0='No')) table(pharm) pharm No Yes 716 7 levels(pharm)-c('No','Yes','no resp') table(pharm) pharm No Yes no resp 716 7 0 pharm-as.factor(recode(nr.B20C,1='no resp')) table(pharm) pharm 0 no resp 723 6 The recode variable just cannot seem to 'remember' I had just recoded 7 values to 'Yes' and 716 to be 'No' and instead it assigns the level '0' which comes from nr.B20C (it has values 0 or 1). This inconvenient as I would like to have ultimately the following table pharm No Yes no resp 716 7 6 (FROM nr.B20C where row has value 1). Background. The variable pharm assess where you used the pharmacy to get your contraception. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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] R5: Lock a class field from within a method?
On Oct 24, 2012, at 2:14 AM, Johannes Graumann wrote: Hello, testclass - setRefClass( testclass, fields = list(testfield = logical), methods = list(validate=function(){testfield-TRUE})) test - testclass$new() test$testfield logical(0) test$validate() test$testfield [1] TRUE Works just fine for me. I would love to be able to do something like testclass - setRefClass( testclass, fields = list(testfield = logical), methods = list(validate=function(){ testfield-TRUE .self$lock(testfield) })) but am unabel to achieve that. Can anyone point out how to go about rendering a field immutable after execution of a specific method? The fact that you used only lock in your code and I am unable to find such a function makes me wonder whether that was an implicit psuedo-code effort and that you do not know about: ?lockBinding -- David Winsemius, MD Alameda, CA, USA __ 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] After sorting a dataframe by date
On Oct 24, 2012, at 2:27 AM, martiny wrote: Ai...I see, i didn't know I can sort rowname. more study to do :) You deleted the context of this thread, but while you are looking at the rownames documentation you might also keep your eyes open for the zoo and xts packages which could convert to a matrix with the dates or date-times as rownames. And you should learn to post in context. Nabble is NOT the way most people correspond on Rhelp. You will find that if you continue to flout local convention that people will begin to ignore your postings. View this message in context: http://r.789695.n4.nabble.com/After-sorting-a-dataframe-by-date-tp4647173p4647291.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. David Winsemius, MD Alameda, CA, USA __ 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] plotting multiple variables in 1 bar graph
I'd greatly appreciate your help in making a bar graph with multiple variables plotted on it. All the help sites I've seen so far only plot 1 variable on the y-axis ... I've spent several hours looking for code to do this but didn't find anything. I'd use the Excel graph except that it doesn't have the sd or se bars. Perhaps something like lattice or ggplot would serve better? Here's something using ggplot (which has prettier colours than lattice) #Something like your data - with considerable licence on unreadable names! abst -structure(list(Count = c(17.03, 22.94, 28.38, 29.72, 28.37, 14.45, 1.51, 0.54, 0.62, 1.52, 62.3, 70.6, 68.82, 64.75, 63.77, 3.17, 2.78, 2.22, 2.03, 1.94, 0.61, 0.33, 0.74, 0.74, 0.58, 0.44, 0.12, 0.37, 0.08, 0.41, 0.04, 0, 0.08, 0, 0.08, 1.96, 1.68, 2.84, 2.06, 3.32, 0, 0, 0, 0, 0), Benthic = structure(c(2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 9L, 9L, 9L, 9L, 9L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 8L, 8L, 8L, 8L, 8L, 7L, 7L, 7L, 7L, 7L), .Label = c(Algae, Coral, Deadcoral, Ind, other, softcoral, something, sponges, xBiotic), class = factor), Time = structure(c(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, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c(T 1, T 2, T 3, T 4, T 5), class = factor)), .Names = c(Count, Benthic, Time), row.names = c(NA, -45L), class = data.frame) head(abst) #Add an arbitrary 'std error' abst$stderr - 0.05*abst$Count library(ggplot2) b - ggplot(subset(abst, Benthic!=something), aes(x = Time, y = Count, fill=Time)) bptot-b + geom_bar(stat = identity, position = dodge) bptot + facet_grid(. ~ Benthic , scales=free_y, margins=T) #or, for unequal scale heights - much easier to see individual trends bwrap - bptot + facet_wrap( ~ Benthic , scales=free, nrow=2) bwrap #Now add error bars bwrap+geom_errorbar(aes(ymin=Count-stderr, ymax=Count+stderr), width=.3) __ 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. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] rJava install - %1 is not a valid Win32 application.
Hello all. Steven's approach didn't work for me. I'm running 64 bit R R.Version() $platform [1] x86_64-pc-mingw32 $arch [1] x86_64 $os [1] mingw32 $system [1] x86_64, mingw32 and downloaded and installed the 64 bit version of Java directly from Oracle. I then tried to load the rJava library and got Error : .onLoad failed in loadNamespace() for 'rJava', details: call: inDL(x, as.logical(local), as.logical(now), ...) error: unable to load shared object 'D:/Users/David Stevens/Documents/R/win-library/2.15/rJava/libs/x64/rJava.dll': LoadLibrary failure: %1 is not a valid Win32 application. Error: package/namespace load failed for 'rJava' I searched my computer for rJava.dll and found several ( 10) copies scattered around. d:\Oneida\CalWaiparadir /s \rjava.dll ... Directory of d:\Program Files\R\R-2.13.1\library\rJava\libs\i386 06/24/2011 10:38 AM80,384 rJava.dll 1 File(s) 80,384 bytes Directory of d:\Program Files\R\R-2.13.1\library\rJava\libs\x64 06/24/2011 10:39 AM55,296 rJava.dll 1 File(s) 55,296 bytes Directory of d:\Program Files\R\R-2.14.1\library\rJava\libs\i386 12/29/2011 11:40 PM81,408 rJava.dll 1 File(s) 81,408 bytes Directory of d:\Program Files\R\R-2.14.1\library\rJava\libs\x64 12/29/2011 11:40 PM55,296 rJava.dll 1 File(s) 55,296 bytes Directory of d:\Program Files\R\R-2.15.0\library\rJava\libs\i386 12/29/2011 11:40 PM81,408 rJava.dll 1 File(s) 81,408 bytes Directory of d:\Program Files\R\R-2.15.0\library\rJava\libs\x64 12/29/2011 11:40 PM55,296 rJava.dll 1 File(s) 55,296 bytes Directory of d:\Program Files\R\R-2.15.1\library\rJava\libs\i386 08/29/2012 01:12 PM57,856 rJava.dll 1 File(s) 57,856 bytes Directory of d:\Program Files\R\R-2.15.1\library\rJava\libs\x64 08/29/2012 01:12 PM58,368 rJava.dll 1 File(s) 58,368 bytes Directory of d:\Users\David Stevens\Documents\R\win-library\2.13\rJava\libs\i386 07/06/2011 10:06 AM80,384 rJava.dll 1 File(s) 80,384 bytes Directory of d:\Users\David Stevens\Documents\R\win-library\2.13\rJava\libs\x64 07/06/2011 10:06 AM55,296 rJava.dll 1 File(s) 55,296 bytes Directory of d:\Users\David Stevens\Documents\R\win-library\2.15\rJava\libs\i386 10/23/2012 12:30 PM57,856 rJava.dll 1 File(s) 57,856 bytes Directory of d:\Users\David Stevens\Documents\R\win-library\2.15\rJava\libs\x64 10/23/2012 12:30 PM58,368 rJava.dll Is there something else I can try? Short of erasing and reinstalling everything? Regards David Stevens On 10/16/2012 9:19 AM, Steven Ranney wrote: Thanks for the information, Simon. I had both the 64-bit version of R and the 64-bit Windows 7, but not the 64-bit version of Java. Now that I've downloaded the proper version of Java, the problem has been solved. Thanks - SR Steven H. Ranney On Mon, Oct 15, 2012 at 5:12 PM, Simon Knapp sleepingw...@gmail.com wrote: My guess would be that your running the 32 bit version of R - and rJava is looking for the 64 bit dll. I'd suggest starting the 64 bit version of R explicitly (e.g. the 64 bit version of Rgui lives at R_HOME/bin/x64/Rgui.exe, whereas the 32 bit version lives at R_HOME/bin/i386/Rgui.exe). On Tue, Oct 16, 2012 at 2:37 AM, Steven Ranney steven.ran...@gmail.com wrote: All -- I'm having a problem with the rJava package. I can download it to my machine (Win 7 64-bit) but when I try to load the package into R (2.15.1, 64-bit version), I get the following error: require(rJava) Loading required package: rJava Error : .onLoad failed in loadNamespace() for 'rJava', details: call: inDL(x, as.logical(local), as.logical(now), ...) error: unable to load shared object 'C:/Users/sranney/Documents/R/win-library/2.15/rJava/libs/x64/rJava.dll': LoadLibrary failure: %1 is not a valid Win32 application. I have verified that the file R is looking for is in the appropriate place, but I continue to get the error. I have tried to download rJava from another source, but still get the error. I have not been able to find another user with this same issue. Thanks for your help -- Steven Ranney [[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
Re: [R] Summary of variables with NA, empty
The examples I gave--Null, Empty string, white space, etc where just examples based on SPSS Modeler's Data Audit node. I just want something that both identifies the columns having missing values-- regardless of what they technically are stored as(NA or a field with space bar hit a couple of times,etc) -- and tabulates based on what type of missing value. This is a basic data exploration step that I thought just maybe comes standard in R and that I just don't know of yet. Hmisc::describe is good and may have to suffice. Missing for the example below using Hmisc::describe was 0 although there was a . And I know that's because of the technical difference. #EXAMPLE data - just one column in this case dput(sample(mydata$COMMUTE_BIN,100)) structure(c(2L, 5L, 3L, 2L, 6L, 3L, 2L, 3L, 4L, 2L, 2L, 4L, 3L, 4L, 3L, 3L, 3L, 6L, 2L, 2L, 2L, 4L, 6L, 4L, 2L, 3L, 2L, 2L, 6L, 3L, 2L, 6L, 3L, 2L, 3L, 4L, 4L, 4L, 5L, 7L, 3L, 5L, 2L, 3L, 2L, 2L, 6L, 7L, 7L, 4L, 3L, 3L, 2L, 2L, 2L, 5L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 2L, 3L, 3L, 6L, 4L, 6L, 2L, 7L, 4L, 6L, 2L, 3L, 2L, 2L, 2L, 3L, 2L, 3L, 4L, 3L, 5L, 3L, 4L, 2L, 3L, 3L, 3L, 3L, 3L, 2L, 4L, 5L, 3L, 2L, 2L, 3L, 1L), .Label = c(, 15, 15 - 24, 25 - 34, 35 - 44, 45 - 54, 55+), class = factor) As David mentioned maybe I will have to create my own function. Maybe something similar to what I got here for identifying a factor columns, column labels and number of levels. #EXAMPLE of formula I will probably need to create for identifying and listing column names and counts of NA and and other missing in a dataframe or table. In this case however I am listing factor columns and excluding columns w/ 32 levels set.seed(1) dat1- data.frame(col1=factor(sample(1:25,10,replace=TRUE)),col2=sample(letters[1:10],10,replace=TRUE),col3=factor(rep(1:5,each=2))) PrintLvls2 - function(x) {print(data.frame(Lvls=sapply(x[sapply(x,function(x) is.factor(x)length(levels(x))=32)],nlevels), Names=sapply(x[sapply(x, function(x) is.factor(x)length(levels(x))=32)], function(y) paste0(levels(y), collapse=, ))), right=FALSE)} PrintLvls2(dat1) Lvls Names col1 92, 6, 7, 10, 15, 16, 17, 23, 24 col2 7b, c, d, e, g, h, j col3 51, 2, 3, 4, 5 Thanks. Dan -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Tuesday, October 23, 2012 3:15 PM To: David Winsemius Cc: Lopez, Dan; R help (r-help@r-project.org) Subject: Re: [R] Summary of variables with NA, empty To highlight: Basically all Null values is a meaningless phrase in R. ?Null ?NA ?NaN have **very specific meanings** in R and have nothing to do with the various sorts of whitespace characters that David mentions (spaces, tabs...). If you wish to use R, you **must** understand the distinctions (the Intro to R tutorial discusses some of this -- have you read it?). There is functionality to test for these sorts of things (is.na, is.null, etc). You need to put in the effort to learn about this if you mean to use R in any serious way, as these will occur in either data I/O (NA's) or data manipulation (e.g. 0/0) -- Bert On Tue, Oct 23, 2012 at 2:44 PM, David Winsemius dwinsem...@comcast.net wrote: On Oct 23, 2012, at 11:17 AM, Lopez, Dan wrote: Hi, Is there a function I can use on my dataframe to give me a concise summary of variables that are NA,blank,etc? Basically all Null values, Empty strings, white space, blank values. Ideally it would look something like the below: # it should only includes the fields with NAs, blanks, etc. Added bonus would be to include column Index. #Valid Records = records that are not NA, blank,etc #ColIndex - what place is column in the original dataframe...1,2,3, ...xth Valid Records Null (NA?)Empty String White Space Blank ValueColIndex Would a Valid Record be defined by grep([^ ], column)? ... i.e. has a non-space character in it What is a ColIndex? How is an Empty String different than White Space or a Blank Value Var1 528 2 Var2 40 20 10 10 3 Var3 58 2 20 .. I generally use describe from package:Hmisc. There are other versions of describe in other packages. It's not going to classify items composed entirely of a varying number of spaces and other non-character items like tabs as a single group. And it's unclear what you will use as an operational definition to separate blanks and
Re: [R] Recode function car package erases previous values
Dear Pancho, I'm not going to respond to the subsequent messages in this thread, since you appear to have solved your problem, just explain that what you did originally was to recode the variable B20_C1, creating the new variable pharm. Then you recoded another variable, nr.B20C, replacing the original version of pharm. I'm not sure why you expected this to give you what you want -- it really doesn't make sense. Best, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Wed, 24 Oct 2012 09:17:25 + Pancho Mulongeni p.mulong...@namibia.pharmaccess.org wrote: Hi all, I am attempting to create a new variable based on values of other variables. The variable is called pharm. It basically takes the numeric code of 1 as yes and 0 to be No from the variable B20_C1 (a question on a survey). However, I would also like to have a level for non-respondents and these are captured in the variable nr.B20C, which is a 1 when there is a non-response on the whole group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will have three levels, Yes No and no resp. See below what happens pharm-as.factor(recode(B20_C1,1='Yes';0='No')) table(pharm) pharm No Yes 716 7 levels(pharm)-c('No','Yes','no resp') table(pharm) pharm No Yes no resp 716 7 0 pharm-as.factor(recode(nr.B20C,1='no resp')) table(pharm) pharm 0 no resp 723 6 The recode variable just cannot seem to 'remember' I had just recoded 7 values to 'Yes' and 716 to be 'No' and instead it assigns the level '0' which comes from nr.B20C (it has values 0 or 1). This inconvenient as I would like to have ultimately the following table pharm No Yes no resp 716 7 6 (FROM nr.B20C where row has value 1). Background. The variable pharm assess where you used the pharmacy to get your contraception. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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] How to pick colums from a ragged array?
HI Stuart, Just a doubt: When I run Rui's function: I got results as: g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),] # ID DATE DG #22 841 20050421 1 #23 841 20050421 2 #38 1019 19870508 2 #39 1019 19870508 1 But, when I look at the id.d 16 814 20020814 2 17 814 20021125 2 18 814 20040429 2 19 814 20040429 2 20 814 20071205 2 21 814 20071205 2 - 323 2005 3 8 323 20060111 2 9 323 20071119 3 10 323 20080107 2 11 323 20080407 1 12 323 20080521 2 13 323 20080521 3 According to the function I wrote earlier, I get res1 flag 58 FALSE 167 TRUE 323 TRUE 547 FALSE 794 FALSE 814 TRUE 841 TRUE 910 FALSE 999 FALSE 1019 TRUE If I understand correctly, you wanted to eliminate 814 and 167 because the DGs are the same. That can be done. I also want to make it clear that why 323 is not included. It is duplicated in the last visit. Now, to eliminate the ones with duplicate DGs: res1- data.frame(flag=tapply(id.d[,2],id.d[,1],FUN=function(x) head(duplicated(x)|duplicated(x,fromLast=TRUE),1)|tail(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res2-id.d[id.d[,1]%in%names(res1[res1$flag==TRUE,])(duplicated(id.d[,1:2])|duplicated(id.d[,1:2],fromLast=TRUE)),] res2[!res2$ID%in% res2[duplicated(res2)|duplicated(res2,fromLast=TRUE),]$ID,] # ID DATE DG #12 323 20080521 2 #13 323 20080521 3 #22 841 20050421 1 #23 841 20050421 2 #38 1019 19870508 2 #39 1019 19870508 1 A.K. - Original Message - From: Stuart Leask stuart.le...@nottingham.ac.uk To: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; Rui Barradas (ruipbarra...@sapo.pt) ruipbarra...@sapo.pt Cc: Sent: Wednesday, October 24, 2012 11:41 AM Subject: RE: [r] How to pick colums from a ragged array? (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and FALSE for whether or not that row should be included...) -Original Message- From: Leask Stuart Sent: 24 October 2012 16:25 To: arun (smartpink...@yahoo.com); 'PIKAL Petr'; Rui Barradas (ruipbarra...@sapo.pt) Subject: RE: [r] How to pick colums from a ragged array? Arun, Petr, Rui, many thanks for your help, and the functions you have written. You'll recall I wanted to remove these first (or last) duplicates, because they represented instances where two different diagnoses (in this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on the same day - so I can't say which was 'first' (or 'last'). Your functions have revealed something I wasn't expecting: In some cases, the diagnoses recorded on the duplicated DATEs are the same! This is a surprise to me, but probably reflects someone going to two different departments in a clinic, and both departments submit data. I have to say that crazy things like this are often a feature of real data, which I'm sure you've come across yourselves. Of course, I don't want to remove records in which I can determine an unambiguous 'first diagnosis'. You have all put in so much effort on my behalf, I'm ashamed to ask, but I wonder if any of the functions you've written could do this with a little more Indexing and the 'duplicate' function So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Test dataset: ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 ,547,794,814,814,814,814,814,814,841,841,841,841,841 ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 ,1019) DATE - c(20060821,20061207,20080102,20090904,20040205,20040205,2005 ,20060111,20071119,20080107,20080407,20080521,20080521,20041005 ,20070905,20020814,20021125,20040429,20040429,20071205,20071205 ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521 ,20091224,20050503,19870508,19870508,19880330) DG- c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,3,2,2,2,1,1) id.d-data.frame(ID,DATE,DG) id.d # Considering Ruis getRepeat function: g.r-getRepeat(id.d) # defaults to first = TRUE getRepeat(id.d, first = FALSE) to get the last ones g.rr-do.call(rbind, g.r) # put the data into a matrix # I can remove the date duplicates with: g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),] I'm not sure how to add this to your suggestions, Arun Petr... Stuart -Original Message- From: PIKAL Petr [mailto:petr.pi...@precheza.cz] Sent: 23 October 2012 15:24 To: Stuart Leask Subject: RE: [r] How to pick colums from a ragged array? Hi I assumed that id.d is data frame id.d - data.frame (ID,DATE ) and fff(id.d) works for me Petr -Original Message- From: Stuart Leask [mailto:stuart.le...@nottingham.ac.uk] Sent: Tuesday, October 23, 2012 3:13 PM To: PIKAL Petr Subject: RE: [r] How to pick
Re: [R] help using optim function
tmuman mumantariq at gmail.com writes: Hi, am very new to R and I've written an optim function, but can't get it to work least.squares.fitter-function(start.params,gr, low.constraints,high.constraints,model.one.stepper,data,scale,ploton=F) { result-optim(par=start.params, method=c('Nelder-Mead'), fn=least.squares.fit, lower=low.constraints, upper=high.constraints,data=data,scale=scale,ploton=ploton) return(result) } least.squares.fitter(c(2,2),c(0,0),c(Inf,Inf),ricker.one.step,dat,'linear') where least.squares.fit is the function returning the difference between model data points and predicted points (residuals, residuals^2 and SSR), which i am trying to minimise and ricker.one.step is the function that generated the predictions I've been trying to figure out whats wrong for hours but can't. You haven't given us much to work with here -- have you read the posting guide (URL at the bottom of every message)? It's not reproducible ( http://tinyurl.com/reproducible-000 ), and you haven't told us what's going wrong. Are you getting error messages? What are they? Warnings? No errors but you have reason to believe the answer is wrong? A few comments: * 'scale' and 'ploton' are not arguments to optim(), so they'd better be accepted by your least.squares.fit() function * the Nelder-Mead algorithm doesn't accept constraints (lower/upper) (see the nloptr package for a Nelder-Mead implementation that does) * except for the constraints, you might be better off with ?nls if all you want to do is least-squares fitting; nlsLM in the minpack.lm package does least-squares fitting with constraints __ 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] for ( i in 23:0 ) { V - vector [ 1 : i ] }
Hello, Try the following. lapply(1:23, function(i) 1:i) As for why yuor code doesn't work, you're assigning 24 times a value to V, on loop exit only the last one is there. A correct way using loops would be V - list() for(i in 1:23) V[[i]] - 1:i Beware that the last vector goes from 1 _down_ to 0. And do read An Introduction to R, file R-intro.pdf in your R/doc directory. Hope this helps, Em 24-10-2012 13:25, colaiutachambers escreveu: I'm used to run that on Matlab for indice=1:23, V=vector(1:indice) end that give me 23 vectors as output. Why the same command on R for ( i in 23:0 ) { V - vector [ 1 : i ] } returns one only vector? How can I obtain the 23 vectors that I need ? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/for-i-in-23-0-V-vector-1-i-tp4647306.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] How to pick colums from a ragged array?
Hi, With the dataset that you provided, and considering that my solution works (ID 323 included), the below code outputs a variable INCLUDE. res1- data.frame(flag=tapply(id.d[,2],id.d[,1],FUN=function(x) head(duplicated(x)|duplicated(x,fromLast=TRUE),1)|tail(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res2-id.d[id.d[,1]%in%names(res1[res1$flag==TRUE,])(duplicated(id.d[,1:2])|duplicated(id.d[,1:2],fromLast=TRUE)),] res3-res2[!res2$ID%in% res2[duplicated(res2)|duplicated(res2,fromLast=TRUE),]$ID,] id.d1-id.d bad-id.d1[id.d1$ID%in%res3$ID,] id.d1$id.d_INCLUDE-TRUE bad$INCLUDE-FALSE res4-merge(id.d1,bad,all=TRUE) res4$INCLUDE[is.na(res4$INCLUDE)]-TRUE res5-res4[,-4] head(res5) # ID DATE DG INCLUDE #1 58 20060821 1 TRUE #2 58 20061207 2 TRUE #3 58 20080102 1 TRUE #4 58 20090904 1 TRUE #5 167 20040205 4 TRUE #6 167 20040205 4 TRUE tail(res5) # ID DATE DG INCLUDE #35 910 20080521 4 TRUE #36 910 20091224 2 TRUE #37 999 20050503 2 TRUE #38 1019 19870508 1 FALSE #39 1019 19870508 2 FALSE #40 1019 19880330 1 FALSE A.K. - Original Message - From: Stuart Leask stuart.le...@nottingham.ac.uk To: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; Rui Barradas (ruipbarra...@sapo.pt) ruipbarra...@sapo.pt Cc: Sent: Wednesday, October 24, 2012 11:41 AM Subject: RE: [r] How to pick colums from a ragged array? (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and FALSE for whether or not that row should be included...) -Original Message- From: Leask Stuart Sent: 24 October 2012 16:25 To: arun (smartpink...@yahoo.com); 'PIKAL Petr'; Rui Barradas (ruipbarra...@sapo.pt) Subject: RE: [r] How to pick colums from a ragged array? Arun, Petr, Rui, many thanks for your help, and the functions you have written. You'll recall I wanted to remove these first (or last) duplicates, because they represented instances where two different diagnoses (in this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on the same day - so I can't say which was 'first' (or 'last'). Your functions have revealed something I wasn't expecting: In some cases, the diagnoses recorded on the duplicated DATEs are the same! This is a surprise to me, but probably reflects someone going to two different departments in a clinic, and both departments submit data. I have to say that crazy things like this are often a feature of real data, which I'm sure you've come across yourselves. Of course, I don't want to remove records in which I can determine an unambiguous 'first diagnosis'. You have all put in so much effort on my behalf, I'm ashamed to ask, but I wonder if any of the functions you've written could do this with a little more Indexing and the 'duplicate' function So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Test dataset: ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 ,547,794,814,814,814,814,814,814,841,841,841,841,841 ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 ,1019) DATE - c(20060821,20061207,20080102,20090904,20040205,20040205,2005 ,20060111,20071119,20080107,20080407,20080521,20080521,20041005 ,20070905,20020814,20021125,20040429,20040429,20071205,20071205 ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521 ,20091224,20050503,19870508,19870508,19880330) DG- c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,3,2,2,2,1,1) id.d-data.frame(ID,DATE,DG) id.d # Considering Ruis getRepeat function: g.r-getRepeat(id.d) # defaults to first = TRUE getRepeat(id.d, first = FALSE) to get the last ones g.rr-do.call(rbind, g.r) # put the data into a matrix # I can remove the date duplicates with: g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),] I'm not sure how to add this to your suggestions, Arun Petr... Stuart -Original Message- From: PIKAL Petr [mailto:petr.pi...@precheza.cz] Sent: 23 October 2012 15:24 To: Stuart Leask Subject: RE: [r] How to pick colums from a ragged array? Hi I assumed that id.d is data frame id.d - data.frame (ID,DATE ) and fff(id.d) works for me Petr -Original Message- From: Stuart Leask [mailto:stuart.le...@nottingham.ac.uk] Sent: Tuesday, October 23, 2012 3:13 PM To: PIKAL Petr Subject: RE: [r] How to pick colums from a ragged array? Hi Petr. I see what you mean it should do, but when I run it I get an error (see below). Stuart ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 + ,547,794,814,814,814,814,814,814,841,841,841,841,841 + ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 + ,1019) DATE - + c(20060821,20061207,20080102,20090904,20040205,20040205,2005 +
Re: [R] parsing a structured object
That's simple and appears to work. Thanks for the prompt response. Ben -- View this message in context: http://r.789695.n4.nabble.com/parsing-a-structured-object-tp4647246p4647334.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] ifelse reformulation
Hi, Try this: test1-read.table(text= id x1 x2 x3 x4 x5 x6 x7 1 1 36 26 21 32 31 27 31 2 2 45 21 46 50 22 36 29 3 3 49 47 35 44 33 31 46 4 4 42 32 38 28 39 45 32 5 5 29 42 39 48 25 35 34 6 6 39 31 30 37 46 43 44 7 7 41 40 25 23 42 40 24 8 8 27 29 47 34 26 38 28 9 9 25 35 29 36 43 34 23 10 10 24 44 37 26 27 46 22 11 11 38 50 32 49 37 24 40 12 12 20 34 48 25 30 41 36 13 13 26 46 20 40 29 20 43 14 14 33 37 49 31 47 30 30 15 15 43 39 27 35 48 47 27 ,sep=,header=TRUE) group-c(40,50,60,70) as.vector(apply(test1,1,function(x) ifelse(any(x[4:6]%in%group),0,1))) # [1] 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 #Comparing the results individually ifelse(test1$x4==40|test1$x4==50|test1$x4==60|test1$x4==70|test1$x5==40|test1$x5==50|test1$x5==60|test1$x5==70|test1$x6==40|test1$x6==50|test1$x6==60|test1$x7==70,0,1) # [1] 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1 as.vector(apply(test1,1,function(x) ifelse(any(x[4:6]==40|x[4:6]==50|x[4:6]==60|x[4:6]==70),0,1))) #[1] 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 A.K. From: Bruno Marques brunos...@gmail.com To: arun smartpink...@yahoo.com Sent: Wednesday, October 24, 2012 12:47 PM Subject: Re: [R] ifelse reformulation Hi Arun, let me ask you just one more thing, please. If i want to compare, not one but a group of values, can i do this: group-c(40,50,60,70) as.vector(apply(test1,1,function(x) ifelse(any(x[4:6]==group),0,1))) What i want is: IF it finds any of the values in group, then 0. I mean, it has to work like a OR... but i think this code will work like an AND... am i wrong? Sorry for my bad english! Best regards, Bruno 2012/10/12 arun smartpink...@yahoo.com HI, Try this: count40- ifelse(test1$x3==40|test1$x4==40|test1$x5==40,0,1) count40 # [1] 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 as.vector(apply(test1,1,function(x) ifelse(any(x[4:6]==40),0,1))) # [1] 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 A.K. - Original Message - From: brunosm brunos...@gmail.com To: r-help@r-project.org Cc: Sent: Friday, October 12, 2012 10:18 AM Subject: Re: [R] ifelse reformulation That was exacly what i was looking for! Thanks a lot! Cheers! -- View this message in context: http://r.789695.n4.nabble.com/ifelse-reformulation-tp4645981p4645990.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.
[R] how to get underlying values being plotted in garchfit predict plot
Hello, I have a time series of 500 returns. I am fitting a garch(1,1) model to this series using fit - garchFit(~garch(1,2), data=y) Then I run: predict(fit,n.ahead=100,plot=TRUE) To get the plot. My question, how can I access the data that is being plotted with the black line. Basically I want the list of predictions for the next 100 times, the function returns the meanForecast(constant), meanError, standardDeviation, and lower and upper intervals based on mean +/- 1.96*MSE but not the values actually being plotted (for the first 100 times, beyond that it shows the mean and conf. interval). Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [r] How to pick colums from a ragged array?
Hello, Using one of Arun's ideas, some post ago, this new function returns a logical index into id.d of the rows that should be _removed_, hence rm1 and rm2. I think getRepLogical - function(x, first = TRUE){ fun - if(first) head else tail dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2))) len - tapply(x[,2], x[,1], FUN = length) lst - lapply(seq_along(dte), function(i) c(dte[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i1 - unlist(lst) dg - tapply(x[,3], x[,1], FUN = function(x) !duplicated(fun(x, 2))) lst - lapply(seq_along(dte), function(i) c(dg[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i2 - unlist(lst) i1 i2 } rm1 - getRepLogical(id.d) rm2 - getRepLogical(id.d, first = FALSE) id.d[rm1, ] id.d[rm2, ] id.d$INCLUDE - !(rm1 | rm2) Hope this helps, Rui Barradas Em 24-10-2012 16:41, Stuart Leask escreveu: (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and FALSE for whether or not that row should be included...) -Original Message- From: Leask Stuart Sent: 24 October 2012 16:25 To: arun (smartpink...@yahoo.com); 'PIKAL Petr'; Rui Barradas (ruipbarra...@sapo.pt) Subject: RE: [r] How to pick colums from a ragged array? Arun, Petr, Rui, many thanks for your help, and the functions you have written. You'll recall I wanted to remove these first (or last) duplicates, because they represented instances where two different diagnoses (in this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on the same day - so I can't say which was 'first' (or 'last'). Your functions have revealed something I wasn't expecting: In some cases, the diagnoses recorded on the duplicated DATEs are the same! This is a surprise to me, but probably reflects someone going to two different departments in a clinic, and both departments submit data. I have to say that crazy things like this are often a feature of real data, which I'm sure you've come across yourselves. Of course, I don't want to remove records in which I can determine an unambiguous 'first diagnosis'. You have all put in so much effort on my behalf, I'm ashamed to ask, but I wonder if any of the functions you've written could do this with a little more Indexing and the 'duplicate' function So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Test dataset: ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 ,547,794,814,814,814,814,814,814,841,841,841,841,841 ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 ,1019) DATE - c(20060821,20061207,20080102,20090904,20040205,20040205,2005 ,20060111,20071119,20080107,20080407,20080521,20080521,20041005 ,20070905,20020814,20021125,20040429,20040429,20071205,20071205 ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521 ,20091224,20050503,19870508,19870508,19880330) DG- c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,3,2,2,2,1,1) id.d-data.frame(ID,DATE,DG) id.d # Considering Ruis getRepeat function: g.r-getRepeat(id.d)# defaults to first = TRUE getRepeat(id.d, first = FALSE) to get the last ones g.rr-do.call(rbind, g.r) # put the data into a matrix # I can remove the date duplicates with: g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),] I'm not sure how to add this to your suggestions, Arun Petr... Stuart -Original Message- From: PIKAL Petr [mailto:petr.pi...@precheza.cz] Sent: 23 October 2012 15:24 To: Stuart Leask Subject: RE: [r] How to pick colums from a ragged array? Hi I assumed that id.d is data frame id.d - data.frame (ID,DATE ) and fff(id.d) works for me Petr -Original Message- From: Stuart Leask [mailto:stuart.le...@nottingham.ac.uk] Sent: Tuesday, October 23, 2012 3:13 PM To: PIKAL Petr Subject: RE: [r] How to pick colums from a ragged array? Hi Petr. I see what you mean it should do, but when I run it I get an error (see below). Stuart ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 + ,547,794,814,814,814,814,814,814,841,841,841,841,841 + ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 + ,1019) DATE - + c(20060821,20061207,20080102,20090904,20040205,20040205,2005 + ,20060111,20071119,20080107,20080407,20080521,20080711,20041005 + ,20070905,20020814,20021125,20040429,20040429,20071205,20080227 + ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 + ,20070112,20070514, 19870508,20040205,20040205, 20091120,20091210 + ,20091224,20050503,19870508,19870508,19880330) id.d - cbind (ID,DATE ) fff-function(data, first=TRUE, remove=FALSE) { + + testfirst - function(x) x[1,2]==x[2,2] testlast -
Re: [R] daylight
Do you care about local topography/terrain? I think most of the calculators/tables that are commonly used assume that you are at a fairly flat place on the earth's surface, but that is not always true. The area where my wife grew up had its longest day closer to the equinox than the summer solstice and if I wanted to calculate the number of hours that direct sunlight would hit solar panels (which I don't have yet) on my house or the solar oven (which I do have) in my back yard, then assuming sunset and sunrise occurred at 90 degrees from vertical would definitely overestimate the time. On Tue, Oct 23, 2012 at 1:45 PM, bambus sonja_...@hotmail.com wrote: hi there, does anyone know how to calculate the amount of daylight on every day of the year in R? I mean the time between sunrise and sunset. thanks -- View this message in context: http://r.789695.n4.nabble.com/daylight-tp4647213.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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] [r] How to pick colums from a ragged array?
Hi Rui, I think now our results are matching except in the INCLUDE column id.d[c(11:13,22:24,38:40),] # ID DATE DG INCLUDE #11 323 20080407 1 TRUE #12 323 20080521 2 FALSE #13 323 20080521 3 TRUE #22 841 20050421 1 TRUE #23 841 20050421 2 FALSE #24 841 20060428 1 TRUE #38 1019 19870508 2 TRUE #39 1019 19870508 1 FALSE #40 1019 19880330 1 TRUE I thought all the rows with the above IDS would be FALSE (from my solution): res4[c(11:13,22:24,38:40),] ID DATE DG INCLUDE #11 323 20080407 1 FALSE #12 323 20080521 2 FALSE #13 323 20080521 3 FALSE #22 841 20050421 1 FALSE #23 841 20050421 2 FALSE #24 841 20060428 1 FALSE #38 1019 19870508 1 FALSE #39 1019 19870508 2 FALSE #40 1019 19880330 1 FALSE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Stuart Leask stuart.le...@nottingham.ac.uk Cc: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; r-help r-help@r-project.org Sent: Wednesday, October 24, 2012 1:41 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Using one of Arun's ideas, some post ago, this new function returns a logical index into id.d of the rows that should be _removed_, hence rm1 and rm2. I think getRepLogical - function(x, first = TRUE){ fun - if(first) head else tail dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2))) len - tapply(x[,2], x[,1], FUN = length) lst - lapply(seq_along(dte), function(i) c(dte[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i1 - unlist(lst) dg - tapply(x[,3], x[,1], FUN = function(x) !duplicated(fun(x, 2))) lst - lapply(seq_along(dte), function(i) c(dg[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i2 - unlist(lst) i1 i2 } rm1 - getRepLogical(id.d) rm2 - getRepLogical(id.d, first = FALSE) id.d[rm1, ] id.d[rm2, ] id.d$INCLUDE - !(rm1 | rm2) Hope this helps, Rui Barradas Em 24-10-2012 16:41, Stuart Leask escreveu: (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and FALSE for whether or not that row should be included...) -Original Message- From: Leask Stuart Sent: 24 October 2012 16:25 To: arun (smartpink...@yahoo.com); 'PIKAL Petr'; Rui Barradas (ruipbarra...@sapo.pt) Subject: RE: [r] How to pick colums from a ragged array? Arun, Petr, Rui, many thanks for your help, and the functions you have written. You'll recall I wanted to remove these first (or last) duplicates, because they represented instances where two different diagnoses (in this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on the same day - so I can't say which was 'first' (or 'last'). Your functions have revealed something I wasn't expecting: In some cases, the diagnoses recorded on the duplicated DATEs are the same! This is a surprise to me, but probably reflects someone going to two different departments in a clinic, and both departments submit data. I have to say that crazy things like this are often a feature of real data, which I'm sure you've come across yourselves. Of course, I don't want to remove records in which I can determine an unambiguous 'first diagnosis'. You have all put in so much effort on my behalf, I'm ashamed to ask, but I wonder if any of the functions you've written could do this with a little more Indexing and the 'duplicate' function So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Test dataset: ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 ,547,794,814,814,814,814,814,814,841,841,841,841,841 ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 ,1019) DATE - c(20060821,20061207,20080102,20090904,20040205,20040205,2005 ,20060111,20071119,20080107,20080407,20080521,20080521,20041005 ,20070905,20020814,20021125,20040429,20040429,20071205,20071205 ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521 ,20091224,20050503,19870508,19870508,19880330) DG- c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,3,2,2,2,1,1) id.d-data.frame(ID,DATE,DG) id.d # Considering Ruis getRepeat function: g.r-getRepeat(id.d) # defaults to first = TRUE getRepeat(id.d, first = FALSE) to get the last ones g.rr-do.call(rbind, g.r) # put the data into a matrix # I can remove the date duplicates with: g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),] I'm not sure how to add this to your suggestions, Arun Petr... Stuart -Original Message- From: PIKAL Petr [mailto:petr.pi...@precheza.cz] Sent: 23 October
Re: [R] Summary of variables with NA, empty
On Oct 24, 2012, at 8:32 AM, Lopez, Dan wrote: The examples I gave--Null, Empty string, white space, etc where just examples based on SPSS Modeler's Data Audit node. I just want something that both identifies the columns having missing values-- regardless of what they technically are stored as(NA or a field with space bar hit a couple of times,etc) -- and tabulates based on what type of missing value. This is a basic data exploration step that I thought just maybe comes standard in R and that I just don't know of yet. In none of your examples below do you create factor columns with any of the features you say that you are hoping to identify. No NA's, no white-space levels, no 999 values. I do not (and never have) used SPSS Modeler's Data Audit, so definition by analogy is not going to work for me. Hmisc::describe is good and may have to suffice. Missing for the example below using Hmisc::describe was 0 although there was a . And I know that's because of the technical difference. Right. Hmisc::describe counts the number of NA's. A value of or is not the same as the R NA missing. is.na(factor()) [1] FALSE is.na(factor(NA)) [1] TRUE is.na(factor( )) [1] FALSE If you want to test for an empty string use nchar(vec) == 0 I offered an earlier suggestion for a grepl test for all spaces. #EXAMPLE data - just one column in this case dput(sample(mydata$COMMUTE_BIN,100)) structure(c(2L, 5L, 3L, 2L, 6L, 3L, 2L, 3L, 4L, 2L, 2L, 4L, 3L, 4L, 3L, 3L, 3L, 6L, 2L, 2L, 2L, 4L, 6L, 4L, 2L, 3L, 2L, 2L, 6L, 3L, 2L, 6L, 3L, 2L, 3L, 4L, 4L, 4L, 5L, 7L, 3L, 5L, 2L, 3L, 2L, 2L, 6L, 7L, 7L, 4L, 3L, 3L, 2L, 2L, 2L, 5L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 2L, 3L, 3L, 6L, 4L, 6L, 2L, 7L, 4L, 6L, 2L, 3L, 2L, 2L, 2L, 3L, 2L, 3L, 4L, 3L, 5L, 3L, 4L, 2L, 3L, 3L, 3L, 3L, 3L, 2L, 4L, 5L, 3L, 2L, 2L, 3L, 1L), .Label = c(, 15, 15 - 24, 25 - 34, 35 - 44, 45 - 54, 55+), class = factor) As David mentioned maybe I will have to create my own function. Maybe something similar to what I got here for identifying a factor columns, column labels and number of levels. #EXAMPLE of formula I will probably need to create for identifying and listing column names and counts of NA and and other missing in a dataframe or table. In this case however I am listing factor columns and excluding columns w/ 32 levels set.seed(1) dat1- data.frame(col1=factor(sample(1:25,10,replace=TRUE)),col2=sample(letters[1:10],10,replace=TRUE),col3=factor(rep(1:5,each=2))) PrintLvls2 - function(x) {print(data.frame(Lvls=sapply(x[sapply(x,function(x) is.factor(x)length(levels(x))=32)],nlevels), Names=sapply(x[sapply(x, function(x) is.factor(x)length(levels(x))=32)], function(y) paste0(levels(y), collapse=, ))), right=FALSE)} PrintLvls2(dat1) Lvls Names col1 92, 6, 7, 10, 15, 16, 17, 23, 24 col2 7b, c, d, e, g, h, j col3 51, 2, 3, 4, 5 I find it good to put in counter-examples such as a column that is non-factor. I thought that a non-factor column would probably break your code, but happily it survived. You might think about writing two functions: one to pick the columns to be assessed and the other to return a structured object from the candidates. -- david. Thanks. Dan -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Tuesday, October 23, 2012 3:15 PM To: David Winsemius Cc: Lopez, Dan; R help (r-help@r-project.org) Subject: Re: [R] Summary of variables with NA, empty To highlight: Basically all Null values is a meaningless phrase in R. ?Null ?NA ?NaN have **very specific meanings** in R and have nothing to do with the various sorts of whitespace characters that David mentions (spaces, tabs...). If you wish to use R, you **must** understand the distinctions (the Intro to R tutorial discusses some of this -- have you read it?). There is functionality to test for these sorts of things (is.na, is.null, etc). You need to put in the effort to learn about this if you mean to use R in any serious way, as these will occur in either data I/O (NA's) or data manipulation (e.g. 0/0) -- Bert On Tue, Oct 23, 2012 at 2:44 PM, David Winsemius dwinsem...@comcast.net wrote: On Oct 23, 2012, at 11:17 AM, Lopez, Dan wrote: Hi, Is there a function I can use on my dataframe to give me a concise summary of variables that are NA,blank,etc? Basically all Null values, Empty strings, white space, blank values. Ideally it would look something like the below: # it should only includes the fields with NAs, blanks, etc. Added bonus would be to include column Index. #Valid Records = records that are not NA, blank,etc #ColIndex - what place is column in the original dataframe...1,2,3, ...xth Valid Records Null
Re: [R] [r] How to pick colums from a ragged array?
Hello, I just realized that function getRepLogical marks the second, not the first (eventually from last) to be removed. The first tapply should be dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2), fromLast = TRUE)) in order to remove the first (or last). Rui Barradas Em 24-10-2012 18:41, Rui Barradas escreveu: Hello, Using one of Arun's ideas, some post ago, this new function returns a logical index into id.d of the rows that should be _removed_, hence rm1 and rm2. I think getRepLogical - function(x, first = TRUE){ fun - if(first) head else tail dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2))) len - tapply(x[,2], x[,1], FUN = length) lst - lapply(seq_along(dte), function(i) c(dte[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i1 - unlist(lst) dg - tapply(x[,3], x[,1], FUN = function(x) !duplicated(fun(x, 2))) lst - lapply(seq_along(dte), function(i) c(dg[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i2 - unlist(lst) i1 i2 } rm1 - getRepLogical(id.d) rm2 - getRepLogical(id.d, first = FALSE) id.d[rm1, ] id.d[rm2, ] id.d$INCLUDE - !(rm1 | rm2) Hope this helps, Rui Barradas Em 24-10-2012 16:41, Stuart Leask escreveu: (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and FALSE for whether or not that row should be included...) -Original Message- From: Leask Stuart Sent: 24 October 2012 16:25 To: arun (smartpink...@yahoo.com); 'PIKAL Petr'; Rui Barradas (ruipbarra...@sapo.pt) Subject: RE: [r] How to pick colums from a ragged array? Arun, Petr, Rui, many thanks for your help, and the functions you have written. You'll recall I wanted to remove these first (or last) duplicates, because they represented instances where two different diagnoses (in this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on the same day - so I can't say which was 'first' (or 'last'). Your functions have revealed something I wasn't expecting: In some cases, the diagnoses recorded on the duplicated DATEs are the same! This is a surprise to me, but probably reflects someone going to two different departments in a clinic, and both departments submit data. I have to say that crazy things like this are often a feature of real data, which I'm sure you've come across yourselves. Of course, I don't want to remove records in which I can determine an unambiguous 'first diagnosis'. You have all put in so much effort on my behalf, I'm ashamed to ask, but I wonder if any of the functions you've written could do this with a little more Indexing and the 'duplicate' function So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Test dataset: ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 ,547,794,814,814,814,814,814,814,841,841,841,841,841 ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 ,1019) DATE - c(20060821,20061207,20080102,20090904,20040205,20040205,2005 ,20060111,20071119,20080107,20080407,20080521,20080521,20041005 ,20070905,20020814,20021125,20040429,20040429,20071205,20071205 ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521 ,20091224,20050503,19870508,19870508,19880330) DG- c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,3,2,2,2,1,1) id.d-data.frame(ID,DATE,DG) id.d # Considering Ruis getRepeat function: g.r-getRepeat(id.d)# defaults to first = TRUE getRepeat(id.d, first = FALSE) to get the last ones g.rr-do.call(rbind, g.r) # put the data into a matrix # I can remove the date duplicates with: g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),] I'm not sure how to add this to your suggestions, Arun Petr... Stuart -Original Message- From: PIKAL Petr [mailto:petr.pi...@precheza.cz] Sent: 23 October 2012 15:24 To: Stuart Leask Subject: RE: [r] How to pick colums from a ragged array? Hi I assumed that id.d is data frame id.d - data.frame (ID,DATE ) and fff(id.d) works for me Petr -Original Message- From: Stuart Leask [mailto:stuart.le...@nottingham.ac.uk] Sent: Tuesday, October 23, 2012 3:13 PM To: PIKAL Petr Subject: RE: [r] How to pick colums from a ragged array? Hi Petr. I see what you mean it should do, but when I run it I get an error (see below). Stuart ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 + ,547,794,814,814,814,814,814,814,841,841,841,841,841 + ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 + ,1019) DATE - + c(20060821,20061207,20080102,20090904,20040205,20040205,2005 + ,20060111,20071119,20080107,20080407,20080521,20080711,20041005 +
Re: [R] [r] How to pick colums from a ragged array?
Hello, Inline. Em 24-10-2012 19:05, arun escreveu: Hi Rui, I think now our results are matching except in the INCLUDE column id.d[c(11:13,22:24,38:40),] # ID DATE DG INCLUDE #11 323 20080407 1TRUE #12 323 20080521 2 FALSE #13 323 20080521 3TRUE #22 841 20050421 1TRUE #23 841 20050421 2 FALSE #24 841 20060428 1TRUE #38 1019 19870508 2TRUE #39 1019 19870508 1 FALSE #40 1019 19880330 1TRUE I thought all the rows with the above IDS would be FALSE Why? Look at the last ID, 1019. The last of all must be included, the date doesn't repeat. And one of the first must also be included, if not we would be completely excluding that date. Or at least this is how I'm understanding the problem. Rui Barradas (from my solution): res4[c(11:13,22:24,38:40),] ID DATE DG INCLUDE #11 323 20080407 1 FALSE #12 323 20080521 2 FALSE #13 323 20080521 3 FALSE #22 841 20050421 1 FALSE #23 841 20050421 2 FALSE #24 841 20060428 1 FALSE #38 1019 19870508 1 FALSE #39 1019 19870508 2 FALSE #40 1019 19880330 1 FALSE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Stuart Leask stuart.le...@nottingham.ac.uk Cc: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; r-help r-help@r-project.org Sent: Wednesday, October 24, 2012 1:41 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Using one of Arun's ideas, some post ago, this new function returns a logical index into id.d of the rows that should be _removed_, hence rm1 and rm2. I think getRepLogical - function(x, first = TRUE){ fun - if(first) head else tail dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2))) len - tapply(x[,2], x[,1], FUN = length) lst - lapply(seq_along(dte), function(i) c(dte[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i1 - unlist(lst) dg - tapply(x[,3], x[,1], FUN = function(x) !duplicated(fun(x, 2))) lst - lapply(seq_along(dte), function(i) c(dg[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i2 - unlist(lst) i1 i2 } rm1 - getRepLogical(id.d) rm2 - getRepLogical(id.d, first = FALSE) id.d[rm1, ] id.d[rm2, ] id.d$INCLUDE - !(rm1 | rm2) Hope this helps, Rui Barradas Em 24-10-2012 16:41, Stuart Leask escreveu: (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and FALSE for whether or not that row should be included...) -Original Message- From: Leask Stuart Sent: 24 October 2012 16:25 To: arun (smartpink...@yahoo.com); 'PIKAL Petr'; Rui Barradas (ruipbarra...@sapo.pt) Subject: RE: [r] How to pick colums from a ragged array? Arun, Petr, Rui, many thanks for your help, and the functions you have written. You'll recall I wanted to remove these first (or last) duplicates, because they represented instances where two different diagnoses (in this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on the same day - so I can't say which was 'first' (or 'last'). Your functions have revealed something I wasn't expecting: In some cases, the diagnoses recorded on the duplicated DATEs are the same! This is a surprise to me, but probably reflects someone going to two different departments in a clinic, and both departments submit data. I have to say that crazy things like this are often a feature of real data, which I'm sure you've come across yourselves. Of course, I don't want to remove records in which I can determine an unambiguous 'first diagnosis'. You have all put in so much effort on my behalf, I'm ashamed to ask, but I wonder if any of the functions you've written could do this with a little more Indexing and the 'duplicate' function So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Test dataset: ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 ,547,794,814,814,814,814,814,814,841,841,841,841,841 ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 ,1019) DATE - c(20060821,20061207,20080102,20090904,20040205,20040205,2005 ,20060111,20071119,20080107,20080407,20080521,20080521,20041005 ,20070905,20020814,20021125,20040429,20040429,20071205,20071205 ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521 ,20091224,20050503,19870508,19870508,19880330) DG- c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,3,2,2,2,1,1) id.d-data.frame(ID,DATE,DG) id.d # Considering Ruis getRepeat function: g.r-getRepeat(id.d)# defaults to first = TRUE getRepeat(id.d, first = FALSE) to get the last ones g.rr-do.call(rbind, g.r) # put the data into
Re: [R] Changing radii line type in radial plots
I am using the package plotrix radial.plot(). Yes, radial.plot() has a line type argument, lty, but that is for the polygons or the radial lines, not the radii or axes of the radial plot.unless I am doing something wrong. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Changing-radii-line-type-in-radial-plots-tp4647238p4647339.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] [r] How to pick colums from a ragged array?
HI Stuart, Just a small comment: id.d1$id.d_INCLUDE-TRUE #is not needed. res1- data.frame(flag=tapply(id.d[,2],id.d[,1],FUN=function(x) head(duplicated(x)|duplicated(x,fromLast=TRUE),1)|tail(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res2-id.d[id.d[,1]%in%names(res1[res1$flag==TRUE,])(duplicated(id.d[,1:2])|duplicated(id.d[,1:2],fromLast=TRUE)),] res3-res2[!res2$ID%in% res2[duplicated(res2)|duplicated(res2,fromLast=TRUE),]$ID,] id.d1-id.d bad-id.d1[id.d1$ID%in%res3$ID,] bad$INCLUDE-FALSE res4-merge(id.d1,bad,all=TRUE) res4$INCLUDE[is.na(res4$INCLUDE)]-TRUE tail(res4) # ID DATE DG INCLUDE #35 910 20080521 4 TRUE #36 910 20091224 2 TRUE #37 999 20050503 2 TRUE #38 1019 19870508 1 FALSE #39 1019 19870508 2 FALSE #40 1019 19880330 1 FALSE A.K. - Original Message - From: Stuart Leask stuart.le...@nottingham.ac.uk To: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; Rui Barradas (ruipbarra...@sapo.pt) ruipbarra...@sapo.pt Cc: Sent: Wednesday, October 24, 2012 11:41 AM Subject: RE: [r] How to pick colums from a ragged array? (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and FALSE for whether or not that row should be included...) -Original Message- From: Leask Stuart Sent: 24 October 2012 16:25 To: arun (smartpink...@yahoo.com); 'PIKAL Petr'; Rui Barradas (ruipbarra...@sapo.pt) Subject: RE: [r] How to pick colums from a ragged array? Arun, Petr, Rui, many thanks for your help, and the functions you have written. You'll recall I wanted to remove these first (or last) duplicates, because they represented instances where two different diagnoses (in this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on the same day - so I can't say which was 'first' (or 'last'). Your functions have revealed something I wasn't expecting: In some cases, the diagnoses recorded on the duplicated DATEs are the same! This is a surprise to me, but probably reflects someone going to two different departments in a clinic, and both departments submit data. I have to say that crazy things like this are often a feature of real data, which I'm sure you've come across yourselves. Of course, I don't want to remove records in which I can determine an unambiguous 'first diagnosis'. You have all put in so much effort on my behalf, I'm ashamed to ask, but I wonder if any of the functions you've written could do this with a little more Indexing and the 'duplicate' function So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Test dataset: ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 ,547,794,814,814,814,814,814,814,841,841,841,841,841 ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 ,1019) DATE - c(20060821,20061207,20080102,20090904,20040205,20040205,2005 ,20060111,20071119,20080107,20080407,20080521,20080521,20041005 ,20070905,20020814,20021125,20040429,20040429,20071205,20071205 ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521 ,20091224,20050503,19870508,19870508,19880330) DG- c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,3,2,2,2,1,1) id.d-data.frame(ID,DATE,DG) id.d # Considering Ruis getRepeat function: g.r-getRepeat(id.d) # defaults to first = TRUE getRepeat(id.d, first = FALSE) to get the last ones g.rr-do.call(rbind, g.r) # put the data into a matrix # I can remove the date duplicates with: g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),] I'm not sure how to add this to your suggestions, Arun Petr... Stuart -Original Message- From: PIKAL Petr [mailto:petr.pi...@precheza.cz] Sent: 23 October 2012 15:24 To: Stuart Leask Subject: RE: [r] How to pick colums from a ragged array? Hi I assumed that id.d is data frame id.d - data.frame (ID,DATE ) and fff(id.d) works for me Petr -Original Message- From: Stuart Leask [mailto:stuart.le...@nottingham.ac.uk] Sent: Tuesday, October 23, 2012 3:13 PM To: PIKAL Petr Subject: RE: [r] How to pick colums from a ragged array? Hi Petr. I see what you mean it should do, but when I run it I get an error (see below). Stuart ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323 + ,547,794,814,814,814,814,814,814,841,841,841,841,841 + ,841,841,841,841,910,910,910,910,910,910,999,1019,1019 + ,1019) DATE - + c(20060821,20061207,20080102,20090904,20040205,20040205,2005 + ,20060111,20071119,20080107,20080407,20080521,20080711,20041005 + ,20070905,20020814,20021125,20040429,20040429,20071205,20080227 + ,20050421,20050421,20060428,20060602,20060816,20061025,20061129 + ,20070112,20070514, 19870508,20040205,20040205, 20091120,20091210 + ,20091224,20050503,19870508,19870508,19880330)
[R] randomly select another observation with same grouping factor and year value, do for every record in dataframe
Hello, I am trying to create a function that will move through each record of a data frame, find the value in the HUC column, then randomly select another observation from the dataframe with the same value in HUC column, as well as the same value in Yr column as the first observation. I want the function to produce a list of the RchID of the first observation, the RchID of the second randomly chosen observation, and several other characteristics of the randomly chosen observation. Below is the code I have written, but it doesn't work. Thanks for any help. Christy test roads=read.csv(streamland23.csv) for (i in 1:nrow (roads)){ Sitetype= roads$Sitetype yr=roads$REACH_Yr initRchid=roads$RchID huc1=roads$HUC sample.df - function(df, n) df[sample(nrow(df), n), , drop = FALSE] selected=sample.df(roads[roads$HUC == huc1 roads$REACH_Yr ==yr , ], 1) output=cbind (initRchid,selected$RchID,selected$Sitetype,selected$REACH_Yr) } Christy Meredith USDA Forest Service Rocky Mountain Research Station PIBO Monitoring Data Analyst Voice: 435-755-3573 Fax: 435-755-3563 This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. [[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] How to pick colums from a ragged array?
Hi, According to the OP So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Rui: By running your modified function (using dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2),fromLast = TRUE))), id.d$INCLUDE - !(rm1 | rm2) head(id.d) # ID DATE DG INCLUDE #1 58 20060821 1 TRUE #2 58 20061207 2 TRUE #3 58 20080102 1 TRUE #4 58 20090904 1 TRUE #5 167 20040205 4 FALSE #6 167 20040205 4 FALSE For #167, DGs are same. Not sure whether to exclude it or not. My modified solution is similar but I am excluding 167 and 814. fun1-function(dat){ res1first- data.frame(flag=tapply(dat[,2],dat[,1],FUN=function(x) head(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res1last- data.frame(flag=tapply(dat[,2],dat[,1],FUN=function(x) tail(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res2first-dat[dat[,1]%in%names(res1first[res1first$flag==TRUE,])(duplicated(dat[,1:2])|duplicated(dat[,1:2],fromLast=TRUE)),] res2last-dat[dat[,1]%in%names(res1last[res1last$flag==TRUE,])(duplicated(dat[,1:2])|duplicated(dat[,1:2],fromLast=TRUE)),] res3first-res2first[!res2first$ID%in% res2first[duplicated(res2first)|duplicated(res2first,fromLast=TRUE),]$ID,] res3last-res2last[!res2last$ID%in% res2last[duplicated(res2last)|duplicated(res2last,fromLast=TRUE),]$ID,] res3firstsubset-do.call(rbind,lapply(split(res3first,res3first$ID),head,1)) res3firstsubset$INCLUDE-FALSE res3lastsubset-do.call(rbind,lapply(split(res3last,res3last$ID),tail,1)) res3lastsubset$INCLUDE-FALSE res4-merge(dat,merge(res3first,merge(res3firstsubset,merge(res3lastsubset,res3last,all=TRUE),all=TRUE),all=TRUE),all=TRUE) res4$INCLUDE[is.na(res4$INCLUDE)]-TRUE res4 } tail(fun1(id.d)) # ID DATE DG INCLUDE #35 910 20080521 4 TRUE #36 910 20091224 2 TRUE #37 999 20050503 2 TRUE #38 1019 19870508 1 TRUE #39 1019 19870508 2 FALSE #40 1019 19880330 1 TRUE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Stuart Leask stuart.le...@nottingham.ac.uk Sent: Wednesday, October 24, 2012 2:50 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Inline. Em 24-10-2012 19:05, arun escreveu: Hi Rui, I think now our results are matching except in the INCLUDE column id.d[c(11:13,22:24,38:40),] # ID DATE DG INCLUDE #11 323 20080407 1 TRUE #12 323 20080521 2 FALSE #13 323 20080521 3 TRUE #22 841 20050421 1 TRUE #23 841 20050421 2 FALSE #24 841 20060428 1 TRUE #38 1019 19870508 2 TRUE #39 1019 19870508 1 FALSE #40 1019 19880330 1 TRUE I thought all the rows with the above IDS would be FALSE Why? Look at the last ID, 1019. The last of all must be included, the date doesn't repeat. And one of the first must also be included, if not we would be completely excluding that date. Or at least this is how I'm understanding the problem. Rui Barradas (from my solution): res4[c(11:13,22:24,38:40),] ID DATE DG INCLUDE #11 323 20080407 1 FALSE #12 323 20080521 2 FALSE #13 323 20080521 3 FALSE #22 841 20050421 1 FALSE #23 841 20050421 2 FALSE #24 841 20060428 1 FALSE #38 1019 19870508 1 FALSE #39 1019 19870508 2 FALSE #40 1019 19880330 1 FALSE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Stuart Leask stuart.le...@nottingham.ac.uk Cc: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; r-help r-help@r-project.org Sent: Wednesday, October 24, 2012 1:41 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Using one of Arun's ideas, some post ago, this new function returns a logical index into id.d of the rows that should be _removed_, hence rm1 and rm2. I think getRepLogical - function(x, first = TRUE){ fun - if(first) head else tail dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2))) len - tapply(x[,2], x[,1], FUN = length) lst - lapply(seq_along(dte), function(i) c(dte[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i1 - unlist(lst) dg - tapply(x[,3], x[,1], FUN = function(x) !duplicated(fun(x, 2))) lst - lapply(seq_along(dte), function(i) c(dg[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst - if(first) lst else lapply(lst, rev) i2 - unlist(lst) i1 i2 } rm1 - getRepLogical(id.d) rm2 - getRepLogical(id.d, first = FALSE) id.d[rm1, ] id.d[rm2, ] id.d$INCLUDE - !(rm1 | rm2) Hope this helps, Rui Barradas Em 24-10-2012 16:41, Stuart Leask escreveu: (And, considering the real application, the functions ideally should probably output a variable INCLUDE, the same length as the original data, with TRUE and
[R] Testing proportional odds assumption in R
Hi, M1 and M2 are extreme in that all or none of the variables have parallel lines on the logit scale. One can try fitting a partial POM, which remains fraught (but not as much as M2) because if the lines intersect for a particular variable where the data lie then there will be numerical problems. For example, try something like M3 - vglm(y ~ x1 + x2 + x3, data = data, family = cumulative(parallel = FALSE ~ x3 - 1)) which will only allow nonparallelism wrt the x3 variable. Another idea is to try transforming each x variable if it crashes... that might help. BTW, can use lrtest(), e.g., lrtest(M3, M2) cheers Thomas I want to test whether the proportional odds assumption for an ordered regression is met. The UCLA website points out that there is no mathematical way to test the proportional odds assumption (http://www.ats.ucla.edu/stat//R/dae/ologit.htm), and use graphical inspection (We were unable to locate a facility in R to perform any of the tests commonly used to test the parallel slopes assumption.). However, I found a pdf by Agresti suggesting a method using the vglm function, the pdf is called Examples of Using R for Modeling Ordinal Data. M1 - vglm(y ~ x1 + x2 + x3, data=data, family=cumulative(parallel=TRUE)) M2 - vglm(y ~ x1 + x2 + x3, data=data, family=cumulative, maxit=100) pchisq(deviance(Mo.1)-deviance(Mo.2), df=df.residual(Mo.1)-df.residual(Mo.2), lower.tail=FALSE) If the test is significant, the proportional odds assumption is (might be) violated. However, running this procedure in my dataset with 5 predictors (3 dichotomous, 2 z-standardized metric) and an ordinal dependent variable (0,1,2,3) in a sample of N=2500 leads to various problems, maybe you can help me out how to solve these. Warning messages: (1) Error in dotC(name = tapplymat1, mat = as.double(mat), as.integer(nr), : NA/NaN/Inf in foreign function call (arg 1 (2) In matrix.power(wz, M = M, power = 0.5, fast = TRUE) : Some weight matrices have negative eigenvalues. They will be assigned NAs (3) In Deviance.categorical.data.vgam(mu = mu, y = y, w = w, residuals = residuals, : fitted values close to 0 or 1 (4) In log(prob) : NaNs produced The last two don't seem to be as critical and the first two, seeing that models with that errors at least provide a p-value (the first to errors lead to a p--value of 1). Thank you [[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] Recode function car package erases previous values
Hi, I think the as.factor in ur code created trouble. library(car) pharm-as.factor(recode(B20_C1,1='Yes';0='No')) pharm-recode(dat1$B20_C1,1='Yes';0='No') pharm[dat1$nrB20C==1]-no resp pharm #[1] no resp No No Yes Yes NA table(pharm) #pharm # No no resp Yes # 2 1 2 A.K. - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Wednesday, October 24, 2012 10:41 AM Subject: RE: [R] Recode function car package erases previous values Hi Arun, I also used to get that error, but what class is your nr.B20C, mine is not a factor, it is numeric and perhaps that's why it works -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Wednesday, October 24, 2012 4:35 PM To: Pancho Mulongeni Cc: R help Subject: Re: [R] Recode function car package erases previous values Hi Pancho, I tried ur method: pharm-as.factor(recode(dat1$B20_C1,1='Yes';0='No')) pharm #[1] NA No No Yes Yes NA #Levels: No Yes pharm[dat1$nrB20C==1]-'no resp' #Warning message: #In `[-.factor`(`*tmp*`, dat1$nr.B20C == 1, value = no resp) : # invalid factor level, NAs generated pharm #[1] NA No No Yes Yes NA #Levels: No Yes Not sure how you got the result. A.K. - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Wednesday, October 24, 2012 9:51 AM Subject: RE: [R] Recode function car package erases previous values -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Wednesday, October 24, 2012 3:31 PM To: Pancho Mulongeni Cc: R help Subject: Re: [R] Recode function car package erases previous values Hi, May be this helps: set.seed(1) dat1-data.frame(B20_C1=c(NA,sample(0:1,4,replace=TRUE),NA),B20_C2=c(NA,sample(0:1,3,replace=TRUE),sample(0:1,2,replace=TRUE)),nrB20C=c(1,NA,NA,NA,NA,NA)) dat1 # B20_C1 B20_C2 nrB20C #1 NA NA 1 #2 0 0 NA #3 0 1 NA #4 0 0 NA #5 1 1 NA #6 NA 1 NA dat1$pharm-ifelse(apply(dat1,1,function(x) all(is.na(x[1:2]))),no response,ifelse(dat1[,1]==1,Yes,No)) dat2-within(dat1,{pharm-factor(pharm)}) levels(dat2$pharm) #[1] No no response Yes dat2 # B20_C1 B20_C2 nrB20C pharm #1 NA NA 1 no response #2 0 0 NA No #3 0 1 NA No #4 0 0 NA No #5 1 1 NA Yes #6 NA 1 NA NA table(dat2$pharm) # No no response Yes # 3 1 1 A.K. Thank you, once I understand what you did I will use it, for now, I use a workaround 1. First I use the recode function pharm-as.factor(recode(B20_C1,1='Yes';0='No')) 2. Now I just subset pharm[nr.B20C==1]-'no resp' and this gives me the desired output No Yes no resp 716 7 6 - Original Message - From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org To: r-help@r-project.org r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 5:17 AM Subject: [R] Recode function car package erases previous values Hi all, I am attempting to create a new variable based on values of other variables. The variable is called pharm. It basically takes the numeric code of 1 as yes and 0 to be No from the variable B20_C1 (a question on a survey). However, I would also like to have a level for non-respondents and these are captured in the variable nr.B20C, which is a 1 when there is a non-response on the whole group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will have three levels, Yes No and no resp. See below what happens pharm-as.factor(recode(B20_C1,1='Yes';0='No')) table(pharm) pharm No Yes 716 7 levels(pharm)-c('No','Yes','no resp') table(pharm) pharm No Yes no resp 716 7 0 pharm-as.factor(recode(nr.B20C,1='no resp')) table(pharm) pharm 0 no resp 723 6 The recode variable just cannot seem to 'remember' I had just recoded 7 values to 'Yes' and 716 to be 'No' and instead it assigns the level '0' which comes from nr.B20C (it has values 0 or 1). This inconvenient as I would like to have ultimately the following table pharm No Yes no resp 716 7 6 (FROM nr.B20C where row has value 1). Background. The variable pharm assess where you used the pharmacy to get your contraception. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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
Re: [R] Assigning values to several consecutives rows in a sequence while leaving some empty
Thank you very much Michael and Berend for your ideas and feddback. I apologize for my mistakes. It's true that I still have much to learn (and I sometimes forget what I read). I'll surely use the dput() command next time I post something and I'll try to be more clear with my questions too. Berend's suggestion worked perfectly! Thanks a lot. -- View this message in context: http://r.789695.n4.nabble.com/Assigning-values-to-several-consecutives-rows-in-a-sequence-while-leaving-some-empty-tp4646956p4647352.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] Kaplan Meier Post Hoc?
This is more of a general question without data. After doing 'survdiff', from the 'survival' package, on strata including four groups (so 4 curves on a Kaplan Meier curve) you get a chi squared p-value whether to reject the null hypothesis or not. Is there a method to followup with pairwise testing on the respective groups? I have searched the library but have come up with nothing. Perhaps I am mistaken in something here. Regards, Charles [[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] How to pick colums from a ragged array?
I mis-typed, missing an if. I think you've got it, but let me try again: The function should: - put FALSE in a column for every instance of an ID IF ( that ID has a first (or last) DATE duplicated ) AND IF (the DGs for the duplicated dates are different). So for the earliest/first date function, INCLUDE should be TRUE, apart from FALSE for _all_ the instances of IDs 167, 841 and 1019 For the latest/last date function, INCLUDE should be TRUE, apart from FALSE for all the instances of ID 323. Stuart -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 24 October 2012 21:30 To: Rui Barradas Cc: R help; Stuart Leask Subject: Re: [r] How to pick colums from a ragged array? Hi, According to the OP So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Rui: By running your modified function (using dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2),fromLast = TRUE))), id.d$INCLUDE - !(rm1 | rm2) head(id.d) # ID DATE DG INCLUDE #158 20060821 1TRUE #258 20061207 2TRUE #358 20080102 1TRUE #458 20090904 1TRUE #5 167 20040205 4 FALSE #6 167 20040205 4 FALSE For #167, DGs are same. Not sure whether to exclude it or not. My modified solution is similar but I am excluding 167 and 814. fun1-function(dat){ res1first- data.frame(flag=tapply(dat[,2],dat[,1],FUN=function(x) head(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res1last- data.frame(flag=tapply(dat[,2],dat[,1],FUN=function(x) tail(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res2first-dat[dat[,1]%in%names(res1first[res1first$flag==TRUE,])(duplicated(dat[,1:2])|duplicated(dat[,1:2],fromLast=TRUE)),] res2last-dat[dat[,1]%in%names(res1last[res1last$flag==TRUE,])(duplicated(dat[,1:2])|duplicated(dat[,1:2],fromLast=TRUE)),] res3first-res2first[!res2first$ID%in% res2first[duplicated(res2first)|duplicated(res2first,fromLast=TRUE),]$ID,] res3last-res2last[!res2last$ID%in% res2last[duplicated(res2last)|duplicated(res2last,fromLast=TRUE),]$ID,] res3firstsubset-do.call(rbind,lapply(split(res3first,res3first$ID),head,1)) res3firstsubset$INCLUDE-FALSE res3lastsubset-do.call(rbind,lapply(split(res3last,res3last$ID),tail,1)) res3lastsubset$INCLUDE-FALSE res4-merge(dat,merge(res3first,merge(res3firstsubset,merge(res3lastsubset,res3last,all=TRUE),all=TRUE),all=TRUE),all=TRUE) res4$INCLUDE[is.na(res4$INCLUDE)]-TRUE res4 } tail(fun1(id.d)) # ID DATE DG INCLUDE #35 910 20080521 4TRUE #36 910 20091224 2TRUE #37 999 20050503 2TRUE #38 1019 19870508 1TRUE #39 1019 19870508 2 FALSE #40 1019 19880330 1TRUE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Stuart Leask stuart.le...@nottingham.ac.uk Sent: Wednesday, October 24, 2012 2:50 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Inline. Em 24-10-2012 19:05, arun escreveu: Hi Rui, I think now our results are matching except in the INCLUDE column id.d[c(11:13,22:24,38:40),] # ID DATE DG INCLUDE #11 323 20080407 1TRUE #12 323 20080521 2 FALSE #13 323 20080521 3TRUE #22 841 20050421 1TRUE #23 841 20050421 2 FALSE #24 841 20060428 1TRUE #38 1019 19870508 2TRUE #39 1019 19870508 1 FALSE #40 1019 19880330 1TRUE I thought all the rows with the above IDS would be FALSE Why? Look at the last ID, 1019. The last of all must be included, the date doesn't repeat. And one of the first must also be included, if not we would be completely excluding that date. Or at least this is how I'm understanding the problem. Rui Barradas (from my solution): res4[c(11:13,22:24,38:40),] ID DATE DG INCLUDE #11 323 20080407 1 FALSE #12 323 20080521 2 FALSE #13 323 20080521 3 FALSE #22 841 20050421 1 FALSE #23 841 20050421 2 FALSE #24 841 20060428 1 FALSE #38 1019 19870508 1 FALSE #39 1019 19870508 2 FALSE #40 1019 19880330 1 FALSE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Stuart Leask stuart.le...@nottingham.ac.uk Cc: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; r-help r-help@r-project.org Sent: Wednesday, October 24, 2012 1:41 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Using one of Arun's ideas, some post ago, this new function returns a logical index into id.d of the rows that should be _removed_, hence rm1 and rm2. I think getRepLogical - function(x, first = TRUE){ fun - if(first) head else tail dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2))) len - tapply(x[,2], x[,1], FUN = length) lst - lapply(seq_along(dte), function(i) c(dte[[i]], rep(FALSE, if(len[[i]] 2) len[[i]] - 2 else 0))) lst
Re: [R] [r] How to pick colums from a ragged array?
Hello, Inline. Em 24-10-2012 22:40, Stuart Leask escreveu: I mis-typed, missing an if. I think you've got it, but let me try again: The function should: - put FALSE in a column for every instance of an ID IF ( that ID has a first (or last) DATE duplicated ) AND IF (the DGs for the duplicated dates are different). So for the earliest/first date function, INCLUDE should be TRUE, apart from FALSE for _all_ the instances of IDs 167, 841 and 1019 For the latest/last date function, INCLUDE should be TRUE, apart from FALSE for all the instances of ID 323. In this case forget my last post and use getRepLogical as I posted it originaly Rui Barradas Stuart -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 24 October 2012 21:30 To: Rui Barradas Cc: R help; Stuart Leask Subject: Re: [r] How to pick colums from a ragged array? Hi, According to the OP So the function should only exclude an ID, having identified a first (or last) DATE duplicate, the DGs for these two dates are different. Rui: By running your modified function (using dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2),fromLast = TRUE))), id.d$INCLUDE - !(rm1 | rm2) head(id.d) # ID DATE DG INCLUDE #158 20060821 1TRUE #258 20061207 2TRUE #358 20080102 1TRUE #458 20090904 1TRUE #5 167 20040205 4 FALSE #6 167 20040205 4 FALSE For #167, DGs are same. Not sure whether to exclude it or not. My modified solution is similar but I am excluding 167 and 814. fun1-function(dat){ res1first- data.frame(flag=tapply(dat[,2],dat[,1],FUN=function(x) head(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res1last- data.frame(flag=tapply(dat[,2],dat[,1],FUN=function(x) tail(duplicated(x)|duplicated(x,fromLast=TRUE),1))) res2first-dat[dat[,1]%in%names(res1first[res1first$flag==TRUE,])(duplicated(dat[,1:2])|duplicated(dat[,1:2],fromLast=TRUE)),] res2last-dat[dat[,1]%in%names(res1last[res1last$flag==TRUE,])(duplicated(dat[,1:2])|duplicated(dat[,1:2],fromLast=TRUE)),] res3first-res2first[!res2first$ID%in% res2first[duplicated(res2first)|duplicated(res2first,fromLast=TRUE),]$ID,] res3last-res2last[!res2last$ID%in% res2last[duplicated(res2last)|duplicated(res2last,fromLast=TRUE),]$ID,] res3firstsubset-do.call(rbind,lapply(split(res3first,res3first$ID),head,1)) res3firstsubset$INCLUDE-FALSE res3lastsubset-do.call(rbind,lapply(split(res3last,res3last$ID),tail,1)) res3lastsubset$INCLUDE-FALSE res4-merge(dat,merge(res3first,merge(res3firstsubset,merge(res3lastsubset,res3last,all=TRUE),all=TRUE),all=TRUE),all=TRUE) res4$INCLUDE[is.na(res4$INCLUDE)]-TRUE res4 } tail(fun1(id.d)) # ID DATE DG INCLUDE #35 910 20080521 4TRUE #36 910 20091224 2TRUE #37 999 20050503 2TRUE #38 1019 19870508 1TRUE #39 1019 19870508 2 FALSE #40 1019 19880330 1TRUE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Stuart Leask stuart.le...@nottingham.ac.uk Sent: Wednesday, October 24, 2012 2:50 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Inline. Em 24-10-2012 19:05, arun escreveu: Hi Rui, I think now our results are matching except in the INCLUDE column id.d[c(11:13,22:24,38:40),] # ID DATE DG INCLUDE #11 323 20080407 1TRUE #12 323 20080521 2 FALSE #13 323 20080521 3TRUE #22 841 20050421 1TRUE #23 841 20050421 2 FALSE #24 841 20060428 1TRUE #38 1019 19870508 2TRUE #39 1019 19870508 1 FALSE #40 1019 19880330 1TRUE I thought all the rows with the above IDS would be FALSE Why? Look at the last ID, 1019. The last of all must be included, the date doesn't repeat. And one of the first must also be included, if not we would be completely excluding that date. Or at least this is how I'm understanding the problem. Rui Barradas (from my solution): res4[c(11:13,22:24,38:40),] ID DATE DG INCLUDE #11 323 20080407 1 FALSE #12 323 20080521 2 FALSE #13 323 20080521 3 FALSE #22 841 20050421 1 FALSE #23 841 20050421 2 FALSE #24 841 20060428 1 FALSE #38 1019 19870508 1 FALSE #39 1019 19870508 2 FALSE #40 1019 19880330 1 FALSE A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Stuart Leask stuart.le...@nottingham.ac.uk Cc: arun (smartpink...@yahoo.com) smartpink...@yahoo.com; PIKAL Petr petr.pi...@precheza.cz; r-help r-help@r-project.org Sent: Wednesday, October 24, 2012 1:41 PM Subject: Re: [r] How to pick colums from a ragged array? Hello, Using one of Arun's ideas, some post ago, this new function returns a logical index into id.d of the rows that should be _removed_, hence rm1 and rm2. I think getRepLogical - function(x, first = TRUE){ fun - if(first) head else tail dte - tapply(x[,2], x[,1], FUN = function(x) duplicated(fun(x, 2))) len - tapply(x[,2], x[,1], FUN
Re: [R] Kaplan Meier Post Hoc?
On Oct 24, 2012, at 4:33 PM, Charles Determan Jr deter...@umn.edu wrote: This is more of a general question without data. After doing 'survdiff', from the 'survival' package, on strata including four groups (so 4 curves on a Kaplan Meier curve) you get a chi squared p-value whether to reject the null hypothesis or not. Is there a method to followup with pairwise testing on the respective groups? I have searched the library but have come up with nothing. Perhaps I am mistaken in something here. Regards, Charles Take a look at ?p.adjust, which provides a generic framework for multiple pairwise comparison adjustment methods. The most conservative, but not always the best approach, would of course be Bonferroni. Regards, Marc Schwartz __ 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] Defining categories
Hello R user, Data below represent year in decimal. I would like to catagorize it in such a way that any valye [0,1] goes to catagory 1 , (1,2] goes to catagory 2 and so on.. Any suggestion how it can be done with if else statement or any other way? 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 Thank you for your help. Bibek __ 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] Defining categories
Hi, May be this: dat1-read.table(text= 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 ,sep=,header=FALSE) dat1$category-ifelse(dat1$V1=1 dat1$V10,1,ifelse(dat1$V11 dat1$V1=2,2,ifelse(dat1$V12dat1$V1=3,3,ifelse(dat1$V13dat1$V1=4,4,ifelse(dat1$V14dat1$V1=5,5,6) head(dat1) # V1 category #1 2.880556 3 #2 0.616667 1 #3 5.08 6 #4 0.858333 1 #5 0.47 1 #6 2.936111 3 A.K. - Original Message - From: bibek sharma mbhpat...@gmail.com To: r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 6:52 PM Subject: [R] Defining categories Hello R user, Data below represent year in decimal. I would like to catagorize it in such a way that any valye [0,1] goes to catagory 1 , (1,2] goes to catagory 2 and so on.. Any suggestion how it can be done with if else statement or any other way? 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 Thank you for your help. Bibek __ 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] Defining categories
See ?cut for a simpler way of doing this. HTH, Jorge.- On Thu, Oct 25, 2012 at 10:02 AM, arun wrote: Hi, May be this: dat1-read.table(text= 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 ,sep=,header=FALSE) dat1$category-ifelse(dat1$V1=1 dat1$V10,1,ifelse(dat1$V11 dat1$V1=2,2,ifelse(dat1$V12dat1$V1=3,3,ifelse(dat1$V13dat1$V1=4,4,ifelse(dat1$V14dat1$V1=5,5,6) head(dat1) #V1 category #1 2.8805563 #2 0.6166671 #3 5.086 #4 0.8583331 #5 0.471 #6 2.9361113 A.K. - Original Message - From: bibek sharma To: r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 6:52 PM Subject: [R] Defining categories Hello R user, Data below represent year in decimal. I would like to catagorize it in such a way that any valye [0,1] goes to catagory 1 , (1,2] goes to catagory 2 and so on.. Any suggestion how it can be done with if else statement or any other way? 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 Thank you for your help. Bibek __ 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. [[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] extracting variance co variance matrix from system package
I run system of equations. The system package gives variance covariance matrix for each equation. I want to extract the variance covariance matrix (of the coefficients) for each equation. How do we extract it?. Y1~X1+X2 Y2~X1+X2 fit.ols-system (system, ols, data)â¦â¦. To extract it I wrote as follows: fit.ols$coefCov [[eq1]].  it did not work. I want it to apply to delta method. I need help please.  Thank you!. . Dereje [[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] Z score
Hi Ved, Sorry, I didn't test it well enough at that time. In your example file, #there were NAs MyFile1 - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77,88 Gene_2,98,22,34 Gene_3,33,43,33 Gene_4,78,,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) #Here, the apply() function outputs a list when I remove the NA from the last row. apply(MyFile1,1,function(x) x[!is.na(x)]) #outputs a list #$Gene_1 #Sample_1 Sample_2 Sample_3 # 87 77 88 #$Gene_2 #Sample_1 Sample_2 Sample_3 # 98 22 34 #$Gene_3 #Sample_1 Sample_2 Sample_3 # 33 43 33 #$Gene_4 #Sample_1 Sample_3 # 78 81 # Without NAs MyFile2 - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77,88 Gene_2,98,22,34 Gene_3,33,43,33 Gene_4,78,48,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) apply(dat3,1,function(x) x[!is.na(x)]) # the output is a matrix # Gene_1 Gene_2 Gene_3 Gene_4 #Sample_1 87 98 33 78 #Sample_2 77 22 43 48 #Sample_3 88 34 33 81 is.matrix(apply(dat3,1,function(x) x[!is.na(x)]) ) #[1] TRUE #Consider another case MyFile3 - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77,88 Gene_2,,22,34 Gene_3,33,43,33 Gene_4,78,,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) t(sapply(lapply(apply(MyFile3,1,function(x) x[!is.na(x)]),function(x) (x-mean(x))/sd(x)),function(x) x[colnames(MyFile3)] )) #works because the apply() output is a list # Sample_1 Sample_2 Sample_3 #Gene_1 0.4931970 -1.1507929 0.6575959 #Gene_2 NA -0.7071068 0.7071068 #Gene_3 -0.5773503 1.1547005 -0.5773503 #Gene_4 -0.7071068 NA 0.7071068 #Yet another case: MyFile4 - read.csv( text= Names,'Sample_1','Sample_2','Sample_3' Gene_1,87,77 Gene_2,,22,34 Gene_3,33,,33 Gene_4,78,,81 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= ) apply(MyFile4,1,function(x) x[!is.na(x)]) #output is a matrix because equal number of NAs were present in each row # Gene_1 Gene_2 Gene_3 Gene_4 #[1,] 87 22 33 78 #[2,] 77 34 33 81 t(sapply(lapply(apply(MyFile4,1,function(x) x[!is.na(x)]),function(x) (x-mean(x))/sd(x)),function(x) x[colnames(MyFile4)] )) #doesn't work #In your dataset, there were no NAs dat1-read.csv(Bcl2_With_expressions.csv,sep=\t,row.names=1) MyFile-dat1[,-1] str(apply(MyFile,1,function(x) x[!is.na(x)])) # a matrix # num [1:29, 1:18] 10.48 10.96 9.28 11.1 10.95 ... #- attr(*, dimnames)=List of 2 # ..$ : chr [1:29] ALL2 MLL8 ALL42 MLL5 ... # ..$ : chr [1:18] BAX BCL2L15 BCL2 BMF ... #In this case, either res2-apply(MyFile,1,function(x) (x-mean(x))/sd(x)) #or res1-apply(apply(MyFile,1,function(x) x[!is.na(x)]),2,function(x) (x-mean(x))/sd(x)) #works identical(res1,res2) #[1] TRUE head(res1,2) # BAX BCL2L15 BCL2 BMF BAD MCL1 BCL2L1 #ALL2 0.1216373 -0.215256 1.040758 -0.4078606 -0.2427741 0.6967070 -0.1054749 #MLL8 0.6565878 -1.446252 1.052566 -0.1825442 -0.2312166 0.9882503 -0.9687260 # BOK BCL2A1 BCL2L14 BAK1 BBC3 BCL2L11 #ALL2 -0.1465807 0.5353133 -0.1772439 -0.3751981 0.6341806 -1.2432273 #MLL8 0.2918296 -0.8466821 0.3088331 -1.4025846 0.7056799 0.9944288 # BID NOXA1 BIK HRK BCL2L2 #ALL2 -2.2961643 0.2105960 -0.9195998 -0.001731806 1.6691590 #MLL8 -0.5103087 0.3433778 1.2352986 -0.568548518 0.3674839 Hope it helps A.K. From: Vedant Sharma vedantg...@gmail.com To: arun smartpink...@yahoo.com Sent: Wednesday, October 24, 2012 7:56 PM Subject: Re: [R] Z score Hello Arun, Thank you. I could manage to get the answer. However, this particular code, however, doesn't seem to work when I try to read from a .csv file (as attached). And, I am inquisitive to find out the reason ! MyFile - read.csv (file.choose(), header=T, row.names=1) MyFile - MyFile [,-1] res2-t(sapply(lapply(apply(MyFile,1,function(x) x[!is.na(x)]),function(x) (x-mean(x))/sd(x)),function(x) x[colnames(MyFile)] )) Thanks again !! Cheers, Ved = On Wed, Oct 24, 2012 at 9:53 PM, arun smartpink...@yahoo.com wrote: Hi, In cases, with more sample columns, you could also use this: res2-t(sapply(lapply(apply(MyFile,1,function(x) x[!is.na(x)]),function(x) (x-mean(x))/sd(x)),function(x) x[colnames(MyFile)] )) res2 # Sample_1 Sample_2 Sample_3 #Gene_1 0.4931970 -1.1507929 0.6575959 #Gene_2 1.1421818 -0.7179429 -0.4242390 #Gene_3 -0.5773503 1.1547005 -0.5773503 #Gene_4 -0.7071068 NA 0.7071068 A.K. - Original Message - From: Vedant Sharma vedantg...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 2:17 AM Subject: [R] Z score Hi, I need to find the z-score of the data present in a speardsheet. The values needs to be
Re: [R] Defining categories
Hi, (Jorge: Thanks for the suggestion.) cut? will be much easier. dat1-read.table(text= 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 ,sep=,header=FALSE) dat1$Categ-cut(dat1$V1,breaks=c(0,1,2,3,4,5,6)) #Either library(car) dat1$Categ-recode(dat1$Categ,'(0,1]'=1;'(1,2]'=2;'(2,3]'=3;'(3,4]'=4;'(4,5]'=5;'(5,6]'=6) #or dat1$Categ-as.numeric(gsub(.*\\,(\\d+).*,\\1,dat1$Categ)) #formats the Categ column. head(dat1) # V1 Categ #1 2.880556 3 #2 0.616667 1 #3 5.08 6 #4 0.858333 1 #5 0.47 1 #6 2.936111 3 A.K. From: Jorge I Velez jorgeivanve...@gmail.com To: arun smartpink...@yahoo.com Cc: bibek sharma mbhpat...@gmail.com; R help r-help@r-project.org Sent: Wednesday, October 24, 2012 7:27 PM Subject: Re: [R] Defining categories See ?cut for a simpler way of doing this. HTH, Jorge.- On Thu, Oct 25, 2012 at 10:02 AM, arun wrote: Hi, May be this: dat1-read.table(text= 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 ,sep=,header=FALSE) dat1$category-ifelse(dat1$V1=1 dat1$V10,1,ifelse(dat1$V11 dat1$V1=2,2,ifelse(dat1$V12dat1$V1=3,3,ifelse(dat1$V13dat1$V1=4,4,ifelse(dat1$V14dat1$V1=5,5,6) head(dat1) # V1 category #1 2.880556 3 #2 0.616667 1 #3 5.08 6 #4 0.858333 1 #5 0.47 1 #6 2.936111 3 A.K. - Original Message - From: bibek sharma To: r-help@r-project.org Cc: Sent: Wednesday, October 24, 2012 6:52 PM Subject: [R] Defining categories Hello R user, Data below represent year in decimal. I would like to catagorize it in such a way that any valye [0,1] goes to catagory 1 , (1,2] goes to catagory 2 and so on.. Any suggestion how it can be done with if else statement or any other way? 2.880556 0.616667 5.08 0.858333 0.47 2.936111 4.258333 0.258333 2.03 2.58 1.09 0.447222 1.87 0.080556 4.03 4.116667 1.63 2.147222 Thank you for your help. Bibek __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing radii line type in radial plots
On 2012-10-24 11:06, bwone wrote: I am using the package plotrix radial.plot(). Yes, radial.plot() has a line type argument, lty, but that is for the polygons or the radial lines, not the radii or axes of the radial plot.unless I am doing something wrong. Thanks! First, even if you must post via Nabble, please do keep context. Now, as to your question: I think I now understand; you want control over the line type of the radial grid. You're correct; that's not currently possible with radial.plot(), but it's easy to modify the function and you can probably nudge Jim Lemon to make the change. In the meantime, here's a fix you can apply yourself: 1. Save the function code (either get the source or just use capture.output: capture.output(radial.plot, file = rp.txt) 2. Edit the function; find the following two lines: polygon(xpos, ypos, border = grid.col, col = grid.bg) segments(0, 0, xpos, ypos, col = grid.col) and add the argument 'lty = grid.lty' to each. Then add 'grid.lty = 1' to the function arguments. Save the modified function as myradial.plot and source() it into your R session and then use it with whatever grid.lty setting you prefer. Peter Ehlers -- View this message in context: http://r.789695.n4.nabble.com/Changing-radii-line-type-in-radial-plots-tp4647238p4647339.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.