[R] Select fixed number of elements
Hi all, I have in my code some vectors that are not of equal size. I would like to be able for each of these vectors select 6 elements that are (almost) equally spaced. So the first one would be at (or close) to the beginning the last one at (or close) to the end and the other 4 equally spaced between first and last element. How can I do something like that on a vector of not known size? I would like to thank you in advance for your help Regards Alex [[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] cannot coerce class function to a data.frame
Helloï¼ I use the egonet function and have a problem idx - sapply(mats,index.egonet) idx - as.data.frame(t(idx)) idx - cbind(idx,filename=rownames(idx)) data - merge(data,idx,by=filename) cannot coerce class function to a data.frame can someone please help me with this problm? Thank you!! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Select fixed number of elements
Hello, Alaois, if x is your vector maybe n - length( x) positions - trunc( quantile( seq( n), prob = 0:5/5)) x[ positions] comes close to what you want. Hth -- Gerrit Hi all, I have in my code some vectors that are not of equal size. I would like to be able for each of these vectors select 6 elements that are (almost) equally spaced. So the first one would be at (or close) to the beginning the last one at (or close) to the end and the other 4 equally spaced between first and last element. How can I do something like that on a vector of not known size? I would like to thank you in advance for your help Regards Alex [[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] Select fixed number of elements
Alaios alaios at yahoo.com writes: I have in my code some vectors that are not of equal size. I would like to be able for each of these vectors select 6 elements that are (almost) equally spaced. So the first one would be at (or close) to the beginning the last one at (or close) to the end and the other 4 equally spaced between first and last element. How can I do something like that on a vector of not known size? I would like to thank you in advance for your help Would something like this be what you are looking for? N - 20 set.seed(16121952) x - runif(N) x rx - range(x) br - seq(rx[1], rx[2], len = 6) sapply(br, function(bx){ x[which.min(abs(x - bx))] }) [1] 0.02910779 0.22708582 0.39239718 0.52419265 0.68940262 0.86889817 Regards Alex -- Kenneth Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Yield to maturity in R
Dear R forum, Just want to know if there is any function / package in R which will calculate Yield to Maturity in R for a given bond? Regards Katherine [[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] Subtotals by id for a large number of columns XXXX
Hi everybody, I have data in the format of the example data below where essentially a large number of indicator variables (coded [0,1]) reflect traits of the same id across multiple rows. I need to represent the data in a 1 row per id format. I see this as being similar to converting from long to wide format, however, there is no time component here: The multiple rows here are all characteristics observed at the same measurement occasion. So, really I just need an individual sum for each variable (for a large number of variables) and for these to be all saved in the same row (along with the id variable and other demographics (e.g., location). Here is the example df and the method I used first: d1-data.frame(id=c(1,1,1,2,2,2,2,3,3,4),location=factor(c(rep(0,7),rep(1,3)), labels=c(A,B)),var1=as.logical(round(runif(10))), var2=as.logical(round(runif(10))),var3=as.logical(round(runif(10 d1 mysum-function(x) aggregate(x,by=list(d1$id),sum) d2-sapply(d1[2:4],mysum) d2 Any help is appreciated!! Thanks! Dan [[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] rpy2 and user defined functions from R
Presumably you need to define 'buzz' first, but I don't see evidence that you've done so. Michael On Oct 30, 2013, at 0:06, Erin Hodgess erinm.hodg...@gmail.com wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R x = R.r.buzz(3) R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Revo R for Arima Implementation
On 28 October 2013 14:26, Anindita Chattopadhyay anindit...@mu-sigma.com wrote: We need to understand how we can implement this in Revo R. Most of the people here contribute to community of R not Revo R. I think it is unfair of you to request from this list to solve your Revo R issue. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fitting multiple horizontal lines to data
Your question doesn't make much sense if you really believe that the best fit is to draw a horizontal line at every unique value of y. What is the actual problem you are trying to solve? Clearly it's not a matter of linear fits, so forget about using lm or other regression tools. -- View this message in context: http://r.789695.n4.nabble.com/Fitting-multiple-horizontal-lines-to-data-tp4679324p4679345.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] Subtotals by id for a large number of columns XXXX
Hi Rui, Thanks for responding. When I make this change, I get an error message: mysum-function(x) tapply(x,d1$id,sum) d2-apply(d1[2:4],mysum) Error in match.fun(FUN) : argument FUN is missing, with no default Thoughts? On Wed, Oct 30, 2013 at 8:01 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, If I understand it correctly, just change mysum to the following. mysum-function(x) tapply(x,d1$id,sum) Hope this helps, Rui Barradas Em 30-10-2013 11:07, Dan Abner escreveu: Hi everybody, I have data in the format of the example data below where essentially a large number of indicator variables (coded [0,1]) reflect traits of the same id across multiple rows. I need to represent the data in a 1 row per id format. I see this as being similar to converting from long to wide format, however, there is no time component here: The multiple rows here are all characteristics observed at the same measurement occasion. So, really I just need an individual sum for each variable (for a large number of variables) and for these to be all saved in the same row (along with the id variable and other demographics (e.g., location). Here is the example df and the method I used first: d1-data.frame(id=c(1,1,1,2,2,**2,2,3,3,4),location=factor(c(** rep(0,7),rep(1,3)), labels=c(A,B)),var1=as.**logical(round(runif(10))), var2=as.logical(round(runif(**10))),var3=as.logical(round(** runif(10 d1 mysum-function(x) aggregate(x,by=list(d1$id),**sum) d2-sapply(d1[2:4],mysum) d2 Any help is appreciated!! Thanks! Dan [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] big speed difference in source btw. R 2.15.2 and R 3.0.2 ?
Did you run the identical code on the identical machine, and did you verify there were no other tasks running which might have limited the RAM available to R? And equally important, did you run these tests in the reverse order (in case R was storing large objects from the first run, thus chewing up RAM)? Dear All, is it known that source works much faster in R 2.15.2 than in R 3.0.2 ? In the example below I observe e.g. for a data.frame with 10^7 rows the following timings: R version 2.15.2 Patched (2012-11-29 r61184) length: 1e+07 user system elapsed 62.040.22 62.26 R version 3.0.2 Patched (2013-10-27 r64116) length: 1e+07 user system elapsed 388.63 176.42 566.41 Is there a way to speed R version 3.0.2 up to the performance of R version 2.15.2? best regards, Heinz Tüchler example: sessionInfo() sample.vec - c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) dump('df0', file='testdump') cat('length:', i, '\n') print(system.time(source('testdump', keep.source = FALSE, encoding=''))) } output for R version 2.15.2 Patched (2012-11-29 r61184): sessionInfo() R version 2.15.2 Patched (2012-11-29 r61184) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', + 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { + df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) + dump('df0', file='testdump') + cat('length:', i, '\n') + print(system.time(source('testdump', keep.source = FALSE, +encoding=''))) + } length: 10 user system elapsed 0 0 0 length: 100 user system elapsed 0 0 0 length: 1000 user system elapsed 0 0 0 length: 1 user system elapsed 0.020.000.01 length: 1e+05 user system elapsed 0.210.000.20 length: 1e+06 user system elapsed 4.470.044.51 length: 1e+07 user system elapsed 62.040.22 62.26 output for R version 3.0.2 Patched (2013-10-27 r64116): sessionInfo() R version 3.0.2 Patched (2013-10-27 r64116) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', + 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { + df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) + dump('df0', file='testdump') + cat('length:', i, '\n') + print(system.time(source('testdump', keep.source = FALSE, +encoding=''))) + } length: 10 user system elapsed 0 0 0 length: 100 user system elapsed 0 0 0 length: 1000 user system elapsed 0 0 0 length: 1 user system elapsed 0.010.000.01 length: 1e+05 user system elapsed 0.360.060.42 length: 1e+06 user system elapsed 6.021.867.88 length: 1e+07 user system elapsed 388.63 176.42 566.41 -- View this message in context: http://r.789695.n4.nabble.com/big-speed-difference-in-source-btw-R-2-15-2-and-R-3-0-2-tp4679314p4679346.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] Can not read Excel file correctly
Dunno how to break this to you, but R reads exactly what is in that file, with the data in exactly the proper row/column locations. -- View this message in context: http://r.789695.n4.nabble.com/Can-not-read-Excel-file-correctly-tp4679306p4679350.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] Optimization failed in fitdistr (Weibull distribution)
Which suggests the OP should verify that the data in ...$Frequency is the data he expects to be there. Rui Barradas wrote Hello, I can't reproduce your error: windfreq - c(1351L, 2147L, 3317L, 4378L, 5527L, 6667L, 7865L, 8970L, 9987L, 10907L, 11905L, 12642L, 131000L, 14983L, 15847L, 16842L, 17757L, 18698L, 19632L, 20626L, 21599L, 22529L, 23325L, 24391L, 25356L, 26267L, 27230L, 28223L, 29190L, 30142L, 31124L, 32104L, 3397L, 3437L, 3562L, 3646L, 3742L, 3824L, 399L, 4013L, 419L, 425L, 432L library(MASS) fitdistr(windfreq, weibull) Hope this helps, Rui Barradas Em 28-10-2013 12:07, kmmoon100 escreveu: Hello everyone, This is Kangmin. I am trying to produce shape and scale of my wind data. My data is based on wind speed frequency with 1km/hr increment. data is described below. Windspeed (km/h)Frequency 1351 2147 3317 4378 5527 6667 7865 8970 9987 10 907 11 905 12 642 13 1000 14 983 15 847 16 842 17 757 18 698 19 632 20 626 21 599 22 529 23 325 24 391 25 356 26 267 27 230 28 223 29 190 30 142 31 124 32 104 33 97 34 37 35 62 36 46 37 42 38 24 39 9 40 13 41 9 42 5 43 2 R codes to calculate shape and scale are described below: Pine.windfrequency.4weeks-read.table(C:/Users/kmoon/Documents/Pine_frequency_4weeks.csv,header=TRUE,sep=,) fitdistr(Pine.windfrequency.4weeks$Frequency, densfun=weibull) I have got an error message when I was using 'fitdistr' function Error in fitdistr(Pine.windfrequency.4weeks$Frequency, densfun = weibull) : optimization failed Please help me calculating shape and scale of weibull distribution. And please understand that I am not an user familiar with R program but I am really trying to make my analysis work on R! Thank you!!! Kangmin. -- View this message in context: http://r.789695.n4.nabble.com/Optimization-failed-in-fitdistr-Weibull-distribution-tp4679167.html Sent from the R help mailing list archive at Nabble.com. __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/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@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/Optimization-failed-in-fitdistr-Weibull-distribution-tp4679178p4679351.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] (no subject)
Hi, I'm looking for a function that takes a list and calculates a score based on how well like attracts like. For example: list1 - c(john, eric, steve, john, eric, scott, john) list2 - c(john, john, john, eric, eric, steve, scott) score(list1) score(list2) Both lists are composed of the same names and frequency of each name. Not sure how else to put it. I am relatively new to R. Have tried the modularity function, but can't seem to get it to work for this purpose. Any help is appreciated. Steve [[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] big speed difference in source btw. R 2.15.2 and R 3.0.2 ?
All was run on the identical machine in independent sessions. I did not restart Windows. I also tried 32bit R 3.0.2 and it seemed slightly faster than 64bit. Using Process Explorer v15.23 (http://technet.microsoft.com/de-de/sysinternals/bb896653) my impression was that R 3.0.2 manages memory in a different way than R 2.15.2. While in R 2.15.2 the physical memory used grows steadily, when sourcing a big file, in R 3.0.2 growth and shrinking cycle. best, Heinz on/am 30.10.2013 13:28, Carl Witthoft wrote/hat geschrieben: Did you run the identical code on the identical machine, and did you verify there were no other tasks running which might have limited the RAM available to R? And equally important, did you run these tests in the reverse order (in case R was storing large objects from the first run, thus chewing up RAM)? Dear All, is it known that source works much faster in R 2.15.2 than in R 3.0.2 ? In the example below I observe e.g. for a data.frame with 10^7 rows the following timings: R version 2.15.2 Patched (2012-11-29 r61184) length: 1e+07 user system elapsed 62.040.22 62.26 R version 3.0.2 Patched (2013-10-27 r64116) length: 1e+07 user system elapsed 388.63 176.42 566.41 Is there a way to speed R version 3.0.2 up to the performance of R version 2.15.2? best regards, Heinz Tüchler example: sessionInfo() sample.vec - c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) dump('df0', file='testdump') cat('length:', i, '\n') print(system.time(source('testdump', keep.source = FALSE, encoding=''))) } output for R version 2.15.2 Patched (2012-11-29 r61184): sessionInfo() R version 2.15.2 Patched (2012-11-29 r61184) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', + 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { + df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) + dump('df0', file='testdump') + cat('length:', i, '\n') + print(system.time(source('testdump', keep.source = FALSE, +encoding=''))) + } length: 10 user system elapsed 0 0 0 length: 100 user system elapsed 0 0 0 length: 1000 user system elapsed 0 0 0 length: 1 user system elapsed 0.020.000.01 length: 1e+05 user system elapsed 0.210.000.20 length: 1e+06 user system elapsed 4.470.044.51 length: 1e+07 user system elapsed 62.040.22 62.26 output for R version 3.0.2 Patched (2013-10-27 r64116): sessionInfo() R version 3.0.2 Patched (2013-10-27 r64116) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', + 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { + df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) + dump('df0', file='testdump') + cat('length:', i, '\n') + print(system.time(source('testdump', keep.source = FALSE, +encoding=''))) + } length: 10 user system elapsed 0 0 0 length: 100 user system elapsed 0 0 0 length: 1000 user system elapsed 0 0 0 length: 1 user system elapsed 0.010.000.01 length: 1e+05 user system elapsed 0.360.060.42 length: 1e+06 user system elapsed 6.021.867.88 length: 1e+07 user system elapsed 388.63 176.42 566.41 -- View this message in context: http://r.789695.n4.nabble.com/big-speed-difference-in-source-btw-R-2-15-2-and-R-3-0-2-tp4679314p4679346.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] omitting integer(0) rows from data frame
I'm not sure if this is correct behavior or not, but it seems counterintuitive to me: dat - data.frame(id=1:5, let=letters[1:5]) # A. omits the first row dat[- 1, ] # B. unexpectedly omits ALL rows dat[- integer(0), ] It would be less surprising if there were no rows omitted in the (B) case. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] rpy2 and user defined functions from R
I did...just didn't show it On Wed, Oct 30, 2013 at 7:01 AM, Michael Weylandt michael.weyla...@gmail.com wrote: Presumably you need to define 'buzz' first, but I don't see evidence that you've done so. Michael On Oct 30, 2013, at 0:06, Erin Hodgess erinm.hodg...@gmail.com wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R x = R.r.buzz(3) R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] omitting integer(0) rows from data frame
Hi, Jack, well, I disagree: What do you expect to grab out of a bucket (= data frame) if you do not at all grab into it (indexing with an _empty_ index, i.e. with nothing)? And changing the sign of nothing is still nothing ... Hth -- Gerrit On Wed, 30 Oct 2013, Jack Tanner wrote: I'm not sure if this is correct behavior or not, but it seems counterintuitive to me: dat - data.frame(id=1:5, let=letters[1:5]) # A. omits the first row dat[- 1, ] # B. unexpectedly omits ALL rows dat[- integer(0), ] It would be less surprising if there were no rows omitted in the (B) case. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Subtotals by id for a large number of columns XXXX
Hi, May be: apply(d1[3:5],2, mysum) var1 var2 var3 1 2 0 1 2 2 2 3 3 1 1 1 4 0 1 0 #or sapply(d1[3:5],mysum) #or library(plyr) ddply(d1[,-2],.(id),colwise(sum)) A.K. On Wednesday, October 30, 2013 8:30 AM, Dan Abner dan.abne...@gmail.com wrote: Hi Rui, Thanks for responding. When I make this change, I get an error message: mysum-function(x) tapply(x,d1$id,sum) d2-apply(d1[2:4],mysum) Error in match.fun(FUN) : argument FUN is missing, with no default Thoughts? On Wed, Oct 30, 2013 at 8:01 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, If I understand it correctly, just change mysum to the following. mysum-function(x) tapply(x,d1$id,sum) Hope this helps, Rui Barradas Em 30-10-2013 11:07, Dan Abner escreveu: Hi everybody, I have data in the format of the example data below where essentially a large number of indicator variables (coded [0,1]) reflect traits of the same id across multiple rows. I need to represent the data in a 1 row per id format. I see this as being similar to converting from long to wide format, however, there is no time component here: The multiple rows here are all characteristics observed at the same measurement occasion. So, really I just need an individual sum for each variable (for a large number of variables) and for these to be all saved in the same row (along with the id variable and other demographics (e.g., location). Here is the example df and the method I used first: d1-data.frame(id=c(1,1,1,2,2,**2,2,3,3,4),location=factor(c(** rep(0,7),rep(1,3)), labels=c(A,B)),var1=as.**logical(round(runif(10))), var2=as.logical(round(runif(**10))),var3=as.logical(round(** runif(10 d1 mysum-function(x) aggregate(x,by=list(d1$id),**sum) d2-sapply(d1[2:4],mysum) d2 Any help is appreciated!! Thanks! Dan [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] omitting integer(0) rows from data frame
dat[- integer(0), ] unexpectedly omits ALL rows It would be less surprising if there were no rows omitted in the (B) case. I tried this on two experienced R users here and their first thought* was, interestingly, as Jack indicated; that -integer(0) should drop nothing. But Gerrit is correct; -integer(0) still evaluates to a zero length vector, not a negative, and asking for a zero-length set of rows is equivalent to asking for no rows. Steve E *Second thought, actually; their first thought was 'why would you do that?'. To be fair we did note that dropping according to an empty 'which' criterion or an unmatched grep() would do this. The 'obvious' fix would presumably be not to wrap the selection in which() at all (eg use 1:5 == 6 directly and not which(1:5 == 6) ), to use regexpr(...)0 instead of grep etc. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Optimization failed in fitdistr (Weibull distribution)
On 29 Oct 2013, at 21:35 , Rolf Turner r.tur...@auckland.ac.nz wrote: On 10/29/13 19:44, peter dalgaard wrote: SNIP There really is no substitute for knowledge and understanding! Did it not occur to you that the Windspeed column needs to enter into your analysis? SNIP Fortune! Actually, I felt that that one came out a bit harsher than actually deserved. It’s quite interesting though, that the regular busybodies complained about the lack of easily reproducible data, but didn’t pick up on the fact that Frequency couldn’t be the right thing to analyze... cheers, Rolf Turner -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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] ggplot2 question: keeping the order as in the input data
Hello! I am using ggplot2 (see the code below) to plot the data in 'myplotdata'. The first column of 'myplotdata' is called att.levels and contains strings; the second column is called WTP and contains numeric values. Notice - I use 'coord.flip()' The command aes(x=att_levels, y=WTP), if I understand correctly, sorts things alphabetically based on the column 'att_levels'. Question 1: How can I reverse the order for x in the plot (also alphabetically but in the opposite direction)? Question 2: How can I just have exactly the same order as in the object 'myplotdata'? Thanks a lot! ggplot(myplotdata, aes(x=att_levels, y=WTP)) + geom_bar(stat=identity,fill=dark orange,colour=black, alpha = 1,position = identity) + geom_text(aes(label=WTP),colour=black,size=4,hjust=1.1,position='dodge') + coord_flip() + xlab() + ylab() -- Dimitri Liakhovitski [[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] Shiny question: what happens after hitting F5
I have a Shiny code that is working. In this code, the user uploads some input files, then runs some analyses (using an actionButton), gets some outputs displayed and can also download some results. I am testing this code. After I've run the analysis and have made some small change to the code, I hit F5. Now, I can start uploading my input files from scratch. However, as soon as I start uploading my input files, I get warnings (one for each file) that look like this: Warning in dir.create(dir) : 'C:\Users\DIMITR~1.LIA\AppData\Local\Temp\RtmpklHtMJ\435e92e733e5f0a8a00f342d' already exists It is still working. But: how could I get rid of these warnings? Thank you! -- Dimitri Liakhovitski [[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] Can not read Excel file correctly
I can't help you with cell A1, but I can make a guess at your date format issue. To start, I would suggest you read thoroughly the XLConnect documentation for how it handles dates (and probably also ?Date in R). In both Excel and R, dates are stored internally as a number, and then displayed with a user-selected format. In Excel, apparently, you have chosen a month-year format. R's default display format is year-month-day. So, it's not an issue with reading the data in, it's an issue of how dates are displayed. If you want to display your dates as month-year, you can do something like mydata$Col3 - format(mydata$Col3, '%m-%Y') But if you do that, you will then have character data, not dates, so you won't be able to do any date calculations. All of this assumes XLConnect is recognizing the Excel date columns as dates, and automatically converting them to the R Date class. If that's not what you want it to do, then you'll have to find the XLConnect documentation that tells you how to prevent it. Hope this helps. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 10/29/13 2:55 PM, Ron Michael ron_michae...@yahoo.com wrote: Hi, I need to read an Excel file which can be available in following link: http://www45.zippyshare.com/v/43626889/file.html Now I wanted to read the 1st sheet of this Excel file. Below are my code so far (I saved that file in 'F:' drive): library(XLConnect) Loading required package: rJava XLConnect 0.2-5 by Mirai Solutions GmbH http://www.mirai-solutions.com , http://miraisolutions.wordpress.com readWorksheetFromFile(f:/Dat1.xlsx, sheet = 1) Col1 Col2 Col3 Col4 1 NA NA 2013-05-01 NA 2 NA NA NA NA 3 1930-01-01 NA NA NA 4 NA 3127312736128730 NA NA 5 NA NA NA NA 6 NA NA NA SAsSag What I saw that, the element in A1 cell is missing. Also the data in C1 A4 are read in different format. In Excel file, it is Month-Year format, however what I see is Year-Month-Day format. I have many such files, therefore I do not want to convert them to csv (or any other). Doing so will be cumbersome. Can somebody here help me how to read that file in proper format? Thanks for your time. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 subject)
What would the calculated score be for the example you give? Jean On Wed, Oct 30, 2013 at 7:03 AM, Stevan Lauriault stevan.lauria...@gmail.com wrote: Hi, I'm looking for a function that takes a list and calculates a score based on how well like attracts like. For example: list1 - c(john, eric, steve, john, eric, scott, john) list2 - c(john, john, john, eric, eric, steve, scott) score(list1) score(list2) Both lists are composed of the same names and frequency of each name. Not sure how else to put it. I am relatively new to R. Have tried the modularity function, but can't seem to get it to work for this purpose. Any help is appreciated. Steve [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rpy2 and user defined functions from R
Could you produce a full working example then? Bit hard to debug without knowing what you did. Michael On Oct 30, 2013, at 9:11, Erin Hodgess erinm.hodg...@gmail.com wrote: I did...just didn't show it On Wed, Oct 30, 2013 at 7:01 AM, Michael Weylandt michael.weyla...@gmail.com wrote: Presumably you need to define 'buzz' first, but I don't see evidence that you've done so. Michael On Oct 30, 2013, at 0:06, Erin Hodgess erinm.hodg...@gmail.com wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R x = R.r.buzz(3) R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rpy2 and user defined functions from R
Erin, one question, can you access the defined functions by key? In lieu of: x = R.r.buzz(3) Can you do: x = R.r['buzz'](3) Alternatively if you need only one or two custom functions have you considered just defining them via python as in: PStr = function(LM) { S - summary(LM); print(S$fstatistic); F - S$fstatistic; P - pf(F[1], F[2], F[3], lower=FALSE); return(P); } r_LMPValFunc = robjects.r(PStr) Best, Collin. On Tue, 29 Oct 2013, Erin Hodgess wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Subtotals by id for a large number of columns XXXX
apply() is a different function from sapply() and has different arguments. - David L Carlson Deparment of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dan Abner Sent: Wednesday, October 30, 2013 7:24 AM To: Rui Barradas Cc: r-help@r-project.org Subject: Re: [R] Subtotals by id for a large number of columns Hi Rui, Thanks for responding. When I make this change, I get an error message: mysum-function(x) tapply(x,d1$id,sum) d2-apply(d1[2:4],mysum) Error in match.fun(FUN) : argument FUN is missing, with no default Thoughts? On Wed, Oct 30, 2013 at 8:01 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, If I understand it correctly, just change mysum to the following. mysum-function(x) tapply(x,d1$id,sum) Hope this helps, Rui Barradas Em 30-10-2013 11:07, Dan Abner escreveu: Hi everybody, I have data in the format of the example data below where essentially a large number of indicator variables (coded [0,1]) reflect traits of the same id across multiple rows. I need to represent the data in a 1 row per id format. I see this as being similar to converting from long to wide format, however, there is no time component here: The multiple rows here are all characteristics observed at the same measurement occasion. So, really I just need an individual sum for each variable (for a large number of variables) and for these to be all saved in the same row (along with the id variable and other demographics (e.g., location). Here is the example df and the method I used first: d1-data.frame(id=c(1,1,1,2,2,**2,2,3,3,4),location=factor(c(** rep(0,7),rep(1,3)), labels=c(A,B)),var1=as.**logical(round(runif(10))), var2=as.logical(round(runif(**10))),var3=as.logical(round(** runif(10 d1 mysum-function(x) aggregate(x,by=list(d1$id),**sum) d2-sapply(d1[2:4],mysum) d2 Any help is appreciated!! Thanks! Dan [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz .ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Shiny question: what happens after hitting F5
I get warnings (one for each file) that look like this: Warning in dir.create(dir) : 'C:\Users\DIMITR~1.LIA\AppData\Local\Temp\RtmpklHtMJ\435e92e733e5f0 a8a00f342d' already exists It is still working. But: how could I get rid of these warnings? Delete the temporary files before running the code? S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 question: keeping the order as in the input data
Try making att_levels (or att.levels, whatever you really call it) into a factor with the levels in the order you like. E.g., aes(x = factor(att_levels, levels=unique(att_levels)), y = WTP) instead of aes(x = att_levels, y = WTP) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dimitri Liakhovitski Sent: Wednesday, October 30, 2013 7:35 AM To: r-help Subject: [R] ggplot2 question: keeping the order as in the input data Hello! I am using ggplot2 (see the code below) to plot the data in 'myplotdata'. The first column of 'myplotdata' is called att.levels and contains strings; the second column is called WTP and contains numeric values. Notice - I use 'coord.flip()' The command aes(x=att_levels, y=WTP), if I understand correctly, sorts things alphabetically based on the column 'att_levels'. Question 1: How can I reverse the order for x in the plot (also alphabetically but in the opposite direction)? Question 2: How can I just have exactly the same order as in the object 'myplotdata'? Thanks a lot! ggplot(myplotdata, aes(x=att_levels, y=WTP)) + geom_bar(stat=identity,fill=dark orange,colour=black, alpha = 1,position = identity) + geom_text(aes(label=WTP),colour=black,size=4,hjust=1.1,position='dodge') + coord_flip() + xlab() + ylab() -- Dimitri Liakhovitski [[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] rpy2 and user defined functions from R
Here we go: buzz function(x) { y - x + pi return(y) } q() Save workspace image? [y/n/c]: python Save workspace image? [y/n/c]: y root@erinminfo [/home/erinminf/public_html]# python Python 2.7.5 (default, Sep 11 2013, 02:14:06) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2 Type help, copyright, credits or license for more information. import rpy2.robjects as R R.r.buzz(3) Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.7/site-packages/rpy2/robjects/__init__.py, line 213, in __getattribute__ raise orig_ae AttributeError: 'R' object has no attribute 'buzz' R.r['buzz'](3) Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.7/site-packages/rpy2/robjects/__init__.py, line 216, in __getitem__ res = _globalenv.get(item) LookupError: 'buzz' not found root@erinminfo [/home/erinminf/public_html]# On Wed, Oct 30, 2013 at 10:16 AM, Collin Lynch coll...@cs.pitt.edu wrote: Erin, one question, can you access the defined functions by key? In lieu of: x = R.r.buzz(3) Can you do: x = R.r['buzz'](3) Alternatively if you need only one or two custom functions have you considered just defining them via python as in: PStr = function(LM) { S - summary(LM); print(S$fstatistic); F - S$fstatistic; P - pf(F[1], F[2], F[3], lower=FALSE); return(P); } r_LMPValFunc = robjects.r(PStr) Best, Collin. On Tue, 29 Oct 2013, Erin Hodgess wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] omitting integer(0) rows from data frame
This is Circle 8.1.13 of 'The R Inferno'. http://www.burns-stat.com/documents/books/the-r-inferno/ Pat On 30/10/2013 13:04, Jack Tanner wrote: I'm not sure if this is correct behavior or not, but it seems counterintuitive to me: dat - data.frame(id=1:5, let=letters[1:5]) # A. omits the first row dat[- 1, ] # B. unexpectedly omits ALL rows dat[- integer(0), ] It would be less surprising if there were no rows omitted in the (B) case. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 me align the legend bar
Hi, I have some code that you can simply execute: require(plotrix) test-matrix(data=rnorm(1,-100,5),nrow=100) color2D.matplot(test,axes=F,xlab=,ylab=,main=color.scale, extremes=c(#FF,#00),show.legend=FALSE) axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10)) color.legend(84,30,125,70,seq(-110,-30,length=11), align=rb,rect.col=color.scale(1:30,1,c(0,1),0),gradient=y) What I would like to do is to make space at the right for the color band . The band should have one color from -110 to -30 with scales of 10. Can someone help me with that? Regards Alex [[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] Subtotals by id for a large number of columns XXXX
On Oct 30, 2013, at 4:07 AM, Dan Abner wrote: Hi everybody, I have data in the format of the example data below where essentially a large number of indicator variables (coded [0,1]) reflect traits of the same id across multiple rows. I need to represent the data in a 1 row per id format. I see this as being similar to converting from long to wide format, however, there is no time component here: The multiple rows here are all characteristics observed at the same measurement occasion. So, really I just need an individual sum for each variable (for a large number of variables) and for these to be all saved in the same row (along with the id variable and other demographics (e.g., location). Here is the example df and the method I used first: d1-data.frame(id=c(1,1,1,2,2,2,2,3,3,4),location=factor(c(rep(0,7),rep(1,3)), labels=c(A,B)),var1=as.logical(round(runif(10))), var2=as.logical(round(runif(10))),var3=as.logical(round(runif(10 d1 Perhaps. mysum-aggregate(d1[-(1:2)],by=d1[1:2] ,sum) mysum id location var1 var2 var3 1 1A021 2 2A121 3 3B102 4 4B110 [[alternative HTML version deleted]] Please learn to use your mail client to post in plain text. (All of the free mailer services support plain text, so continuing to post in HYML is evidence of willful refusal to adhere to the posting guidelines.) -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] omitting integer(0) rows from data frame
On Oct 30, 2013, at 6:04 AM, Jack Tanner wrote: I'm not sure if this is correct behavior or not, but it seems counterintuitive to me: dat - data.frame(id=1:5, let=letters[1:5]) # A. omits the first row dat[- 1, ] # B. unexpectedly omits ALL rows dat[- integer(0), ] It would be less surprising if there were no rows omitted in the (B) case. Yes. It is surprising. It is also teh reason why the construction is also not returning what a user might expect: dat[-which(dat$id 5), ] #[1] id let #0 rows (or 0-length row.names) (And yes I know that many people never use which with a logical. I'm just not one of those for what I consider good reasons.) `subset` may be preferred, at least for console interaction: subset( dat, !(id 5) ) id let 1 1 a 2 2 b 3 3 c 4 4 d 5 5 e -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Subtotals by id for a large number of columns XXXX
Hi David, 1) Thanks very much. Your code shows that this was much simpler than I anticipated. 2) I have made the appropriate changes to email in plain text. My apologies. Thanks! Dan On Wed, Oct 30, 2013 at 1:17 PM, David Winsemius dwinsem...@comcast.net wrote: On Oct 30, 2013, at 4:07 AM, Dan Abner wrote: Hi everybody, I have data in the format of the example data below where essentially a large number of indicator variables (coded [0,1]) reflect traits of the same id across multiple rows. I need to represent the data in a 1 row per id format. I see this as being similar to converting from long to wide format, however, there is no time component here: The multiple rows here are all characteristics observed at the same measurement occasion. So, really I just need an individual sum for each variable (for a large number of variables) and for these to be all saved in the same row (along with the id variable and other demographics (e.g., location). Here is the example df and the method I used first: d1-data.frame(id=c(1,1,1,2,2,2,2,3,3,4),location=factor(c(rep(0,7),rep(1,3)), labels=c(A,B)),var1=as.logical(round(runif(10))), var2=as.logical(round(runif(10))),var3=as.logical(round(runif(10 d1 Perhaps. mysum-aggregate(d1[-(1:2)],by=d1[1:2] ,sum) mysum id location var1 var2 var3 1 1A021 2 2A121 3 3B102 4 4B110 [[alternative HTML version deleted]] Please learn to use your mail client to post in plain text. (All of the free mailer services support plain text, so continuing to post in HYML is evidence of willful refusal to adhere to the posting guidelines.) -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
You should cc r-help on all correspondence so everyone can follow the thread. Clearly I'm missing something. Perhaps others are, too. I don't know what you mean by a score based on the co-localization of names unless you give an example. Jean On Wed, Oct 30, 2013 at 10:34 AM, Stevan Lauriault stevan.lauria...@gmail.com wrote: It would depend on the algorithm. Which is why I'm writing. I'm asking if anyone knows of a preexisting algorithm that would calculate a score based on the co-localization of names. S On Wed, Oct 30, 2013 at 10:56 AM, Adams, Jean jvad...@usgs.gov wrote: What would the calculated score be for the example you give? Jean On Wed, Oct 30, 2013 at 7:03 AM, Stevan Lauriault stevan.lauria...@gmail.com wrote: Hi, I'm looking for a function that takes a list and calculates a score based on how well like attracts like. For example: list1 - c(john, eric, steve, john, eric, scott, john) list2 - c(john, john, john, eric, eric, steve, scott) score(list1) score(list2) Both lists are composed of the same names and frequency of each name. Not sure how else to put it. I am relatively new to R. Have tried the modularity function, but can't seem to get it to work for this purpose. Any help is appreciated. Steve [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 question: keeping the order as in the input data
Indeed, it helped - thank you, Bill. And now - how could I now avoid the reversal on my axis with att_levels? Currently it starts with the last one being the first one on the graph and ends with the first one... On Wed, Oct 30, 2013 at 12:04 PM, William Dunlap wdun...@tibco.com wrote: Try making att_levels (or att.levels, whatever you really call it) into a factor with the levels in the order you like. E.g., aes(x = factor(att_levels, levels=unique(att_levels)), y = WTP) instead of aes(x = att_levels, y = WTP) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dimitri Liakhovitski Sent: Wednesday, October 30, 2013 7:35 AM To: r-help Subject: [R] ggplot2 question: keeping the order as in the input data Hello! I am using ggplot2 (see the code below) to plot the data in 'myplotdata'. The first column of 'myplotdata' is called att.levels and contains strings; the second column is called WTP and contains numeric values. Notice - I use 'coord.flip()' The command aes(x=att_levels, y=WTP), if I understand correctly, sorts things alphabetically based on the column 'att_levels'. Question 1: How can I reverse the order for x in the plot (also alphabetically but in the opposite direction)? Question 2: How can I just have exactly the same order as in the object 'myplotdata'? Thanks a lot! ggplot(myplotdata, aes(x=att_levels, y=WTP)) + geom_bar(stat=identity,fill=dark orange,colour=black, alpha = 1,position = identity) + geom_text(aes(label=WTP),colour=black,size=4,hjust=1.1,position='dodge') + coord_flip() + xlab() + ylab() -- Dimitri Liakhovitski [[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. -- Dimitri Liakhovitski [[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] rpy2 and user defined functions from R
Solve: I wrote the buzz function to buzz.R And now I have: from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage as STAP with open(buzz.R,r) as f: string = '''.join(f.readlines()) buzz = STAP(string,buzz) buzz.buzz(3) And all is well! Thanks, Erin On Wed, Oct 30, 2013 at 11:05 AM, Erin Hodgess erinm.hodg...@gmail.comwrote: Here we go: buzz function(x) { y - x + pi return(y) } q() Save workspace image? [y/n/c]: python Save workspace image? [y/n/c]: y root@erinminfo [/home/erinminf/public_html]# python Python 2.7.5 (default, Sep 11 2013, 02:14:06) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2 Type help, copyright, credits or license for more information. import rpy2.robjects as R R.r.buzz(3) Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.7/site-packages/rpy2/robjects/__init__.py, line 213, in __getattribute__ raise orig_ae AttributeError: 'R' object has no attribute 'buzz' R.r['buzz'](3) Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.7/site-packages/rpy2/robjects/__init__.py, line 216, in __getitem__ res = _globalenv.get(item) LookupError: 'buzz' not found root@erinminfo [/home/erinminf/public_html]# On Wed, Oct 30, 2013 at 10:16 AM, Collin Lynch coll...@cs.pitt.eduwrote: Erin, one question, can you access the defined functions by key? In lieu of: x = R.r.buzz(3) Can you do: x = R.r['buzz'](3) Alternatively if you need only one or two custom functions have you considered just defining them via python as in: PStr = function(LM) { S - summary(LM); print(S$fstatistic); F - S$fstatistic; P - pf(F[1], F[2], F[3], lower=FALSE); return(P); } r_LMPValFunc = robjects.r(PStr) Best, Collin. On Tue, 29 Oct 2013, Erin Hodgess wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
Just guessing, would the following help? list1 - c(john, eric, steve, john, eric, scott, john) list2 - c(john, john, john, eric, eric, steve, scott) max(rle(list1)$lengths) max(rle(list2)$lengths) Clint Clint BowmanINTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600FAX:(360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels:300 Desmond Drive, Lacey, WA 98503-1274 On Wed, 30 Oct 2013, Adams, Jean wrote: You should cc r-help on all correspondence so everyone can follow the thread. Clearly I'm missing something. Perhaps others are, too. I don't know what you mean by a score based on the co-localization of names unless you give an example. Jean On Wed, Oct 30, 2013 at 10:34 AM, Stevan Lauriault stevan.lauria...@gmail.com wrote: It would depend on the algorithm. Which is why I'm writing. I'm asking if anyone knows of a preexisting algorithm that would calculate a score based on the co-localization of names. S On Wed, Oct 30, 2013 at 10:56 AM, Adams, Jean jvad...@usgs.gov wrote: What would the calculated score be for the example you give? Jean On Wed, Oct 30, 2013 at 7:03 AM, Stevan Lauriault stevan.lauria...@gmail.com wrote: Hi, I'm looking for a function that takes a list and calculates a score based on how well like attracts like. For example: list1 - c(john, eric, steve, john, eric, scott, john) list2 - c(john, john, john, eric, eric, steve, scott) score(list1) score(list2) Both lists are composed of the same names and frequency of each name. Not sure how else to put it. I am relatively new to R. Have tried the modularity function, but can't seem to get it to work for this purpose. Any help is appreciated. Steve [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] big speed difference in source btw. R 2.15.2 and R 3.0.2 ?
I see a big 2.15.2/3.0.2 speed difference in parse() (which is used by source()) when it is parsing long vectors of numeric data. dump/source has never been an efficient way of transferring data between different R session, but it is much worse now for long vectors. In 2.15.2 doubling the size of the vector (of lengths in the range 10^4 to 10^7) makes the time to parse go up by a factor of c. 2.1. In 3.0.2 that factor is more like 4.4. n elapsed-2.15.2 elapsed-3.0.2 2048 0.003 0.018 4096 0.006 0.065 8192 0.013 0.254 16384 0.025 1.067 32768 0.050 4.114 65536 0.10016.236 131072 0.21966.013 262144 0.808 291.883 524288 2.022 1285.265 1048576 4.918NA 2097152 9.857NA 4194304 22.916NA 8388608 49.671NA 16777216101.042NA 33554432512.719NA I tried this with 64-bit R on a Linux box. The NA's represent sizes that did not finish while I was at a 1 1/2 hour dentist's apppointment. The timing function was: test - function(n = 2^(11:25)) { tf - tempfile() on.exit(unlink(tf)) t(sapply(n, function(n){ dput(log(seq_len(n)), file=tf) print(c(n=n, system.time(parse(file=tf))[1:3])) })) } Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carl Witthoft Sent: Wednesday, October 30, 2013 5:29 AM To: r-help@r-project.org Subject: Re: [R] big speed difference in source btw. R 2.15.2 and R 3.0.2 ? Did you run the identical code on the identical machine, and did you verify there were no other tasks running which might have limited the RAM available to R? And equally important, did you run these tests in the reverse order (in case R was storing large objects from the first run, thus chewing up RAM)? Dear All, is it known that source works much faster in R 2.15.2 than in R 3.0.2 ? In the example below I observe e.g. for a data.frame with 10^7 rows the following timings: R version 2.15.2 Patched (2012-11-29 r61184) length: 1e+07 user system elapsed 62.040.22 62.26 R version 3.0.2 Patched (2013-10-27 r64116) length: 1e+07 user system elapsed 388.63 176.42 566.41 Is there a way to speed R version 3.0.2 up to the performance of R version 2.15.2? best regards, Heinz Tüchler example: sessionInfo() sample.vec - c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) dump('df0', file='testdump') cat('length:', i, '\n') print(system.time(source('testdump', keep.source = FALSE, encoding=''))) } output for R version 2.15.2 Patched (2012-11-29 r61184): sessionInfo() R version 2.15.2 Patched (2012-11-29 r61184) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', + 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { + df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) + dump('df0', file='testdump') + cat('length:', i, '\n') + print(system.time(source('testdump', keep.source = FALSE, +encoding=''))) + } length: 10 user system elapsed 0 0 0 length: 100 user system elapsed 0 0 0 length: 1000 user system elapsed 0 0 0 length: 1 user system elapsed 0.020.000.01 length: 1e+05 user system elapsed 0.210.000.20 length: 1e+06 user system elapsed 4.470.044.51 length: 1e+07 user system elapsed 62.040.22 62.26 output for R version 3.0.2 Patched (2013-10-27 r64116): sessionInfo() R version 3.0.2 Patched (2013-10-27 r64116) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', +
[R] multiple concurrent write in R
I have over 200 CPUs could write to the same file at the same time, does someone know how to handle the multiple concurrent write in R? [[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] mapping data to a geographic map of Europe
Hi Jim, thats the second time that you helped me in a short while so thanks a lot! But it seems to me quite laborious and error-prone to first select all the relevant countries in this long list and then to create a color vector. But perhaps I get it all wrong. For the color vector I first did this imagecolors-color.scale(mydata$GPIndex ,c(1,0,0),0,c(0,0,1)) because I wanted the colors to scale from dark red (bad ones) to dark blue (good ones). But it went somehow wrong. By the way can you tell me what I did wrong? Nevertheless I than createt a color vector looking loke this: eurocol=c(#FFFF,8,#71FF,#39FF,8,8,#39FF,rep(8,10),#2FFF ,8,#00FF,8,#00FF,#00FF ,#55FF,8,#64FF,2, #83FF,8,8,#8BFF ,#F0FF ,rep(8,20),#F7FF ,rep(8,18),#, rep(8,120)) And than world.map-map('world', fill = TRUE,col =eurocol ,xlim=c(-12,35),ylim=c(37,70)) Beside the wrong colors it worked okay. But I am not really happy with this solution. Did I misapprehend you? Best regards and thanks again Claudi Zitat von Jim Lemon j...@bitwrit.com.au: On 10/30/2013 04:02 AM, palad...@trustindata.de wrote: Hello, I would like to draw a map of Europe. Each country should be colored depending on how it scores in an index called GPIndex. Say a dark red for real bad countries a light red for those which are not so bad, light blue for the fairly good ones and so on up to the really good ones in a dark blue. I never worked with geographic maps before so I tried library maps but I didn't get far,- especially because all examples I found only seem to work for the United states. So I'm a bit lost. I would be nice if somebody could help me. Hi Claudia, If you draw a map of Europe something like this: world.map-map('world', fill = TRUE, col = 1:10,xlim=c(-15,40),ylim=c(37,70)) you have a col argument that you can pass the colors you want. What you must do is look at the names component of world.map: $names [1] Denmark [2] USSR [3] Italy [4] Netherlands [5] Iraq ... to get the indices of the countries. Say Denmark was fairly good, USSR was fairly bad, and so on. You could then pass colors like this: col=c(lightblue,lightred,...) in the call to map for as many countries as you wanted. Pass NA for those countries that you don't want to color. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] omitting integer(0) rows from data frame
It would be less surprising if there were no rows omitted in the (B) case. -integer(0) is identical to integer(0), so how could '[' handle them differently? Yes. It is surprising. It is also teh reason why the construction is also not returning what a user might expect: dat[-which(dat$id 5), ] #[1] id let #0 rows (or 0-length row.names) (And yes I know that many people never use which with a logical. I'm just not one of those for what I consider good reasons.) `subset` may be preferred, at least for console interaction: subset( dat, !(id 5) ) Preferring to use which(logical) is ok, as long as you are careful, but subset() will not let you use which(). subset(dat, -which(id5)) Error in subset.data.frame(dat, -which(id 5)) : 'subset' must evaluate to logical Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Wednesday, October 30, 2013 10:28 AM To: Jack Tanner Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] omitting integer(0) rows from data frame On Oct 30, 2013, at 6:04 AM, Jack Tanner wrote: I'm not sure if this is correct behavior or not, but it seems counterintuitive to me: dat - data.frame(id=1:5, let=letters[1:5]) # A. omits the first row dat[- 1, ] # B. unexpectedly omits ALL rows dat[- integer(0), ] It would be less surprising if there were no rows omitted in the (B) case. Yes. It is surprising. It is also teh reason why the construction is also not returning what a user might expect: dat[-which(dat$id 5), ] #[1] id let #0 rows (or 0-length row.names) (And yes I know that many people never use which with a logical. I'm just not one of those for what I consider good reasons.) `subset` may be preferred, at least for console interaction: subset( dat, !(id 5) ) id let 1 1 a 2 2 b 3 3 c 4 4 d 5 5 e -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] omitting integer(0) rows from data frame
Both PBurns and DWin are correct. I just thought I'd add a clunky safety check approach I use now and then: Before doing the actual subset, i.e. df[-which(something),] , do something like if (length(which(something)) 1 ) {skip the subsetting} else df[-which(something)] -- View this message in context: http://r.789695.n4.nabble.com/omitting-integer-0-rows-from-data-frame-tp4679353p4679386.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] getPortfolio(frontier)$weight
Dear all, It does not work function getWeights in the fPortfolio package. Returns a vector instead of a matrix. can anyone help me? Thanks in advance. Massimiliano [[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] rpy2 and user defined functions from R
I don't believe that rpy2 will load a saved workspace. When I have worked with this I always load my functions by sourcing an r file separately: R.r['source'](MyFuncs.r) Best, Collin. On Wed, 30 Oct 2013, Erin Hodgess wrote: Here we go: buzz function(x) { y - x + pi return(y) } q() Save workspace image? [y/n/c]: python Save workspace image? [y/n/c]: y root@erinminfo [/home/erinminf/public_html]# python Python 2.7.5 (default, Sep 11 2013, 02:14:06) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2 Type help, copyright, credits or license for more information. import rpy2.robjects as R R.r.buzz(3) Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.7/site-packages/rpy2/robjects/__init__.py, line 213, in __getattribute__ raise orig_ae AttributeError: 'R' object has no attribute 'buzz' R.r['buzz'](3) Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.7/site-packages/rpy2/robjects/__init__.py, line 216, in __getitem__ res = _globalenv.get(item) LookupError: 'buzz' not found root@erinminfo [/home/erinminf/public_html]# On Wed, Oct 30, 2013 at 10:16 AM, Collin Lynch coll...@cs.pitt.edu wrote: Erin, one question, can you access the defined functions by key? In lieu of: x = R.r.buzz(3) Can you do: x = R.r['buzz'](3) Alternatively if you need only one or two custom functions have you considered just defining them via python as in: PStr = function(LM) { S - summary(LM); print(S$fstatistic); F - S$fstatistic; P - pf(F[1], F[2], F[3], lower=FALSE); return(P); } r_LMPValFunc = robjects.r(PStr) Best, Collin. On Tue, 29 Oct 2013, Erin Hodgess wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@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] multiple concurrent write in R
I think the answer is no. Use the master process to manage IO. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Zhifa Liu zhifa...@gmail.com wrote: I have over 200 CPUs could write to the same file at the same time, does someone know how to handle the multiple concurrent write in R? [[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] rpy2 and user defined functions from R
if you don't need to exchange big data between r and python, pyper might be better than rpy2. On Oct 30, 2013 12:08 AM, Erin Hodgess erinm.hodg...@gmail.com wrote: Hello again! I'm using python with a module rpy2 to call functions from R. It works fine on built in R functions like rnorm. However, I would like to access user-defined functions as well. For those of you who use this, I have: import rpy2.robjects as R x = R.r.buzz(3) R object as no attribute buzz (user defined function of buzz) This is on a Centos 5 machine with R-3.0.2 and python of 2.7.5. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] big speed difference in source btw. R 2.15.2 and R 3.0.2 ?
Best thanks for confirming my impression. I use dump for storing large data.frames with a number of attributes for each variable. save/load is much faster, but I am unsure, if such files will be readable by R versions years later. What format/functions would you suggest for data storage/transfer between different (future) R versions? best regards, Heinz on/am 30.10.2013 20:11, William Dunlap wrote/hat geschrieben: I see a big 2.15.2/3.0.2 speed difference in parse() (which is used by source()) when it is parsing long vectors of numeric data. dump/source has never been an efficient way of transferring data between different R session, but it is much worse now for long vectors. In 2.15.2 doubling the size of the vector (of lengths in the range 10^4 to 10^7) makes the time to parse go up by a factor of c. 2.1. In 3.0.2 that factor is more like 4.4. n elapsed-2.15.2 elapsed-3.0.2 2048 0.003 0.018 4096 0.006 0.065 8192 0.013 0.254 16384 0.025 1.067 32768 0.050 4.114 65536 0.10016.236 131072 0.21966.013 262144 0.808 291.883 524288 2.022 1285.265 1048576 4.918NA 2097152 9.857NA 4194304 22.916NA 8388608 49.671NA 16777216101.042NA 33554432512.719NA I tried this with 64-bit R on a Linux box. The NA's represent sizes that did not finish while I was at a 1 1/2 hour dentist's apppointment. The timing function was: test - function(n = 2^(11:25)) { tf - tempfile() on.exit(unlink(tf)) t(sapply(n, function(n){ dput(log(seq_len(n)), file=tf) print(c(n=n, system.time(parse(file=tf))[1:3])) })) } Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carl Witthoft Sent: Wednesday, October 30, 2013 5:29 AM To: r-help@r-project.org Subject: Re: [R] big speed difference in source btw. R 2.15.2 and R 3.0.2 ? Did you run the identical code on the identical machine, and did you verify there were no other tasks running which might have limited the RAM available to R? And equally important, did you run these tests in the reverse order (in case R was storing large objects from the first run, thus chewing up RAM)? Dear All, is it known that source works much faster in R 2.15.2 than in R 3.0.2 ? In the example below I observe e.g. for a data.frame with 10^7 rows the following timings: R version 2.15.2 Patched (2012-11-29 r61184) length: 1e+07 user system elapsed 62.040.22 62.26 R version 3.0.2 Patched (2013-10-27 r64116) length: 1e+07 user system elapsed 388.63 176.42 566.41 Is there a way to speed R version 3.0.2 up to the performance of R version 2.15.2? best regards, Heinz Tüchler example: sessionInfo() sample.vec - c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) dump('df0', file='testdump') cat('length:', i, '\n') print(system.time(source('testdump', keep.source = FALSE, encoding=''))) } output for R version 2.15.2 Patched (2012-11-29 r61184): sessionInfo() R version 2.15.2 Patched (2012-11-29 r61184) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', + 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { + df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) + dump('df0', file='testdump') + cat('length:', i, '\n') + print(system.time(source('testdump', keep.source = FALSE, +encoding=''))) + } length: 10 user system elapsed 0 0 0 length: 100 user system elapsed 0 0 0 length: 1000 user system elapsed 0 0 0 length: 1 user system elapsed 0.020.000.01 length: 1e+05 user system elapsed 0.210.000.20 length: 1e+06 user system elapsed 4.470.044.51 length: 1e+07 user system elapsed 62.040.22 62.26 output for R version 3.0.2 Patched (2013-10-27 r64116): sessionInfo() R version 3.0.2 Patched (2013-10-27 r64116) Platform: x86_64-w64-mingw32/x64 (64-bit)
Re: [R] multiple concurrent write in R
On Linux, at least, you can have various processes write into the same file, by opening it with r+ mode and calling seek() to position the file pointer before writing. E.g., library(parallel) cl4 - makeCluster(4) tf - tempfile() cat(rep(, 2*length(cl4)), sep=\n, file=tf) readLines(tf) [1] [8] z - parLapply(cl4, 8:1, function(i, tf){ f - file(tf, open=r+) on.exit(close(f)) seek(f, (i-1)*9, rw=w) ret - c(i, Sys.getpid()) cat(ret, file=f); ret}, tf=tf) readLines(tf) [1] 1 22406- 2 22406- 3 22397- 4 22397- 5 22388- 6 22388- 7 22379- [8] 8 22379- Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Wednesday, October 30, 2013 12:58 PM To: Zhifa Liu; r-help@r-project.org Subject: Re: [R] multiple concurrent write in R I think the answer is no. Use the master process to manage IO. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Zhifa Liu zhifa...@gmail.com wrote: I have over 200 CPUs could write to the same file at the same time, does someone know how to handle the multiple concurrent write in R? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help me align the legend bar
You could use the mar= argument of the par() function to define a wider plot margin on the right, then change the first and third arguments of color.legend() to make the legend fit in the margin. For example, par(mar=c(3, 1, 3, 7)) color2D.matplot(test, axes=F, xlab=, ylab=, main=color.scale, extremes=c(#FF,#00), show.legend=FALSE) axis(1, at=seq(1, ncol(test), length.out=10), labels=seq(201, 300, length.out=10)) color.legend(105, 30, 115, 70, seq(-110, -30, length=11), align=rb, rect.col=color.scale(1:30, 1, c(0,1), 0), gradient=y) Jean On Wed, Oct 30, 2013 at 12:09 PM, Alaios ala...@yahoo.com wrote: Hi, I have some code that you can simply execute: require(plotrix) test-matrix(data=rnorm(1,-100,5),nrow=100) color2D.matplot(test,axes=F,xlab=,ylab=,main=color.scale, extremes=c(#FF,#00),show.legend=FALSE) axis(1,at=seq(1,ncol(test),length.out=10),labels=seq(201,300,length.out=10)) color.legend(84,30,125,70,seq(-110,-30,length=11), align=rb,rect.col=color.scale(1:30,1,c(0,1),0),gradient=y) What I would like to do is to make space at the right for the color band . The band should have one color from -110 to -30 with scales of 10. Can someone help me with that? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] big speed difference in source btw. R 2.15.2 and R 3.0.2 ?
I have to defer to others for policy declarations like how long the current format used by load and save should be readable. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: Heinz Tuechler [mailto:tuech...@gmx.at] Sent: Wednesday, October 30, 2013 1:43 PM To: William Dunlap Cc: Carl Witthoft; r-help@r-project.org Subject: Re: [R] big speed difference in source btw. R 2.15.2 and R 3.0.2 ? Best thanks for confirming my impression. I use dump for storing large data.frames with a number of attributes for each variable. save/load is much faster, but I am unsure, if such files will be readable by R versions years later. What format/functions would you suggest for data storage/transfer between different (future) R versions? best regards, Heinz on/am 30.10.2013 20:11, William Dunlap wrote/hat geschrieben: I see a big 2.15.2/3.0.2 speed difference in parse() (which is used by source()) when it is parsing long vectors of numeric data. dump/source has never been an efficient way of transferring data between different R session, but it is much worse now for long vectors. In 2.15.2 doubling the size of the vector (of lengths in the range 10^4 to 10^7) makes the time to parse go up by a factor of c. 2.1. In 3.0.2 that factor is more like 4.4. n elapsed-2.15.2 elapsed-3.0.2 2048 0.003 0.018 4096 0.006 0.065 8192 0.013 0.254 16384 0.025 1.067 32768 0.050 4.114 65536 0.10016.236 131072 0.21966.013 262144 0.808 291.883 524288 2.022 1285.265 1048576 4.918NA 2097152 9.857NA 4194304 22.916NA 8388608 49.671NA 16777216101.042NA 33554432512.719NA I tried this with 64-bit R on a Linux box. The NA's represent sizes that did not finish while I was at a 1 1/2 hour dentist's apppointment. The timing function was: test - function(n = 2^(11:25)) { tf - tempfile() on.exit(unlink(tf)) t(sapply(n, function(n){ dput(log(seq_len(n)), file=tf) print(c(n=n, system.time(parse(file=tf))[1:3])) })) } Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carl Witthoft Sent: Wednesday, October 30, 2013 5:29 AM To: r-help@r-project.org Subject: Re: [R] big speed difference in source btw. R 2.15.2 and R 3.0.2 ? Did you run the identical code on the identical machine, and did you verify there were no other tasks running which might have limited the RAM available to R? And equally important, did you run these tests in the reverse order (in case R was storing large objects from the first run, thus chewing up RAM)? Dear All, is it known that source works much faster in R 2.15.2 than in R 3.0.2 ? In the example below I observe e.g. for a data.frame with 10^7 rows the following timings: R version 2.15.2 Patched (2012-11-29 r61184) length: 1e+07 user system elapsed 62.040.22 62.26 R version 3.0.2 Patched (2013-10-27 r64116) length: 1e+07 user system elapsed 388.63 176.42 566.41 Is there a way to speed R version 3.0.2 up to the performance of R version 2.15.2? best regards, Heinz Tüchler example: sessionInfo() sample.vec - c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) dump('df0', file='testdump') cat('length:', i, '\n') print(system.time(source('testdump', keep.source = FALSE, encoding=''))) } output for R version 2.15.2 Patched (2012-11-29 r61184): sessionInfo() R version 2.15.2 Patched (2012-11-29 r61184) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C [5] LC_TIME=German_Switzerland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base sample.vec - + c('source', 'causes', 'R', 'to', 'accept', 'its', 'input', 'from', 'the', + 'named', 'file', 'or', 'URL', 'or', 'connection') dmp.size - c(10^(1:7)) set.seed(37) for(i in dmp.size) { + df0 - data.frame(x=sample(sample.vec, i, replace=TRUE)) + dump('df0', file='testdump') + cat('length:', i, '\n') + print(system.time(source('testdump',
Re: [R] (no subject)
On 10/30/2013 11:03 PM, Stevan Lauriault wrote: Hi, I'm looking for a function that takes a list and calculates a score based on how well like attracts like. For example: list1- c(john, eric, steve, john, eric, scott, john) list2- c(john, john, john, eric, eric, steve, scott) score(list1) score(list2) Both lists are composed of the same names and frequency of each name. Not sure how else to put it. I am relatively new to R. Have tried the modularity function, but can't seem to get it to work for this purpose. Hi Steve, My first guess would be a distance function. Something like the variance of the indices of the various names: by(1:length(list1),list1,var) by(1:length(list2),list2,var) How you will handle the NAs generated by single names is another matter. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mapping data to a geographic map of Europe
On 10/31/2013 03:04 AM, palad...@trustindata.de wrote: Hi Jim, thats the second time that you helped me in a short while so thanks a lot! But it seems to me quite laborious and error-prone to first select all the relevant countries in this long list and then to create a color vector. But perhaps I get it all wrong. For the color vector I first did this imagecolors-color.scale(mydata$GPIndex ,c(1,0,0),0,c(0,0,1)) because I wanted the colors to scale from dark red (bad ones) to dark blue (good ones). But it went somehow wrong. By the way can you tell me what I did wrong? Nevertheless I than createt a color vector looking loke this: eurocol=c(#FFFF,8,#71FF,#39FF,8,8,#39FF,rep(8,10),#2FFF ,8,#00FF,8,#00FF,#00FF ,#55FF,8,#64FF,2, #83FF,8,8,#8BFF ,#F0FF ,rep(8,20),#F7FF ,rep(8,18),#, rep(8,120)) And than world.map-map('world', fill = TRUE,col =eurocol ,xlim=c(-12,35),ylim=c(37,70)) Beside the wrong colors it worked okay. But I am not really happy with this solution. Did I misapprehend you? Hi Claudi, Maybe. You write that the transformation of GPIndex to colors went wrong. Let's see: # make up GPIndex GPIndex-c(sample(1:100,33),rep(NA,165)) # transform to colors eurocol-color.scale(GPIndex,c(1,0),0,c(0,1)) world.map-map('world',fill=TRUE, col=eurocol,xlim=c(-12,35),ylim=c(37,70)) This gives me what I would expect, and checking the colors against the country names (world.map$names) looks like the correct colors have been displayed. Obviously I left a lot of areas out (missed UK and Ireland for example) as I didn't want to overplot individual countries with areas. Does this look okay to you? Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] an rpy2, R cgi type question
Hi again. I'm putting together a little project with R, python, and a website. So I have an HTML file, a py file, an R file. Here is the HTML file: form action=/cgi-bin/radio4.py method=post target=_blank input type=radio name=subject value=Integrate / Integrate input type=radio name=subject value=Differentiate / Differentiate input type=radio name=subject value=Graph / Graph Function input type=text name=func1 br / input type=submit value=Select Subject / /form Now the radio4.py file: # Import modules for CGI handling import cgi, cgitb from sympy import * import sys from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage as STAP with open(bz2.R,r) as f: string=''.join(f.readlines()) etest = STAP(string,etest) etest.etest(500) # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('subject'): subject = form.getvalue('subject') else: subject = Not set if form.getvalue('func1'): func1 = form.getvalue('func1') else: func1 = Not entered print Content-type:text/html\r\n\r\n print html print head print titleTest Project/title print /head print body print h2 Selected Action is %s/h2 % subject print h3 output function is %s/h3 % func1 print /body print /html Finally, the bz2.R file: etest - function(n=100) { y - rnorm(n) pdf(file=lap1.png) plot(y) dev.off() } The radio4.py file is in a cgi-bin directory, along with the bz2.R file. I keep getting the Internal server error. Thanks for any help. Sincerely, Erin This is R version 3.0.2 and Python 2.7.5 -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Rterm
Hi, Whenever I try to open R from Emacs, it says : apply: Searching for program: permission denied, Rterm I have the new ESS with the latest Emacs version and R-3.0.2. Also, when I open Emacs, it says : No version of R could be found on your system. I wonder if there is anything I could do to fix the problem. Please help me, -- *Patrick Rioux* [[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] Irregular time series frequencies
Hi everyone, I have a data frame with email addresses in the first column and in the second column a list of times (of different lengths) at which an email was sent from the user in the first column. Here is an example of my data: Email Email_sent j...@doe.com 2013-09-26 15:59:55 2013-09-27 09:48:29 2013-09-27 10:00:02 2013-09-27 10:12:54 j...@shoe.com 2013-09-26 09:50:28 2013-09-26 14:41:24 2013-09-26 14:51:36 2013-09-26 17:50:10 2013-09-27 13:34:02 2013-09-27 14:41:10 2013-09-27 15:37:36 ... I cannot find any way to calculate the frequencies between each email sent for each user: j...@doe.com 0.02 email / hour j...@shoe.com 0.15 email / hour ... Can anyone help me on this problem? The ultimate goal (which seems amibitious at this time) is to calculate, for each user, the frequencies between each mail per day, between the first email sent and the last email sent each day (to avoid taking nights into account), i.e.: 2013-09-26 2013-09-27 j...@doe.com 1.32 emails / hour 0.56 emails / hour j...@shoe.com 10.57 emails / hour 2.54 emails / hour ... At this time it seems pretty impossible, but I guess I will eventually find a way :-) Thanks a lot, Sartene Bel R learner ___ Qu'y a-t-il ce soir à la télé ? D'un coup d'œil, visualisez le programme sur Voila.fr http://tv.voila.fr/programmes/chaines-tnt/ce-soir.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] getting p-value for comparing to gam's from gmcv
I am trying to compare two different GAM fits. I have something like Course.bam20 -bam(zGrade ~ Rep + ISE + White + Female + Years + AP_TOTAL + MATH + HSGPA+ EOP + factor(P7APrior, ordered = FALSE)+s(Yfrm7A,k=20), data= Course, na.action = na.exclude,samfrac =0.1) Course.bam4 -bam(zGrade ~ Rep + ISE + White + Female + Years + AP_TOTAL + MATH + HSGPA+ EOP + factor(P7APrior, ordered = FALSE)+s(Yfrm7A,k=4), data= Course, na.action = na.exclude,samfrac =0.1) anova(Course.bam20, Course.bam4) Model 1: zGrade ~ Rep + ISE + White + Female + Years + AP_TOTAL + MATH + HSGPA + EOP + factor(P7APrior, ordered = FALSE) + s(Yfrm7A, k = 20) Model 2: zGrade ~ Rep + ISE + White + Female + Years + AP_TOTAL + MATH + HSGPA + EOP + factor(P7APrior, ordered = FALSE) + s(Yfrm7A, k = 4) Resid. Df Resid. Dev Df Deviance 14721.7 1907.0 24724.5 1913.5 -2.7919 -6.4986 How can I get a p-value out of the anova? [[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] an rpy2, R cgi type question
Erin can you share the internal error details? As a first guess are the files executable by all? CGI requires world rwx. Best, Collin. On Wed, 30 Oct 2013, Erin Hodgess wrote: Hi again. I'm putting together a little project with R, python, and a website. So I have an HTML file, a py file, an R file. Here is the HTML file: form action=/cgi-bin/radio4.py method=post target=_blank input type=radio name=subject value=Integrate / Integrate input type=radio name=subject value=Differentiate / Differentiate input type=radio name=subject value=Graph / Graph Function input type=text name=func1 br / input type=submit value=Select Subject / /form Now the radio4.py file: # Import modules for CGI handling import cgi, cgitb from sympy import * import sys from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage as STAP with open(bz2.R,r) as f: string=''.join(f.readlines()) etest = STAP(string,etest) etest.etest(500) # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('subject'): subject = form.getvalue('subject') else: subject = Not set if form.getvalue('func1'): func1 = form.getvalue('func1') else: func1 = Not entered print Content-type:text/html\r\n\r\n print html print head print titleTest Project/title print /head print body print h2 Selected Action is %s/h2 % subject print h3 output function is %s/h3 % func1 print /body print /html Finally, the bz2.R file: etest - function(n=100) { y - rnorm(n) pdf(file=lap1.png) plot(y) dev.off() } The radio4.py file is in a cgi-bin directory, along with the bz2.R file. I keep getting the Internal server error. Thanks for any help. Sincerely, Erin This is R version 3.0.2 and Python 2.7.5 -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] an rpy2, R cgi type question
Hi again: Here is the web output: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmas...@erinm.info and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. I did indeed check permissions and they seem to be in order. Thanks, Erin On Wed, Oct 30, 2013 at 10:51 PM, Collin Lynch coll...@cs.pitt.edu wrote: Erin can you share the internal error details? As a first guess are the files executable by all? CGI requires world rwx. Best, Collin. On Wed, 30 Oct 2013, Erin Hodgess wrote: Hi again. I'm putting together a little project with R, python, and a website. So I have an HTML file, a py file, an R file. Here is the HTML file: form action=/cgi-bin/radio4.py method=post target=_blank input type=radio name=subject value=Integrate / Integrate input type=radio name=subject value=Differentiate / Differentiate input type=radio name=subject value=Graph / Graph Function input type=text name=func1 br / input type=submit value=Select Subject / /form Now the radio4.py file: # Import modules for CGI handling import cgi, cgitb from sympy import * import sys from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage as STAP with open(bz2.R,r) as f: string=''.join(f.readlines()) etest = STAP(string,etest) etest.etest(500) # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('subject'): subject = form.getvalue('subject') else: subject = Not set if form.getvalue('func1'): func1 = form.getvalue('func1') else: func1 = Not entered print Content-type:text/html\r\n\r\n print html print head print titleTest Project/title print /head print body print h2 Selected Action is %s/h2 % subject print h3 output function is %s/h3 % func1 print /body print /html Finally, the bz2.R file: etest - function(n=100) { y - rnorm(n) pdf(file=lap1.png) plot(y) dev.off() } The radio4.py file is in a cgi-bin directory, along with the bz2.R file. I keep getting the Internal server error. Thanks for any help. Sincerely, Erin This is R version 3.0.2 and Python 2.7.5 -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.