Re: [R] How to read only specified columns from a data file
read.table() looks at the first five rows when determining how many columns there are. If there are more columns in row 7 and you do not specify that in the read.table() command directly, they will be wrapped to the next row. This was discussed on the list within the last couple weeks. Sarah On Wed, Mar 16, 2011 at 7:54 AM, Luis Ridao luri...@gmail.com wrote: David, Thanks for your tip but it seems I'm having problems with the number of columns R manages to read in. Below it s an example of the data read in: inp[1:20,] V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1. log_fy_coff -1.007600 0.119520 1. NA NA NA 2 2. log_fy_coff -0.935010 0.112840 0.8896 1. NA NA 3 3. log_fy_coff -0.876260 0.107500 0.8219 0.8847 1. NA NA 4 4. log_fy_coff -0.683090 0.103030 0.7656 0.8143 0.8747 1. NA 5 5. log_fy_coff -0.623500 0.100980 0.7206 0.7636 0.8086 0.8764 1. 6 6. log_fy_coff -0.583330 0.098978 0.6819 0.7214 0.7615 0.8150 0.8762 7 1. NA NA NA NA NA NA 8 7. log_fy_coff -0.676790 0.096608 0.6521 0.6892 0.7254 0.7719 0.8148 9 0.8717 1. NA NA NA NA NA NA 10 8. log_fy_coff -0.696060 0.093761 0.6297 0.6654 0.6988 0.7405 0.7750 11 0.8116 0.8643 1.00 NA NA NA NA NA 12 9. log_fy_coff -0.527060 0.089949 0.6003 0.6347 0.6667 0.7060 0.7367 as you see there are only 9 columns in inp and the rest is read in in the following row(see row 7) I just don't understand why this is happening (using fill=T does not help either) Best, Luis On Tue, Mar 15, 2011 at 5:15 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 15, 2011, at 1:11 PM, rex.dw...@syngenta.com wrote: I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab - read.table(myfile, skip=2)[,1:5] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Luis Ridao Sent: Tuesday, March 15, 2011 11:53 AM To: r-help@r-project.org Subject: [R] How to read only specified columns from a data file R-help, I'm trying to read a data file with plenty of columns. I just need the first 5 but it doe not work by doing something like: mycols - rep(NULL, 430) ; mycols[c(1:4)] - NA read.table(myfile, skip=2, colClasses=mycols) I would have suggested: mycols - rep(NULL, 430) ; mycols[1:5] - rep(numeric, 5) inp - read.table(myfile, skip=2, colClasses=mycols) head(inp) -- David. Any suggestions? -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 set the starting value in lme
Daniel Kaschek daniel.kaschek at physik.uni-freiburg.de writes: Hi Jia, in order to test if the failing parameter estimation really has to do with wrong initial values, you could first simulate data with your mixed effects model. Just assume parameters, produce a data set with these parameters, add noise and look if you can estimate the parameters correctly with varying initial guesses. PS. Correlations between random effects close to 1.0 (or -1.0) are usually a sign of insufficient data. Further questions along these lines should probably go to the r-sig-mixed-models list ... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] model fine, predict gives an error
Yes, I did send an attachment - but I forgot that attachments might be removed, no? Here it is: http://rapidshare.com/files/452815636/drmData.RData Antje On 16 March 2011 12:19, Mike Marchywka marchy...@hotmail.com wrote: Date: Wed, 16 Mar 2011 08:17:49 +0100 From: niederlein-rs...@yahoo.de To: r-help@r-project.org Subject: Re: [R] model fine, predict gives an error Anybody who can help me with this issue? did you post your data? I was curious so I thought I may look but you need to post data so people can determine if they can produce and fix your problem. Any complaints about bad/ singular matricies are likely to depend on data being bad in some way. On 15 March 2011 14:15, Antje Niederlein wrote: Hi there, I try to model some dose response curves (drc-package). In most cases it is fine but now I got some data which produces me the following error: load(drmData.RData) library(drc) drmObj - drm(value ~ concentration, cmpd_respvar, data = drmData, fct = LL.4()) predict(drmObj) Error in chol.default(0.99 * object$fit$hessian + 0.01 * diag(dim(object$fit$hessian)[1])) : the leading minor of order 2 is not positive definite Error in resultMat[, 2] - estSE : replacement has length zero Can anybody explain to me why the calculation of the dose response model works but the prediction fails? Anything I can do in this case? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] No response after click the show Rules button on Tab Associate.
-Original Message- From: Graham Williams [mailto:graham.willi...@togaware.com] Sent: Saturday, March 12, 2011 7:19 PM To: Xiaobo Gu Cc: r-help@r-project.org Subject: Re: No response after click the show Rules button on Tab Associate. On 10 March 2011 02:07, Xiaobo Gu guxiaobo1...@gmail.com wrote: set transactions ...[35 item(s), 8 transaction(s)] done [0.00s]. That does not look right? I think it's because there are to few sample records, so all the rules are with 100% confidence Sorry - I think you might have misunderstood - have a look at the data - there are not 35 items - there are 8 items. There are 35 transactions. You have the wrong variables selected. You need to . Another Data Mining tool we use generates the following rules which Rattle does not show, Is that Rattle can't detect rules with multiple item output, or is that Rattle just does not show them on the interface? {Beef};{Cake,Apple};0.6;0.225 {Cake};{Beef,Apple};0.75;0.225 {Apple};{Beef,Cake};0.9;0.225 Be sure to make items your Target and tx_no your Ident rather than the other way around. Regards, Graham __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] table() reading problem
I have the following problem: I have some string with numbers like k. I want to have a table like the function table() gives. However I am not able to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem to work either. The levels keep bothering me. This is an example of the code: k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 x-table(k) dim(x) [1] 6 x[1] #But i only want the one 1 9 x-data.frame(x) x[1,1] #You are not allowed to use this one for example 3*x[1,1] is impossible [1] 1 Levels: 1 2 3 5 6 9 I hope anyone has an idea of using the table function without this inconvenience. I thought about writing a counter myself, but that seems complicated. Because I have to examine very large examples later on, I don't want to slow the calculations down if possible. Thanks for your help in advance. Frederique -- View this message in context: http://r.789695.n4.nabble.com/table-reading-problem-tp3381174p3381174.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] table() result issue
Dear reader, I have the following problem: I have some string with numbers like k. I want to have a table like the function table() gives. However I am not able to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem to work either. The levels keep bothering me. This is an example of the code: k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 x-table(k) dim(x) [1] 6 x[4] #But I only want to read the five 5 1 x-data.frame(x) x[4,1] #You are not allowed to use this five for example 3*x[4,1] is impossible [1] 5 Levels: 1 2 3 5 6 9 I hope anyone has an idea of using the table function without this inconvenience. I thought about writing a counter myself, but that seems complicated. Because I have to examine very large examples later on, I don't want to slow the calculations down if possible. Thanks for your help in advance. Frederique [[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] objects memory limits
Dear list, I'm a quite new user of R-project, and I've a doubt on objects memory: I open a new R session and the command memory.limits() gives me 1535 Mb of memory (the PC has 2 Gb RAM and 32 bit), I create an integer vector object of 2e8 size, so about 2e8*4 bytes (800Mb) of memory are allocated, a size smaller then memory available. But when I try to make the dataframe of this object it gives me Errore: cannot allocate vector of size 762.9 Mb. Why cannot I create a dataframe of an object with size smaller then memory available? I also tried to halve the object size but the situation doesn't changes. In R, is the memory of dataframe object smaller then vector object one? Are there different memory limits between objects? Is there a possibility to change limits? This is the command sequence: R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit) ls() character(0) memory.limit() [1] 1535 x=integer(2e8) object.size(x) 80024 bytes rm(x) ls() character(0) x=data.frame(integer(2e8)) Errore: cannot allocate vector of size 762.9 Mb Inoltre: Warning messages: 1: In as.data.frame.integer(x[[i]], optional = TRUE) : Reached total allocation of 1535Mb: see help(memory.size) 2: In as.data.frame.integer(x[[i]], optional = TRUE) : Reached total allocation of 1535Mb: see help(memory.size) 3: In as.data.frame.integer(x[[i]], optional = TRUE) : Reached total allocation of 1535Mb: see help(memory.size) 4: In as.data.frame.integer(x[[i]], optional = TRUE) : Reached total allocation of 1535Mb: see help(memory.size) x=data.frame(integer(1e8)) Errore: cannot allocate vector of size 381.5 Mb Inoltre: Warning messages: 1: In unlist(vlist, recursive = FALSE, use.names = FALSE) : Reached total allocation of 1535Mb: see help(memory.size) 2: In unlist(vlist, recursive = FALSE, use.names = FALSE) : Reached total allocation of 1535Mb: see help(memory.size) 3: In unlist(vlist, recursive = FALSE, use.names = FALSE) : Reached total allocation of 1535Mb: see help(memory.size) 4: In unlist(vlist, recursive = FALSE, use.names = FALSE) : Reached total allocation of 1535Mb: see help(memory.size) Many thanks. Kind regards. Dr. Francesca Bader University of Trieste Italy [[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] Aggregating dataset to means/day
Hi, I have a dataset with many observations some days while only one others. I would like to calculate a mean value per day and then do regression analysis on the means. This is what I have: YearDayTimeherring.density 200747 10.36 2.2 200747 11.50 1.1 200747 14.24 1.4 200766 9.352.5 This is what I want: YearDay herring.density 2007 47 1.57 2007 66 2.25 I would also might like to extract means between time 10-16 (h) so that YearDay herring.density 2007 471.25 Any idea on how to do this? I have tried means07-tapply(herring.density,Day,mean) Then I get means for every day, but means07 won't fit when plotted against days, because it is now shorter than Day. I also get a lot of NA values where there are only 1 observation that day... Help would be much appreciated! Cheers, Ole Andreas [[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] a question
Hi, I must seek a favour regarding of R project, can we make an application out of R. I mean a small application that automatically runs and do the estimation automatically. Because the things I do is that I copy codes from script to work book and then it runs and gives the output. can it be done automatically? I will appreaciate if you could answer. Best Regards Jeela [[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] proportional symbol map ggplot
Hello Scott, Thank you for the tips (I have posted the issue on the google group too), but there's nothing on these or other websites that gives an answer on our question. Following the traditional used rules of making a symbol plot, the used symbols should have the same proportions, based on area, then the values have. Unfortunately, this is not so in the plots we make with the code below (scale_area). Yours sincerely, Ann Frederix - Original Message - From: Scott Chamberlain To: Strategische Analyse CSD Hasselt Sent: Monday, March 14, 2011 4:05 PM Subject: Re: [R] proportional symbol map ggplot There is a ggplot2 google groups mailing list that you may get more appropriate help from: http://groups.google.com/group/ggplot2?pli=1 and the ggplot2 website is very helpful http://had.co.nz/ggplot2/ On Monday, March 14, 2011 at 9:41 AM, Strategische Analyse CSD Hasselt wrote: Hello, we want to plot a proportional symbol map with ggplot. Symbols' area should have the same proportions as the scaled variable. Hereby an example we found on http://www.r-bloggers.com/bubble-chart-by-using-ggplot2/ . In this example we see the proportions of the symbols' area are different from the proportions of the scaled variable: crime - read.csv(http://datasets.flowingdata.com/crimeRatesByState2008.csv;, header=TRUE, sep=\t) p - ggplot(crime, aes(murder,burglary,size=population, label=state)) p - p+geom_point(colour=red) +scale_area(to=c(1,20))+geom_text(size=3) Example: proportion population Pennsylvania/Tennessee= 2.003 proportion symbols' area Pennsylvania/Tennessee= +/- 2.50 proportion population California/Florida= 2.005 proportion symbols' area California/Florida= +/-2.25 What we would like is that the proportion of the symbols' area is also equal to 2.0. We see the same in the legend: proportion population 1.6e+07 / 4.0e+06 = 4.0 proportion symbols' area 1.6e+07 / 4.0e+06= +/-5.0 Thanks in advance! Ann Frederix Robbie Heremans __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Matrix building to remove for loops
Thanks, we're almost there. The 3rd statement needs to satisfy fi_2[r,c]-fi_2[c,r] where rc. On Tue, Mar 15, 2011 at 10:06 PM, Henrique Dallazuanna www...@gmail.comwrote: Try this: fi_2 - diag(1, i) fi_2[lower.tri(fi_2)] - 1 - runif(sum(lower.tri(fi_2))) ^ .5 fi_2[upper.tri(fi_2)] - fi_2[lower.tri(fi_2)] On Tue, Mar 15, 2011 at 7:51 PM, Brian Pellerin brianpatrickpelle...@gmail.com wrote: Hello R users, I would like to reduce the number of for loops in my code. I build these matrices (5 times). The main diagonal are 1s and the two sides along the main diagonal mirror each other as follows: i-5 fi-matrix(0,nrow=i,ncol=i)#floral inhibition matrix for(r in 1:i){ for(c in 1:i){ if(r==c){ fi[r,c]-1 }else if(rc){ fi[r,c]-1-runif(1)^.5 }else{ fi[r,c]-fi[c,r] } } } fi Any thoughts? Sincerely, Brian [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] Does R have a const object?
On 3/15/2011 2:23 PM, Uwe Ligges wrote: On 15.03.2011 15:53, xiagao1982 wrote: Hi, all, Does R have a const object concept like which is in C++ language? I want to set some data frames as constant to avoid being modified unintentionally. Thanks! Although there is almost never a No in R, the best short answer is: No. This is just the flexibility of R. I've just discovered a new class of geometries based on pi - 2.3 ?Constants -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] get information out of table() result
I have the following problem: I have some string with numbers like k. I want to have a table like the function table() gives. However I am not able to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem to work either. The levels keep bothering me. This is an example of the code: k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 x-table(k) dim(x) [1] 6 x[4] #But I only want to read the five 5 1 x-data.frame(x) x[4,1] #You are not allowed to use this five for example 3*x[4,1] is impossible [1] 5 Levels: 1 2 3 5 6 9 I hope anyone has an idea of using the table function without this inconvenience. I thought about writing a counter myself, but that seems complicated. Because I have to examine very large examples later on, I don't want to slow the calculations down if possible. Thanks for your help in advance. Frederique -- View this message in context: http://r.789695.n4.nabble.com/get-information-out-of-table-result-tp3381445p3381445.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] Scope of variable?
I know this is a very elementary question... I could not find a solution looking at old posts. I am unable to access a variable outside the scope of a for loop, even when the variable was defined before the loop: haar - function() { a = c(1.4560773, 2.3752412, 0.9798882, 3.0909252, 2.3986487, 1.8581543) for (i in c(1:100)) { m = matrix(rnorm(36)+1i*rnorm(36),6) qrm = qr(m) Q = qr.Q(qrm) eival = eigen(Q, only.values=T) ph = Arg(eival$values) v = Mod(ph) a = cat(a,v) } hist(a) } The hist command does not plot because a is null there. How do I plot a? I tried using assign(a, a, envir = .GlobalEnv) but that does not help either... Neither did using - Any help is most welcome. Ravi -- View this message in context: http://r.789695.n4.nabble.com/Scope-of-variable-tp3381485p3381485.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to read only specified columns from a data file
This is my code: mycols - rep(NULL, 430) ; mycols[c(1,3:5)] - rep(numeric, 4) ; mycols[c(2)] - rep(character,1) inp - read.table(myfile, skip=2, colClasses=mycols,fill=T) head(inp) Best, Luis On Wed, Mar 16, 2011 at 1:03 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 16, 2011, at 8:13 AM, Sarah Goslee wrote: read.table() looks at the first five rows when determining how many columns there are. If there are more columns in row 7 and you do not specify that in the read.table() command directly, they will be wrapped to the next row. This was discussed on the list within the last couple weeks. In addition to Sarah's comments, I also not that you did not include your code. I don't think it could have been identical to the code I suggested, which was in turn based on the code you had proposed. So ... what did you do to get that result? -- David. Sarah On Wed, Mar 16, 2011 at 7:54 AM, Luis Ridao luri...@gmail.com wrote: David, Thanks for your tip but it seems I'm having problems with the number of columns R manages to read in. Below it s an example of the data read in: inp[1:20,] V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1. log_fy_coff -1.007600 0.119520 1. NA NA NA 2 2. log_fy_coff -0.935010 0.112840 0.8896 1. NA NA 3 3. log_fy_coff -0.876260 0.107500 0.8219 0.8847 1. NA NA 4 4. log_fy_coff -0.683090 0.103030 0.7656 0.8143 0.8747 1. NA 5 5. log_fy_coff -0.623500 0.100980 0.7206 0.7636 0.8086 0.8764 1. 6 6. log_fy_coff -0.583330 0.098978 0.6819 0.7214 0.7615 0.8150 0.8762 7 1. NA NA NA NA NA NA 8 7. log_fy_coff -0.676790 0.096608 0.6521 0.6892 0.7254 0.7719 0.8148 9 0.8717 1. NA NA NA NA NA NA 10 8. log_fy_coff -0.696060 0.093761 0.6297 0.6654 0.6988 0.7405 0.7750 11 0.8116 0.8643 1.00 NA NA NA NA NA 12 9. log_fy_coff -0.527060 0.089949 0.6003 0.6347 0.6667 0.7060 0.7367 as you see there are only 9 columns in inp and the rest is read in in the following row(see row 7) I just don't understand why this is happening (using fill=T does not help either) Best, Luis On Tue, Mar 15, 2011 at 5:15 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 15, 2011, at 1:11 PM, rex.dw...@syngenta.com wrote: I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab - read.table(myfile, skip=2)[,1:5] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Luis Ridao Sent: Tuesday, March 15, 2011 11:53 AM To: r-help@r-project.org Subject: [R] How to read only specified columns from a data file R-help, I'm trying to read a data file with plenty of columns. I just need the first 5 but it doe not work by doing something like: mycols - rep(NULL, 430) ; mycols[c(1:4)] - NA read.table(myfile, skip=2, colClasses=mycols) I would have suggested: mycols - rep(NULL, 430) ; mycols[1:5] - rep(numeric, 5) inp - read.table(myfile, skip=2, colClasses=mycols) head(inp) -- David. Any suggestions? -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Questions on dividing lists and tapply
Awesome,that worked! Thanks. On Wed, Mar 16, 2011 at 6:46 AM, Henrique Dallazuanna www...@gmail.comwrote: Try this: mapply('/', l1, l2, SIMPLIFY = FALSE) and tapply(1:5, lapply(indxLi, as.numeric), sum) On Tue, Mar 15, 2011 at 6:06 PM, Rohit Pandey rohitpandey...@gmail.com wrote: Hello R community, I have two questions about using R. The first is about dividing each element of a list with another similar sized list. So, if the first list has two elements and so does the second, then the result should also be a list with two elements. For example, the inputs are: list(matrix(1:6,ncol=2),matrix(1:6,ncol=2))-l1 l2-list(1:3,2) I want to get a list, l3 with the first element being l1[[1]]/l2[[1]] and the second one, l1[[2]]/l2[[2]]. I had asked a similar question before and the solution using mapply works well for a list and a vector, but for two lists, it will return an array (and not a list). My second question is about the tapply function. tapply(1:5,list(c(1,1,2,2,3),c(1,2,1,1,3)),sum) will give me: 123 1 1 2 NA 2 7 NA NA 3 NA NA 5 The index here is a list: list(c(1,1,2,2,3),c(1,2,1,1,3)). However, if I get the same index list through one of the other apply functions (like by) for example, indxLi-by(rbind(c(1,1,2,2,3),c(1,2,1,1,3)),1:2,function(x){return(x)}) then the tapply no longer works with this list. tapply(1:5,indxLi,sum) gives me the error: Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? Is there a way to use the above list in the tapply function? Many thanks in advance, -- Thanks, Rohit Mob: 91 9819926213 [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Thanks, Rohit Mob: 91 9819926213 [[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] table() reading problem
It isn't entirely clear to me what you want. table() can function with many kinds of data, not just integers, so it returns a vector with names. For your case, with integer classes, you seem to possibly want: x - table(k) x - rbind(as.numeric(names(x)), as.numeric(x)) x [,1] [,2] [,3] [,4] [,5] [,6] [1,]123569 [2,]923111 but a more general approach is: x - table(k) x[1] 1 9 names(x[1]) [1] 1 as.numeric(names(x[1])) [1] 1 Sarah On Wed, Mar 16, 2011 at 5:20 AM, fre fre_stam...@hotmail.com wrote: I have the following problem: I have some string with numbers like k. I want to have a table like the function table() gives. However I am not able to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem to work either. The levels keep bothering me. This is an example of the code: k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 x-table(k) dim(x) [1] 6 x[1] #But i only want the one 1 9 x-data.frame(x) x[1,1] #You are not allowed to use this one for example 3*x[1,1] is impossible [1] 1 Levels: 1 2 3 5 6 9 I hope anyone has an idea of using the table function without this inconvenience. I thought about writing a counter myself, but that seems complicated. Because I have to examine very large examples later on, I don't want to slow the calculations down if possible. Thanks for your help in advance. Frederique -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Persistent storage between package invocations
No. First, please use path.expand(~) for this, and it does not necessarily mean the home directory (and in principle it might not expand at all). In practice I think it will always be *a* home directory, but on Windows there may be more than one (and watch out for local/roaming profile differences). Ok - I did remember that something like path.expand existed, I just couldn't find it. (And I always get confused by the difference between normalizePath and path.expand). Second, it need not be writeable, and so many package authors write rubbish in my home directory that I usually arrange it not be writeable to R test processes. So at a minimum I need to check if the home directory is writeable, and fail gracefully if not. What about using the registry on windows? Does R provide any convenience functions for adding/accessing entries? If you want something writeable across processes, use dirname(tempdir()) . I was really looking for options to be persistent between instances - i.e. so you decide once, and not need to be asked again. In a similar way, it would be nice if you could choose a CRAN mirror once and then not be asked again - and not need to know anything about how to set options during startup. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 read only specified columns from a data file
On Mar 16, 2011, at 8:13 AM, Sarah Goslee wrote: read.table() looks at the first five rows when determining how many columns there are. If there are more columns in row 7 and you do not specify that in the read.table() command directly, they will be wrapped to the next row. This was discussed on the list within the last couple weeks. In addition to Sarah's comments, I also not that you did not include your code. I don't think it could have been identical to the code I suggested, which was in turn based on the code you had proposed. So ... what did you do to get that result? -- David. Sarah On Wed, Mar 16, 2011 at 7:54 AM, Luis Ridao luri...@gmail.com wrote: David, Thanks for your tip but it seems I'm having problems with the number of columns R manages to read in. Below it s an example of the data read in: inp[1:20,] V1 V2V3 V4 V5 V6 V7 V8 V9 1 1. log_fy_coff -1.007600 0.119520 1. NA NA NA 2 2. log_fy_coff -0.935010 0.112840 0.8896 1. NA NA 3 3. log_fy_coff -0.876260 0.107500 0.8219 0.8847 1. NA NA 4 4. log_fy_coff -0.683090 0.103030 0.7656 0.8143 0.8747 1. NA 5 5. log_fy_coff -0.623500 0.100980 0.7206 0.7636 0.8086 0.8764 1. 6 6. log_fy_coff -0.583330 0.098978 0.6819 0.7214 0.7615 0.8150 0.8762 7 1.NA NA NA NA NA NA 8 7. log_fy_coff -0.676790 0.096608 0.6521 0.6892 0.7254 0.7719 0.8148 9 0.8717 1.NA NA NA NA NA NA 10 8. log_fy_coff -0.696060 0.093761 0.6297 0.6654 0.6988 0.7405 0.7750 11 0.8116 0.8643 1.00 NA NA NA NA NA 12 9. log_fy_coff -0.527060 0.089949 0.6003 0.6347 0.6667 0.7060 0.7367 as you see there are only 9 columns in inp and the rest is read in in the following row(see row 7) I just don't understand why this is happening (using fill=T does not help either) Best, Luis On Tue, Mar 15, 2011 at 5:15 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 15, 2011, at 1:11 PM, rex.dw...@syngenta.com wrote: I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab - read.table(myfile, skip=2)[,1:5] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Luis Ridao Sent: Tuesday, March 15, 2011 11:53 AM To: r-help@r-project.org Subject: [R] How to read only specified columns from a data file R-help, I'm trying to read a data file with plenty of columns. I just need the first 5 but it doe not work by doing something like: mycols - rep(NULL, 430) ; mycols[c(1:4)] - NA read.table(myfile, skip=2, colClasses=mycols) I would have suggested: mycols - rep(NULL, 430) ; mycols[1:5] - rep(numeric, 5) inp - read.table(myfile, skip=2, colClasses=mycols) head(inp) -- David. Any suggestions? -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Aggregating dataset to means/day
Hi, Look at ?aggregate. df - read.table(textConnection(Year Day Time herring.density 2007 47 10.36 2.2 2007 47 11.50 1.1 2007 47 14.24 1.4 2007 66 9.35 2.5), header=TRUE) You could do this: aggregate(herring.density~Year+Day, data=df, FUN=mean) And for the second question: aggregate(herring.density~Year+Day, data=df[df$Time=10 df$Time=16,], FUN=mean) Alternatively, you can use the function summaryBy in the doBy package. You use it exactly the same way as aggregate. You'll only get different column names. HTH, Ivan Le 3/16/2011 11:17, OA Fatnes a écrit : Hi, I have a dataset with many observations some days while only one others. I would like to calculate a mean value per day and then do regression analysis on the means. This is what I have: YearDayTimeherring.density 200747 10.36 2.2 200747 11.50 1.1 200747 14.24 1.4 200766 9.352.5 This is what I want: YearDay herring.density 2007 47 1.57 2007 66 2.25 I would also might like to extract means between time 10-16 (h) so that YearDay herring.density 2007 471.25 Any idea on how to do this? I have tried means07-tapply(herring.density,Day,mean) Then I get means for every day, but means07 won't fit when plotted against days, because it is now shorter than Day. I also get a lot of NA values where there are only 1 observation that day... Help would be much appreciated! Cheers, Ole Andreas [[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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] File Save As...
No, defaults are evaluated in the evaluation frame of the function. That's why you can use local variables in them, e.g. the way rgamma uses 1/rate as a default for scale. Oops, yes, I was getting confused with promises - non-missing arguments are promises evaluated in the parent frame. But the point isn't evaluation here: the point is the parsing. A function gets its source attribute when it is parsed, so getSrcFilename needs to be passed something that was parsed in the script. Still, it would be nice to have a function that, by default, would return the location of the calling script. You can also hack something together using sys.frames(), but it would be nice to have official R support for it. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 read only specified columns from a data file
On Wed, Mar 16, 2011 at 9:07 AM, Luis Ridao luri...@gmail.com wrote: This is my code: mycols - rep(NULL, 430) ; mycols[c(1,3:5)] - rep(numeric, 4) ; mycols[c(2)] - rep(character,1) rep(NULL, 430) does not give you a vector of length 430; it gives you a NULL vector, and at the end of this process mycols is of length 5. So read.table() does exactly what you've told it, and reads in the columns as calculated from the first five rows, and gives the first five columns the classes specified in mycols. According to the documentation for read.table(), you want NULL rather than NULL anyway, and rep(NULL, 430) should work as expected. Sarah inp - read.table(myfile, skip=2, colClasses=mycols,fill=T) head(inp) Best, Luis On Wed, Mar 16, 2011 at 1:03 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 16, 2011, at 8:13 AM, Sarah Goslee wrote: read.table() looks at the first five rows when determining how many columns there are. If there are more columns in row 7 and you do not specify that in the read.table() command directly, they will be wrapped to the next row. This was discussed on the list within the last couple weeks. In addition to Sarah's comments, I also not that you did not include your code. I don't think it could have been identical to the code I suggested, which was in turn based on the code you had proposed. So ... what did you do to get that result? -- David. Sarah On Wed, Mar 16, 2011 at 7:54 AM, Luis Ridao luri...@gmail.com wrote: David, Thanks for your tip but it seems I'm having problems with the number of columns R manages to read in. Below it s an example of the data read in: inp[1:20,] V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1. log_fy_coff -1.007600 0.119520 1. NA NA NA 2 2. log_fy_coff -0.935010 0.112840 0.8896 1. NA NA 3 3. log_fy_coff -0.876260 0.107500 0.8219 0.8847 1. NA NA 4 4. log_fy_coff -0.683090 0.103030 0.7656 0.8143 0.8747 1. NA 5 5. log_fy_coff -0.623500 0.100980 0.7206 0.7636 0.8086 0.8764 1. 6 6. log_fy_coff -0.583330 0.098978 0.6819 0.7214 0.7615 0.8150 0.8762 7 1. NA NA NA NA NA NA 8 7. log_fy_coff -0.676790 0.096608 0.6521 0.6892 0.7254 0.7719 0.8148 9 0.8717 1. NA NA NA NA NA NA 10 8. log_fy_coff -0.696060 0.093761 0.6297 0.6654 0.6988 0.7405 0.7750 11 0.8116 0.8643 1.00 NA NA NA NA NA 12 9. log_fy_coff -0.527060 0.089949 0.6003 0.6347 0.6667 0.7060 0.7367 as you see there are only 9 columns in inp and the rest is read in in the following row(see row 7) I just don't understand why this is happening (using fill=T does not help either) Best, Luis On Tue, Mar 15, 2011 at 5:15 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 15, 2011, at 1:11 PM, rex.dw...@syngenta.com wrote: I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab - read.table(myfile, skip=2)[,1:5] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Luis Ridao Sent: Tuesday, March 15, 2011 11:53 AM To: r-help@r-project.org Subject: [R] How to read only specified columns from a data file R-help, I'm trying to read a data file with plenty of columns. I just need the first 5 but it doe not work by doing something like: mycols - rep(NULL, 430) ; mycols[c(1:4)] - NA read.table(myfile, skip=2, colClasses=mycols) I would have suggested: mycols - rep(NULL, 430) ; mycols[1:5] - rep(numeric, 5) inp - read.table(myfile, skip=2, colClasses=mycols) head(inp) -- David. Any suggestions? -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] a question
What operating system are you working with? On windows, making it run by double clicking on it from explorer is not going to work. You will probably have to write a batch file that invokes Rterm or Rscript (see documentation for which you want to use). So if your script file is myscript.r, you could use Rterm myscript.r so long as the R executable directory is in the search path. On linux, make sure to start your script starts with #!/usr/bin/env Rscript, and make it executable (i.e. chmod +x myscript.r). Now it should run when you type ./myscript.r HTH, Jon -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 03/16/2011 06:18:09 AM: [image removed] [R] a question Jeela Mohammadian to: r-help 03/16/2011 08:59 AM Sent by: r-help-boun...@r-project.org Hi, I must seek a favour regarding of R project, can we make an application out of R. I mean a small application that automatically runs and do the estimation automatically. Because the things I do is that I copy codes from script to work book and then it runs and gives the output. can it be done automatically? I will appreaciate if you could answer. Best Regards Jeela [[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] get information out of table() result
table() returns a named vector. You need the names and the values. Or you could read my reply to one of the OTHER appearances of this email in my inbox; I think I've seen three, though I only replied to one and now this. It truly is unnecessary to send your query several times in quick succession, especially as many of the US potential respondents are just getting to their computers. Using different email addresses just makes us suspicious and less-inclined to be helpful. If you don't receive a response in a day or so, then it's acceptable to ask again, ideally with your further attempts to solve your own problem included. Most messages that never receive replies were so badly stated that nobody could figure out how to answer. But since you've now gotten two replies, that shouldn't be necessary. Sarah PS Unless this is some sort of Nabble glitch resending your message multiple times, in which case you should join the list the normal way. On Wed, Mar 16, 2011 at 7:23 AM, fre fre_stam...@hotmail.com wrote: I have the following problem: I have some string with numbers like k. I want to have a table like the function table() gives. However I am not able to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem to work either. The levels keep bothering me. This is an example of the code: k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 x-table(k) dim(x) [1] 6 x[4] #But I only want to read the five 5 1 x-data.frame(x) x[4,1] #You are not allowed to use this five for example 3*x[4,1] is impossible [1] 5 Levels: 1 2 3 5 6 9 I hope anyone has an idea of using the table function without this inconvenience. I thought about writing a counter myself, but that seems complicated. Because I have to examine very large examples later on, I don't want to slow the calculations down if possible. Thanks for your help in advance. Frederique -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
Michael Friendly wrote: This is just the flexibility of R. I've just discovered a new class of geometries based on pi - 2.3 ?Constants This is a must-fortune. Dieter -- View this message in context: http://r.789695.n4.nabble.com/Does-R-have-a-const-object-tp3356972p3381748.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] proportional symbol map ggplot
On Mon, Mar 14, 2011 at 9:41 AM, Strategische Analyse CSD Hasselt csd...@fedpolhasselt.be wrote: Hello, we want to plot a proportional symbol map with ggplot. Symbols' area should have the same proportions as the scaled variable. Hereby an example we found on http://www.r-bloggers.com/bubble-chart-by-using-ggplot2/ . In this example we see the proportions of the symbols' area are different from the proportions of the scaled variable: crime - read.csv(http://datasets.flowingdata.com/crimeRatesByState2008.csv;, header=TRUE, sep=\t) p - ggplot(crime, aes(murder,burglary,size=population, label=state)) p - p+geom_point(colour=red) +scale_area(to=c(1,20))+geom_text(size=3) Example: proportion population Pennsylvania/Tennessee= 2.003 proportion symbols' area Pennsylvania/Tennessee= +/- 2.50 proportion population California/Florida= 2.005 proportion symbols' area California/Florida= +/-2.25 What we would like is that the proportion of the symbols' area is also equal to 2.0. To do that you need to make sure the lower limit extends to 0 and the size of the smallest circle is also 0. I think something like scale_area(to=c(0, 20), limits = c(0, 4e7), breaks = 1:4 * 1e7) should suffice. It would also be helpful if you stated how you calculated the areas. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Scope of variable?
?cat cat prints text, and returns an invisible NULL. Also, it is general practice to assign values using '-' even inside of functions, for reasons detailed in ?- -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 03/16/2011 07:41:36 AM: [image removed] [R] Scope of variable? Ravi Kulkarni to: r-help 03/16/2011 09:07 AM Sent by: r-help-boun...@r-project.org I know this is a very elementary question... I could not find a solution looking at old posts. I am unable to access a variable outside the scope of a for loop, even when the variable was defined before the loop: haar - function() { a = c(1.4560773, 2.3752412, 0.9798882, 3.0909252, 2.3986487, 1.8581543) for (i in c(1:100)) { m = matrix(rnorm(36)+1i*rnorm(36),6) qrm = qr(m) Q = qr.Q(qrm) eival = eigen(Q, only.values=T) ph = Arg(eival$values) v = Mod(ph) a = cat(a,v) } hist(a) } The hist command does not plot because a is null there. How do I plot a? I tried using assign(a, a, envir = .GlobalEnv) but that does not help either... Neither did using - Any help is most welcome. Ravi -- View this message in context: http://r.789695.n4.nabble.com/Scope- of-variable-tp3381485p3381485.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] a question
On Mar 16, 2011, at 9:07 AM, Jonathan P Daily wrote: What operating system are you working with? On windows, making it run by double clicking on it from explorer is not going to work. You will probably have to write a batch file that invokes Rterm or Rscript (see documentation for which you want to use). So if your script file is myscript.r, you could use Rterm myscript.r so long as the R executable directory is in the search path. On linux, make sure to start your script starts with #!/usr/bin/env Rscript, and make it executable (i.e. chmod +x myscript.r). Now it should run when you type ./myscript.r There may be additional routes to success. Gabor Grothendieck has written a suite of batch files for Windows applications and you couldfollow the example code in building your particular clickable routine, and Dirk Eddelbeuttel has written Little R or more accurately `littler` which is designed to support non-interactive, special purpose R sessions. -- David. HTH, Jon -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 03/16/2011 06:18:09 AM: [image removed] [R] a question Jeela Mohammadian to: r-help 03/16/2011 08:59 AM Sent by: r-help-boun...@r-project.org Hi, I must seek a favour regarding of R project, can we make an application out of R. I mean a small application that automatically runs and do the estimation automatically. Because the things I do is that I copy codes from script to work book and then it runs and gives the output. can it be done automatically? I will appreaciate if you could answer. Best Regards Jeela David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Scope of variable?
Hi, Not sure what you are trying to do with the cat command, but cat returns an invisible NULL (as described in the doc), so a = cat(a,v) just sets a to NULL Martyn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ravi Kulkarni Sent: 16 March 2011 11:42 To: r-help@r-project.org Subject: [R] Scope of variable? I know this is a very elementary question... I could not find a solution looking at old posts. I am unable to access a variable outside the scope of a for loop, even when the variable was defined before the loop: haar - function() { a = c(1.4560773, 2.3752412, 0.9798882, 3.0909252, 2.3986487, 1.8581543) for (i in c(1:100)) { m = matrix(rnorm(36)+1i*rnorm(36),6) qrm = qr(m) Q = qr.Q(qrm) eival = eigen(Q, only.values=T) ph = Arg(eival$values) v = Mod(ph) a = cat(a,v) } hist(a) } The hist command does not plot because a is null there. How do I plot a? I tried using assign(a, a, envir = .GlobalEnv) but that does not help either... Neither did using - Any help is most welcome. Ravi -- View this message in context: http://r.789695.n4.nabble.com/Scope-of-variable-tp3381485p3381485.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. This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] making dataframes
Dear all, I have a dataframe which looks like this (dummy): date-c(jan, feb, mar, apr, may, june, july, aug,sep,oct,nov,dec) col1-c(8.2,5.4,4.3,4.1,3.1,2.5,1.1,4.5,3.2,1.9,7.8,6.5) col2-c(3.1,2.3,4.7,6.9,7.5,1.1,3.6,8.5,7.5,2.5,4.1,2.3) dum-data.frame(cbind(date,col1,col2)) dum date col1 col2 1 jan 8.2 3.1 2 feb 5.4 2.3 3 mar 4.3 4.7 4 apr 4.1 6.9 5 may 3.1 7.5 6 june 2.5 1.1 7 july 1.1 3.6 8 aug 4.5 8.5 9 sep 3.2 7.5 10 oct 1.9 2.5 11 nov 7.8 4.1 12 dec 6.5 2.3 I would like to convert this data.frame into something that looks like this: date rainfall category 1 jan 8.2 col1 2 feb 5.4 col1 3 mar 4.3 col1 4 apr 4.1 col1 5 may 3.1 col1 6 june 2.5 col1 7 july 1.1 col1 8 aug 4.5 col1 9 sep 3.2 col1 10 oct 1.9 col1 11 nov 7.8 col1 12 dec 6.5 col1 1 jan 3.1 col2 2 feb 2.3 col2 3 mar 4.7 col2 4 apr 6.9 col2 5 may 7.5 col2 6 june 1.1 col2 7 july3.6 col2 8 aug 8.5 col2 9 sep 7.5 col2 10 oct 2.5 col2 11 nov 4.1 col2 12 dec 2.3 col2 So the column-names become categories. The dataset is rather large with many columns and a lengthy date-string. Is there an easy way to do this? Thank you for your help, Kind regards, Saskia van Pelt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] making dataframes
require(reshape2) melt(dum, id = 1) On Wednesday, March 16, 2011 at 9:28 AM, pelt wrote: Dear all, I have a dataframe which looks like this (dummy): date-c(jan, feb, mar, apr, may, june, july, aug,sep,oct,nov,dec) col1-c(8.2,5.4,4.3,4.1,3.1,2.5,1.1,4.5,3.2,1.9,7.8,6.5) col2-c(3.1,2.3,4.7,6.9,7.5,1.1,3.6,8.5,7.5,2.5,4.1,2.3) dum-data.frame(cbind(date,col1,col2)) dum date col1 col2 1 jan 8.2 3.1 2 feb 5.4 2.3 3 mar 4.3 4.7 4 apr 4.1 6.9 5 may 3.1 7.5 6 june 2.5 1.1 7 july 1.1 3.6 8 aug 4.5 8.5 9 sep 3.2 7.5 10 oct 1.9 2.5 11 nov 7.8 4.1 12 dec 6.5 2.3 I would like to convert this data.frame into something that looks like this: date rainfall category 1 jan 8.2 col1 2 feb 5.4 col1 3 mar 4.3 col1 4 apr 4.1 col1 5 may 3.1 col1 6 june 2.5 col1 7 july 1.1 col1 8 aug 4.5 col1 9 sep 3.2 col1 10 oct 1.9 col1 11 nov 7.8 col1 12 dec 6.5 col1 1 jan 3.1 col2 2 feb 2.3 col2 3 mar 4.7 col2 4 apr 6.9 col2 5 may 7.5 col2 6 june 1.1 col2 7 july 3.6 col2 8 aug 8.5 col2 9 sep 7.5 col2 10 oct 2.5 col2 11 nov 4.1 col2 12 dec 2.3 col2 So the column-names become categories. The dataset is rather large with many columns and a lengthy date-string. Is there an easy way to do this? Thank you for your help, Kind regards, Saskia van Pelt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Scope of variable?
I think you meant: a - c(a, v) and not a - cat(a, v) On Wed, Mar 16, 2011 at 7:41 AM, Ravi Kulkarni ravi.k...@gmail.com wrote: I know this is a very elementary question... I could not find a solution looking at old posts. I am unable to access a variable outside the scope of a for loop, even when the variable was defined before the loop: haar - function() { a = c(1.4560773, 2.3752412, 0.9798882, 3.0909252, 2.3986487, 1.8581543) for (i in c(1:100)) { m = matrix(rnorm(36)+1i*rnorm(36),6) qrm = qr(m) Q = qr.Q(qrm) eival = eigen(Q, only.values=T) ph = Arg(eival$values) v = Mod(ph) a = cat(a,v) } hist(a) } The hist command does not plot because a is null there. How do I plot a? I tried using assign(a, a, envir = .GlobalEnv) but that does not help either... Neither did using - Any help is most welcome. Ravi -- View this message in context: http://r.789695.n4.nabble.com/Scope-of-variable-tp3381485p3381485.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'x' values must be positive.
b [1] 2 1 1 1 1 1 pie(b) Error in pie(b) : 'x' values must be positive. Can someone help me? And sorry i am an beginner -- View this message in context: http://r.789695.n4.nabble.com/x-values-must-be-positive-tp3381744p3381744.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] a question on sqldf's handling of missing value and factor
Dear Gabor: I did not have time to look at this issue these few days. Now I saw your investigation. I am very grateful that you quickly identify the root cause of this. It seems that a little caution needs to be exercised when applying sqldf to text file with large number of blanks (I have no control over how the client files are produced). thank you again for such a good solution! -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-sqldf-s-handling-of-missing-value-and-factor-tp3331007p3381867.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] instrumental variable as distance
Dear R-help , Here I try to explain the problem setting problem setting: we have four variables y: outcome x:exposure u:confounder z:Instrumental Variable ##we have instrumental variable as distance between centers and patients place, we have many ##centers for exp:three centers c1,c1,c3 and of course n patients. we aim to find out what would happen if a well defined group of patients were treated by provider c1 or c2 rather than provider B. ##Instrumental Variable: distance centers and patients ##i:number of patients ##If we have 3 centers c1,c2,c3 ##d1:distance between center c1 and patient (i) ##d2:distance between center c2 and patient (i) ##d3:distance between center c3 and patient (i) ##To generate distance d1,d2,d3 and choice nearest center n-10 wcoord-runif(n, min=0, max=1) hcoord-runif(n, min=0, max=1) ## (w1,h1),(w2,h2),(w3,h3) position of the 3 centers w1-0.9 h1-0.3 w2-0.2 h2-0.6 w3-0.7 h3-0.1 d1-sqrt((wcoord-w1)^2 +(hcoord-h1)^2) d2-sqrt((wcoord-w2)^2 +(hcoord-h2)^2) d3-sqrt((wcoord-w3)^2 +(hcoord-h3)^2) ##m:nearest center to patient m-pmin(d1,d2,d3) z-cbind(d1,d2,d3,m) d1d2 d3 m [1,] 0.87142373 0.2750814 0.89725053 0.27508142 [2,] 0.64285521 0.5237454 0.78950397 0.52374540 [3,] 0.06799528 0.7101305 0.30996833 0.06799528 [4,] 0.41636986 0.7966441 0.67216852 0.41636986 [5,] 0.29930080 0.7204538 0.02085061 0.02085061 ###Instrumental Variable as relative distance R1 R2 R3 R1-(d1/sum(m)) R2-(d2/sum(m)) R3-(d3/sum(m)) z-cbind(d1,d2,d3,m,R1,R2,R3) z d1d2d3 m R1 R2 [1,] 0.47371700 0.4791628 0.2733683 0.27336832 0.17374723 0.17574461 [2,] 0.04784215 0.7305729 0.2384407 0.04784215 0.01754727 0.26795537 [3,] 0.06238730 0.8167800 0.2820744 0.06238730 0.02288206 0.29957393 R3 [1,] 0.10026448 [2,] 0.08745394 [3,] 0.10345767 ##generate confounders as : u-rnorm(n,0,1) C:center choice I think we can use multinomial model as rmultinom(n, size, prob). I want to generate the data like that i d1 d2 d3 m R1 R2 R3 P1 P2 P3 C U Y1 Y2 Y3 Yi any one have text or notes about that? Yours Sincerely, Tamer -- View this message in context: http://r.789695.n4.nabble.com/instrumental-variable-as-distance-tp3381900p3381900.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] making dataframes
Try this: reshape(dum, direction = 'long', idvar = 'date', varying = list(c('col1', 'col2'))) On Wed, Mar 16, 2011 at 11:28 AM, pelt p...@knmi.nl wrote: Dear all, I have a dataframe which looks like this (dummy): date-c(jan, feb, mar, apr, may, june, july, aug,sep,oct,nov,dec) col1-c(8.2,5.4,4.3,4.1,3.1,2.5,1.1,4.5,3.2,1.9,7.8,6.5) col2-c(3.1,2.3,4.7,6.9,7.5,1.1,3.6,8.5,7.5,2.5,4.1,2.3) dum-data.frame(cbind(date,col1,col2)) dum date col1 col2 1 jan 8.2 3.1 2 feb 5.4 2.3 3 mar 4.3 4.7 4 apr 4.1 6.9 5 may 3.1 7.5 6 june 2.5 1.1 7 july 1.1 3.6 8 aug 4.5 8.5 9 sep 3.2 7.5 10 oct 1.9 2.5 11 nov 7.8 4.1 12 dec 6.5 2.3 I would like to convert this data.frame into something that looks like this: date rainfall category 1 jan 8.2 col1 2 feb 5.4 col1 3 mar 4.3 col1 4 apr 4.1 col1 5 may 3.1 col1 6 june 2.5 col1 7 july 1.1 col1 8 aug 4.5 col1 9 sep 3.2 col1 10 oct 1.9 col1 11 nov 7.8 col1 12 dec 6.5 col1 1 jan 3.1 col2 2 feb 2.3 col2 3 mar 4.7 col2 4 apr 6.9 col2 5 may 7.5 col2 6 june 1.1 col2 7 july 3.6 col2 8 aug 8.5 col2 9 sep 7.5 col2 10 oct 2.5 col2 11 nov 4.1 col2 12 dec 2.3 col2 So the column-names become categories. The dataset is rather large with many columns and a lengthy date-string. Is there an easy way to do this? Thank you for your help, Kind regards, Saskia van Pelt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'x' values must be positive.
It's ok, i solved it. It wasn't an integer, -- View this message in context: http://r.789695.n4.nabble.com/x-values-must-be-positive-tp3381744p3381859.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] 'x' values must be positive.
'b' appears to be characters. try pie(as.integer(b)) On Wed, Mar 16, 2011 at 9:28 AM, rens picca...@hotmail.com wrote: b [1] 2 1 1 1 1 1 pie(b) Error in pie(b) : 'x' values must be positive. Can someone help me? And sorry i am an beginner -- View this message in context: http://r.789695.n4.nabble.com/x-values-must-be-positive-tp3381744p3381744.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'x' values must be positive.
On 16-Mar-11 13:28:00, rens wrote: b [1] 2 1 1 1 1 1 pie(b) Error in pie(b) : 'x' values must be positive. Can someone help me? And sorry i am an beginner The problem (as indicated by the marks around each value) is that the variable 'b' is a vector of *characters*, not of numbers. Compare the result of x - c(2,1,1,1,1,1) x # [1] 2 1 1 1 1 1 pie(x) with the result of b - c(2,1,1,1,1,1) b # [1] 2 1 1 1 1 1 pie(b) # Error in pie(b) : 'x' values must be positive. and: typeof(x) # [1] double typeof(b) # [1] character The underlying important question is: How was the vector 'b' constructed? You clearly expect 'b' to be numeric, but it is of type character. The reason for this is what you need to find out! Hoping this helps, Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 16-Mar-11 Time: 14:48:47 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'x' values must be positive.
Hi, b is a character vector. Try as.numeric(b). You probably need to read some documentation about R. Ivan Le 3/16/2011 14:28, rens a écrit : b [1] 2 1 1 1 1 1 pie(b) Error in pie(b) : 'x' values must be positive. Can someone help me? And sorry i am an beginner -- View this message in context: http://r.789695.n4.nabble.com/x-values-must-be-positive-tp3381744p3381744.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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 read only specified columns from a data file
Thanks Sarah. Best, Luis On Wed, Mar 16, 2011 at 1:19 PM, Sarah Goslee sarah.gos...@gmail.com wrote: On Wed, Mar 16, 2011 at 9:07 AM, Luis Ridao luri...@gmail.com wrote: This is my code: mycols - rep(NULL, 430) ; mycols[c(1,3:5)] - rep(numeric, 4) ; mycols[c(2)] - rep(character,1) rep(NULL, 430) does not give you a vector of length 430; it gives you a NULL vector, and at the end of this process mycols is of length 5. So read.table() does exactly what you've told it, and reads in the columns as calculated from the first five rows, and gives the first five columns the classes specified in mycols. According to the documentation for read.table(), you want NULL rather than NULL anyway, and rep(NULL, 430) should work as expected. Sarah inp - read.table(myfile, skip=2, colClasses=mycols,fill=T) head(inp) Best, Luis On Wed, Mar 16, 2011 at 1:03 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 16, 2011, at 8:13 AM, Sarah Goslee wrote: read.table() looks at the first five rows when determining how many columns there are. If there are more columns in row 7 and you do not specify that in the read.table() command directly, they will be wrapped to the next row. This was discussed on the list within the last couple weeks. In addition to Sarah's comments, I also not that you did not include your code. I don't think it could have been identical to the code I suggested, which was in turn based on the code you had proposed. So ... what did you do to get that result? -- David. Sarah On Wed, Mar 16, 2011 at 7:54 AM, Luis Ridao luri...@gmail.com wrote: David, Thanks for your tip but it seems I'm having problems with the number of columns R manages to read in. Below it s an example of the data read in: inp[1:20,] V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1. log_fy_coff -1.007600 0.119520 1. NA NA NA 2 2. log_fy_coff -0.935010 0.112840 0.8896 1. NA NA 3 3. log_fy_coff -0.876260 0.107500 0.8219 0.8847 1. NA NA 4 4. log_fy_coff -0.683090 0.103030 0.7656 0.8143 0.8747 1. NA 5 5. log_fy_coff -0.623500 0.100980 0.7206 0.7636 0.8086 0.8764 1. 6 6. log_fy_coff -0.583330 0.098978 0.6819 0.7214 0.7615 0.8150 0.8762 7 1. NA NA NA NA NA NA 8 7. log_fy_coff -0.676790 0.096608 0.6521 0.6892 0.7254 0.7719 0.8148 9 0.8717 1. NA NA NA NA NA NA 10 8. log_fy_coff -0.696060 0.093761 0.6297 0.6654 0.6988 0.7405 0.7750 11 0.8116 0.8643 1.00 NA NA NA NA NA 12 9. log_fy_coff -0.527060 0.089949 0.6003 0.6347 0.6667 0.7060 0.7367 as you see there are only 9 columns in inp and the rest is read in in the following row(see row 7) I just don't understand why this is happening (using fill=T does not help either) Best, Luis On Tue, Mar 15, 2011 at 5:15 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 15, 2011, at 1:11 PM, rex.dw...@syngenta.com wrote: I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab - read.table(myfile, skip=2)[,1:5] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Luis Ridao Sent: Tuesday, March 15, 2011 11:53 AM To: r-help@r-project.org Subject: [R] How to read only specified columns from a data file R-help, I'm trying to read a data file with plenty of columns. I just need the first 5 but it doe not work by doing something like: mycols - rep(NULL, 430) ; mycols[c(1:4)] - NA read.table(myfile, skip=2, colClasses=mycols) I would have suggested: mycols - rep(NULL, 430) ; mycols[1:5] - rep(numeric, 5) inp - read.table(myfile, skip=2, colClasses=mycols) head(inp) -- David. Any suggestions? -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
On 16/03/11 13:04, Michael Friendly wrote: On 3/15/2011 2:23 PM, Uwe Ligges wrote: On 15.03.2011 15:53, xiagao1982 wrote: Hi, all, Does R have a const object concept like which is in C++ language? I want to set some data frames as constant to avoid being modified unintentionally. Thanks! Although there is almost never a No in R, the best short answer is: No. This is just the flexibility of R. I've just discovered a new class of geometries based on pi - 2.3 ?Constants Yes, but you can still print(base::pi) and rm(pi) to get back to our flat world, and you can't assign(pi, 4, pos = package:base) Error in assign(pi, 4, pos = package:base) : cannot change value of locked binding for 'pi' Just a feature of the search path. Morale: if you want base::pi, write base::pi. Allan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in X11
Dear all, I've installed R-2.12.2 on a server with Suse 10 linux OS. When I try to create images I got this error: png(filename=hola.png) Error in X11(paste(png::, filename, sep = ), width, height, pointsize, : unable to start device PNG In addition: Warning message: In png(filename = hola.png) : no png support in this version of R It happens the same with jpeg. I would really appreciated if anyone could help. Thanks in advance. Regards, Núria [[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] export list to csv
Hi everybody. I have list like this: l-list(data.frame(q1=c(1,2,check),q2=c(3,check,5)), data.frame(q1=c(check,1),q2=c(4,5))) names(l)-c(A,B) rownames(l[[1]])-c(aa,bb,cc) rownames(l[[2]])-c(aa,bb) Every object has the same number of columns but different number of rows. Does anyone know if it is possible to export such kind of list, into one csv file, and keeping all the names? Thanks in advance Andrija [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] table() result issue
k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 names(table(k)) [1] 1 2 3 5 6 9 as.numeric(names(table(k))) [1] 1 2 3 5 6 9 x - table(k) as.numeric(names(table(k)))[4] [1] 5 You can always save the (numeric version of the) names as an object, too. Does that help? Dennis 2011/3/16 Frédérique Kuiper fre_stam...@hotmail.com Dear reader, I have the following problem: I have some string with numbers like k. I want to have a table like the function table() gives. However I am not able to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem to work either. The levels keep bothering me. This is an example of the code: k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 x-table(k) dim(x) [1] 6 x[4] #But I only want to read the five 5 1 x-data.frame(x) x[4,1] #You are not allowed to use this five for example 3*x[4,1] is impossible [1] 5 Levels: 1 2 3 5 6 9 I hope anyone has an idea of using the table function without this inconvenience. I thought about writing a counter myself, but that seems complicated. Because I have to examine very large examples later on, I don't want to slow the calculations down if possible. Thanks for your help in advance. Frederique [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Data frame loop
R users, I am trying to use a numeric vector to extract rows from a data frame. I want to extract two rows per unique WEEK (27 weeks) based on variable DOW_NUM by using pairs of vector (s3) elements in the order they appear. For example, vector initial elements 7 and 5 will be used to extract row numbers 2 and 4 from the dataframe, vector elements 4 and 5 will extract rows 8 and 9 from the data frame, and so on. The loop below will extract two rows per week when a given pair of indices are input for s3, however, I have been unsuccessful in coding the indices such that they generate the sequence I need. Also, if anyone knows a way to accomplish this without using loops I would be very interested in learning how to do so. Thank you, Mike DF - data.frame(DATE=numeric(0),DOW=character(0),DOW_NUM=numeric(0),WEEK=numeric(0)) for (j in 1:max(DF1WD$WEEK)) { DF - rbind(DF, DF1WD[DF1WD$DOW_NUM %in% s3[ : ] DF1WD$WEEK %in% j, ]) } WK1 - DF1WD[DF1WD$DOW_NUM %in% s3[1:2] DF1WD$WEEK %in% 1, ] WK2 - DF1WD[DF1WD$DOW_NUM %in% s3[3:4] DF1WD$WEEK %in% 2, ] WK3 - DF1WD[DF1WD$DOW_NUM %in% s3[5:6] DF1WD$WEEK %in% 3, ] . . . WK27- DF1WD[DF1WD$DOW_NUM %in% s3[53:54] DF1WD$WEEK %in% 27, ] SCHEDULE - rbind(WK1,WK2,WK3,...,WK27) DF1WD - structure(list(DATE = structure(c(15461, 15462, 15463, 15464, 15467, 15468, 15469, 15470, 15471, 15474, 15475, 15476, 15477, 15478, 15481, 15482, 15483, 15484, 15485, 15488, 15489, 15490, 15491, 15492, 15495, 15496, 15497, 15498, 15499, 15502, 15503, 15504, 15505, 15506, 15509, 15510, 15511, 15512, 15513, 15516, 15517, 15518, 15519, 15520, 15523, 15524, 15525, 15526, 15527, 15530, 15531, 15532, 15533, 15534, 15537, 15538, 15539, 15540, 15541, 15544, 15545, 15546, 15547, 15548, 15551, 15552, 15553, 15554, 1, 15558, 15559, 15560, 15561, 15562, 15565, 15566, 15567, 15568, 15569, 15572, 15573, 15574, 15575, 15576, 15579, 15580, 15581, 15582, 15583, 15586, 15587, 15588, 15589, 15590, 15593, 15594, 15595, 15596, 15597, 15600, 15601, 15602, 15603, 15604, 15607, 15608, 15609, 15610, 15611, 15614, 15615, 15616, 15617, 15618, 15621, 15622, 15623, 15624, 15625, 15628, 15629, 15630, 15631, 15632, 15635, 15636, 15637, 15638, 15639, 15642, 15643, 15644), class = Date), DOW = c(Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon, Tue, Wed), DOW_NUM = c(4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5), WEEK = c(1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 27, 27, 27)), .Names = c(DATE, DOW, DOW_NUM, WEEK), row.names = c(1L, 2L, 3L, 4L, 7L, 8L, 9L, 10L, 11L, 14L, 15L, 16L, 17L, 18L, 21L, 22L, 23L, 24L, 25L, 28L, 29L, 30L, 31L, 32L, 35L, 36L, 37L, 38L, 39L, 42L, 43L, 44L, 45L, 46L, 49L, 50L, 51L, 52L, 53L, 56L, 57L, 58L, 59L, 60L, 63L, 64L, 65L, 66L, 67L, 70L, 71L, 72L, 73L, 74L, 77L, 78L, 79L, 80L, 81L, 84L, 85L, 86L, 87L, 88L, 91L, 92L, 93L, 94L, 95L, 98L, 99L, 100L, 101L, 102L, 105L, 106L, 107L, 108L, 109L, 112L, 113L, 114L, 115L, 116L, 119L, 120L, 121L, 122L, 123L, 126L, 127L, 128L, 129L, 130L, 133L, 134L, 135L, 136L, 137L, 140L, 141L, 142L, 143L, 144L, 147L, 148L, 149L, 150L, 151L, 154L, 155L, 156L, 157L, 158L, 161L, 162L, 163L, 164L, 165L, 168L, 169L, 170L, 171L, 172L, 175L, 176L, 177L, 178L, 179L, 182L, 183L, 184L), class = data.frame) s3 - c(7, 5, 4, 5, 7, 6, 3, 5, 3, 6, 7, 4, 6, 5, 7, 3, 4, 5, 3, 7, 4, 6, 5, 6, 3, 7, 4, 7, 4, 6, 3, 5, 7, 3, 6, 4, 5, 7, 3, 4, 5, 6, 4, 6, 3, 5, 7, 5, 4, 7, 6, 3, 5, 4) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] export list to csv
Use dput: dput(l, file = l_str.txt) Then, to read again: l - dget(file = 'l_str.txt') On Wed, Mar 16, 2011 at 11:55 AM, andrija djurovic djandr...@gmail.com wrote: Hi everybody. I have list like this: l-list(data.frame(q1=c(1,2,check),q2=c(3,check,5)), data.frame(q1=c(check,1),q2=c(4,5))) names(l)-c(A,B) rownames(l[[1]])-c(aa,bb,cc) rownames(l[[2]])-c(aa,bb) Every object has the same number of columns but different number of rows. Does anyone know if it is possible to export such kind of list, into one csv file, and keeping all the names? Thanks in advance Andrija [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
On Wed, Mar 16, 2011 at 10:54 AM, Allan Engelhardt all...@cybaea.com wrote: On 16/03/11 13:04, Michael Friendly wrote: On 3/15/2011 2:23 PM, Uwe Ligges wrote: On 15.03.2011 15:53, xiagao1982 wrote: Hi, all, Does R have a const object concept like which is in C++ language? I want to set some data frames as constant to avoid being modified unintentionally. Thanks! Although there is almost never a No in R, the best short answer is: No. This is just the flexibility of R. I've just discovered a new class of geometries based on pi - 2.3 ?Constants Yes, but you can still print(base::pi) and rm(pi) to get back to our flat world, and you can't assign(pi, 4, pos = package:base) Error in assign(pi, 4, pos = package:base) : cannot change value of locked binding for 'pi' Just a feature of the search path. Morale: if you want base::pi, write base::pi. Try this: old.pi - pi assignInNamespace(pi, 2.3, ns = base) pi [1] 2.3 base::pi [1] 2.3 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] calculating AUCs for each of the 1000 boot strap samples
Hallo, I modified a code given by Andrija, a contributor in the list to achieve two objectives: create 1000 samples from a list of 207 samples with each of the samples cointaining 20 good and 20 bad. THis i have achievedcalcuate AUC each of the 1000 samples, this i get an error. Please see the code below and assist me. data-data.frame(id=1:(165+42),main_samp$SCORE, x=rep(c(BAD,GOOD),c(42,165))) f-function(x) { + str.sample-list() + for (i in 1:length(levels(x$x))) + { + str.sample[[i]]-x[x$x==levels(x$x)[i] ,][sample(tapply(x$x,x$x,length)[i],20,rep=T),] + } + strat.sample-do.call(rbind,str.sample) + return(strat.sample$main_samp.SCORE) + } f(data) [1] 706 633 443 843 756 743 730 843 706 730 606 743 768 768 743 763 608 730 743 743 530 813 813 831 793 900 793 693 900 738 706 831 [33] 818 758 718 831 768 638 770 738 repl-list() auc-list() for(i in 1:1000) + { + repl[[i]]-f(data) + auc[[i]]-colAUC(repl[[i]],rep(c(BAD,GOOD)),plotROC=FALSE,alg=ROC) + } Error in colAUC(repl[[i]], rep(c(BAD, GOOD)), plotROC = FALSE, alg = ROC) : colAUC: length(y) and nrow(X) must be the same Thanks alotTaby [[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] export list to csv
Soryy, I didn't explain well what I want. I would like to have a table in csv on txt file like this: $A q1q2 aa 1 3 bb 2 check cc check 5 $B q1 q2 aa check 4 bb 1 5 The same as write.csv of any data frame. On Wed, Mar 16, 2011 at 4:03 PM, Henrique Dallazuanna www...@gmail.comwrote: Use dput: dput(l, file = l_str.txt) Then, to read again: l - dget(file = 'l_str.txt') On Wed, Mar 16, 2011 at 11:55 AM, andrija djurovic djandr...@gmail.com wrote: Hi everybody. I have list like this: l-list(data.frame(q1=c(1,2,check),q2=c(3,check,5)), data.frame(q1=c(check,1),q2=c(4,5))) names(l)-c(A,B) rownames(l[[1]])-c(aa,bb,cc) rownames(l[[2]])-c(aa,bb) Every object has the same number of columns but different number of rows. Does anyone know if it is possible to export such kind of list, into one csv file, and keeping all the names? Thanks in advance Andrija [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in X11
nqueralt at clinic.ub.es writes: I've installed R-2.12.2 on a server with Suse 10 linux OS. When I try to create images I got this error: png(filename=hola.png) Error in X11(paste(png::, filename, sep = ), width, height, pointsize, : FAQ 7.19: http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html#How-do-I-produce-PNG-graphics-in-batch-mode_003f __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Re; Fitting a Beta distribution
I want to fit some p-values to a beta distribution. But the problem is some of the values have 0s and 1's. I am getting an error if I use the MASS function to do this. Is there anyway to get around this? -- Thanks, Jim. [[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] Does R have a const object?
On 16/03/11 15:04, Gabor Grothendieck wrote: On Wed, Mar 16, 2011 at 10:54 AM, Allan Engelhardtall...@cybaea.com wrote: [...] Yes, but you can still print(base::pi) and rm(pi) to get back to our flat world, and you can't assign(pi, 4, pos = package:base) Error in assign(pi, 4, pos = package:base) : cannot change value of locked binding for 'pi' Just a feature of the search path. Morale: if you want base::pi, write base::pi. Try this: old.pi- pi assignInNamespace(pi, 2.3, ns = base) pi [1] 2.3 base::pi [1] 2.3 Ah! assignInNamespace does an unlockBinding under the covers which obviously is Evil(tm). The answer clearly is to do assignInNamespace(unlockBinding, function (...) {warning(be safe);}, ns=base) in your .Rprofile! Let's Keep R Safe, Folks! Allan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Singularity problem
Dear R, If I have remembered correctly, a square matrix is singular if and only if its determinant is zero. I am a bit confused by the following code error. Can someone give me a hint? a - matrix(c(1e20,1e2,1e3,1e3),2) det(a) [1] 1e+23 solve(a) Error in solve.default(a) : system is computationally singular: reciprocal condition number = 1e-17 Thanks in advance! Feng -- Feng Li Department of Statistics Stockholm University 106 91 Stockholm, Sweden http://feng.li/ [[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] export list to csv
Hi, You could try this (others surely have better solutions): out_file - file(file.csv, open=a) #creates a file in append mode for (i in seq_along(l)){ write.table(names(l)[i], file=out_file, sep=,, dec=., quote=FALSE, col.names=FALSE, row.names=FALSE) #writes the name of the list elements (A, B, etc) write.table(l[[i]], file=out_file, sep=,, dec=., quote=FALSE, col.names=NA, row.names=TRUE) #writes the data.frames } close(out_file) #close connection to file.csv HTH, Ivan Le 3/16/2011 16:14, andrija djurovic a écrit : Soryy, I didn't explain well what I want. I would like to have a table in csv on txt file like this: $A q1q2 aa 1 3 bb 2 check cc check 5 $B q1 q2 aa check 4 bb 1 5 The same as write.csv of any data frame. On Wed, Mar 16, 2011 at 4:03 PM, Henrique Dallazuannawww...@gmail.comwrote: Use dput: dput(l, file = l_str.txt) Then, to read again: l- dget(file = 'l_str.txt') On Wed, Mar 16, 2011 at 11:55 AM, andrija djurovicdjandr...@gmail.com wrote: Hi everybody. I have list like this: l-list(data.frame(q1=c(1,2,check),q2=c(3,check,5)), data.frame(q1=c(check,1),q2=c(4,5))) names(l)-c(A,B) rownames(l[[1]])-c(aa,bb,cc) rownames(l[[2]])-c(aa,bb) Every object has the same number of columns but different number of rows. Does anyone know if it is possible to export such kind of list, into one csv file, and keeping all the names? Thanks in advance Andrija [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
Just as a heads-up: it is likely that unlocking the bindings in base for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly more, will start signaling warnings in the near future. Doing this may be useful at times for debugging but it can mess up assumptions others make about how things in base work and so reduce code reliability. Best, luke On Wed, 16 Mar 2011, Allan Engelhardt wrote: On 16/03/11 15:04, Gabor Grothendieck wrote: On Wed, Mar 16, 2011 at 10:54 AM, Allan Engelhardtall...@cybaea.com wrote: [...] Yes, but you can still print(base::pi) and rm(pi) to get back to our flat world, and you can't assign(pi, 4, pos = package:base) Error in assign(pi, 4, pos = package:base) : cannot change value of locked binding for 'pi' Just a feature of the search path. Morale: if you want base::pi, write base::pi. Try this: old.pi- pi assignInNamespace(pi, 2.3, ns = base) pi [1] 2.3 base::pi [1] 2.3 Ah! assignInNamespace does an unlockBinding under the covers which obviously is Evil(tm). The answer clearly is to do assignInNamespace(unlockBinding, function (...) {warning(be safe);}, ns=base) in your .Rprofile! Let's Keep R Safe, Folks! Allan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Luke Tierney Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: l...@stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
On Wed, Mar 16, 2011 at 6:04 AM, Michael Friendly frien...@yorku.ca wrote: On 3/15/2011 2:23 PM, Uwe Ligges wrote: On 15.03.2011 15:53, xiagao1982 wrote: Hi, all, Does R have a const object concept like which is in C++ language? I want to set some data frames as constant to avoid being modified unintentionally. Thanks! Although there is almost never a No in R, the best short answer is: No. This is just the flexibility of R. I've just discovered a new class of geometries based on pi - 2.3 ?Constants Nope, that should be: pi - 3.2 'This is Indiana House Bill No. 246, 1897, known as the Indiana pi bill. Towards the end of section 2 it says plainly that The ratio of the diameter and circumference is as five-fourths to four, which means pi is 3.2. The section goes on the criticize [...] past values of pi as wholly wanting and misleading.' http://www.agecon.purdue.edu/crd/localgov/second%20level%20pages/indiana_pi_bill.htm /Henrik -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
On Wed, Mar 16, 2011 at 11:49 AM, luke-tier...@uiowa.edu wrote: Just as a heads-up: it is likely that unlocking the bindings in base for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly more, will start signaling warnings in the near future. Doing this may be useful at times for debugging but it can mess up assumptions others make about how things in base work and so reduce code reliability. That seems ok for pi, T and F but if its extended to everything in base then I would hope there is a nowarn= argument or other easy way to avoid the warning message. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
On Wed, 16 Mar 2011, Gabor Grothendieck wrote: On Wed, Mar 16, 2011 at 11:49 AM, luke-tier...@uiowa.edu wrote: Just as a heads-up: it is likely that unlocking the bindings in base for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly more, will start signaling warnings in the near future. Doing this may be useful at times for debugging but it can mess up assumptions others make about how things in base work and so reduce code reliability. That seems ok for pi, T and F but if its extended to everything in base then I would hope there is a nowarn= argument or other easy way to avoid the warning message. That would defeat the purpose. Unlocking things in base may be useful for experimenting or debugging but it is not a good idea otherwise. [? assignInNamespace could be more explicit on htis and will be soon.] There is a reason we lock bindings in the first place, and that is so one can assume that these bindings have certain values and certain properties and one can write reliable programs against these assumptions. Best, luke -- Luke Tierney Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: l...@stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Re; Fitting a Beta distribution
If yoy write out the likelihood equations for an independent sample size n from the beta(a,b) distribution: L \propto \prod_i dbeta(y_i,a,b) log(L) = constant + \sum_i dbeta(y_i,a,b,log=TRUE) log(L)= constant + \sum_i (a-1) log(y_i) + (b-i) log(1-y_i) you see that your problem comes from trying to calculate log(0.0). So one pragmatic approach will be to replace your measured 0's by some epsilon and your measured 1's by (1-epsilon), and maybe do some sensitivity analysis for the choice of epsilon. If you have exactly one measured y_i=0.0, and the rest in (0,1), then the log-likelihood will be constant + (a-1)*(-\infty) + ordinary (finite) log-likelihood, suggesting that maximization will choose a=1 to avoid the -\infty term. This indicates that choosing the epsilon too small will give a huge bias in direction of estimating a=1. Kjetil On Wed, Mar 16, 2011 at 11:14 AM, Jim Silverton jim.silver...@gmail.com wrote: I want to fit some p-values to a beta distribution. But the problem is some of the values have 0s and 1's. I am getting an error if I use the MASS function to do this. Is there anyway to get around this? -- Thanks, Jim. [[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] Newbie-ish question on iteratively applying function to dataframe
Brilliant - that was really useful! On Tue, Mar 15, 2011 at 3:46 PM, Ista Zahn iz...@psych.rochester.edu wrote: Hi Claus, On Tue, Mar 15, 2011 at 9:33 AM, Claus O'Rourke claus.orou...@gmail.com wrote: Hi, I am trying to recursively apply a function to a selection of columns in a dataframe. I've had a look around and from what I have read, I should be using some version of the apply function, but I'm really having some headaches with it. I would just do it in a loop (see below) Let me be more specific with an example. Say I have a data frame similar to the following A x y z r1 r2 r3 r4 0.1 0.2 0.1 ... 0.1 0.3 ... 0.2 ... i.e., a number of columns, each of the same length, and all containing real numbers. Of these columns, I want to model one variable, say A, as a function of other variables, say x, y, z, and any one of my r1, r2, r3, ... variables. i.e., I want to model A ~ x + y + z + r1 A ~ x + y + z + r2 A ~ x + y + z + rn But where the number of 'r' variables I will have will be large, and I don't know the specific number of these variables in advance. My question first is, how can I select all the columns in a dataframe that have a heading that matches a string pattern? ?grep And then related to this, what would be the best way of repeatedly applying my modelling function to the result? Well, I don't know about the best way. But why not just set.seed(21 ) dat - as.data.frame(matrix(rnorm(10 ), ncol=100, dimnames=list (1:1000, c(A, x, y, z, paste(r, 1:96, sep= ) mods - list() for(i in grep(r, names(dat ), value=TRUE)) { mods[[i]] - lm(as.formula(paste(A ~ x + y + z + , i)), data=dat ) } Note that you should be cautious about making any inferences based on this kind of method. In the example above 9 r variables are significant at the .05 level, even though the data was generated randomly: sort(sapply(mods, function(x) coef(summary(x))[5, 4])) Best, Ista Many thanks for any help for this occasional R armature. Claus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Re; Fitting a Beta distribution
Jim Silverton jim.silverton at gmail.com writes: I want to fit some p-values to a beta distribution. But the problem is some of the values have 0s and 1's. I am getting an error if I use the MASS function to do this. Is there anyway to get around this? The probability *density* of an exact 0 or 1 can be infinite (as you can see by experimenting with dbeta() a bit) -- although it may (?) require shape parameters 1, I don't remember. The general practice (see e.g. Smithson and Verkuilen better lemon squeezer paper), as far as I know, is to take something like (x+e)/(1+2*e) where e is a small fudge factor (that can be justified e.g. on Bayesian grounds ...) Presumably if these are p-values then they aren't *exactly* 0/1, just very close to it ... ? Would be interested to hear what others had to say. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Singularity problem
Numeric underflow. Try qr.solve(a) Allan On 16/03/11 15:28, Feng Li wrote: Dear R, If I have remembered correctly, a square matrix is singular if and only if its determinant is zero. I am a bit confused by the following code error. Can someone give me a hint? a- matrix(c(1e20,1e2,1e3,1e3),2) det(a) [1] 1e+23 solve(a) Error in solve.default(a) : system is computationally singular: reciprocal condition number = 1e-17 Thanks in advance! Feng __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
On Wed, Mar 16, 2011 at 12:16 PM, luke-tier...@uiowa.edu wrote: On Wed, 16 Mar 2011, Gabor Grothendieck wrote: On Wed, Mar 16, 2011 at 11:49 AM, luke-tier...@uiowa.edu wrote: Just as a heads-up: it is likely that unlocking the bindings in base for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly more, will start signaling warnings in the near future. Doing this may be useful at times for debugging but it can mess up assumptions others make about how things in base work and so reduce code reliability. That seems ok for pi, T and F but if its extended to everything in base then I would hope there is a nowarn= argument or other easy way to avoid the warning message. That would defeat the purpose. Unlocking things in base may be useful for experimenting or debugging but it is not a good idea otherwise. [? assignInNamespace could be more explicit on htis and will be soon.] There is a reason we lock bindings in the first place, and that is so one can assume that these bindings have certain values and certain properties and one can write reliable programs against these assumptions. Its useful for being able to set defaults for arguments that do not have defaults. That cannot break existing programs. Note that if this feature is implemented in a heavy handed manner it could cause havoc as at least one package that is depended upon by literally dozens of other packages (and possibly hundreds if one takes into account dependencies of dependencies) cannot function. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Does R have a const object?
On Wed, Mar 16, 2011 at 4:16 PM, luke-tier...@uiowa.edu wrote: That would defeat the purpose. Unlocking things in base may be useful for experimenting or debugging but it is not a good idea otherwise. You are making experimenting in R more awkward? Then I'm throwing That would defeat the purpose straight back at you. I remember when R was all about the experimenting. Of course it was called Splus back then and was only available in grainy black-and-white... Oh well, I guess its one small step towards becoming a proper grown-up language. Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
On Wed, 16 Mar 2011, Barry Rowlingson wrote: On Wed, Mar 16, 2011 at 4:16 PM, luke-tier...@uiowa.edu wrote: That would defeat the purpose. Unlocking things in base may be useful for experimenting or debugging but it is not a good idea otherwise. You are making experimenting in R more awkward? Then I'm throwing That would defeat the purpose straight back at you. I remember when R was all about the experimenting. Of course it was called Splus back then and was only available in grainy black-and-white... And how does seeing a warning reminding you that you are dong something experimental that might break things make experimenting more awkward? Since you wouldn't like to see such warnings in production code this does make doing something in production code that can break other people's code more awkward. As I do actually care bout whether my code works or not I'm fine with that. luke Oh well, I guess its one small step towards becoming a proper grown-up language. Barry -- Luke Tierney Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: l...@stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Singularity problem
On Wed, Mar 16, 2011 at 8:28 AM, Feng Li m...@feng.li wrote: Dear R, If I have remembered correctly, a square matrix is singular if and only if its determinant is zero. I am a bit confused by the following code error. Can someone give me a hint? a - matrix(c(1e20,1e2,1e3,1e3),2) det(a) [1] 1e+23 solve(a) Error in solve.default(a) : system is computationally singular: reciprocal condition number = 1e-17 You are right, a matrix is mathematically singular iff its determinant is zero. However, this condition is useless in practice since in practice one cares about the matrix being computationally singular, i.e. so close to singular that it cannot be inverted using the standard precision of real numbers. And that's what your matrix is (and the error message you got says so). You can write your matrix as a = 1e20 * matrix (c(1, 1e-18, 1e-17, 1e-17), 2, 2) Compared to the first element, all of the other elements are nearly zero, so the matrix is numerically nearly singular even though the determinant is 1e23. A better measure of how numerically unstable the inversion of a matrix is is the condition number which IIRC is something like the largest eigenvalue divided by the smallest eigenvalue. Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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² for non-linear model
Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! Anna __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Saving summary outputs in a table form
Dear R help, Is there a way to extract a variable ( one column) from my summary statistics to save it in a table form? My post-factor analysis summary statistics gave me the output below. Is there anyway to just save the mean of all the phi? The filename of this summary output is postun2010sum. Also is there a way to just save phi(,2) or phi(,3) in a table form on my desktop? Any help would be deeply appreciated. Thank you very much and I would be grateful for any comments. Mean SD Naive SE Time-series SE LambdaR.64.6.1 -2.441402 0.37438 0.0118390 0.0099447 LambdaR.64.6.20.918276 0.34265 0.0108355 0.0101326 LambdaR.64.6.30.216445 0.32877 0.0103965 0.0108384 LambdaR.64.10.1 -0.269011 0.16282 0.0051488 0.0078555 LambdaR.64.10.2 1.379486 0.20658 0.0065327 0.0070898 LambdaR.64.10.3 0.235941 0.15448 0.0048851 0.0063958 phi.1.2 1.095283 0.11438 0.0036170 0.0060156 phi.1.3 -0.141687 0.16288 0.0051507 0.0101297 phi.2.2 0.890038 0.11511 0.0036401 0.0057195 phi.2.3 0.104225 0.15570 0.0049238 0.0090702 phi.3.2 -0.379830 0.21483 0.0067936 0.0078231 phi.3.3 -0.266584 0.32148 0.0101661 0.0102912 phi.4.2 -1.056815 0.37530 0.0118682 0.0149568 phi.4.3 -1.193200 0.31209 0.0098691 0.0129749 phi.5.2 0.364988 0.16384 0.0051812 0.0084784 phi.5.3 -1.324649 0.18231 0.0057652 0.0063309 phi.6.2 -1.078973 0.41542 0.0131368 0.0154569 phi.6.3 0.275169 0.44999 0.0142300 0.0157746 phi.7.2 -1.055651 0.36960 0.0116879 0.0132779 phi.7.3 0.664266 0.47810 0.0151190 0.0169993 phi.8.2 -0.869908 0.34998 0.0110672 0.0111003 phi.8.3 0.276252 0.42348 0.0133915 0.0124475 phi.9.2 -0.587335 0.26497 0.0083792 0.0090293 phi.9.3 0.085117 0.37280 0.0117891 0.0134057 phi.10.2 -0.996298 0.39233 0.0124066 0.0128439 phi.10.3 -0.392418 0.38979 0.0123263 0.0138242 -- View this message in context: http://r.789695.n4.nabble.com/Saving-summary-outputs-in-a-table-form-tp3381959p3381959.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] How to read Cumulative proportion in using princomp?
Dear all, result-summary(princomp(x,cor=TRUE)) result Importance of components: Comp.1Comp.2 Comp.3 Comp.4 Standard deviation 1.642136 1.0114376 0.45146892 0.27669119 Proportion of Variance 0.674153 0.2557515 0.05095605 0.01913950 Cumulative Proportion 0.674153 0.9299044 0.98086050 1. I want to read Cumlative Proportion listed above. But I cannot find it in result, instead, R gives me followed, which is not same with above: result[2] $loadings Loadings: Comp.1 Comp.2 Comp.3 Comp.4 YC.T 0.183 0.935 0.250 0.172 YC.Rad 0.581 -0.130 -0.413 0.689 YC.Rain -0.537 0.308 -0.784 YC.ETPM 0.583 0.119 -0.389 -0.703 Comp.1 Comp.2 Comp.3 Comp.4 SS loadings 1.00 1.00 1.00 1.00 Proportion Var 0.25 0.25 0.25 0.25 Cumulative Var 0.25 0.50 0.75 1.00 I am wondering how can I calculate Cumulative Proportion in the first result. Thank you very much -- View this message in context: http://r.789695.n4.nabble.com/How-to-read-Cumulative-proportion-in-using-princomp-tp3381881p3381881.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] Scope of variable?
Of course! Works fine now. Thanks, Martyn and Jim... Ravi -- View this message in context: http://r.789695.n4.nabble.com/Scope-of-variable-tp3381485p3381932.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] Reorganize data frame
Hi group, I am trying to convert the organization of a data frame so I can do some correlations between stocks, I have something like this: stock.returns - data.frame(rbind(c(MSFT,20110301,0.05),c(MSFT,20110302,0.01),c(GOOG,20110301,-0.01),c(GOOG,20110302,0.04))) colnames(stock.returns) - c(Ticker,Date,Return) stock.returns Ticker Date Return 1 MSFT 20110301 0.05 2 MSFT 20110302 0.01 3 GOOG 20110301 -0.01 4 GOOG 20110302 0.04 And want to convert it to this: stock.returns - data.frame(rbind(c(20110301,0.05,-0.01),c(20110302,0.01,0.04))) colnames(stock.returns) - c(Date,MSFT,GOOG) stock.returns Date MSFT GOOG 1 20110301 0.05 -0.01 2 20110302 0.01 0.04 Can anyone offer any suggestions? Thanks, Chris -- View this message in context: http://r.789695.n4.nabble.com/Reorganize-data-frame-tp3381929p3381929.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] suppress GUI window when loading a library
When some libraries (e.g., VIM and Rcmdr) are loaded, they automatically display a GUI window. Is there a way to load the library but suppress the window? greg gregory carey university of colorado __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] generate bivariate or multivariate gamma distribution in R
Hi, there: Is there any quick function to generate bivariate or multivariate gamma distribution? Thanks. Yulei __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fetch uneven
Hi I have a vector m: m [1] ABC transporters [2] 2 [3] Acetyl-CoA [4] 1 [5] Energie [6] 1 [7] FAD Biosynthese [8] 1 [9] Glyoxylate and dicarboxylate metabolism [10] 1 [11] Transport [12] 1 and i want to do take the even or uneven numbers out of them you can do it lik this: a-m[c(1,3,5,7,9,11)] but i want to do this automatic and i never now how long the vector is. Can someone help me? -- View this message in context: http://r.789695.n4.nabble.com/fetch-uneven-tp3381949p3381949.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding linear regression data to plot
I know I can add line to graph with abline(), but I would like to print R-squared, F-test value, Residuals and other statistics from lm() to a graph. I don't know how to access the values from summary(), so that I can use them in a following code or print them in a graph. -- View this message in context: http://r.789695.n4.nabble.com/adding-linear-regression-data-to-plot-tp3357946p3382135.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] table() reading problem
On 16/03/11 09:20, fre wrote: I have the following problem: I have some string with numbers like k. I want to have a table like the function table() gives. However I am not able to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem The first row, as you call it, is accessible as the vector dimnames(x)$k (or as.numeric(dimnames(x)$k) if you need numbers, not strings). to work either. The levels keep bothering me. This is an example of the code: k-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1) table(k) k 1 2 3 5 6 9 9 2 3 1 1 1 Maybe something like matrix(c(as.integer(dimnames(x)$k), x), nrow=2, byrow=TRUE) is what you are looking for? Hope this helps Allan x-table(k) dim(x) [1] 6 x[1] #But i only want the one 1 9 x-data.frame(x) x[1,1] #You are not allowed to use this one for example 3*x[1,1] is impossible [1] 1 Levels: 1 2 3 5 6 9 I hope anyone has an idea of using the table function without this inconvenience. I thought about writing a counter myself, but that seems complicated. Because I have to examine very large examples later on, I don't want to slow the calculations down if possible. Thanks for your help in advance. Frederique -- View this message in context: http://r.789695.n4.nabble.com/table-reading-problem-tp3381174p3381174.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] export list to csv
How about? sink(andrija.csv) l sink() -- View this message in context: http://r.789695.n4.nabble.com/export-list-to-csv-tp3381992p3382062.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] Bootstrap memory use?
Hi, the boot function from the boot library seems to use an implausible quantity of memory; is this to be expected, or am I doing something wrong? Specifically, the vector I wish to bootstrap off is about 17000 entries long length(fes) [1] 16988 bm - function(x,indexes) mean(x[indexes]) then if I do, eg: b - boot(fes,statistic=bm,R=1) then R fairly rapidly shoots up to using about 40% of the RAM on this machine (which has 12G of the stuff). If I up the replications to say 50,000, then it chews all the available system memory and brings my computer to a grinding halt. I can see that that's probably far too many bootstrap resamplings, but I can't see why it needs so much memory... Regards, Matthew -- Matthew Vernon, Research Fellow Ecology and Epidemiology Group, University of Warwick http://blogs.warwick.ac.uk/mcvernon __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 one character in the name of dataframes repeatedly
Hello Ivan, Thank you very much for your comments, they were really useful and I’ll try to memorize and use them in the future. Getting back to my problem… well, I try to put it in a different way because I’m afraid this is gonna be a little bit more difficult than I thought. So, here is my refreshed database (it is a little bit more similar to my original database than my previous ’df’ database in my previous letter, although still simplified). id -c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3) a -c(3,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3) b -c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2) c -c(1,3,2,3,2,1,2,3,3,2,2,3,1,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2) d -c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2) e -c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,2,1,3) df -data.frame(id,a,b,c,d,e) df Basically what I would like to do is to get the distributions of the numbers for each column (a,b,c,d,e) and for each group (1,2,3) (for this latter grouping see my column ’id’). So, for column ’a’ and for number ’1’ (for the latter see column ’id’): as.numeric(table(df[1:10,2]))[1]/sum(as.numeric(table(df[1:10,2]))) as.numeric(table(df[1:10,2]))[2]/sum(as.numeric(table(df[1:10,2]))) Fist time you get: [1] 0.3, then you get: [1] 0.7 Just to briefly explain my results: in column ’a’ (and regarding only those records which have number ’1’ in column ’id’) we can say that: number 1 occured 3 times, and number 3 occured 7 times. 3 / (3+7) = 0.3, and 7 / (3+7) = 0.7 Again, just to show you another example. For column ’a’ and for number ’2’ (for the latter grouping see again column ’id’): as.numeric(table(df[11:20,2]))[1]/sum(as.numeric(table(df[11:20,2]))) as.numeric(table(df[11:20,2]))[2]/sum(as.numeric(table(df[11:20,2]))) as.numeric(table(df[11:20,2]))[3]/sum(as.numeric(table(df[11:20,2]))) After running the codes the results are: 0.4, 0.3, 0.3. Let me explain a little again: in column ’a’ and regarding only those observations which have number ’2’ in column ’id’) we can say that Number 1 occured 4 times number 2 occured 3 times and number 3 occured 3 times. Now the results are obvious: 4/10 = 0.4, 3/10=0.3, 3/10=0.3 etc. So this is what I would like to do. Calculating distributions for each custom-defined subsets and then collecting these values into a data frame. The reason I wanted to sort out the problem with indices like ’i’, ’k’ etc. (you know we discussed it previously) was because I’m gonna have to change the input ’df’ dataframe on a regular basis and hence both the overall number of rows and columns might change over time… Thank you again, Laszlo -- View this message in context: http://r.789695.n4.nabble.com/changing-one-character-in-the-name-of-dataframes-repeatedly-tp3348390p3382288.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] cross validation? when rlm, lmrob or lmRob
Dear community, I have fitted a model using comands above, (rlm, lmrob or lmRob). I don't have new data to validate de models obtained. I was wondering if exists something similar to CVlm in robust regression. In case there isn't, any suggestion for validation would be appreciated. Thanks, u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/cross-validation-when-rlm-lmrob-or-lmRob-tp3382189p3382189.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] fetch uneven
See ?seq for generating index vectors of different kinds. /Henrik On Wed, Mar 16, 2011 at 7:43 AM, rens picca...@hotmail.com wrote: Hi I have a vector m: m [1] ABC transporters [2] 2 [3] Acetyl-CoA [4] 1 [5] Energie [6] 1 [7] FAD Biosynthese [8] 1 [9] Glyoxylate and dicarboxylate metabolism [10] 1 [11] Transport [12] 1 and i want to do take the even or uneven numbers out of them you can do it lik this: a-m[c(1,3,5,7,9,11)] but i want to do this automatic and i never now how long the vector is. Can someone help me? -- View this message in context: http://r.789695.n4.nabble.com/fetch-uneven-tp3381949p3381949.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] read.table() with \t as seperator, all other programs report equal fields each row, read.table() returns unequal row length error
hi, list R is undoudtedly my favorite statistic tool, however, the data inputnpart has long been a pain. most data I have to deal with are irregular and contains special character. Recently I get a tab delimited data, read.table(filename,sep=\t) constantly return erors for certain rows does not has xyz elements while all other programs such as perl,python, awk all report equal row length if use \t as seperator. I scout through the problematic row, sometimes it is because a row contains a #, so I go back to specify comment.char= next it will be some other problems, for some rows I simply can't figure out what the problem is. can I have any guru suggestion to save this pain now and in the future, is CSV a safer format? or can anyone let me know what are the fundamental principles I must bear in mind when do preliminary data processing using other programs such as perl to ensure the output can be readily feed into R. best yong __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 read Cumulative proportion in using princomp?
Hi, The values are calculated on the fly in the summary function stats:::print.summary.princomp using vars - result$sdev^2 vars - vars/sum(vars) cumsum(vars) Martyn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ian_zhangty Sent: 16 March 2011 14:19 To: r-help@r-project.org Subject: [R] How to read Cumulative proportion in using princomp? Dear all, result-summary(princomp(x,cor=TRUE)) result Importance of components: Comp.1Comp.2 Comp.3 Comp.4 Standard deviation 1.642136 1.0114376 0.45146892 0.27669119 Proportion of Variance 0.674153 0.2557515 0.05095605 0.01913950 Cumulative Proportion 0.674153 0.9299044 0.98086050 1. I want to read Cumlative Proportion listed above. But I cannot find it in result, instead, R gives me followed, which is not same with above: result[2] $loadings Loadings: Comp.1 Comp.2 Comp.3 Comp.4 YC.T 0.183 0.935 0.250 0.172 YC.Rad 0.581 -0.130 -0.413 0.689 YC.Rain -0.537 0.308 -0.784 YC.ETPM 0.583 0.119 -0.389 -0.703 Comp.1 Comp.2 Comp.3 Comp.4 SS loadings 1.00 1.00 1.00 1.00 Proportion Var 0.25 0.25 0.25 0.25 Cumulative Var 0.25 0.50 0.75 1.00 I am wondering how can I calculate Cumulative Proportion in the first result. Thank you very much -- View this message in context: http://r.789695.n4.nabble.com/How-to-read-Cumulative-proportion-in-using -princomp-tp3381881p3381881.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. This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Singularity problem
Peter Langfelder wrote: On Wed, Mar 16, 2011 at 8:28 AM, Feng Li lt;m...@feng.ligt; wrote: Dear R, If I have remembered correctly, a square matrix is singular if and only if its determinant is zero. I am a bit confused by the following code error. Can someone give me a hint? a - matrix(c(1e20,1e2,1e3,1e3),2) det(a) [1] 1e+23 solve(a) Error in solve.default(a) : system is computationally singular: reciprocal condition number = 1e-17 You are right, a matrix is mathematically singular iff its determinant is zero. However, this condition is useless in practice since in practice one cares about the matrix being computationally singular, i.e. so close to singular that it cannot be inverted using the standard precision of real numbers. And that's what your matrix is (and the error message you got says so). You can write your matrix as a = 1e20 * matrix (c(1, 1e-18, 1e-17, 1e-17), 2, 2) Compared to the first element, all of the other elements are nearly zero, so the matrix is numerically nearly singular even though the determinant is 1e23. A better measure of how numerically unstable the inversion of a matrix is is the condition number which IIRC is something like the largest eigenvalue divided by the smallest eigenvalue. svd(a) indicates the problem. largest singular value / smallest singular value=1e17 (condition number) -- reciprocal condition number=1e-17 and the standard solve can't handle that. (pivoted) QR decomposition does help. And so does SVD. Berend -- View this message in context: http://r.789695.n4.nabble.com/Singularity-problem-tp3382093p3382465.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] Does R have a const object?
On Wed, 16 Mar 2011, Gabor Grothendieck wrote: On Wed, Mar 16, 2011 at 12:16 PM, luke-tier...@uiowa.edu wrote: On Wed, 16 Mar 2011, Gabor Grothendieck wrote: On Wed, Mar 16, 2011 at 11:49 AM, luke-tier...@uiowa.edu wrote: Just as a heads-up: it is likely that unlocking the bindings in base for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly more, will start signaling warnings in the near future. Doing this may be useful at times for debugging but it can mess up assumptions others make about how things in base work and so reduce code reliability. That seems ok for pi, T and F but if its extended to everything in base then I would hope there is a nowarn= argument or other easy way to avoid the warning message. That would defeat the purpose. Unlocking things in base may be useful for experimenting or debugging but it is not a good idea otherwise. [? assignInNamespace could be more explicit on htis and will be soon.] There is a reason we lock bindings in the first place, and that is so one can assume that these bindings have certain values and certain properties and one can write reliable programs against these assumptions. Its useful for being able to set defaults for arguments that do not have defaults. That cannot break existing programs. Until the next program decides do co change those defaults and either can't or does and you end up with incompatible assumptions. It also make the code with the added defaults inconsistent with the documentation though, which is not a good idea. It may seem convenient but it isn't a good idea in production code that is intended to play well with other production code. Note that if this feature is implemented in a heavy handed manner it could cause havoc as at least one package that is depended upon by literally dozens of other packages (and possibly hundreds if one takes into account dependencies of dependencies) cannot function. The reason I sent my initial message is so those who do this sort of thing can start thinking about other approaches. I do not expect to need this change for closures any time soon, but will need it for constants and primitives. It may be useful for some closures as well, so that change may come farther down the line. luke -- Luke Tierney Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: l...@stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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² for non-linear model
On Mar 16, 2011, at 12:53 PM, Anna Gretschel wrote: Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! You should do more searching. I can remember at least two threads in the last few years that discussed this issue. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 read Cumulative proportion in using princomp?
On 2011-03-16 10:31, Martyn Byng wrote: Hi, The values are calculated on the fly in the summary function stats:::print.summary.princomp using vars- result$sdev^2 vars- vars/sum(vars) cumsum(vars) Or you could use the prcomp summary function (maybe you should use prcomp() for you model?): stats:::summary.prcomp(result)$importance[3, ] Use str() to inspect the components of the summary function. Peter Ehlers Martyn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ian_zhangty Sent: 16 March 2011 14:19 To: r-help@r-project.org Subject: [R] How to read Cumulative proportion in using princomp? Dear all, result-summary(princomp(x,cor=TRUE)) result Importance of components: Comp.1Comp.2 Comp.3 Comp.4 Standard deviation 1.642136 1.0114376 0.45146892 0.27669119 Proportion of Variance 0.674153 0.2557515 0.05095605 0.01913950 Cumulative Proportion 0.674153 0.9299044 0.98086050 1. I want to read Cumlative Proportion listed above. But I cannot find it in result, instead, R gives me followed, which is not same with above: result[2] $loadings Loadings: Comp.1 Comp.2 Comp.3 Comp.4 YC.T 0.183 0.935 0.250 0.172 YC.Rad 0.581 -0.130 -0.413 0.689 YC.Rain -0.537 0.308 -0.784 YC.ETPM 0.583 0.119 -0.389 -0.703 Comp.1 Comp.2 Comp.3 Comp.4 SS loadings 1.00 1.00 1.00 1.00 Proportion Var 0.25 0.25 0.25 0.25 Cumulative Var 0.25 0.50 0.75 1.00 I am wondering how can I calculate Cumulative Proportion in the first result. Thank you very much -- View this message in context: http://r.789695.n4.nabble.com/How-to-read-Cumulative-proportion-in-using -princomp-tp3381881p3381881.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. This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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² for non-linear model
Dear Anna, What is your goal in obtaining a value for R^2 ? I believe it is not provided for a non-linear model, because it does not make much sense. It certainly will not have the same interpretation as in a linear model, and all the ways it *could* be defined come with their own sets of problems. A more precise definition of what you want (say you have a particular formula but do not know how to get the necessary information out of the model) may get a better answer. Best regards, Josh On Wed, Mar 16, 2011 at 9:53 AM, Anna Gretschel ana-...@web.de wrote: Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! Anna __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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² for non-linear model
Am 16.03.2011 18:15, schrieb David Winsemius: On Mar 16, 2011, at 12:53 PM, Anna Gretschel wrote: Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! You should do more searching. I can remember at least two threads in the last few years that discussed this issue. yes there are threads concidering this topic but they are all about the theory not about how to get the value of r^2 for a non-linear model in R. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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² for non-linear model
You can't. R^2 has no (consistent, sensible) meaning for nonlinear models. If you don't understand why not, get local help or do some reading. Cheers, Bert On Wed, Mar 16, 2011 at 9:53 AM, Anna Gretschel ana-...@web.de wrote: Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! Anna __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 467-7374 http://devo.gene.com/groups/devo/depts/ncb/home.shtml __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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² for non-linear model
Am 16.03.2011 18:19, schrieb Joshua Wiley: Dear Anna, What is your goal in obtaining a value for R^2 ? I believe it is not provided for a non-linear model, because it does not make much sense. It certainly will not have the same interpretation as in a linear model, and all the ways it *could* be defined come with their own sets of problems. A more precise definition of what you want (say you have a particular formula but do not know how to get the necessary information out of the model) may get a better answer. Best regards, Josh On Wed, Mar 16, 2011 at 9:53 AM, Anna Gretschelana-...@web.de wrote: Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! Anna __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dear Josh, I actually want to find out the goodness of fit. I have to make choises between a linear and an exponential model and I thought comparing their r squares would give me an idea of which one better explains the correlation of the data. So if r squared does not work for non-linear regression - do you have an idea how to calculate some goodness of fit? Thank you a lot for replying! Cheers, Anna __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?
Its useful for being able to set defaults for arguments that do not have defaults. That cannot break existing programs. Until the next program decides do co change those defaults and either can't or does and you end up with incompatible assumptions. It also make the code with the added defaults inconsistent with the documentation though, which is not a good idea. It may seem convenient but it isn't a good idea in production code that is intended to play well with other production code. I like the name the ruby community has for these sort of changes: monkey patching. It's an evocative term! Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Data frame loop
R users, I found a solution to my own question. I just needed to insert (j+(j-1)):(2*j) as the indices for vector s3. No need to respond. Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding linear regression data to plot
Hi, ?summary.lm describes what summary statistics get calculated and returned, so ll - lm(y ~ x) ss - summary(ll) ss$fstatistic for example would give the F statistic Martyn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of derek Sent: 16 March 2011 15:47 To: r-help@r-project.org Subject: Re: [R] adding linear regression data to plot I know I can add line to graph with abline(), but I would like to print R-squared, F-test value, Residuals and other statistics from lm() to a graph. I don't know how to access the values from summary(), so that I can use them in a following code or print them in a graph. -- View this message in context: http://r.789695.n4.nabble.com/adding-linear-regression-data-to-plot-tp33 57946p3382135.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. This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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² for non-linear model
Is there any way that this could be made into a fortune -- perhaps by omitting the poster's identity? yes there are threads concidering this topic but they are all about the theory not about how to get the value of r^2 for a non-linear model in R. :=) Cheers, Bert Anna: I say this because you have just been told that the theory tells you that you CANNOT calculate R^2 for a nonlinear model. On Wed, Mar 16, 2011 at 10:25 AM, Anna Gretschel ana-...@web.de wrote: Am 16.03.2011 18:15, schrieb David Winsemius: On Mar 16, 2011, at 12:53 PM, Anna Gretschel wrote: Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! You should do more searching. I can remember at least two threads in the last few years that discussed this issue. yes there are threads concidering this topic but they are all about the theory not about how to get the value of r^2 for a non-linear model in R. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Reorganize data frame
Here's one way: ans = reshape(stock.returns,idvar='Date', +varying=list(names(stock.returns)[-1]), +direction='long', +times=names(stock.returns)[-1], +v.names='Return',timevar='Ticker') rownames(ans) = NULL ans Date Ticker Return 1 20110301 MSFT 0.05 2 20110302 MSFT 0.01 3 20110301 GOOG -0.01 4 20110302 GOOG 0.04 - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Wed, 16 Mar 2011, chris99 wrote: Hi group, I am trying to convert the organization of a data frame so I can do some correlations between stocks, I have something like this: stock.returns - data.frame(rbind(c(MSFT,20110301,0.05),c(MSFT,20110302,0.01),c(GOOG,20110301,-0.01),c(GOOG,20110302,0.04))) colnames(stock.returns) - c(Ticker,Date,Return) stock.returns Ticker Date Return 1 MSFT 20110301 0.05 2 MSFT 20110302 0.01 3 GOOG 20110301 -0.01 4 GOOG 20110302 0.04 And want to convert it to this: stock.returns - data.frame(rbind(c(20110301,0.05,-0.01),c(20110302,0.01,0.04))) colnames(stock.returns) - c(Date,MSFT,GOOG) stock.returns Date MSFT GOOG 1 20110301 0.05 -0.01 2 20110302 0.01 0.04 Can anyone offer any suggestions? Thanks, Chris -- View this message in context: http://r.789695.n4.nabble.com/Reorganize-data-frame-tp3381929p3381929.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] Saving summary outputs in a table form
Hi, You should carefully and thoroughly read the help page for the extraction operators. See ?[ Let's say your output below is in a data.frame called df. You can do something like this: df[, Mean] To select only some specific phi rows, you probably need to set some regular expressions, see ?grep Row.names that start with phi.1.: grep(pattern=^phi\\.1\\., x=row.names(df)) Row.names that start with phi. and end up with 2: grep(pattern=^phi\\.[0-9]+\\.2$, x=row.names(df)) So in your data.frame: df[grep(pattern=^phi\\.1\\., x=row.names(df)), ] df[grep(pattern=^phi\\.1\\., x=row.names(df)), Mean] See ?write.table if you want to write a data.frame to a file. HTH, Ivan Le 3/16/2011 15:47, Haillie a écrit : Dear R help, Is there a way to extract a variable ( one column) from my summary statistics to save it in a table form? My post-factor analysis summary statistics gave me the output below. Is there anyway to just save the mean of all the phi? The filename of this summary output is postun2010sum. Also is there a way to just save phi(,2) or phi(,3) in a table form on my desktop? Any help would be deeply appreciated. Thank you very much and I would be grateful for any comments. Mean SD Naive SE Time-series SE LambdaR.64.6.1 -2.441402 0.37438 0.0118390 0.0099447 LambdaR.64.6.20.918276 0.34265 0.0108355 0.0101326 LambdaR.64.6.30.216445 0.32877 0.0103965 0.0108384 LambdaR.64.10.1 -0.269011 0.16282 0.0051488 0.0078555 LambdaR.64.10.2 1.379486 0.20658 0.0065327 0.0070898 LambdaR.64.10.3 0.235941 0.15448 0.0048851 0.0063958 phi.1.2 1.095283 0.11438 0.0036170 0.0060156 phi.1.3 -0.141687 0.16288 0.0051507 0.0101297 phi.2.2 0.890038 0.11511 0.0036401 0.0057195 phi.2.3 0.104225 0.15570 0.0049238 0.0090702 phi.3.2 -0.379830 0.21483 0.0067936 0.0078231 phi.3.3 -0.266584 0.32148 0.0101661 0.0102912 phi.4.2 -1.056815 0.37530 0.0118682 0.0149568 phi.4.3 -1.193200 0.31209 0.0098691 0.0129749 phi.5.2 0.364988 0.16384 0.0051812 0.0084784 phi.5.3 -1.324649 0.18231 0.0057652 0.0063309 phi.6.2 -1.078973 0.41542 0.0131368 0.0154569 phi.6.3 0.275169 0.44999 0.0142300 0.0157746 phi.7.2 -1.055651 0.36960 0.0116879 0.0132779 phi.7.3 0.664266 0.47810 0.0151190 0.0169993 phi.8.2 -0.869908 0.34998 0.0110672 0.0111003 phi.8.3 0.276252 0.42348 0.0133915 0.0124475 phi.9.2 -0.587335 0.26497 0.0083792 0.0090293 phi.9.3 0.085117 0.37280 0.0117891 0.0134057 phi.10.2 -0.996298 0.39233 0.0124066 0.0128439 phi.10.3 -0.392418 0.38979 0.0123263 0.0138242 -- View this message in context: http://r.789695.n4.nabble.com/Saving-summary-outputs-in-a-table-form-tp3381959p3381959.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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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² for non-linear model + comparing linear + non-linear models
Dear Bert, so what can I do to obtain a goodness of fit for a non-linear model if r² does not work? And here comes my next question: is it apropriate to comopare a linear and a non-linear model with anova()? Thank you so much for answering, Anna Am 16.03.2011 18:54, schrieb Bert Gunter: Is there any way that this could be made into a fortune -- perhaps by omitting the poster's identity? yes there are threads concidering this topic but they are all about the theory not about how to get the value of r^2 for a non-linear model in R. :=) Cheers, Bert Anna: I say this because you have just been told that the theory tells you that you CANNOT calculate R^2 for a nonlinear model. On Wed, Mar 16, 2011 at 10:25 AM, Anna Gretschelana-...@web.de wrote: Am 16.03.2011 18:15, schrieb David Winsemius: On Mar 16, 2011, at 12:53 PM, Anna Gretschel wrote: Dear List, how can I obtain the value of r suqared for a non-linear model? For linear models it can be found in the summary() of the model but for non-linear models I just don't know. Please help! You should do more searching. I can remember at least two threads in the last few years that discussed this issue. yes there are threads concidering this topic but they are all about the theory not about how to get the value of r^2 for a non-linear model in R. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] adding linear regression data to plot
On 2011-03-16 08:47, derek wrote: I know I can add line to graph with abline(), but I would like to print R-squared, F-test value, Residuals and other statistics from lm() to a graph. I don't know how to access the values from summary(), so that I can use them in a following code or print them in a graph. It seems that you need to discover the ever-useful str() function. str(summary(your model)) will show you that you can get: summary(model)$r.squared etc. For the coefficients, I would use: coef(model). Peter Ehlers -- View this message in context: http://r.789695.n4.nabble.com/adding-linear-regression-data-to-plot-tp3357946p3382135.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.