[R] How to get a running mean result by R?
Hi R users: I have a big data and want to calculate the running mean of this data . How can I get this kind of result ? I have check the command mean it seems mean could not get the running mean? -- TANG Jie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] change factor to mtrix
i wish to change a column of factor variable to multiple columns of zero-ones for example, my factor could be ff=c('a','a','b','b','c','c') then I want to have two columns (for three levels) that are 0 0 0 0 1 0 1 0 0 1 0 1 how can i do this fast? [[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] Instant search for R documentation
Hi, I just wanted to share with you that we made a website over the weekend that allows instant search of the R documentation on CRAN, see: www.Rdocumentation.org. It's a first version, so any feedback/comments/criticism most welcome. Best regards, Jonathan [[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] Question on Simple Repeated Loops
On 12-06-2013, at 04:53, Abdul Rahman bin Kassim (Dr.) rahm...@frim.gov.my wrote: Dear R-User, Appreciate any helps. It looks simple, but I don't have a clue. Given that I have a dataframe of tree population with three variables: sp=species , d0=initial_size grow=growth increment from initial size per year How can I calculate the future growth increment of each tree for the next 3 years. The following Rscript was written, #-- a0 - data.frame(d0=seq(5,50,5) , sp=gl(2,5,10), grow=rep(0.5,10)) a2- list() for( i in 1:3){ a1 - a0$d0+a0$grow a2[[i]] - cbind(sp=a0$sp,d0=a1+i,yr=i) } as.data.frame(do.call(cbind,a2)) as.data.frame(do.call(cbind,a2)) sp d0 yr sp d0 yr sp d0 yr 1 1 6.5 1 1 7.5 2 1 8.5 3 2 1 11.5 1 1 12.5 2 1 13.5 3 3 1 16.5 1 1 17.5 2 1 18.5 3 4 1 21.5 1 1 22.5 2 1 23.5 3 5 1 26.5 1 1 27.5 2 1 28.5 3 6 2 31.5 1 2 32.5 2 2 33.5 3 7 2 36.5 1 2 37.5 2 2 38.5 3 8 2 41.5 1 2 42.5 2 2 43.5 3 9 2 46.5 1 2 47.5 2 2 48.5 3 10 2 51.5 1 2 52.5 2 2 53.5 3 #- but the results did not produce the expected future d0. I think its my R script d0=a1+i in the a2[[i]] - cbind(sp=a0$sp,d0=a1+i,yr=i). Interested to know the correct way of writing the repeated loops in R. The expected results is: sp d0 yr sp d0 yr sp d0 yr 1 1 6.5 1 1 7.0 2 1 7.5 3 2 1 11.5 1 1 12.0 2 1 12.5 3 3 1 16.5 1 1 17.0 2 1 17.5 3 4 1 21.5 1 1 22.0 2 1 22.5 3 5 1 26.5 1 1 27.0 2 1 27.5 3 6 2 31.5 1 2 32.0 2 2 32.5 3 7 2 36.5 1 2 37.0 2 2 37.5 3 8 2 41.5 1 2 42.0 2 2 42.5 3 9 2 46.5 1 2 47.0 2 2 47.5 3 10 2 51.5 1 2 52.0 2 2 52.5 3 Why is the expression a1 - a0$d0+a0$grow inside the for loop? It doesn't depend on i. I don't understand your expected result. Fpr species 1 the initial value in column d0 is 5. I assume that this is in year 0. So with a growth increment of .5 in year 1 I would expect d0 to be 5.5, in year 2it is 6 and in year 3 it would be 6.5. So see if this does what you seem to want (and remove the redundant expression for a1) a3- list() for( i in 1:3){ a3[[i]] - cbind(sp=a0$sp,d0=a0$d0+i*a0$grow,yr=i) } as.data.frame(do.call(cbind,a3)) #sp d0 yr sp d0 yr sp d0 yr # 1 1 5.5 1 1 6 2 1 6.5 3 # 2 1 10.5 1 1 11 2 1 11.5 3 # 3 1 15.5 1 1 16 2 1 16.5 3 # 4 1 20.5 1 1 21 2 1 21.5 3 # 5 1 25.5 1 1 26 2 1 26.5 3 # 6 2 30.5 1 2 31 2 2 31.5 3 # 7 2 35.5 1 2 36 2 2 36.5 3 # 8 2 40.5 1 2 41 2 2 41.5 3 # 9 2 45.5 1 2 46 2 2 46.5 3 # 10 2 50.5 1 2 51 2 2 51.5 3 Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 using code
Hello, Simply assign the output of a function to a variable: xyzuvw - importdata(...) and then use that output. In this case, a data.frame with, among others, vectors 'x' and 'y'. You need to read an R introductory text. I recommend An Introduction to R, file R-intro.pdf in your doc directory. Rui Barradas Em 12-06-2013 00:59, John McDermott escreveu: Hello, Thanks for the help! Your answer resolved my problem with the function I listed, but brought up a larger question. How is the output of the importdata function stored for use with other functions (as in, how do I call on that data for use with other functions)? As a simple example I have another function: meanXY = function(xyzuvw) { xy = c(mean(xyzuvw$x), mean(xyzuvw$y)) return(xy) } I know that the xyzuvw portion is referring to the output of the importdata function, but I don't know how to call up the necessary data (hope this makes sense). Thanks again for the help! John On 6/11/13 3:05 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, I believe you are making a confusion on how to call a function in R. You don't replace the argument in the function declaration. what you do is to call the function like this: importdata(~/path to/filename.xyzuvwrgb) leaving the function definition alone. Hope this helps, Rui Barradas Em 11-06-2013 19:52, John McDermott escreveu: Hi R-helpers, I inherited some code that I'm trying to use. As a very new R user I'm having some confusion. I have some input files in the form: filename.xyzuvwrgb which I'm trying to import using: importdata = function(filename) { p = scan(filename,what=list(x = double(), y = double(), z = double(), u = double(),v=double(),w=double()),skip=1,flush=TRUE,sep= ) return(data.frame(x=p$x, y=p$y, z=p$z, u=p$u, v=p$v, w=p$w)) } For the filename I replaced both with ~/path to/filename.xyzuvwrgb and I get the following errors: Error: unexpected string constant in importdata = function(~/Desktop/thrustScarp1.xyzuvw Error: no function to return from, jumping to top level Error: unexpected '}' in } I'm assuming it has to do with how I am using/formatted the function(filename) portion. How can I get this to work? Thanks for the help! [[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] change factor to mtrix
On 06/12/2013 05:47 PM, Gallon Li wrote: i wish to change a column of factor variable to multiple columns of zero-ones for example, my factor could be ff=c('a','a','b','b','c','c') then I want to have two columns (for three levels) that are 0 0 0 0 1 0 1 0 0 1 0 1 how can i do this fast? Hi Gallon, If you want exactly the output shown above, it is not trivial. You could convert ff to a factor, then use as.numeric to get: a = 1 b = 2 c = 3 If you subtract one and display the numbers in two digits of binary: a = 00 b = 01 c = 10 Then if you apply as.character and strsplit, you can get: a = 0 0 b = 0 1 c = 1 0 Finally, as.numeric will give you numbers. This does not produce the numbers above, but it might give you an idea of what to do. 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] loops for matrices
I have to use a loop (while or for) to return the result of hadamard product. now it returns a matrix, but when I use is.matrix() to check, it returns FALSE, whats wrong? Matrix.mul - function(A, B) { while(is.matrix(A) == FALSE | is.matrix(B) == FALSE ) {print(error) break} while(is.matrix(A) == T is.matrix(B) == T) { n - dim(A)[1]; m - dim(A)[2]; p - dim(B)[1]; q - dim(B)[2]; while(m == p) { C - matrix(0, nrow = n , ncol = q) for(s in 1:n) { for(t in 1:q) { c - array(0, dim = m ) for(k in 1:m) { c[k] - A[s,k] * B[k, t] } C[s, t] - sum(c) } } print(C) break } while(m != p) { print(error) break } break } } [[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] Version 1.3.2 of apcluster package (+ last announcement of Webinar)
Dear colleagues, This is to inform you that Version 1.3.2 of the R package *apcluster* has been released on CRAN yesterday (note that it may still take a few more hours until the Windows binary will be available). We added a plotting function that also allows for plotting clustering results along with multi-dimensional data (by superimposing clusters in a scatterplot matrix). Moreover, we improved the handling of missing values. For more details, see the following URLs: http://www.bioinf.jku.at/software/apcluster/ http://cran.r-project.org/web/packages/apcluster/index.html Furthermore, I want to remind you that I will be giving a webinar on the apcluster package on Thursday, June 13, 2013, 7:00pm CEST (10:00am PDT). The outline of the one-hour webinar is as follows: - Introduction to affinity propagation (AP) clustering - The apcluster package, its algorithms, and visualization tools - Live apcluster demonstration - Question and Answer period To register for the webinar, please visit the following URL: https://www3.gotomeeting.com/register/503109182 The webinar is kindly brought to you by the Orange County R User Group and will be moderated by its president, Ray DiGiacomo, Jr. Best regards, Ulrich *Dr. Ulrich Bodenhofer* Associate Professor Institute of Bioinformatics *Johannes Kepler University* Altenberger Str. 69 4040 Linz, Austria Tel. +43 732 2468 4526 Fax +43 732 2468 4539 bodenho...@bioinf.jku.at mailto:bodenho...@bioinf.jku.at http://www.bioinf.jku.at/ http://www.bioinf.jku.at __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] loops for matrices
The comments on StackOverflow are fair, I believe... Please dput() your matrices, so that your code becomes reproducible! On Wednesday 12 June 2013 11:14:35 maggy yan wrote: I have to use a loop (while or for) to return the result of hadamard product. now it returns a matrix, but when I use is.matrix() to check, it returns FALSE, whats wrong? Matrix.mul - function(A, B) { while(is.matrix(A) == FALSE | is.matrix(B) == FALSE ) {print(error) break} while(is.matrix(A) == T is.matrix(B) == T) { n - dim(A)[1]; m - dim(A)[2]; p - dim(B)[1]; q - dim(B)[2]; while(m == p) { C - matrix(0, nrow = n , ncol = q) for(s in 1:n) { for(t in 1:q) { c - array(0, dim = m ) for(k in 1:m) { c[k] - A[s,k] * B[k, t] } C[s, t] - sum(c) } } print(C) break } while(m != p) { print(error) break } break } } [[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] Caret train with glmnet give me Error arguments imply differing number of rows
Hi Max, I think I get the cause of this error. I left unintentionally some NA's in the y parameter of train(). Here is the example to reproduce it: X - matrix(seq(1:100, 10, 10) Y - seq(1:10) Y[1] - NA fit - train(X, Y, method=glmnet, preProcess=c(center,scale)) Regards, Ferran 2013/6/11 Mxkuhn mxk...@gmail.com The data size isn't an issue. Can you send a reproducible example? Max On Jun 11, 2013, at 10:31 AM, Ferran Casarramona ferran.casarram...@gmail.com wrote: Hello, I'm training a set of data with Caret package using an elastic net (glmnet). Most of the time train works ok, but when the data set grows in size I get the following error: Error en { : task 1 failed - arguments imply differing number of rows: 9, 10 and several warnings like this one: 1: In eval(expr, envir, enclos) : model fit failed for Resample01 My call to train function is like this: fit - train(TrainingPreCols, TrainingFrame[,PCol], method=glmnet, preProcess = c(center,scale)) When TrainingPreCols is 17420 obs. of 27 variables, the function works ok. But with a size of 47000 obs of 27 variables I get the former error. ¿Could be the amount of data the cause of this error? Any help is appreciated, Ferran P.D.: This is my sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 LC_MONETARY=Spanish_Spain.1252 [4] LC_NUMERIC=C LC_TIME=Spanish_Spain.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] glmnet_1.9-3Matrix_1.0-12 doSNOW_1.0.7iterators_1.0.6 snowfall_1.84-4 [6] snow_0.3-12 caret_5.16-04 reshape2_1.2.2 plyr_1.8 lattice_0.20-6 [11] cluster_1.14.4 foreach_1.4.1 loaded via a namespace (and not attached): [1] codetools_0.2-8 grid_2.15.0 stringr_0.6.2 tools_2.15.0 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to get a running mean result by R?
Hello, You can use, for instance, function ma() in package forecast. # if not yet installed #install.packages('forecast', dependencies = TRUE) library(forecast) ?ma Hope this helps, Rui Barradas Em 12-06-2013 08:21, Jie Tang escreveu: Hi R users: I have a big data and want to calculate the running mean of this data . How can I get this kind of result ? I have check the command mean it seems mean could not get the running mean? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bytes to Numeric/Float conversion
Actually I am using rJava, running some map-reduce using R. The data send is in bytes, but actually it is floating-point number. On R side, I need to convert this byte into Float. But I couldn't find any function. I am try using rawToChar() which convert into character. And later on as.double to convert it. But it is not giving the exact value. Could any one help me out. On Tue, Jun 11, 2013 at 6:01 PM, Bikash Agrawal er.bikas...@gmail.comwrote: Is there any packages available in R, that can convert Bytes array to Float. Using rJava we can do it. But it is kind of slow. Is there any R specific packages. I am having problem converting my bytes array to floating point. Could any one help me with this problem. Thanks Bikash -- With Best Regards Bikash Agrawal Web/Software Developer Mobile: +47 92502701 www.bikashagrawal.com.np -- With Best Regards Bikash Agrawal Web/Software Developer Mobile: +47 92502701 www.bikashagrawal.com.np [[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] Instant search for R documentation
On 6/12/2013 1:03 AM, jonathan cornelissen wrote: Hi, I just wanted to share with you that we made a website over the weekend that allows instant search of the R documentation on CRAN, see: www.Rdocumentation.org. It's a first version, so any feedback/comments/criticism most welcome. Interesting. Are you aware of the following: * help.start() * The R Wiki (the fourth item under Documentation on the left at r-project.org). Might you want to consider merging your rdocumentation.org with this? - NOTE: The R Wiki unfortunately has not gotten the attention and development I believe it deserves. I'm not sure why this is. The standard Wikipedia gets many contributors. One difference I noticed is that to edit this, one needs to login. That's not true for Wikimedia projects. Beyond that, with stardard Mediawiki markup language can intimidate some people. Fortunately, difficulties in using the Mediawiki softaware will soon be reduced. One of the primary priorities of the software development team at the Wikimedia Foundation is modifying the Mediawiki software to include a beta version of a visual (WYSIWYG) editor. I saw a demo of a beta version of this a month ago. It's already available for limited use, but I don't think it's quite ready yet. I think it might be wise to check for it later this year. * The sos package with its vignette for searching CRAN packages and getting the result sorted to place first the package with the most matches. Hope this helps. Spencer Best regards, Jonathan [[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] Add a column to a dataframe based on multiple other column values
Tom, Here is my solution. Note that I assume the columns are interleaved as you describe below. I'm sure others will have better replies. Note that using dput helps the helpers. # From dput(mdat) mdat-structure(list(x1 = c(2L, 2L, 2L, 3L, 3L, 30L, 32L, 33L, 33L), y1 = c(100L, 100L, 100L, 0L, 0L, 0L, 100L, 82L, 0L), x2 = c(190L, 192L, 192L, 195L, 198L, 198L, 868L, 870L, 871L), y2 = c(99L, 63L, 63L, 99L, 98L, 100L, 100L, 100L, 82L), x3 = c(1430L, 1431L, 1444L, 1499L, 1500L, 1451L, 1451L, 1490L, 1494L), y3 = c(79L, 75L, 51L, 50L, 80L, 97L, 97L, 97L, 85L), output = c(89, 69, 57, 74.5, 89, 65.6667, 99, 93, 55.6667)), .Names = c(x1, y1, x2, y2, x3, y3, output), class = data.frame, row.names = c(NA, -9L)) mdat.pure-mdat[,-ncol(mdat)] # Function to apply to rows theFunk-function(x) { nxy-length(x)/2 idx-seq_len(nxy) xvec-x[idx*2 - 1] yvec-x[idx*2] mean(yvec[xvec10]) } # Apply the function to rows output-apply(mdat.pure, 1, theFunk) Or mdat.pure$output-apply(mdat.pure, 1, theFunk) will put the calculated column at the end of mdat.pure. Note that I haven't taken account of missing values. Hope this helps, KW -- On Jun 12, 2013, at 6:00 AM, r-help-requ...@r-project.org wrote: Message: 35 Date: Tue, 11 Jun 2013 17:07:12 +0100 From: Tom Oates toate...@gmail.com To: r-help@r-project.org Subject: [R] Add a column to a dataframe based on multiple other column values Message-ID: cagudn1cxlfxxnzdwquo515h_h5qekfmuyg5msdb1qn6gbq7...@mail.gmail.com Content-Type: text/plain Hi I have a dataframe as below: x1y1x2y2x3y3output 21001909914307989 21001926314317569 21001926314445157 301959914995074.5 301989815008089 30019810014519765.6667 3210086810014519799 338287010014909793 3308718214948555.6667 In reality the dataframe has pairs of columns x y up to a large number. As you can see from the column labelled output in the dataframe; I want to calculate the mean of each row of the yn columns, but only to include each yn value in the calculation of the mean if the corresponding xn column value is greater than 10. So for row 1; you will see that only y2 y3 are included in calculating the output column, but for row 6 y1-y3 are all included. Because the number of paired x y columns is large I am not sure the best way to achieve this. Thanks in advance Tom __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bytes to Numeric/Float conversion
On 13-06-12 6:54 AM, Bikash Agrawal wrote: Actually I am using rJava, running some map-reduce using R. The data send is in bytes, but actually it is floating-point number. On R side, I need to convert this byte into Float. But I couldn't find any function. I am try using rawToChar() which convert into character. And later on as.double to convert it. But it is not giving the exact value. Could any one help me out. If you want exact transfer from bytes, use raw connections. For example: con - rawConnection(raw(0), r+) writeBin(pi, con) rawConnectionValue(con) [1] 18 2d 44 54 fb 21 09 40 seek(con,0) [1] 8 readBin(con, numeric) [1] 3.141593 Depending on how you created the bytes, you may need to do some fiddling with the optional parameters size and endian of readBin to read them properly. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] QR factorization for aov
On Jun 11, 2013, at 20:26 , Mimi Celis wrote: I am looking at the aov function in R. I see that it uses a modified QR factorization routine dqrdc2 based on the Linpack routine dqrdc. Pivoting is done different than the original Linpack function. My questions: * Why is it necessary to modify the pivoting strategy? Something necessary for aov? * Will the LAPACK function dgeqp3 work well or would the pivoting have o be modified? As far as I have understood it, the issue is that to generate the sequential ANOVA table based on a single QR factorization, you can't have it swapping terms around, because there are cases where the order of terms matters. So LAPACK won't do. Or rather, to use it, you'd need to rethink the algoritm; you may need refactorizing for each line the ANOVA table. It's not necessarily impossible or seriously inefficient, just one of the things that nobody seems to have an aching desire to tackle. -pd Thank you MRC [[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. -- 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.
Re: [R] change factor to mtrix
On Jun 12, 2013, at 09:47 , Gallon Li wrote: i wish to change a column of factor variable to multiple columns of zero-ones for example, my factor could be ff=c('a','a','b','b','c','c') then I want to have two columns (for three levels) that are 0 0 0 0 1 0 1 0 0 1 0 1 how can i do this fast? Maybe not fast, but quick: fff - factor(ff) model.matrix(~fff)[,-1] fffb fffc 100 200 310 410 501 601 Possibly faster, skipping some red tape: CC - contrasts(fff) CC b c a 0 0 b 1 0 c 0 1 CC[fff,] b c a 0 0 a 0 0 b 1 0 b 1 0 c 0 1 c 0 1 [[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. -- 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.
Re: [R] Big, complex, well-structured .R file for demonstration?
Just because you have an editor that can let you see the organization within the file does not mean the code itself is well-structured. If you do put a lot of code in one file, you will be more likely in your next project that builds on this one to load code you do not need (bloat), and that is a very practical defect in the structure of the current project. Regardless of any arguments you can think of to the contrary, that is why single large files with otherwise well-structured code are uncommon. --- 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. Thorsten Jolitz tjol...@gmail.com wrote: Greg Snow 538...@gmail.com writes: Some would argue that big and well structured are not compatible. Part of structuring a project well is knowing when and how to break it into smaller pieces, so those authors who are best at creating well structured R code will often split it between several small files rather than one big file. As Emacs Org-mode has proven for text files, this structuring into smaller pieces can be done in one single file too (that is structured as a hierarchical outline tree) an this can be even more convenient than to deal with many small files. But otherwise I agree with you, its much better to split a file up before it becomes a growing mess. On Tue, Jun 11, 2013 at 9:06 AM, Thorsten Jolitz tjol...@gmail.com wrote: Hi List, I'm looking for a rather big, but well structured R file that contains as much of R language features as possible (i.e. that uses a lot of the functionality described in the 'R Reference Card' and, if possible, S4 classes too). I want to check some code I wrote against such a file and use it for demonstration purposes. However, most .R files I find out there are rather short without much structure. Any links to candidate (open source) files would be appreciated. -- cheers, Thorsten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Combining CSV data
Great, thanks Arun, but I seem to be running into this error. Not sure what did I miss. result-data.frame(final_ouput[,-5],read.table(text=as.character(final_output$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE)colnames(result)[5:7]-paste0(DataComment,1:3) Error: unexpected symbol in result-data.frame(final_ouput[,-5],read.table(text=as.character(final_output$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE)colnames On Tue, Jun 11, 2013 at 5:09 PM, arun smartpink...@yahoo.com wrote: HI, You could use: result3- data.frame(result2[,-5],read.table(text=as.character(result2$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE) colnames(result3)[5:7]- paste0(DataComment,1:3) A.K. From: Shreya Rawal rawal.shr...@gmail.com To: arun smartpink...@yahoo.com Sent: Tuesday, June 11, 2013 4:22 PM Subject: Re: [R] Combining CSV data Hey Arun, I guess you could guide me with this a little bit. I have been working on the solution Jim suggested (and also because that I could understand it with my little knowledge of R :)) So with these commands I am able to get the data in this format: fileA - read.csv(text = Row_ID_CR, Data1,Data2,Data3 + 1, aa, bb, cc + 2, dd, ee, ff, as.is = TRUE) fileB - read.csv(text = Row_ID_N, Src_Row_ID, DataN1 + 1a, 1, This is comment 1 + 2a, 1, This is comment 2 + 3a, 2, This is comment 1 + 4a, 1, This is comment 3, as.is = TRUE) # get rid of leading/trailing blanks on comments fileB$DataN1 - gsub(^ *| *$, , fileB$DataN1) # merge together result - merge(fileA, fileB, by.x = 'Row_ID_CR', by.y = Src_Row_ID) # now partition by Row_ID_CR and aggregate the comments result2 - do.call(rbind, + lapply(split(result, result$Row_ID_CR), function(.grp){ + cbind(.grp[1L, -c(5,6)], comment = paste(.grp$DataN1, collapse = '|')) + }) + ) Row_ID_CR Data1Data2Data3 comment 1 1aa bb cc This is comment 1| This is comment 2| This is comment 3 2 2dd ee ff This is comment 1| This is Comment 2 I can even split the last column by this: strsplit(as.character(result2$comment), split='\\|') [[1]] [1] This is comment 1 This is comment 2 This is comment 3 [[2]] [1] This is comment 1 This is comment 2 but now I am not sure how to combine everything together. I guess by now you must have realized how new I am to R :) Thanks!! Shreya On Tue, Jun 11, 2013 at 1:02 PM, arun smartpink...@yahoo.com wrote: Hi, If the dataset is like this with the comments in the order: dat2-read.table(text= Row_ID_N, Src_Row_ID, DataN1 1a, 1, This is comment 1 2a, 1, This is comment 2 3a, 2, This is comment 1 4a, 1, This is comment 3 ,sep=,,header=TRUE,stringsAsFactors=FALSE) dat3-read.table(text= Row_ID_N, Src_Row_ID, DataN1 1a, 1, This is comment 1 2a, 1, This is comment 2 3a, 2, This is comment 1 # 4a, 1, This is comment 3 5a, 2, This is comment 2 # ,sep=,,header=TRUE,stringsAsFactors=FALSE) library(stringr) library(plyr) fun1- function(data1,data2){ data2$DataN1- str_trim(data2$DataN1) res- merge(data1,data2,by.x=1,by.y=2) res1- res[,-5] res2- ddply(res1,.(Row_ID_CR,Data1,Data2,Data3),summarize,DataN1=list(DataN1)) Mx1- max(sapply(res2[,5],length)) res3- data.frame(res2[,-5],do.call(rbind,lapply(res2[,5],function(x){ c(x,rep(NA,Mx1-length(x))) })),stringsAsFactors=FALSE) colnames(res3)[grep(X,colnames(res3))]- paste0(DataComment,gsub([[:alpha:]],,colnames(res3)[grep(X,colnames(res3))])) res3 } fun1(dat1,dat2) # Row_ID_CRData1Data2Data3 DataComment1 #1 1 aa bb cc This is comment 1 #2 2 dd ee ff This is comment 1 # DataComment2 DataComment3 #1 This is comment 2 This is comment 3 #2 NA NA fun1(dat1,dat3) # Row_ID_CRData1Data2Data3 DataComment1 #1 1 aa bb cc This is comment 1 #2 2 dd ee ff This is comment 1 #
Re: [R] agnes() in package cluster on R 2.14.1 and R 3.0.1
Hugo Varet vareth...@gmail.com on Tue, 11 Jun 2013 15:15:36 +0200 writes: Dear Martin, Thank you for your answer. Here is the exact call to agnes(): setwd(E:/Hugo) library(cluster) load(mydata.rda) tableauTani-dist.binary(mydata, method = 4, diag = FALSE, upper = FALSE) resAgnes.Tani-agnes(tableauTani, diss = inherits(tableauTani, dist),method = ward) classe.agnTani.3 - cutree(resAgnes.Tani, 3) I'm going to send you the data in a separated e-mail. Thank you, Hugo, and I got that alright. I can see that many of the distances are *identical*, because your data is completely binary. From experience, I know that this can lead (for some algorithms) to arbitrary decisions in clustering, namely when two *pairs* of observations / clusters have exactly the same distance, it is somewhat random which of the pair is merged / fused first, in a bottom up hierarchical algorithm such as agnes(). To reproduce your example (above) I need however to know *where* you got the the dist.binary() function from. It is not part of standard R nor of the cluster package. Regards, Martin Regards, Hugo Le lundi 10 juin 2013, Martin Maechler maech...@stat.math.ethz.ch a écrit : Hugo Varet vareth...@gmail.com on Sun, 9 Jun 2013 11:43:32 +0200 writes: Dear R users, I discovered something strange using the function agnes() of the cluster package on R 3.0.1 and on R 2.14.1. Indeed, the clusterings obtained are different whereas I ran exactly the same code. hard to believe... but .. I quickly looked at the source code of the function and I discovered that there was an important change: agnes() in R 2.14.1 used a FORTRAN code whereas agnes() in R 3.0.1 uses a C code. well, it does so quite a bit longer, e.g., also in R 2.15.0 Here is one of the contingency table between R 2.14.1 and R 3.0.1: classe.agnTani.2.14.1 classe.agnTani.3.0.1 12 3 174 0229 2 02350 3 120 0 15 So, I was wondering if it was normal that the C and FORTRAN codes give different results? It's not normal, and I'm pretty sure I have had many many examples which gave identical results. Can you provide a reproducible example, please? If the example is too large [for dput() ], please send me the *.rda file produced from save(your data, file=the file I neeed) *and* a the exact call to agnes() for your data. Thank you in advance! Martin Maechler, the one you could have e-mailed directly to using maintainer(cluster) ... Best regards, Hugo Varet [[alternative HTML version deleted]] ^ try to avoid, please ^ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. yes indeed, please. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] GGally installation problems
Hi, I was trying to install the GGally package, but was getting errors. Here is what I get: install.packages(GGally) Installing package(s) into â/Users/ts2w/Library/R/2.15/libraryâ (as âlibâ is unspecified) Warning in install.packages : Â package âGGallyâ is not available (for R version 2.15.2) install.packages(GGally,repos=http://cran-r.project.org;) Installing package(s) into â/Users/ts2w/Library/R/2.15/libraryâ (as âlibâ is unspecified) Warning in install.packages : Â cannot open: HTTP status was '404 Not Found' Warning in install.packages : Â cannot open: HTTP status was '404 Not Found' Warning in install.packages : Â unable to access index for repository http://cran-r.project.org/src/contrib Warning in install.packages : Â package âGGallyâ is not available (for R version 2.15.2) Warning in install.packages : Â cannot open: HTTP status was '404 Not Found' Warning in install.packages : Â cannot open: HTTP status was '404 Not Found' Warning in install.packages : Â unable to access index for repository http://cran-r.project.org/bin/macosx/leopard/contrib/2.15 thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Combining CSV data
HI Shreya, #Looks like you run the two line code as a single line. result3- data.frame(result2[,-5],read.table(text=as.character(result2$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE) colnames(result3)[5:7]- paste0(DataComment,1:3) result3 # Row_ID_CR Data1 Data2 Data3 DataComment1 #1 1 aa bb cc This is comment 1 #2 2 dd ee ff This is comment 1 # DataComment2 DataComment3 #1 This is comment 2 This is comment 3 #2 NA NA A.K. From: Shreya Rawal rawal.shr...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; jim holtman jholt...@gmail.com Sent: Wednesday, June 12, 2013 8:58 AM Subject: Re: [R] Combining CSV data Great, thanks Arun, but I seem to be running into this error. Not sure what did I miss. result-data.frame(final_ouput[,-5],read.table(text=as.character(final_output$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE)colnames(result)[5:7]-paste0(DataComment,1:3) Error: unexpected symbol in result-data.frame(final_ouput[,-5],read.table(text=as.character(final_output$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE)colnames On Tue, Jun 11, 2013 at 5:09 PM, arun smartpink...@yahoo.com wrote: HI, You could use: result3- data.frame(result2[,-5],read.table(text=as.character(result2$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE) colnames(result3)[5:7]- paste0(DataComment,1:3) A.K. From: Shreya Rawal rawal.shr...@gmail.com To: arun smartpink...@yahoo.com Sent: Tuesday, June 11, 2013 4:22 PM Subject: Re: [R] Combining CSV data Hey Arun, I guess you could guide me with this a little bit. I have been working on the solution Jim suggested (and also because that I could understand it with my little knowledge of R :)) So with these commands I am able to get the data in this format: fileA - read.csv(text = Row_ID_CR, Data1, Data2, Data3 + 1, aa, bb, cc + 2, dd, ee, ff, as.is = TRUE) fileB - read.csv(text = Row_ID_N, Src_Row_ID, DataN1 + 1a, 1, This is comment 1 + 2a, 1, This is comment 2 + 3a, 2, This is comment 1 + 4a, 1, This is comment 3, as.is = TRUE) # get rid of leading/trailing blanks on comments fileB$DataN1 - gsub(^ *| *$, , fileB$DataN1) # merge together result - merge(fileA, fileB, by.x = 'Row_ID_CR', by.y = Src_Row_ID) # now partition by Row_ID_CR and aggregate the comments result2 - do.call(rbind, + lapply(split(result, result$Row_ID_CR), function(.grp){ + cbind(.grp[1L, -c(5,6)], comment = paste(.grp$DataN1, collapse = '|')) + }) + ) Row_ID_CR Data1 Data2 Data3 comment 1 1 aa bb cc This is comment 1| This is comment 2| This is comment 3 2 2 dd ee ff This is comment 1| This is Comment 2 I can even split the last column by this: strsplit(as.character(result2$comment), split='\\|') [[1]] [1] This is comment 1 This is comment 2 This is comment 3 [[2]] [1] This is comment 1 This is comment 2 but now I am not sure how to combine everything together. I guess by now you must have realized how new I am to R :) Thanks!! Shreya On Tue, Jun 11, 2013 at 1:02 PM, arun smartpink...@yahoo.com wrote: Hi, If the dataset is like this with the comments in the order: dat2-read.table(text= Row_ID_N, Src_Row_ID, DataN1 1a, 1, This is comment 1 2a, 1, This is comment 2 3a, 2, This is comment 1 4a, 1, This is comment 3 ,sep=,,header=TRUE,stringsAsFactors=FALSE) dat3-read.table(text= Row_ID_N, Src_Row_ID, DataN1 1a, 1, This is comment 1 2a, 1, This is comment 2 3a, 2, This is comment 1 # 4a, 1, This is comment 3 5a, 2, This is comment 2 # ,sep=,,header=TRUE,stringsAsFactors=FALSE) library(stringr) library(plyr) fun1- function(data1,data2){ data2$DataN1- str_trim(data2$DataN1) res- merge(data1,data2,by.x=1,by.y=2) res1- res[,-5] res2- ddply(res1,.(Row_ID_CR,Data1,Data2,Data3),summarize,DataN1=list(DataN1)) Mx1- max(sapply(res2[,5],length)) res3- data.frame(res2[,-5],do.call(rbind,lapply(res2[,5],function(x){
Re: [R] Combining CSV data
Ah that makes sense. This looks perfect now. Thanks for your help on this! On Wed, Jun 12, 2013 at 9:10 AM, arun smartpink...@yahoo.com wrote: HI Shreya, #Looks like you run the two line code as a single line. result3- data.frame(result2[,-5],read.table(text=as.character(result2$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE) colnames(result3)[5:7]- paste0(DataComment,1:3) result3 # Row_ID_CR Data1Data2Data3 DataComment1 #1 1aa bb cc This is comment 1 #2 2dd ee ff This is comment 1 # DataComment2 DataComment3 #1 This is comment 2 This is comment 3 #2 NA NA A.K. From: Shreya Rawal rawal.shr...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; jim holtman jholt...@gmail.com Sent: Wednesday, June 12, 2013 8:58 AM Subject: Re: [R] Combining CSV data Great, thanks Arun, but I seem to be running into this error. Not sure what did I miss. result-data.frame(final_ouput[,-5],read.table(text=as.character(final_output$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE)colnames(result)[5:7]-paste0(DataComment,1:3) Error: unexpected symbol in result-data.frame(final_ouput[,-5],read.table(text=as.character(final_output$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE)colnames On Tue, Jun 11, 2013 at 5:09 PM, arun smartpink...@yahoo.com wrote: HI, You could use: result3- data.frame(result2[,-5],read.table(text=as.character(result2$comment),sep=|,fill=TRUE,na.strings=),stringsAsFactors=FALSE) colnames(result3)[5:7]- paste0(DataComment,1:3) A.K. From: Shreya Rawal rawal.shr...@gmail.com To: arun smartpink...@yahoo.com Sent: Tuesday, June 11, 2013 4:22 PM Subject: Re: [R] Combining CSV data Hey Arun, I guess you could guide me with this a little bit. I have been working on the solution Jim suggested (and also because that I could understand it with my little knowledge of R :)) So with these commands I am able to get the data in this format: fileA - read.csv(text = Row_ID_CR, Data1,Data2,Data3 + 1, aa, bb, cc + 2, dd, ee, ff, as.is = TRUE) fileB - read.csv(text = Row_ID_N, Src_Row_ID, DataN1 + 1a, 1, This is comment 1 + 2a, 1, This is comment 2 + 3a, 2, This is comment 1 + 4a, 1, This is comment 3, as.is = TRUE) # get rid of leading/trailing blanks on comments fileB$DataN1 - gsub(^ *| *$, , fileB$DataN1) # merge together result - merge(fileA, fileB, by.x = 'Row_ID_CR', by.y = Src_Row_ID) # now partition by Row_ID_CR and aggregate the comments result2 - do.call(rbind, + lapply(split(result, result$Row_ID_CR), function(.grp){ + cbind(.grp[1L, -c(5,6)], comment = paste(.grp$DataN1, collapse = '|')) + }) + ) Row_ID_CR Data1Data2Data3 comment 1 1aa bb cc This is comment 1| This is comment 2| This is comment 3 2 2dd ee ff This is comment 1| This is Comment 2 I can even split the last column by this: strsplit(as.character(result2$comment), split='\\|') [[1]] [1] This is comment 1 This is comment 2 This is comment 3 [[2]] [1] This is comment 1 This is comment 2 but now I am not sure how to combine everything together. I guess by now you must have realized how new I am to R :) Thanks!! Shreya On Tue, Jun 11, 2013 at 1:02 PM, arun smartpink...@yahoo.com wrote: Hi, If the dataset is like this with the comments in the order: dat2-read.table(text= Row_ID_N, Src_Row_ID, DataN1 1a, 1, This is comment 1 2a, 1, This is comment 2 3a, 2, This is comment 1 4a, 1, This is comment 3 ,sep=,,header=TRUE,stringsAsFactors=FALSE) dat3-read.table(text= Row_ID_N, Src_Row_ID, DataN1 1a, 1, This is comment 1 2a, 1, This is comment 2 3a, 2, This is comment 1 # 4a, 1, This is comment 3 5a, 2, This is comment 2 # ,sep=,,header=TRUE,stringsAsFactors=FALSE) library(stringr) library(plyr) fun1- function(data1,data2){ data2$DataN1- str_trim(data2$DataN1) res- merge(data1,data2,by.x=1,by.y=2) res1- res[,-5] res2-
Re: [R] survreg with measurement uncertainties
survreg allows interval censored data, if that is how you want to represent measurement uncertainty. See ?Surv -Original Message- From: Kyle Penner [mailto:kpen...@as.arizona.edu] Sent: Tuesday, June 11, 2013 8:02 PM To: r-help@r-project.org Subject: [R] survreg with measurement uncertainties Hello, I have some measurements that I am trying to fit a model to. I also have uncertainties for these measurements. Some of the measurements are not well detected, so I'd like to use a limit instead of the actual measurement. (I am always dealing with upper limits, i.e. left censored data.) I have successfully run survreg using the combination of well detected measurements and limits, but I would like to include the measurement uncertainty (for the well detected measurements) in the fitting. As far as I can tell, survreg doesn't support this. Does anyone have a suggestion for how to accomplish this? Thanks, Kyle ** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 using code
Have a look at http://www.burns-stat.com/documents/tutorials/impatient-r/ . I think the section on blank screen syndrome may help. John Kane Kingston ON Canada -Original Message- From: montana3...@gmail.com Sent: Tue, 11 Jun 2013 16:59:34 -0700 To: ruipbarra...@sapo.pt Subject: Re: [R] help using code Hello, Thanks for the help! Your answer resolved my problem with the function I listed, but brought up a larger question. How is the output of the importdata function stored for use with other functions (as in, how do I call on that data for use with other functions)? As a simple example I have another function: meanXY = function(xyzuvw) { xy = c(mean(xyzuvw$x), mean(xyzuvw$y)) return(xy) } I know that the xyzuvw portion is referring to the output of the importdata function, but I don't know how to call up the necessary data (hope this makes sense). Thanks again for the help! John On 6/11/13 3:05 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, I believe you are making a confusion on how to call a function in R. You don't replace the argument in the function declaration. what you do is to call the function like this: importdata(~/path to/filename.xyzuvwrgb) leaving the function definition alone. Hope this helps, Rui Barradas Em 11-06-2013 19:52, John McDermott escreveu: Hi R-helpers, I inherited some code that I'm trying to use. As a very new R user I'm having some confusion. I have some input files in the form: filename.xyzuvwrgb which I'm trying to import using: importdata = function(filename) { p = scan(filename,what=list(x = double(), y = double(), z = double(), u = double(),v=double(),w=double()),skip=1,flush=TRUE,sep= ) return(data.frame(x=p$x, y=p$y, z=p$z, u=p$u, v=p$v, w=p$w)) } For the filename I replaced both with ~/path to/filename.xyzuvwrgb and I get the following errors: Error: unexpected string constant in importdata = function(~/Desktop/thrustScarp1.xyzuvw Error: no function to return from, jumping to top level Error: unexpected '}' in } I'm assuming it has to do with how I am using/formatted the function(filename) portion. How can I get this to work? Thanks for the help! [[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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] survreg with measurement uncertainties
I will assume that you are talking about uncertainty in the response. Then one simple way to fit the model is to use case weights that are proprional to 1/variance, along with +cluster(id) in the model statement to get a correct variance for this case. In linear models this would be called the White or Horvitz-Thompsen or GEE working independence variance estimate, depending on which literature you happen to be reading (economics, survey sampling, or biostat). Now if you are talking about errors in the predictor variables, that is a much harder problem. Terry Therneau On 06/12/2013 05:00 AM, Kyle Penner wrote: Hello, I have some measurements that I am trying to fit a model to. I also have uncertainties for these measurements. Some of the measurements are not well detected, so I'd like to use a limit instead of the actual measurement. (I am always dealing with upper limits, i.e. left censored data.) I have successfully run survreg using the combination of well detected measurements and limits, but I would like to include the measurement uncertainty (for the well detected measurements) in the fitting. As far as I can tell, survreg doesn't support this. Does anyone have a suggestion for how to accomplish this? Thanks, Kyle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggpairs in GGally replaces plotmatrix in ggplot2
Thanks, I obviously read the help incorrectly. It does give the same results as plotmatrix(dat1) I take back some of the nasty thoughts I was thinking about ggpairs(). Any idea of the problem with RSudio? Keith notices the same speed difference (but no crash) on a Mac while I'm runnng Ubuntu 12.10. John Kane Kingston ON Canada -Original Message- From: istaz...@gmail.com Sent: Tue, 11 Jun 2013 17:54:55 -0400 To: kw1...@gmail.com Subject: Re: [R] ggpairs in GGally replaces plotmatrix in ggplot2 I think the ggpairs equivalent is ggpairs(dat1, upper=list(continuous=points), axisLabels=show) oddly enough. ggpairs(dat1) should default to the same graph as plotmatrix(dat1) but there seems to be a conflict between the default axisLabels=internal and density plots. Or something. There is a bug report at https://github.com/ggobi/ggally/issues/18 that may be related. Best, Ista On Tue, Jun 11, 2013 at 4:07 PM, Keith S Weintraub kw1...@gmail.com wrote: Yes. I was able to run it in RStudio but it did seem much slower than in R.app (on the Mac). Note that the it that I ran still didn't give the same results as plotmatrix. Thanks, KW -- On Jun 11, 2013, at 11:16 AM, John Kane jrkrid...@inbox.com wrote: Note that the code below might not work in RStudio. I am gettting an intermittant crash when I use the ggpairs() command in RStudio and sometimes I get a density plot and sometimes not. Also the command is taking 3-5 minutes to execute. This may just be a peculiarity of my machine but the code works fine and fairly fast in a terminal. John Kane Kingston ON Canada __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Add a column to a dataframe based on multiple other column values
HI, You could also try: dat2- dat1[-ncol(dat1)] fun1- function(dat,value){ datNew- dat n1- ncol(datNew) indx1- seq(1,n1,by=2) indx2- indx1+1 datNew[indx2][datNew[indx1] value]-NA dat$output-rowMeans(datNew[indx2],na.rm=TRUE) dat } fun1(dat2,10) # x1 y1 x2 y2 x3 y3 output #1 2 100 190 99 1430 79 89.0 #2 2 100 192 63 1431 75 69.0 #3 2 100 192 63 1444 51 57.0 #4 3 0 195 99 1499 50 74.5 #5 3 0 198 98 1500 80 89.0 #6 30 0 198 100 1451 97 65.7 #7 32 100 868 100 1451 97 99.0 #8 33 82 870 100 1490 97 93.0 #9 33 0 871 82 1494 85 55.7 A.K. - Original Message - From: arun smartpink...@yahoo.com To: Tom Oates toate...@gmail.com Cc: R help r-help@r-project.org Sent: Tuesday, June 11, 2013 5:23 PM Subject: Re: [R] Add a column to a dataframe based on multiple other column values HI, May be this helps: dat1- read.table(text= x1 y1 x2 y2 x3 y3 output 2 100 190 99 1430 79 89 2 100 192 63 1431 75 69 2 100 192 63 1444 51 57 3 0 195 99 1499 50 74.5 3 0 198 98 1500 80 89 30 0 198 100 1451 97 65.6667 32 100 868 100 1451 97 99 33 82 870 100 1490 97 93 33 0 871 82 1494 85 55.6667 ,sep=,header=TRUE) dat1$output2-apply(dat1[,-7],1,function(x) {indx-((seq(x)-1)%%2+1);indx1-indx==1; indx2-indx==2;mean(x[indx2][x[indx1]10])}) dat1 # x1 y1 x2 y2 x3 y3 output output2 #1 2 100 190 99 1430 79 89.0 89.0 #2 2 100 192 63 1431 75 69.0 69.0 #3 2 100 192 63 1444 51 57.0 57.0 #4 3 0 195 99 1499 50 74.5 74.5 #5 3 0 198 98 1500 80 89.0 89.0 #6 30 0 198 100 1451 97 65.7 65.7 #7 32 100 868 100 1451 97 99.0 99.0 #8 33 82 870 100 1490 97 93.0 93.0 #9 33 0 871 82 1494 85 55.7 55.7 A.K. - Original Message - From: Tom Oates toate...@gmail.com To: r-help@r-project.org Cc: Sent: Tuesday, June 11, 2013 12:07 PM Subject: [R] Add a column to a dataframe based on multiple other column values Hi I have a dataframe as below: x1 y1 x2 y2 x3 y3 output 2 100 190 99 1430 79 89 2 100 192 63 1431 75 69 2 100 192 63 1444 51 57 3 0 195 99 1499 50 74.5 3 0 198 98 1500 80 89 30 0 198 100 1451 97 65.6667 32 100 868 100 1451 97 99 33 82 870 100 1490 97 93 33 0 871 82 1494 85 55.6667 In reality the dataframe has pairs of columns x y up to a large number. As you can see from the column labelled output in the dataframe; I want to calculate the mean of each row of the yn columns, but only to include each yn value in the calculation of the mean if the corresponding xn column value is greater than 10. So for row 1; you will see that only y2 y3 are included in calculating the output column, but for row 6 y1-y3 are all included. Because the number of paired x y columns is large I am not sure the best way to achieve this. Thanks in advance Tom [[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] Windows R_LIBS_USER confusion under R-3.0.1
I would appreciate ideas about MS Windows install issues. I'm at our stats summer camp and have been looking at a lot of Windows R installs and there are some wrinkles about R_LIBS_USER. On a clean Win7 or Win8 system, with R-3.0.1, we see the user library for packages defaulting to $HOME/R/win-library. I think that's awesome, the way it should be. Yea! But it does not appear that way on all systems, and I think it is because of lingering after-effects of previous R installs. In previous versions of R, R_LIBS_USER defaulted to $HOME/AppData/Roaming/... That was not so great because it was (default) hidden to the students and they were disoriented about how something that does not exist (or show) could hold packages. Aside from teaching them how to configure the file manager, we could navigate that. The problem is that with R-3.0.1, sometimes we are seeing the user package installs going into $HOME/AppData/Roaming/ In the user account, there is no $HOME/.Rprofile or $HOME/.Renviron. I hate to tell non-expert users that they ought to go fishing in the Windows registry, but I'm starting to suspect that is what they ought to do. What do you think? PJ -- Paul E. Johnson Professor, Political Science Assoc. Director 1541 Lilac Lane, Room 504 Center for Research Methods University of Kansas University of Kansas http://pj.freefaculty.org http://quant.ku.edu [[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] assigning global columns selection for all subset functions in script
Thanks very much, John. This is very helpful. Burnette From: John Kane [via R] [mailto:ml-node+s789695n4669297...@n4.nabble.com] Sent: Tuesday, June 11, 2013 5:35 PM To: Crombie, Burnette N Subject: Re: assigning global columns selection for all subset functions in script index the columns to select lets say you want to select a set of colmns 2,4,6,8 Try something like this. (not run) mycols - c(2,4,6,8) select(mydata[ , mycols] , mdata$x == 3) John Kane Kingston ON Canada -Original Message- From: [hidden email]/user/SendEmail.jtp?type=nodenode=4669297i=0 Sent: Tue, 11 Jun 2013 09:18:25 -0700 (PDT) To: [hidden email]/user/SendEmail.jtp?type=nodenode=4669297i=1 Subject: [R] assigning global columns selection for all subset functions in script How do I let R know that I always want to select the same columns in my subset functions (below), so that I don't have to keep copy/pasting the same selection? (thanks) devUni2 - subset(devUni1, dind02 != 52, select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year)) devUni3 - subset(devUni2, lfsr94 == 1 | lfsr94 == 2 , select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year)) devUni4 - subset(devUni3, class94 6 , select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year)) devUni5 - subset(devUni4, relref95 10 | relref95 ==13 | relref95 =14, select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year)) -- View this message in context: http://r.789695.n4.nabble.com/assigning-global-columns-selection-for-all-subset-functions-in-script-tp4669252.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email]/user/SendEmail.jtp?type=nodenode=4669297i=2 mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email]/user/SendEmail.jtp?type=nodenode=4669297i=3 mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/assigning-global-columns-selection-for-all-subset-functions-in-script-tp4669252p4669297.html To unsubscribe from assigning global columns selection for all subset functions in script, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4669252code=YmNyb21iaWVAdXRrLmVkdXw0NjY5MjUyfC0xMzI5MzM0NzI3. NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/assigning-global-columns-selection-for-all-subset-functions-in-script-tp4669252p4669343.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-SIG-Mac] problem with the installation of r commander on a mac
Dear all, I am trying to install R and the Rcmdr package on a MacOSX 10.8.4. It appears that I keep getting the error message Erreur : le chargement du package ou de l'espace de noms a échoué pour 'Rcmdr' no matter what my approach is. Even downloading XQuartz-2.7.4 did not help. I found the same problem outlined on the following website https://stat.ethz.ch/pipermail/r-help/2012-October/325305.html and was wondering whether a solution to the problem has been stated since then and if you could help me with instructions how to proceed ? Thank you very much for your help ! Kind regards, Susanne __ Susanne ETTINGER Postdoctoral researcher - Laboratoire Magmas et Volcans UBP - UMR6524 CNRS - M163 IRD 5, rue Kessler 63038 Clermont-Ferrand - Tel : ++33 (0)6.18.27.54.93 Fax : ++33 (0)4.73.34.67.44 - susanne.ettin...@gmail.com __ The eye sees only what the mind is prepared to comprehend. Robertson Davies __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Permutation test for GLM with proportional data
Dear all, I am trying to run permutation tests for GLM using the glmperm package. When I created my model, I followed The R book and Mixed effects models and extensions in ecology with R. In both books, response variables were specified by using cbind(). That is, response variable is in a matrix. This approach is not a problem at all to run glm(). However, when I run glm.perm(), it seems that response variable with cbind() is not good. This is because glm.perm asks a vector of response variable, not a matrix. Does glm() generate a vector for a response variable using cbind()? If it does, is there any way to extract the vector? Alternatively, I would like to know if there are other options to run permutation tests for GLM with proportion data. Thank you for reading this message. Yours, Kota This email may be confidential and subject to legal privilege, it may not reflect the views of the University of Canterbury, and it is not guaranteed to be virus free. If you are not an intended recipient, please notify the sender immediately and erase all copies of the message and any attachments. Please refer to http://www.canterbury.ac.nz/emaildisclaimer for more information. [[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] assigning global columns selection for all subset functions in script
Thanks, David. I appreciate your help. Your solution is the idea I also had but wasn't quite sure if it was allowed in this case. That's a simple fix. Burnette From: David Winsemius [via R] [mailto:ml-node+s789695n4669295...@n4.nabble.com] Sent: Tuesday, June 11, 2013 5:31 PM To: Crombie, Burnette N Subject: Re: assigning global columns selection for all subset functions in script On Jun 11, 2013, at 9:18 AM, bcrombie wrote: How do I let R know that I always want to select the same columns in my subset functions (below), so that I don't have to keep copy/pasting the same selection? (thanks) devUni2 - subset(devUni1, dind02 != 52, select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year)) Perhaps: devUni3 - subset(devUni2, lfsr94 == 1 | lfsr94 == 2 , select=names(devUni2) ) Or just create a character vector: desired - names(devUni2) devUni3 - subset(devUni2, lfsr94 == 1 | lfsr94 == 2 , select=desired ) Because I am lazy I exprimented a bit to avoid adding all those quote marks: desired - expression(paidhre, earnhre,earnwke,uhourse,hourslw,otc,ind02, dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year) as.character(as.list(desired)) [1] paidhre earnhre earnwke uhourse hourslw otc ind02 [8] dind02 occ00docc00 lfsr94 class94 relref95 smsastat [15] stateweight year devUni4 - subset(devUni3, class94 6 , select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year)) devUni5 - subset(devUni4, relref95 10 | relref95 ==13 | relref95 =14, select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lfsr94,class94,relref95,smsastat,state,weight,year)) -- David Winsemius Alameda, CA, USA __ [hidden email]/user/SendEmail.jtp?type=nodenode=4669295i=0 mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/assigning-global-columns-selection-for-all-subset-functions-in-script-tp4669252p4669295.html To unsubscribe from assigning global columns selection for all subset functions in script, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4669252code=YmNyb21iaWVAdXRrLmVkdXw0NjY5MjUyfC0xMzI5MzM0NzI3. NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/assigning-global-columns-selection-for-all-subset-functions-in-script-tp4669252p4669345.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] odds ratio per standard deviation
Without context this is a shot in the dark, but my guess is this is referring to something like a logistic regression where the odds ratio (exponential of the coefficient) refers to the change in odds for the outcome for a 1 unit change in x. Now often a 1 unit change in x is very meaningful, but other times it is not that meaningful, e.g. if x is measuring the size of diamonds in carats and the data does not span an entire carat, or x is measured in days and our x variable spans years. In these cases it can make more sense to talk about the change in the odds relative to a different step size than just a 1 unit change in x, a reasonable thing to use is the change in odds for a one standard deviation change in x (much smaller than 1 for the diamonds, much larger for the days), this may be the odds ratio per standard deviation that you mention. On Tue, Jun 11, 2013 at 7:38 PM, vinhnguyen04x imvi...@yahoo.com.vn wrote: Hi all i have a question: why and when do we use odds ratio per standard deviation instead of odds ratio? -- View this message in context: http://r.789695.n4.nabble.com/odds-ratio-per-standard-deviation-tp4669315.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[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] Fw: Hi, can you supply tablet pc?
Hi, Kejora here. I didn't get your reply. Tq, Kejora --- From: l...@asquote.com To: r-h...@stat.math.ethz.ch Date: 2013-06-07 Subject: Hi, can you supply tablet pc? Hi. Kejora here. I find you on google. Aere you doing distributing business? We have a clients who need tablet pc urgently(first order about 500 pcs). If you can provide, please send you products with price(!!!) to me. Quadcore with 3G are prefered. Tell me your phone or skype if you like to. I'll call you if your price is good. Thanks, Kejora __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Proper way to implement package internal functions
[previously posted on Stack Overflow: http://stackoverflow.com/questions/17034309/hiding-undocumented-functions-in-a-package-use-of-function-name ] I've got some functions I need to make available in a package, and I don't want to export them or write much documentation for them. I'd just hide them inside another function but they need to be available to several functions so doing it that way becomes a scoping and maintenance issue. What is the right way to do this? By that I mean do they need special names, do they go somewhere other than the R subdirectory, can I put them in a single file, etc? I've checked out the manuals (e.g. Writing R Extensions 1.6.1), and what I'm after is like the .internals concept in the core, but I don't see any instructions about how to do this generally. For example, if I have functions foo1 and foo2 in a file foofunc.R, and these are intended for internal use only, should they be called foo1 or .foo1? And the file that holds them, should it be .foofunc.R or foofunc-internals? What should the Rd look like, or do I even need one? I know people do this in packages all the time and I feel like I've seen this somewhere, but I can't find any resources just now. Perhaps a suggestion of a package that does things this way which I could study would be sufficient. Thanks, Bryan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Proper way to implement package internal functions
On 12/06/2013 10:44 AM, Bryan Hanson wrote: [previously posted on Stack Overflow: http://stackoverflow.com/questions/17034309/hiding-undocumented-functions-in-a-package-use-of-function-name ] I've got some functions I need to make available in a package, and I don't want to export them or write much documentation for them. I'd just hide them inside another function but they need to be available to several functions so doing it that way becomes a scoping and maintenance issue. What is the right way to do this? By that I mean do they need special names, do they go somewhere other than the R subdirectory, can I put them in a single file, etc? I've checked out the manuals (e.g. Writing R Extensions 1.6.1), and what I'm after is like the .internals concept in the core, but I don't see any instructions about how to do this generally. For example, if I have functions foo1 and foo2 in a file foofunc.R, and these are intended for internal use only, should they be called foo1 or .foo1? And the file that holds them, should it be .foofunc.R or foofunc-internals? What should the Rd look like, or do I even need one? I know people do this in packages all the time and I feel like I've seen this somewhere, but I can't find any resources just now. Perhaps a suggestion of a package that does things this way which I could study would be sufficient. The best way to do this is simply not to export those functions in your NAMESPACE file. If you want to use a naming convention internally to remind yourself that those are private, you can do so, but R doesn't force one on you, and there are no really popular conventions in use. R won't complain if you don't document those functions at all. There may have been other advice in the version 1.6.1 manual, but that is seriously out of date, more than 10 years old. I recommend that you update to 3.0.1. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-SIG-Mac] problem with the installation of r commander on a mac
Dear Susanne, Installation instructions for the Rcmdr are at http://socserv.socsci.mcmaster.ca/jfox/Misc/Rcmdr/installation-notes.html, but you've apparently done what you normally need to do to get it to work. Though you don't say so, I assume that you have the latest versions of R (3.0.1) and the Rcmdr (1.9-6), and that you've not only downloaded XQuartz, but installed it (a necessary step on Mac OS X 10.8). Beyond that, you haven't provided much detail about the error, but I suspect that for some reason XQuartz isn't finding your display. One way to check whether the error is particular to the Rcmdr is to try to load the tcltk package in R directly via library(tcltk). You might also try starting the XQuartz app *before* you start R. It's a bit disconcerting that others have occasionally reported a similar problem, solved the problem, but, as far as I know, failed to post the solution to this list, which seems to me a common courtesy. If I knew the solution, I could add it to the Rcmdr installation notes. I'm not a frequent user of Mac OS X, and I've never experienced problems installing the Rcmdr on it. I imagine that other list members will be able to offer more concrete help. Best, John --- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Susanne.Ettinger Sent: Wednesday, June 12, 2013 10:06 AM To: r-help@r-project.org Subject: Re: [R] [R-SIG-Mac] problem with the installation of r commander on a mac Dear all, I am trying to install R and the Rcmdr package on a MacOSX 10.8.4. It appears that I keep getting the error message Erreur : le chargement du package ou de l'espace de noms a échoué pour 'Rcmdr' no matter what my approach is. Even downloading XQuartz-2.7.4 did not help. I found the same problem outlined on the following website https://stat.ethz.ch/pipermail/r-help/2012-October/325305.html and was wondering whether a solution to the problem has been stated since then and if you could help me with instructions how to proceed ? Thank you very much for your help ! Kind regards, Susanne __ Susanne ETTINGER Postdoctoral researcher - Laboratoire Magmas et Volcans UBP - UMR6524 CNRS - M163 IRD 5, rue Kessler 63038 Clermont-Ferrand - Tel : ++33 (0)6.18.27.54.93 Fax : ++33 (0)4.73.34.67.44 - susanne.ettin...@gmail.com __ The eye sees only what the mind is prepared to comprehend. Robertson Davies __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] simulation from truncated skew normal
I am not aware of any such command so, I think, you may have to write one yourself: invert the CDF and use uniform random variable (runif) to sample Mikhail On Tuesday, June 11, 2013 16:18:59 cassie jones wrote: Hello R-users, I am trying to simulate from truncated skew normal distribution. I know there are ways to simulate from skewed normal distribution such as rsn(sn) or rsnorm(VGAM), but I could not find any command to simulate from a truncated skew-normal distribution. Does anyone know how to do that? Any help is appreciated. Thanks in advance. Cassie [[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] Proper way to implement package internal functions
Thanks Duncan... Silly me, it's section 1.6.1 not version 1.6.1! So this warning from check is not a problem in the long run: * checking for missing documentation entries ... WARNING Undocumented code objects: ‘ang0to2pi’ ‘dAB’ ‘doBoxesIntersect’ ... All user-level objects in a package should have documentation entries. if I understand correctly. I guess the reason I didn't find any documentation is the wide lattitude which is possible. Thank you. Bryan On Jun 12, 2013, at 10:57 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/06/2013 10:44 AM, Bryan Hanson wrote: [previously posted on Stack Overflow: http://stackoverflow.com/questions/17034309/hiding-undocumented-functions-in-a-package-use-of-function-name ] I've got some functions I need to make available in a package, and I don't want to export them or write much documentation for them. I'd just hide them inside another function but they need to be available to several functions so doing it that way becomes a scoping and maintenance issue. What is the right way to do this? By that I mean do they need special names, do they go somewhere other than the R subdirectory, can I put them in a single file, etc? I've checked out the manuals (e.g. Writing R Extensions 1.6.1), and what I'm after is like the .internals concept in the core, but I don't see any instructions about how to do this generally. For example, if I have functions foo1 and foo2 in a file foofunc.R, and these are intended for internal use only, should they be called foo1 or .foo1? And the file that holds them, should it be .foofunc.R or foofunc-internals? What should the Rd look like, or do I even need one? I know people do this in packages all the time and I feel like I've seen this somewhere, but I can't find any resources just now. Perhaps a suggestion of a package that does things this way which I could study would be sufficient. The best way to do this is simply not to export those functions in your NAMESPACE file. If you want to use a naming convention internally to remind yourself that those are private, you can do so, but R doesn't force one on you, and there are no really popular conventions in use. R won't complain if you don't document those functions at all. There may have been other advice in the version 1.6.1 manual, but that is seriously out of date, more than 10 years old. I recommend that you update to 3.0.1. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to get a running mean result by R?
Look at the filter() function. 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 Jie Tang Sent: Wednesday, June 12, 2013 12:21 AM To: r-help@r-project.org Subject: [R] How to get a running mean result by R? Hi R users: I have a big data and want to calculate the running mean of this data . How can I get this kind of result ? I have check the command mean it seems mean could not get the running mean? -- TANG Jie [[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] odds ratio per standard deviation
[Replies transposed so as to achieve bottom-posting ... ] On 12-Jun-2013 14:53:02 Greg Snow wrote: On Tue, Jun 11, 2013 at 7:38 PM, vinhnguyen04x imvi...@yahoo.com.vn wrote: Hi all i have a question: why and when do we use odds ratio per standard deviation instead of odds ratio? -- View this message in context: http://r.789695.n4.nabble.com/odds-ratio-per-standard-deviation-tp4669315.htm l Sent from the R help mailing list archive at Nabble.com. __ Without context this is a shot in the dark, but my guess is this is referring to something like a logistic regression where the odds ratio (exponential of the coefficient) refers to the change in odds for the outcome for a 1 unit change in x. Now often a 1 unit change in x is very meaningful, but other times it is not that meaningful, e.g. if x is measuring the size of diamonds in carats and the data does not span an entire carat, or x is measured in days and our x variable spans years. In these cases it can make more sense to talk about the change in the odds relative to a different step size than just a 1 unit change in x, a reasonable thing to use is the change in odds for a one standard deviation change in x (much smaller than 1 for the diamonds, much larger for the days), this may be the odds ratio per standard deviation that you mention. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com I think there is one comment that needs to be made about this! The odds ratio per unit change in x means exactly what it says, and can be converted into the odds ratio per any other amount of change in x very easily. With x originally in (say) days, and with estimated logistic regression logodds = a + b*x, if you change your unit of x to, say weeks, so that x' = x/7, then this is equivalent to changing b to b' = 7*b. Now just take your sliderule; no need for R (oops, now off-topic ... ). Another comment: I do not favour blindly standardising a variable relative to its standard deviation in the data. The SD may be what it is for any number of reasons, ranging from x being randomly sampled fron a population to x being assigned specific values in a designed experiment. Since, for exactly the same meanings of the variables in the regression, the standard deviation may change from one set of data to another of exactly the same kind, the odds per standard deviation could vary from dataset to dataset of the same investigation, and even vary dramatically. That looks like a situation to avoid, unless it is very carefully discussed! The one argument that might give some sense to odds ratio per standard deviation could apply when x has been sampled from a population in which the variation of x can be approximately described by a Normal distribution. Then odds ratio per standard deviation refers to a change from, say, the mean/median of the population to the 84th percentile, or from the 31st percentile to the 69th percentile, or from the 69th percentile to the 93rd percentile, etc. But these steps cover somewhat different proportions of the populatipn: 50th to 85th = 35%; 31st to 69th = 38%; 69th to 93rd = 24%. So you are still facing issues of what you mean, or what you want to mean. Simpler to stick to the original odds per unit of x and then apply it to whatever multiple of the unit you happen to be interested in as a change (along with the reasons for that interest). Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 12-Jun-2013 Time: 17:14:00 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] agnes() in package cluster on R 2.14.1 and R 3.0.1
Dear Martin, Thank you for your answer. I got the dist.binary() function in the ade4 package. It gives several distances for binary data. I agree with you, some individuals probably share the same profile in my data. Regards, Hugo [[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] Default colors for barplot() XXXX
Hi everyone, I have the following call to the barplot() function which produces the desired stacked bar chart. HOWEVER, barplot() chooses 4 different shades of gray for the stacks. If I want to use the legend=NULL argument in combination with a separate call to legend() to customize the legend, how do I figure out exactly what shades of gray barplot() has choosen? Can these color names be extracted from the barplot after saving it as an object? barplot(table(credit_rating_num,clu_), xlab=Cluster Label, ylab=Frequency, ylim=c(0,7000), legend=c(C2,C3,C4,C5)) Thank you, 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.
[R] Functions within functions - environments
Dear list, I have a problem with nested functions and I don't manage to get it solved. I know I should be looking in environments, and I have tried a lot, but it keeps on erroring. An easy version of the problem is as follows: innerfunction-function() { print(paste(a, from inner function)) print(paste(b, from inner function)) setwd(wd) } middlefunction-function() { b=b print(paste(b, from middle function)) innerfunction() } outerfunction-function() { a=a print(paste(a, from outer function)) middlefunction() } outerfunction() Here, R will tell me that the inner function has no clue what a or b is. So what I want, is the inner function to recognize a and b. Any suggestions? Many thanks! Rik -- Rik Verdonck Research group of Molecular Developmental Physiology and Signal Transduction KULeuven, Faculty of Science Naamsestraat 59, Bus 02465 B-3000 Leuven,Belgium Tel. +32 16 32 39 65 Fax +32 16 32 39 02 http://bio.kuleuven.be/df/JV/index2.htm rik.verdo...@bio.kuleuven.be Please consider the environment before printing this e-mail [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to cast a numeric argument to a two-dimensional array in an inline C function?
Hello -- For convenience, I would like to use a two dimensional array inside an inline C function. However, any numeric array in R is passed to C code as double *. So, how can I cast a (double *) to a double[][]? thank you for your time, Mikhail [[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] Functions within functions - environments
Hello, See the help page for parent.frame, and use its argument to go back to the frames of variables 'a' and 'b': innerfunction-function() { env1 - parent.frame(1) # for 'b' env2 - parent.frame(2) # for 'a' print(paste(env2$a, from inner function)) print(paste(env1$b, from inner function)) setwd(wd) } Now it complains about 'wd'. (Are you sure you want to hard code the number of frames to go back to? It seems better to write normal functions, i.e., functions with arguments. innerfunction would have 2 args and middlefunction just one, 'a'.) Hope this helps, Rui Barradas Em 12-06-2013 18:42, Rik Verdonck escreveu: Dear list, I have a problem with nested functions and I don't manage to get it solved. I know I should be looking in environments, and I have tried a lot, but it keeps on erroring. An easy version of the problem is as follows: innerfunction-function() { print(paste(a, from inner function)) print(paste(b, from inner function)) setwd(wd) } middlefunction-function() { b=b print(paste(b, from middle function)) innerfunction() } outerfunction-function() { a=a print(paste(a, from outer function)) middlefunction() } outerfunction() Here, R will tell me that the inner function has no clue what a or b is. So what I want, is the inner function to recognize a and b. Any suggestions? Many thanks! Rik __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Default colors for barplot() XXXX
On Jun 12, 2013, at 12:37 PM, Dan Abner dan.abne...@gmail.com wrote: Hi everyone, I have the following call to the barplot() function which produces the desired stacked bar chart. HOWEVER, barplot() chooses 4 different shades of gray for the stacks. If I want to use the legend=NULL argument in combination with a separate call to legend() to customize the legend, how do I figure out exactly what shades of gray barplot() has choosen? Can these color names be extracted from the barplot after saving it as an object? barplot(table(credit_rating_num,clu_), xlab=Cluster Label, ylab=Frequency, ylim=c(0,7000), legend=c(C2,C3,C4,C5)) Thank you, Dan The help file defines the 'col' argument as: col a vector of colors for the bars or bar components. By default, grey is used if height is a vector, and a gamma-corrected grey palette if height is a matrix. However, that is lacking a bit of detail in the latter case, albeit one of the examples on the page uses the gray.colors() function. The easiest way to get that detail (in this case or for any function more generally) is to look at the source code for the function, within which you would see: ... else if (is.matrix(height)) { if (is.null(col)) col - gray.colors(nrow(height)) ... A better approach would be to simply take proactive control of the colors when you call barplot() and define the 'col' argument to colors of your choosing, which you can then use in the call to legend(). Regards, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Functions within functions - environments
A function looks up free variables in the environment in which the function was defined, not in the environment in which the function was called. The latter is called something like 'dynamic scoping' and usually leads to trouble, the former is 'lexical scoping' and leads to predictable results. You can do dynamic scoping in R (using get(), assign(), and parent.frame()), but it leads to code that only works correctly in favorable circumstances. You should pass data from the caller to the callee via the argument list, not via free variables. To use lexical scoping define your functions as: outerfunction-function() { middlefunction-function() { innerfunction-function() { print(paste(a, from inner function)) print(paste(b, from inner function)) # setwd(wd) # wd was not defined in your mail } b=b print(paste(b, from middle function)) innerfunction() } a=a print(paste(a, from outer function)) middlefunction() } outerfunction() [1] a from outer function [1] b from middle function [1] a from inner function [1] b from inner function (One can change the environment of a function after it is defined, but there is not often a need to do that.) 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 Rik Verdonck Sent: Wednesday, June 12, 2013 10:42 AM To: r-help@r-project.org Subject: [R] Functions within functions - environments Dear list, I have a problem with nested functions and I don't manage to get it solved. I know I should be looking in environments, and I have tried a lot, but it keeps on erroring. An easy version of the problem is as follows: innerfunction-function() { print(paste(a, from inner function)) print(paste(b, from inner function)) setwd(wd) } middlefunction-function() { b=b print(paste(b, from middle function)) innerfunction() } outerfunction-function() { a=a print(paste(a, from outer function)) middlefunction() } outerfunction() Here, R will tell me that the inner function has no clue what a or b is. So what I want, is the inner function to recognize a and b. Any suggestions? Many thanks! Rik -- Rik Verdonck Research group of Molecular Developmental Physiology and Signal Transduction KULeuven, Faculty of Science Naamsestraat 59, Bus 02465 B-3000 Leuven,Belgium Tel. +32 16 32 39 65 Fax +32 16 32 39 02 http://bio.kuleuven.be/df/JV/index2.htm rik.verdo...@bio.kuleuven.be Please consider the environment before printing this e-mail [[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] grDevices::convertColor XYZ space is it really xyY?
grDevices::convertColor has arguments 'from' and 'to' which can take on value 'XYZ'. Can someone confirm that 'XYZ' is the same as the CIE chromaticity coordinates that are also sometimes refered to as 'xyY' in the literature? Or are these the CIE tristimulus values? It looks to me like the first case is true, but I would appreciate hearing from one of the people in the know. Thanks, Bryan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grDevices::convertColor XYZ space is it really xyY?
On 12/06/2013 2:45 PM, Bryan Hanson wrote: grDevices::convertColor has arguments 'from' and 'to' which can take on value 'XYZ'. Can someone confirm that 'XYZ' is the same as the CIE chromaticity coordinates that are also sometimes refered to as 'xyY' in the literature? Or are these the CIE tristimulus values? It looks to me like the first case is true, but I would appreciate hearing from one of the people in the know. Thanks, Bryan According to the referenced web page from ?convertColor (i.e. http://www.brucelindbloom.com/), XYZ is not xyY, though the conversion looks pretty simple. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grDevices::convertColor XYZ space is it really xyY?
Bryan Hanson hanson at depauw.edu writes: grDevices::convertColor has arguments 'from' and 'to' which can take on value 'XYZ'. Can someone confirm that 'XYZ' is the same as the CIE chromaticity coordinates are also sometimes refered to as 'xyY' in the literature? Or are these the CIE tristimulus values? It looks to me like the first case is true, but I would appreciate hearing from one of the people in know. Thanks, Bryan I.'d look at the code or put in some known data to test it, but XYZ are tristimulus values and xyY are chromaticity coordinated and the luminance which is the Y tristimulus value for the CIE 1931 standard observer. Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fetching and Saving warnings from a function
Hello again, Let say I have following user defined function: Myfn - function(x) { if (x 0) { warning(Negative value) } return(x) } Now I want to create some function which will save the Warnings from 'Myfn', so that I can use those warnings later for more analysis. Therefore I was thinking of following type of function: ProposedWarningStoreFunction - function() { .... } therefore,if I run 'ProposedWarningStoreFunction', I should get following kind of results: Warnings - ProposedWarningStoreFunction({Result - Myfn(-4)}) Result -4 Warnings In Myfn(-3) : Negative value Can somebody here point me how to achieve this? Or is it possible to achieve at all? Thank you for your help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to fit the cumulative probability distributive functiion with the gamma distribution?
Hello everyone, I'm trying to fit the PDF of time series datasets with the gamma distribution. Nonetheless, this isn't possible for several datasets since the gamma distribution can only been used to fit continuous distribution. For instance, gam-fitdrib(hist-c(24,7,4,1,2,1,0,0,0,1,0,0),gamma) will yield an error message. To solve this issue, I decided to fit the cumulative distributive function i.e. gam-fitdistr(hist_cum-c(24,31,35,36,38,39,39,39,40,40,40)). Now I don't know how to obtain the corresponding CDF of the gamma distribution which will fit the empirical CDF. I have already tried some instructions like pgamma(seq(4,4*12,4), scale=1/gam$estimate[2],shape=gam$estimate[1]) without success as you can see on this picture https://docs.google.com/file/d/0BwjZP-sfazLMaDM2bHBDYnFOSWs/edit?usp=sharing where the curve in blue was supposed to be the fitted gamma CDF. I said was supposed because I was obliged to use the instruction par(new=T) in order to super-impose the fitted gamma CDF Cheers Armel [[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] Fetching and Saving warnings from a function
?withCallingHandlers E.g., R f - function(expr) { warnings - character() withCallingHandlers(expr, warning=function(e){ warnings - c(warnings, conditionMessage(e)) invokeRestart(muffleWarning) }) warnings } R f(1:10) character(0) R f(warning(Hmm)) [1] Hmm R f({warning(Hmm); x - 666 ; warning(Possible problem)}) [1] Hmm Possible problem R x [1] 666 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 Christofer Bogaso Sent: Wednesday, June 12, 2013 12:07 PM To: r-help Subject: [R] Fetching and Saving warnings from a function Hello again, Let say I have following user defined function: Myfn - function(x) { if (x 0) { warning(Negative value) } return(x) } Now I want to create some function which will save the Warnings from 'Myfn', so that I can use those warnings later for more analysis. Therefore I was thinking of following type of function: ProposedWarningStoreFunction - function() { .... } therefore,if I run 'ProposedWarningStoreFunction', I should get following kind of results: Warnings - ProposedWarningStoreFunction({Result - Myfn(-4)}) Result -4 Warnings In Myfn(-3) : Negative value Can somebody here point me how to achieve this? Or is it possible to achieve at all? Thank you for your help. [[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] survreg with measurement uncertainties
Hi Terry, Thanks for your quick reply. I am talking about uncertainty in the response. I have 2 follow up questions: 1) my understanding from the documentation is that 'id' in cluster(id) should be the same when the predictors are not independent. Is this correct? (To be more concrete: my data are brightnesses at different wavelengths. Each brightness is an independent measurement, so the elements of id should all be different?) 2) I tested survreg with uncertainties on an example where I already know the answer (and where I am not using limits), and it does not converge. Below is the code I used, does anything jump out as incorrect? data = c(144.53, 1687.68, 5397.91) err = c(8.32, 471.22, 796.67) model = c(71.60, 859.23, 1699.19) id = c(1, 2, 3) This works (2.9 is the answer from simple chi_sq fitting): survreg(Surv(time = data, event = c(1,1,1))~model-1, dist='gaussian', init=c(2.9)) This does not converge (2.1 is the answer from chi_sq fitting): survreg(Surv(time = data, event = c(1,1,1))~model-1+cluster(id), weights=1/(err^2), dist='gaussian', init=c(2.1)) And this does, but the answer it returns is wonky: data[2] = 3*err[2] # data[2] is very close to 3*err[2] already survreg(Surv(time = data, event = c(1,2,1))~model-1+cluster(id), weights=1/(err^2), dist='gaussian', init=c(2.1)) Thanks, Kyle On Wed, Jun 12, 2013 at 6:51 AM, Terry Therneau thern...@mayo.edu wrote: I will assume that you are talking about uncertainty in the response. Then one simple way to fit the model is to use case weights that are proprional to 1/variance, along with +cluster(id) in the model statement to get a correct variance for this case. In linear models this would be called the White or Horvitz-Thompsen or GEE working independence variance estimate, depending on which literature you happen to be reading (economics, survey sampling, or biostat). Now if you are talking about errors in the predictor variables, that is a much harder problem. Terry Therneau On 06/12/2013 05:00 AM, Kyle Penner wrote: Hello, I have some measurements that I am trying to fit a model to. I also have uncertainties for these measurements. Some of the measurements are not well detected, so I'd like to use a limit instead of the actual measurement. (I am always dealing with upper limits, i.e. left censored data.) I have successfully run survreg using the combination of well detected measurements and limits, but I would like to include the measurement uncertainty (for the well detected measurements) in the fitting. As far as I can tell, survreg doesn't support this. Does anyone have a suggestion for how to accomplish this? Thanks, Kyle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a new var from conditional values in other vars
Hi, Try this: set.seed(25) dat1- data.frame(A=sample(1:30,100,replace=TRUE),B=sample(1:35,100,replace=TRUE),C=sample(1:25,100,replace=TRUE)) dat1$pattern-with(dat1,ifelse(A20 B=2.5 C=20,Normal,ifelse(A 20 B 2.5 C 20,Increased,ifelse(A =20 B 2.5 C =20,Low,Other head(dat1) # A B C pattern #1 13 20 5 Other #2 21 15 4 Low #3 5 24 1 Other #4 27 13 6 Low #5 4 4 10 Other #6 30 19 22 Other A.K. I am newbie to R coming from SAS (basic user). Quite a difficult move I have a dataframe named kappa exported from csv file kappa-read.csv(kappacsv, header=TRUE, sep=;, dec=.) kappa contains 3 numeric vars (A,B and C) I want to create a new var called pattern depending on the values of the conditions in A, B and C I have tried many ways one has been this: kappa$pattern1-99 # create a new numeric var in kappa dataframe if (A=20 B=2.5 C =20){kappa$pattern-Normal} else if (A 20 B 2.5 C 20){kappa$pattern-Increased} else if (A =20 B 2.5 C =20){kappa$pattern-Low} else {kappa$pattern-“Other”} The code does not work and I get errors all the time. Any help will be greatly appreciated Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grDevices::convertColor XYZ space is it really xyY?
Ken, I followed your suggestion and perhaps I don't understand what to expect from convertColor or maybe I'm not using it correctly. Consider the following tests: D65 - c(0.3127, 0.329, 0.3583) # D65 chromaticity coordinates X - D65[1]*D65[3]/D65[2] # conversion per brucelindbloom.com Y - D65[3] Z - D65[3]*D65[3]/D65[2] XYZ - data.frame(X = X, Y = Y, Z = Z) # D65 in tristimulus values (?) colnames(XYZ) - c(X, Y, Z) tst1 - convertColor(XYZ, from = XYZ, to = sRGB) tst2 - convertColor(D65, from = XYZ, to = sRGB) # none of these are 1,1,1, namely white (they are ~ 0.6, 0.6, 0.6) So it looks like D65, a white standard, does not come back to something near white in the sRGB space. What am I doing wrong here, or what do I misunderstand? Please don't say everything! Thanks, Bryan On Jun 12, 2013, at 2:57 PM, Ken Knonlauch ken.knobla...@inserm.fr wrote: Bryan Hanson hanson at depauw.edu writes: grDevices::convertColor has arguments 'from' and 'to' which can take on value 'XYZ'. Can someone confirm that 'XYZ' is the same as the CIE chromaticity coordinates are also sometimes refered to as 'xyY' in the literature? Or are these the CIE tristimulus values? It looks to me like the first case is true, but I would appreciate hearing from one of the people in know. Thanks, Bryan I.'d look at the code or put in some known data to test it, but XYZ are tristimulus values and xyY are chromaticity coordinated and the luminance which is the Y tristimulus value for the CIE 1931 standard observer. Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] grDevices::convertColor XYZ space is it really xyY?
You seem to treating the input values as xyY when they should be XYZ (case matters). So, I would do something like this D65 - c(0.3127, 0.329, 0.3583) X - 100 * D65[1] Y - 100 * D65[2] Z - 100 * D65[3] XYZ - data.frame(X = X, Y = Y, Z = Z) convertColor(XYZ, from = XYZ, to = sRGB) [,1] [,2] [,3] [1,]111 Quoting Bryan Hanson han...@depauw.edu: Ken, I followed your suggestion and perhaps I don't understand what to expect from convertColor or maybe I'm not using it correctly. Consider the following tests: D65 - c(0.3127, 0.329, 0.3583) # D65 chromaticity coordinates X - D65[1]*D65[3]/D65[2] # conversion per brucelindbloom.com Y - D65[3] Z - D65[3]*D65[3]/D65[2] XYZ - data.frame(X = X, Y = Y, Z = Z) # D65 in tristimulus values (?) colnames(XYZ) - c(X, Y, Z) tst1 - convertColor(XYZ, from = XYZ, to = sRGB) tst2 - convertColor(D65, from = XYZ, to = sRGB) # none of these are 1,1,1, namely white (they are ~ 0.6, 0.6, 0.6) So it looks like D65, a white standard, does not come back to something near white in the sRGB space. What am I doing wrong here, or what do I misunderstand? Please don't say everything! Thanks, Bryan On Jun 12, 2013, at 2:57 PM, Ken Knonlauch ken.knobla...@inserm.fr wrote: Bryan Hanson hanson at depauw.edu writes: grDevices::convertColor has arguments 'from' and 'to' which can take on value 'XYZ'. Can someone confirm that 'XYZ' is the same as the CIE chromaticity coordinates are also sometimes refered to as 'xyY' in the literature? Or are these the CIE tristimulus values? It looks to me like the first case is true, but I would appreciate hearing from one of the people in know. Thanks, Bryan I.'d look at the code or put in some known data to test it, but XYZ are tristimulus values and xyY are chromaticity coordinated and the luminance which is the Y tristimulus value for the CIE 1931 standard observer. Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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.
Re: [R] grDevices::convertColor XYZ space is it really xyY?
Thank you Ken. 90% of my problem was missing the factor of 100. I was just inputing xyY as a test, I wasn't sure whether the docs were being clear about nomenclature. Speaking thereof, the D65 values used in the example: I thought they were chromaticity coordinates, but apparently they are tristimulus values - is that correct? Thanks again. This solves several problems in a package I am developing. Bryan On Jun 12, 2013, at 4:36 PM, Ken Knoblauch ken.knobla...@inserm.fr wrote: You seem to treating the input values as xyY when they should be XYZ (case matters). So, I would do something like this D65 - c(0.3127, 0.329, 0.3583) X - 100 * D65[1] Y - 100 * D65[2] Z - 100 * D65[3] XYZ - data.frame(X = X, Y = Y, Z = Z) convertColor(XYZ, from = XYZ, to = sRGB) [,1] [,2] [,3] [1,]111 Quoting Bryan Hanson han...@depauw.edu: Ken, I followed your suggestion and perhaps I don't understand what to expect from convertColor or maybe I'm not using it correctly. Consider the following tests: D65 - c(0.3127, 0.329, 0.3583) # D65 chromaticity coordinates X - D65[1]*D65[3]/D65[2] # conversion per brucelindbloom.com Y - D65[3] Z - D65[3]*D65[3]/D65[2] XYZ - data.frame(X = X, Y = Y, Z = Z) # D65 in tristimulus values (?) colnames(XYZ) - c(X, Y, Z) tst1 - convertColor(XYZ, from = XYZ, to = sRGB) tst2 - convertColor(D65, from = XYZ, to = sRGB) # none of these are 1,1,1, namely white (they are ~ 0.6, 0.6, 0.6) So it looks like D65, a white standard, does not come back to something near white in the sRGB space. What am I doing wrong here, or what do I misunderstand? Please don't say everything! Thanks, Bryan On Jun 12, 2013, at 2:57 PM, Ken Knonlauch ken.knobla...@inserm.fr wrote: Bryan Hanson hanson at depauw.edu writes: grDevices::convertColor has arguments 'from' and 'to' which can take on value 'XYZ'. Can someone confirm that 'XYZ' is the same as the CIE chromaticity coordinates are also sometimes refered to as 'xyY' in the literature? Or are these the CIE tristimulus values? It looks to me like the first case is true, but I would appreciate hearing from one of the people in know. Thanks, Bryan I.'d look at the code or put in some known data to test it, but XYZ are tristimulus values and xyY are chromaticity coordinated and the luminance which is the Y tristimulus value for the CIE 1931 standard observer. Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 This message was sent using IMP, the Internet Messaging Program. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grDevices::convertColor XYZ space is it really xyY?
If they sum to 1 then they are one and the same. Look at how chromaticity coordinates are defined in terms of the tristimulus values. Quoting Bryan Hanson han...@depauw.edu: Thank you Ken. 90% of my problem was missing the factor of 100. I was just inputing xyY as a test, I wasn't sure whether the docs were being clear about nomenclature. Speaking thereof, the D65 values used in the example: I thought they were chromaticity coordinates, but apparently they are tristimulus values - is that correct? Thanks again. This solves several problems in a package I am developing. Bryan On Jun 12, 2013, at 4:36 PM, Ken Knoblauch ken.knobla...@inserm.fr wrote: You seem to treating the input values as xyY when they should be XYZ (case matters). So, I would do something like this D65 - c(0.3127, 0.329, 0.3583) X - 100 * D65[1] Y - 100 * D65[2] Z - 100 * D65[3] XYZ - data.frame(X = X, Y = Y, Z = Z) convertColor(XYZ, from = XYZ, to = sRGB) [,1] [,2] [,3] [1,]111 Quoting Bryan Hanson han...@depauw.edu: Ken, I followed your suggestion and perhaps I don't understand what to expect from convertColor or maybe I'm not using it correctly. Consider the following tests: D65 - c(0.3127, 0.329, 0.3583) # D65 chromaticity coordinates X - D65[1]*D65[3]/D65[2] # conversion per brucelindbloom.com Y - D65[3] Z - D65[3]*D65[3]/D65[2] XYZ - data.frame(X = X, Y = Y, Z = Z) # D65 in tristimulus values (?) colnames(XYZ) - c(X, Y, Z) tst1 - convertColor(XYZ, from = XYZ, to = sRGB) tst2 - convertColor(D65, from = XYZ, to = sRGB) # none of these are 1,1,1, namely white (they are ~ 0.6, 0.6, 0.6) So it looks like D65, a white standard, does not come back to something near white in the sRGB space. What am I doing wrong here, or what do I misunderstand? Please don't say everything! Thanks, Bryan On Jun 12, 2013, at 2:57 PM, Ken Knonlauch ken.knobla...@inserm.fr wrote: Bryan Hanson hanson at depauw.edu writes: grDevices::convertColor has arguments 'from' and 'to' which can take on value 'XYZ'. Can someone confirm that 'XYZ' is the same as the CIE chromaticity coordinates are also sometimes refered to as 'xyY' in the literature? Or are these the CIE tristimulus values? It looks to me like the first case is true, but I would appreciate hearing from one of the people in know. Thanks, Bryan I.'d look at the code or put in some known data to test it, but XYZ are tristimulus values and xyY are chromaticity coordinated and the luminance which is the Y tristimulus value for the CIE 1931 standard observer. Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 This message was sent using IMP, the Internet Messaging Program. -- 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.
Re: [R] [R-SIG-Mac] problem with the installation of r commander on a mac
Dear Susanne, You started this thread on r-help (though R-SIG-Mac would have been more appropriate), and so I'm copying my response to the r-help list. People will find it confusing if the messages are simply kept private. It's not obvious to me exactly what your problem is now. In particular, is the Rcmdr package working when you start XQuartz before R? I see that you've installed and loaded the FactoMineR package. Presumably the Rcmdr package was already installed. Then you executed an R script provided by the authors of the FactoMineR package, which reinstalls and then modifies the Rcmdr package. I think that this is ill-advised (as opposed to providing an Rcmdr plug-in package for FactoMineR, as used to be the case), and if you're having problems with their script, you should really contact the authors. If I read the messages correctly, the script produces warnings, not errors, oddly relating to the language you're using (odd because the authors of the FactoMineR package are French) and it's possible that everything will work correctly despite the warnings. I hope this helps, John -Original Message- From: Susanne.Ettinger [mailto:susanne.ettin...@gmail.com] Sent: Wednesday, June 12, 2013 11:44 AM To: John Fox Subject: Re: [R] [R-SIG-Mac] problem with the installation of r commander on a mac Dear John, thank you very much for your quick reply - I realize I sent this email to the list without being a member, but I am a very beginner and started this morning the installation process of R. I have been printing out any possibly available information on how to get started with R and I am following the exercices exposed in the book written by Cornillon et al. (2012) to use FactoMineR to do some PCA analysis on vulnerability data. I downloaded the 3.0.1 version of R and have the 1.9-6 package of Rcmdr. I also checked into the library(tcltk) but do not get an error message, this seems to work fine. Since I open XQuartz before starting the Rcmdr library, I am getting a different error message than the ones of this morning. This is what it looks like : install.packages() --- SVP sélectionner un miroir CRAN pour cette session --- essai de l'URL 'http://cran.univ- lyon1.fr/bin/macosx/contrib/3.0/FactoMineR_1.25.tgz' Content type 'application/x-gzip' length 3397827 bytes (3.2 Mb) URL ouverte == downloaded 3.2 Mb Les packages binaires téléchargés sont dans /var/folders/06/z7b6z3y102xgxls2xh251p5wgp/T//Rtmp13nIpm/downl oaded_packages library(FactoMineR) Le chargement a nécessité le package : car Le chargement a nécessité le package : MASS Le chargement a nécessité le package : nnet Le chargement a nécessité le package : ellipse Attachement du package : ellipse L'objet suivant est masqué from package:car: ellipse Le chargement a nécessité le package : lattice Le chargement a nécessité le package : cluster Le chargement a nécessité le package : scatterplot3d Le chargement a nécessité le package : leaps source(http://factominer.free.fr/install-facto-fr.r;) essai de l'URL 'http://cran.univ- lyon1.fr/bin/macosx/contrib/3.0/Rcmdr_1.9-6.tgz' Content type 'application/x-gzip' length 3759850 bytes (3.6 Mb) URL ouverte == downloaded 3.6 Mb The downloaded binary packages are in /var/folders/06/z7b6z3y102xgxls2xh251p5wgp/T//Rtmp13nIpm/downl oaded_packages essai de l'URL 'http://cran.univ- lyon1.fr/bin/macosx/contrib/3.0/FactoMineR_1.25.tgz' Content type 'application/x-gzip' length 3397827 bytes (3.2 Mb) URL ouverte == downloaded 3.2 Mb The downloaded binary packages are in /var/folders/06/z7b6z3y102xgxls2xh251p5wgp/T//Rtmp13nIpm/downl oaded_packages Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 1 est incorrecte dans cet environnement linguistique Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 5 est incorrecte dans cet environnement linguistique Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 31 est incorrecte dans cet environnement linguistique Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 35 est incorrecte dans cet environnement linguistique Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 81 est incorrecte dans cet environnement linguistique Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 84 est incorrecte dans cet environnement linguistique Avis dans
[R] how to maximize the log-likelihood function with EM algorithm
Hi R users, I am trying to fit a Mixed Markov Model and ran into trouble with maximizing the log-likelihood function. I attached my R codes and the problem I have right now is that the maximization may end in some local maximum by specifying different start values. I am thinking if we can improve the maximization with EM algorithm. Any help will be greatly appreciated! purch_1 = c(0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1) purch_2 = c(0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1) purch_3 = c(0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1) purch_4 = c(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1) purch_5 = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) freq = c(352,44,26,14,20,5,7,12,14,5,5,5,5,3,3,7,21,3,4,3,5,2,3,5,9,2,0,6,5,5,7,24) switch_1 = c(0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0) switch_2 = c(0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0) switch_3 = c(0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0) switch_4 = c(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0) full = cbind(purch_1,purch_2,purch_3,purch_4,purch_5,freq,switch_1,switch_2,switch_3,switch_4) markovdata = data.frame(full) library(maxLik) set.seed(123) loglikelihood = function(param) { pi_1 = param[1] p0_1 = param[2] p00_1 = param[3] p11_1 = param[4] p0_2 = param[5] p00_2 = param[6] p11_2 = param[7] y = markovdata$freq* log( pi_1* (p0_1^(1-markovdata$purch_1)) *((1-p0_1)^markovdata$purch_1) * ((p00_1^(1-markovdata$switch_1))*((1-p00_1)^markovdata$switch_1)) ^ (1-markovdata$purch_1) * ((p11_1^(1-markovdata$switch_1))*((1-p11_1)^markovdata$switch_1)) ^ markovdata$purch_1 * ((p00_1^(1-markovdata$switch_2))*((1-p00_1)^markovdata$switch_2)) ^ (1-markovdata$purch_2) * ((p11_1^(1-markovdata$switch_2))*((1-p11_1)^markovdata$switch_2)) ^ markovdata$purch_2 * ((p00_1^(1-markovdata$switch_3))*((1-p00_1)^markovdata$switch_3)) ^ (1-markovdata$purch_3) * ((p11_1^(1-markovdata$switch_3))*((1-p11_1)^markovdata$switch_3)) ^ markovdata$purch_3 * ((p00_1^(1-markovdata$switch_4))*((1-p00_1)^markovdata$switch_4)) ^ (1-markovdata$purch_4) * ((p11_1^(1-markovdata$switch_4))*((1-p11_1)^markovdata$switch_4)) ^ markovdata$purch_4 + (1-pi_1)*
[R] Cannot install RPostgreSQL
Hello everyone, I am extremely new to R. I have yet to write any complicated code myself, however I have been learning largely by reading code that has already been written. Long story short, I have been running a code that makes use of the RPostgreSQL package for some time now. For some reason I just recently started to get an error. Whenever I try to load the RPostgreSQL package I get: library(RPostgreSQL) Error in library(RPostgreSQL) : there is no package called ‘RPostgreSQL’ I also tried install.packages(RPostgreSQL) and install.packages(RPostgreSQL). I've attached a text document of the resulting error here. Error.txt http://r.789695.n4.nabble.com/file/n4669380/Error.txt I'm running R version 2.15.1 on Ubuntu. I can't seem to find a solution to the problem online. And let me be clear, I was able to load this package without an issue no longer than a week ago. Any help you can offer would be much appreciated. Thanks, Drew -- View this message in context: http://r.789695.n4.nabble.com/Cannot-install-RPostgreSQL-tp4669380.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] rewrite script to eliminate constant object reference
I'm adding a column (region) to a data frame (devUni8), and the (region) column will be populated by a numeric code that is a function of another column (state) in that data frame. See part of the script below. How can I rewrite this so that I could apply the conditions to any data frame without having to keep typing its name (in this case, devUni8$). I've heard the attach() function is to be avoided, and I'm not good at with, while, or if statements right now. I've tried some other things but keep getting object not found errors. Assistance appreciated. Thanks. #Create Region Variable # devUni8$region=0 #Assign Northeast States # devUni8$region[devUni8$state = 11 devUni8$state = 23 | devUni8$state = 51 devUni8$state = 55] = 1 #Assign Southeast States # devUni8$region[devUni8$state = 56 devUni8$state = 64 ] = 2 -- View this message in context: http://r.789695.n4.nabble.com/rewrite-script-to-eliminate-constant-object-reference-tp4669393.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-SIG-Mac] problem with the installation of r commander on a mac
Le mercredi 12 juin 2013 à 16:52 -0400, John Fox a écrit : Dear Susanne, You started this thread on r-help (though R-SIG-Mac would have been more appropriate), and so I'm copying my response to the r-help list. People will find it confusing if the messages are simply kept private. It's not obvious to me exactly what your problem is now. In particular, is the Rcmdr package working when you start XQuartz before R? I see that you've installed and loaded the FactoMineR package. Presumably the Rcmdr package was already installed. Then you executed an R script provided by the authors of the FactoMineR package, which reinstalls and then modifies the Rcmdr package. I think that this is ill-advised (as opposed to providing an Rcmdr plug-in package for FactoMineR, as used to be the case), and if you're having problems with their script, you should really contact the authors. If I read the messages correctly, the script produces warnings, not errors, oddly relating to the language you're using (odd because the authors of the FactoMineR package are French) and it's possible that everything will work correctly despite the warnings. It's possible that the file http://factominer.free.fr/add-menu-facto-fr.txt that the FactoMineR script downloads is not read using the correct encoding (it is in CP2152), and thus contains invalid UTF-8 characters. So indeed I would reinstall Rcmdr using install.packages(Rcmdr) and load Rcmdr separately using library(Rcmdr) If that works, the bug is in FactoMineR's nonstandard way of installing a menu. A workaround might be to use their English install script: source(http://factominer.free.fr/install-facto.r;) Regards I hope this helps, John -Original Message- From: Susanne.Ettinger [mailto:susanne.ettin...@gmail.com] Sent: Wednesday, June 12, 2013 11:44 AM To: John Fox Subject: Re: [R] [R-SIG-Mac] problem with the installation of r commander on a mac Dear John, thank you very much for your quick reply - I realize I sent this email to the list without being a member, but I am a very beginner and started this morning the installation process of R. I have been printing out any possibly available information on how to get started with R and I am following the exercices exposed in the book written by Cornillon et al. (2012) to use FactoMineR to do some PCA analysis on vulnerability data. I downloaded the 3.0.1 version of R and have the 1.9-6 package of Rcmdr. I also checked into the library(tcltk) but do not get an error message, this seems to work fine. Since I open XQuartz before starting the Rcmdr library, I am getting a different error message than the ones of this morning. This is what it looks like : install.packages() --- SVP sélectionner un miroir CRAN pour cette session --- essai de l'URL 'http://cran.univ- lyon1.fr/bin/macosx/contrib/3.0/FactoMineR_1.25.tgz' Content type 'application/x-gzip' length 3397827 bytes (3.2 Mb) URL ouverte == downloaded 3.2 Mb Les packages binaires téléchargés sont dans /var/folders/06/z7b6z3y102xgxls2xh251p5wgp/T//Rtmp13nIpm/downl oaded_packages library(FactoMineR) Le chargement a nécessité le package : car Le chargement a nécessité le package : MASS Le chargement a nécessité le package : nnet Le chargement a nécessité le package : ellipse Attachement du package : ellipse L'objet suivant est masqué from package:car: ellipse Le chargement a nécessité le package : lattice Le chargement a nécessité le package : cluster Le chargement a nécessité le package : scatterplot3d Le chargement a nécessité le package : leaps source(http://factominer.free.fr/install-facto-fr.r;) essai de l'URL 'http://cran.univ- lyon1.fr/bin/macosx/contrib/3.0/Rcmdr_1.9-6.tgz' Content type 'application/x-gzip' length 3759850 bytes (3.6 Mb) URL ouverte == downloaded 3.6 Mb The downloaded binary packages are in /var/folders/06/z7b6z3y102xgxls2xh251p5wgp/T//Rtmp13nIpm/downl oaded_packages essai de l'URL 'http://cran.univ- lyon1.fr/bin/macosx/contrib/3.0/FactoMineR_1.25.tgz' Content type 'application/x-gzip' length 3397827 bytes (3.2 Mb) URL ouverte == downloaded 3.2 Mb The downloaded binary packages are in /var/folders/06/z7b6z3y102xgxls2xh251p5wgp/T//Rtmp13nIpm/downl oaded_packages Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 1 est incorrecte dans cet environnement linguistique Avis dans grepl(\n, lines, fixed = TRUE) : la chaîne de caractères entrée 5 est incorrecte dans cet
Re: [R] rewrite script to eliminate constant object reference
If you want an easy way to change the name of the data frame for assignment then you may want a macro. There is an article in the R journal ( http://cran.r-project.org/doc/Rnews/Rnews_2001-3.pdf) on creating macros and there are tools that help with creating macros in the gtools package. Though what you are trying to do may work a little better using `findInterval` or `merge`. On Wed, Jun 12, 2013 at 2:36 PM, bcrombie bcrom...@utk.edu wrote: I'm adding a column (region) to a data frame (devUni8), and the (region) column will be populated by a numeric code that is a function of another column (state) in that data frame. See part of the script below. How can I rewrite this so that I could apply the conditions to any data frame without having to keep typing its name (in this case, devUni8$). I've heard the attach() function is to be avoided, and I'm not good at with, while, or if statements right now. I've tried some other things but keep getting object not found errors. Assistance appreciated. Thanks. #Create Region Variable # devUni8$region=0 #Assign Northeast States # devUni8$region[devUni8$state = 11 devUni8$state = 23 | devUni8$state = 51 devUni8$state = 55] = 1 #Assign Southeast States # devUni8$region[devUni8$state = 56 devUni8$state = 64 ] = 2 -- View this message in context: http://r.789695.n4.nabble.com/rewrite-script-to-eliminate-constant-object-reference-tp4669393.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[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] rewrite script to eliminate constant object reference
Check out 'with' and 'within'. Sent from my Verizon Wireless 4G LTE Smartphone Original message From: bcrombie bcrom...@utk.edu Date: 06/12/2013 16:36 (GMT-05:00) To: r-help@r-project.org Subject: [R] rewrite script to eliminate constant object reference I'm adding a column (region) to a data frame (devUni8), and the (region) column will be populated by a numeric code that is a function of another column (state) in that data frame. See part of the script below. How can I rewrite this so that I could apply the conditions to any data frame without having to keep typing its name (in this case, devUni8$). I've heard the attach() function is to be avoided, and I'm not good at with, while, or if statements right now. I've tried some other things but keep getting object not found errors. Assistance appreciated. Thanks. #Create Region Variable # devUni8$region=0 #Assign Northeast States # devUni8$region[devUni8$state = 11 devUni8$state = 23 | devUni8$state = 51 devUni8$state = 55] = 1 #Assign Southeast States # devUni8$region[devUni8$state = 56 devUni8$state = 64 ] = 2 -- View this message in context: http://r.789695.n4.nabble.com/rewrite-script-to-eliminate-constant-object-reference-tp4669393.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. [[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] rewrite script to eliminate constant object reference
Hi, Here are some examples using the mtcars dataset that you can modify to work with your data. ## Here is my first try using within. ## Somehow the elements of region that ## should be zero are converted to NA mtcars - within(mtcars, { region - 0 region[gear==4carb==4] - 1 region[gear==3carb==1] - 2 }) ## Here is a second try with an ugly ## hack to fix the NA problem mtcars - within(mtcars, { region - NA region[gear==4carb==4] - 1 region[gear==3carb==1] - 2 region[is.na(region)] - 0 }) ## Here is an alternative using with ## instead of within mtcars$region - 0 mtcars$region[with(mtcars, gear==4carb==4)] - 1 mtcars$region[with(mtcars, gear==3carb==1)] - 2 Best, Ista On Wed, Jun 12, 2013 at 4:36 PM, bcrombie bcrom...@utk.edu wrote: I'm adding a column (region) to a data frame (devUni8), and the (region) column will be populated by a numeric code that is a function of another column (state) in that data frame. See part of the script below. How can I rewrite this so that I could apply the conditions to any data frame without having to keep typing its name (in this case, devUni8$). I've heard the attach() function is to be avoided, and I'm not good at with, while, or if statements right now. I've tried some other things but keep getting object not found errors. Assistance appreciated. Thanks. #Create Region Variable # devUni8$region=0 #Assign Northeast States # devUni8$region[devUni8$state = 11 devUni8$state = 23 | devUni8$state = 51 devUni8$state = 55] = 1 #Assign Southeast States # devUni8$region[devUni8$state = 56 devUni8$state = 64 ] = 2 -- View this message in context: http://r.789695.n4.nabble.com/rewrite-script-to-eliminate-constant-object-reference-tp4669393.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. [[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] new data
Hi, Try this: final3New-read.table(file=real_data_cecilia.txt,sep=\t) final3New1-read.csv(real_data_cecilia_new.csv) fun2-function(dat){ indx- duplicated(dat)|duplicated(dat,fromLast=TRUE) dat1- subset(dat[indx,],dummy==1) dat2- dat1[order(dat1$dimension),] indx1- as.numeric(row.names(dat2)) names(indx1)- (seq_along(indx1)-1)%/%2+1 dat3- dat[c(indx1,indx1+1),] dat3$id- names(c(indx1,indx1+1)) lst1- lapply(split(dat3,dat3$id),function(x){ x1- x[-1,] x2- x1[which.min(abs(x1$dimension[1]-x1$dimension[-1]))+1,] x3- subset(x,dummy==1) rowNx2- as.numeric(row.names(x2)) rowNx3- as.numeric(row.names(x3)) x4- x3[which.min(abs(rowNx2-rowNx3)),] x5- rbind(x4,x2) x6- x[is.na(match(row.names(x),row.names(x5))),] }) dat4- do.call(rbind,lst1) row.names(dat4)- gsub(.*\\.,,row.names(dat4)) indxNew1- sort(as.numeric(unique(row.names(dat4 dat0- subset(dat[indx,],dummy==0) if(nrow(dat0)0){ dat20-dat0[order(dat0$dimension),] indx0- as.numeric(row.names(dat20)) names(indx0)- (seq_along(indx0)-1)%/%2+1 dat30- dat[c(indx0-1,indx0),] dat30$id- names(c(indx0-1,indx0)) lst0- lapply(split(dat30,dat30$id),function(x) { x1- subset(x,dummy==1) x2- subset(x,dummy==0) x3- x1[which.min(abs(x1$dimension- unique(x2$dimension))),] rowNx2- as.numeric(row.names(x2)) rowNx3- as.numeric(row.names(x3)) x4- x2[which.min(abs(rowNx2-rowNx3)),] x5- rbind(x3,x4) x6- x[is.na(match(row.names(x),row.names(x5))),] }) dat40- do.call(rbind,lst0) row.names(dat40)- gsub(.*\\.,,row.names(dat40)) indxNew0- sort(as.numeric(unique(row.names(dat40 res1Del-dat[indxNew1,] res0Del-dat[indxNew0,] indx10-sort(as.numeric(union(row.names(res0Del),row.names(res1Del if(length(indx10)%%2==1){ res10Del-unique(rbind(res1Del,res0Del)) indx10New- sort(as.numeric(row.names(res10Del))) resF- dat[-indx10New,] resF } else{ resF- dat[-indx10,] resF } } else{ resF- dat[-indxNew1,] } } ###Old Function fun3- function(dat){ indx- duplicated(dat) dat1- subset(dat[indx,],dummy==1) dat0- subset(dat[indx,],dummy==0) indx1- as.numeric(row.names(dat1)) indx11- sort(c(indx1,indx1+1)) indx0- as.numeric(row.names(dat0)) indx00- sort(c(indx0,indx0-1)) indx10- sort(c(indx11,indx00)) res - dat[-indx10,] res } ##Applying fun1() (from previous post) res5Percent- fun1(final3New,0.05,50) res5Percent1- fun1(final3New1,0.05,50) res10Percent- fun1(final3New,0.10,200) res10Percent1- fun1(final3New1,0.10,200) res20Percent- fun1(final3New,0.20,100) res20Percent1- fun1(final3New1,0.20,100) ###Applying fun2() res5F2- fun2(res5Percent) res5F2_1- fun2(res5Percent1) res10F2- fun2(res10Percent) res10F2_1- fun2(res10Percent1) res20F2- fun2(res20Percent) res20F2_1- fun2(res20Percent1) #Applying fun3() res5F3- fun3(res5Percent) res5F3_1- fun3(res5Percent1) res10F3- fun3(res10Percent) res10F3_1- fun3(res10Percent1) res20F3- fun3(res20Percent) res20F3_1- fun3(res20Percent1) vec1- rep(c(res5F2,res10F2,res20F2),2) vec2- rep(c(res5F3,res10F3,res20F3),2) vec1[4:6]-paste(vec1[4:6],_1,sep=) vec2[4:6]-paste(vec2[4:6],_1,sep=) resTbl-data.frame( Dataset=rep(rep(c(final3New,final3New1),each=3),2),Funct=rep(c(fun2,fun3),each=6),do.call(rbind,lapply(as.list(c(vec1,vec2)),function(x) {x1-get(x);c(N_row=nrow(x1),Sub0_Nrow=nrow(subset(x1,dummy==0)),Sub1_Nrow=nrow(subset(x1,dummy==1)),Uniq_Nrow=nrow(unique(x1)))})),stringsAsFactors=FALSE) row.names(resTbl)- c(vec1,vec2) resTbl # Dataset Funct N_row Sub0_Nrow Sub1_Nrow Uniq_Nrow #res5F2 final3New fun2 276 138 138 276 #res10F2 final3New fun2 454 227 227 454 #res20F2 final3New fun2 284 142 142 284 #res5F2_1 final3New1 fun2 288 144 144 288 #res10F2_1 final3New1 fun2 488 244 244 488 #res20F2_1 final3New1 fun2 310 155 155 310 #res5F3 final3New fun3 276 138 138 276 #res10F3 final3New fun3 452 226 226 452 #res20F3 final3New fun3 284 142 142 284 #res5F3_1 final3New1 fun3 288 144 144 288 #res10F3_1 final3New1 fun3 488 244 244 488 #res20F3_1 final3New1 fun3 310 155 155 310 head(res5F2_1,4) # firm year industry dummy dimension #1 500622043 2004 1 1 1172 #2 501611886 2004 1 0 1183 #3 500778787 2004 1 1 5680 #4
Re: [R] Proper way to implement package internal functions
On 13/06/13 03:34, Bryan Hanson wrote: SNIP So this warning from check is not a problem in the long run: * checking for missing documentation entries ... WARNING Undocumented code objects: ‘ang0to2pi’ ‘dAB’ ‘doBoxesIntersect’ ... All user-level objects in a package should have documentation entries. if I understand correctly. I guess the reason I didn't find any documentation is the wide lattitude which is possible. I think you *might* get flak about the warnings if you submit your package to CRAN. I find such warnings annoying, anyhow. To avoid them you can create a *.Rd file listing all the undocumented functions in your package with an alias for the name of each such function and a usage line for each such function. Only a mild pain in the pohutukawa, and it only needs to be done once. (Possibly with some updating if new undocumented functions are added to the package.) The *.Rd file can be called anything you like (as long as it ends in .Rd and doesn't conflict with other *.Rd filled. However a fairly common convention is to name the file melvin-internal.Rd where melvin is the name of your package. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Proper way to implement package internal functions
On Jun 12, 2013, at 16:34, Bryan Hanson han...@depauw.edu wrote: Thanks Duncan... Silly me, it's section 1.6.1 not version 1.6.1! So this warning from check is not a problem in the long run: * checking for missing documentation entries ... WARNING Undocumented code objects: ‘ang0to2pi’ ‘dAB’ ‘doBoxesIntersect’ ... All user-level objects in a package should have documentation entries. What does your NAMESPACE file say? MW if I understand correctly. I guess the reason I didn't find any documentation is the wide lattitude which is possible. Thank you. Bryan On Jun 12, 2013, at 10:57 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/06/2013 10:44 AM, Bryan Hanson wrote: [previously posted on Stack Overflow: http://stackoverflow.com/questions/17034309/hiding-undocumented-functions-in-a-package-use-of-function-name ] I've got some functions I need to make available in a package, and I don't want to export them or write much documentation for them. I'd just hide them inside another function but they need to be available to several functions so doing it that way becomes a scoping and maintenance issue. What is the right way to do this? By that I mean do they need special names, do they go somewhere other than the R subdirectory, can I put them in a single file, etc? I've checked out the manuals (e.g. Writing R Extensions 1.6.1), and what I'm after is like the .internals concept in the core, but I don't see any instructions about how to do this generally. For example, if I have functions foo1 and foo2 in a file foofunc.R, and these are intended for internal use only, should they be called foo1 or .foo1? And the file that holds them, should it be .foofunc.R or foofunc-internals? What should the Rd look like, or do I even need one? I know people do this in packages all the time and I feel like I've seen this somewhere, but I can't find any resources just now. Perhaps a suggestion of a package that does things this way which I could study would be sufficient. The best way to do this is simply not to export those functions in your NAMESPACE file. If you want to use a naming convention internally to remind yourself that those are private, you can do so, but R doesn't force one on you, and there are no really popular conventions in use. R won't complain if you don't document those functions at all. There may have been other advice in the version 1.6.1 manual, but that is seriously out of date, more than 10 years old. I recommend that you update to 3.0.1. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a new var from conditional values in other vars
Hi `Bangali`, You can type in the R Console ?with() ?ifelse() The details and some examples are there. In addition to ?with(), you can use: ?within dat1-within(dat1,pattern-ifelse(A20 B=2.5 C=20,Normal,ifelse(A 20 B 2.5 C 20,Increased,ifelse(A =20 B 2.5 C =20,Low,Other library(plyr) ?mutate() dat1New-mutate(dat1,pattern=ifelse(A20 B=2.5 C=20,Normal,ifelse(A 20 B 2.5 C 20,Increased,ifelse(A =20 B 2.5 C =20,Low,Other identical(dat1,dat1New) #[1] TRUE dat2-transform(dat1,pattern=ifelse(A20 B=2.5 C=20,Normal,ifelse(A 20 B 2.5 C 20,Increased,ifelse(A =20 B 2.5 C =20,Low,Other identical(dat1,dat2) #[1] TRUE A.K. Arun, Many thanks! The code works perfectly well. It seems that ifelse + with do the trick much better than if/else statement. Now I need to understand the mechanichs of what you did. Can you provide a link on how to use with - Original Message - From: arun smartpink...@yahoo.com To: R help r-help@r-project.org Cc: Sent: Wednesday, June 12, 2013 4:03 PM Subject: Re: Creating a new var from conditional values in other vars Hi, Try this: set.seed(25) dat1- data.frame(A=sample(1:30,100,replace=TRUE),B=sample(1:35,100,replace=TRUE),C=sample(1:25,100,replace=TRUE)) dat1$pattern-with(dat1,ifelse(A20 B=2.5 C=20,Normal,ifelse(A 20 B 2.5 C 20,Increased,ifelse(A =20 B 2.5 C =20,Low,Other head(dat1) # A B C pattern #1 13 20 5 Other #2 21 15 4 Low #3 5 24 1 Other #4 27 13 6 Low #5 4 4 10 Other #6 30 19 22 Other A.K. I am newbie to R coming from SAS (basic user). Quite a difficult move I have a dataframe named kappa exported from csv file kappa-read.csv(kappacsv, header=TRUE, sep=;, dec=.) kappa contains 3 numeric vars (A,B and C) I want to create a new var called pattern depending on the values of the conditions in A, B and C I have tried many ways one has been this: kappa$pattern1-99 # create a new numeric var in kappa dataframe if (A=20 B=2.5 C =20){kappa$pattern-Normal} else if (A 20 B 2.5 C 20){kappa$pattern-Increased} else if (A =20 B 2.5 C =20){kappa$pattern-Low} else {kappa$pattern-“Other”} The code does not work and I get errors all the time. Any help will be greatly appreciated Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Proper way to implement package internal functions
Hi Rolf... Thanks. I discovered the approach you described by looking at the source for spatstat, which as it turns out does exactly that. I also discovered by testing that if you don't export a pattern, but rather export the specific names, not including the functions one wants to hide, that the warning goes away. Since it is less work to change the export statement compared to even a minimal Rd, that's the way I went. It's interesting that there is not more info about these options available. Thanks, Bryan On Jun 12, 2013, at 6:46 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote: On 13/06/13 03:34, Bryan Hanson wrote: SNIP So this warning from check is not a problem in the long run: * checking for missing documentation entries ... WARNING Undocumented code objects: ‘ang0to2pi’ ‘dAB’ ‘doBoxesIntersect’ ... All user-level objects in a package should have documentation entries. if I understand correctly. I guess the reason I didn't find any documentation is the wide lattitude which is possible. I think you *might* get flak about the warnings if you submit your package to CRAN. I find such warnings annoying, anyhow. To avoid them you can create a *.Rd file listing all the undocumented functions in your package with an alias for the name of each such function and a usage line for each such function. Only a mild pain in the pohutukawa, and it only needs to be done once. (Possibly with some updating if new undocumented functions are added to the package.) The *.Rd file can be called anything you like (as long as it ends in .Rd and doesn't conflict with other *.Rd filled. However a fairly common convention is to name the file melvin-internal.Rd where melvin is the name of your package. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] identify data points by certain criteria
Hey I want to identify data points by criteria, here is an example of my 1min data Time Var1 Var2 00:001 0 00:010 0 00:021 0 00:031 0 00:040 0 00:051 0 00:061 0 00:071 0 00:081 0 00:090 0 00:101 0 00:111 0 00:121 0 00:130 0 I want to identify the data points where Var1=0 and Var2=0, ( in this example shud be the points highlighted above), then calculate the time duration between these data points, (in this example, shud be 3min, 5 min and 4min), then identify the starting point of the max time duration ( in this example shud be the starting point of 5-min-duration, return the data points at 00:09), finally return the value in Time column ( in this example shud be 00:09) Thanks for your help! [[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] identify data points by certain criteria
On Jun 12, 2013, at 5:55 PM, Ye Lin wrote: Hey I want to identify data points by criteria, here is an example of my 1min data Time Var1 Var2 00:001 0 00:010 0 00:021 0 00:031 0 00:040 0 00:051 0 00:061 0 00:071 0 00:081 0 00:090 0 00:101 0 00:111 0 00:121 0 00:130 0 I want to identify the data points where Var1=0 and Var2=0, ( in this example shud be the points highlighted above), then calculate the time duration between these data points, (in this example, shud be 3min, 5 min and 4min), then identify the starting point of the max time duration ( in this example shud be the starting point of 5-min-duration, return the data points at 00:09), finally return the value in Time column ( in this example shud be 00:09) While you are waiting for an answer you might want to read the Posting Guide: http://www.R-project.org/posting-guide.html Points to pay special attention to: Plain-text. Posting code. Posting examples in form that can be pasted into console session (dump or dput functions). Providing context for problem (such as describing the conventions for your time-scale) and your background (since this looks like a homework exercise.) Thanks for your help! [[alternative HTML version deleted]] __ 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] Cannot install RPostgreSQL
Hello, If you carefully check the error message, it is clearly written: RS-PostgreSQL.h:23:26: fatal error: libpq-fe.h: No such file or directory Some header files are missing. Here is the result of a quick search on the web: libpq-dev for Ubuntu. If I may suggest, you should upgrade the version of R. Regards, Pascal On 13/06/13 03:13, Drew wrote: Hello everyone, I am extremely new to R. I have yet to write any complicated code myself, however I have been learning largely by reading code that has already been written. Long story short, I have been running a code that makes use of the RPostgreSQL package for some time now. For some reason I just recently started to get an error. Whenever I try to load the RPostgreSQL package I get: library(RPostgreSQL) Error in library(RPostgreSQL) : there is no package called ‘RPostgreSQL’ I also tried install.packages(RPostgreSQL) and install.packages(RPostgreSQL). I've attached a text document of the resulting error here. Error.txt http://r.789695.n4.nabble.com/file/n4669380/Error.txt I'm running R version 2.15.1 on Ubuntu. I can't seem to find a solution to the problem online. And let me be clear, I was able to load this package without an issue no longer than a week ago. Any help you can offer would be much appreciated. Thanks, Drew -- View this message in context: http://r.789695.n4.nabble.com/Cannot-install-RPostgreSQL-tp4669380.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] odds ratio per standard deviation
L. Snow, Ted, Many thanks, I am sorry to made a question without context. I use three parameters of facial temperature, heart rate, and respiratory rate to distinguish infectious patients from healthy subjects. So I use logistic regression to generate a classification model and calculate the odds ratio for these three parameters. In my case, I would like to know what kinds of odds ratio can be used, odds ratio per standard deviation or odds ratio. Thanks you in advance for your help -- View this message in context: http://r.789695.n4.nabble.com/odds-ratio-per-standard-deviation-tp4669315p4669411.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] identify data points by certain criteria
Hi, Not clear about the 'Time' column. dat1- read.table(text= Time Var1 Var2 00:00 1 0 00:01 0 0 00:02 1 0 00:03 1 0 00:04 0 0 00:05 1 0 00:06 1 0 00:07 1 0 00:08 1 0 00:09 0 0 00:10 1 0 00:11 1 0 00:12 1 0 00:13 0 0 ,sep=,header=TRUE,stringsAsFactors=FALSE) indx-which(rowSums(dat1[,-1])==0) dat1[indx[which.max(c(1,diff(as.numeric(gsub(.*:,,dat1[,1][indx])],] # Time Var1 Var2 #10 00:09 0 0 dat1[indx[which.max(c(1,diff(as.numeric(gsub(.*:,,dat1[,1][indx])],Time] #[1] 00:09 A.K. - Original Message - From: Ye Lin ye...@lbl.gov To: R help r-help@r-project.org Cc: Sent: Wednesday, June 12, 2013 8:55 PM Subject: [R] identify data points by certain criteria Hey I want to identify data points by criteria, here is an example of my 1min data Time Var1 Var2 00:00 1 0 00:01 0 0 00:02 1 0 00:03 1 0 00:04 0 0 00:05 1 0 00:06 1 0 00:07 1 0 00:08 1 0 00:09 0 0 00:10 1 0 00:11 1 0 00:12 1 0 00:13 0 0 I want to identify the data points where Var1=0 and Var2=0, ( in this example shud be the points highlighted above), then calculate the time duration between these data points, (in this example, shud be 3min, 5 min and 4min), then identify the starting point of the max time duration ( in this example shud be the starting point of 5-min-duration, return the data points at 00:09), finally return the value in Time column ( in this example shud be 00:09) Thanks for your help! [[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.