Re: [R] Looking up the directory a file is located in
On Thu, Nov 18, 2010 at 12:00 AM, Cliff Clive cliffcl...@gmail.com wrote: Basically I'm just looking for a command that can look up the name of the directory of the script that is running. If I move or copy the script to another directory, it should be able to read the name of the new directory without me having to edit the code. Once I have identified the directory, I can insert it into the setwd() command and continue with my program. This is a fairly-frequently asked question, and the questioner is rarely satisfied with the answer. How is your script starting? Either: a) R is starting in that directory, so that the working directory is already set, or b) Whatever runs the script knows where it is in order to start it, so could pass that directory to the script somehow, either by a global parameter, or an environment variable. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stacking consecutive columns
On Nov 17, 2010, at 16:37 , Graves, Gregory wrote: Follows is the exact solution to this: v - NULL #note that decreasing is FALSE so preceding year preceeds for(i in 2:46) { kk - melt(yearmonth[, c(1, i, i+1)], id.vars=month, variable_name=year) v[[i-1]] - kk[order(kk$year, decreasing=FALSE),] } x - do.call(cbind, v) write.table(x,clipboard,sep= ,col.names=NA) #export to Excell via Ctrl-V Just wondering, was anything wrong with y1 - cbind(yearmonth[,-1], foo = NA) names(y1) - names(yearmonth) rbind(yearmonth, y1) ? (untested, of course) -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] filling large matrix( or dist object) with values from small matrix.
The script below provides a trivial example of filling a large matrix with values from a small one with corresponding row and column details. this is fine for a small example but too slow for many large examples ( my small matrices are 65x65 and my large matrices up to 900x900, and I have many permutations to fill. is there a more efficient way to achieve this M-as.matrix(as.dist(matrix(x,nrow=4,ncol=4,dimnames=list(c(A,B,C,D),c(A,B,C,D) N-matrix(NA,nrow=8,ncol=8,dimnames=list(c(A,B,C,D,A,B,C,D),c(A,B,C,D,A,B,C,D))) for (r in 1:nrow(N)){ for (c in 1:(ncol(N))){ N[r,c]=M[rownames(N)[r],colnames(N)[c]] } } thanks Nevil Amos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] The *makesweave* Package for Using Make with Sweave Efficiently
Hi R Community, I've just completed the initial version of (Linux-based) R package, called *makesweave*, for using Make to build Sweave documents efficiently. The idea is that R is started once (per shell) as a background process, then Make builds each Sweave source file, using the same R instance. More information in the package vignette. Feedback very welcome. regards -- Charlotte Maia http://sites.google.com/site/maiagx ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] lubridate v2.2 available on cran
Version 2.2 of the lubridate package is now available. lubridate makes it easier to work with date-time data. For example, it provides: * simple functions to extract and modify components of a date-time, such as years, months, days, hours, minutes, and seconds: year(), month(), day(), ... * quick and easy functions to parse date-times: ymd(), dmy(), mdy(), ... * helper functions for handling time zones: with_tz(), force_tz() * three new time span objects -- durations, periods, and intervals -- based on the time span classes of http://joda.org and the boost C++ library. The new version includes: * division, modulo, and integer methods for time spans. * cleaner display formats for time span objects * a namespace for the package For an example of how you might use lubridate, calculate the number of days until christmas with: (ymd(2010-12-25) - today()) / ddays(1) --- Garrett Grolemund Rice University [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 catch warnings
Dear Michael, I would like to thank you for your reply. This line made things easier. One more question what If I want to halt or pause the program when a warning happens? Right now I get only a message printed but it would be nicer if the execution is paused so to try to print more values. Best REgards Alex --- On Thu, 11/18/10, Michael Bedward michael.bedw...@gmail.com wrote: From: Michael Bedward michael.bedw...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 1:26 AM Hi Alex, Something like this ? x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=function(w) cat(problem values: , yy, \n) ) } Michael On 18 November 2010 03:19, Alaios ala...@yahoo.com wrote: Hello when my code executes I receive the message that were some warnings. I want to catch warning messages at run time so to print some local variables and try to understand why this warning happens. I searched on internet and I tried withCallingHandlers( which seems to work but as I used Rkward the result is awful. I get a prompt to copy paste a value only while at the same time my background window with my code is not anymore accessible. Actually I get the warning that In f[cbind(shweights[, 1], shweights[, 2])] * shweights[, ... : longer object length is not a multiple of shorter object length and what I want is when the warning appear to be able to print the value shweights[,1] shweights[,2] to see what is going on. Any easier way to do that? Best REgards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to catch warnings
Sorry Alex, I don't quite follow what you want. What do you mean by it would be nicer if the execution is paused so to try to print more values ? Michael On 18 November 2010 21:11, Alaios ala...@yahoo.com wrote: Dear Michael, I would like to thank you for your reply. This line made things easier. One more question what If I want to halt or pause the program when a warning happens? Right now I get only a message printed but it would be nicer if the execution is paused so to try to print more values. Best REgards Alex --- On Thu, 11/18/10, Michael Bedward michael.bedw...@gmail.com wrote: From: Michael Bedward michael.bedw...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 1:26 AM Hi Alex, Something like this ? x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=function(w) cat(problem values: , yy, \n) ) } Michael On 18 November 2010 03:19, Alaios ala...@yahoo.com wrote: Hello when my code executes I receive the message that were some warnings. I want to catch warning messages at run time so to print some local variables and try to understand why this warning happens. I searched on internet and I tried withCallingHandlers( which seems to work but as I used Rkward the result is awful. I get a prompt to copy paste a value only while at the same time my background window with my code is not anymore accessible. Actually I get the warning that In f[cbind(shweights[, 1], shweights[, 2])] * shweights[, ... : longer object length is not a multiple of shorter object length and what I want is when the warning appear to be able to print the value shweights[,1] shweights[,2] to see what is going on. Any easier way to do that? Best REgards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Why some times R-halts?
Hello everyone. I have written a small function that returns a 3*n array where n is typicall between 5-55. I issued in R shweights-shadowing_weights(x,xr) and I got the result in less that one sec. then I tried to see what is inside the shweights array and thus I issued the edit(shweights) which 10 mins right now is busy and got no reply yet back. As I am using rkward I tried from gui the same (workspace- double click on variable) this gives me the message fetching information. Please wait. Right now I can not do anything there is a interupt running command key in the gui which does not seem to be working. I also tried ctrl+c which broke the execution after 15mins. What do you do in such cases and why R sometimes looks like has problems with even simple tasks? I would like to thank you in advance for your help Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot vs print ??
Hello everybody. My question arised from the output of lattice's histogram. But might be extended to any other object that could be printed. I think I've understood your answers, print calls the plot function when the object to be printed is a trellis plot object. I guess I can always use plot instead. ?? -- View this message in context: http://r.789695.n4.nabble.com/plot-vs-print-tp3045256p3048408.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] rgl, multiple graphics ??
Hello I just get one plot How can I concoct several rgl plots? -- View this message in context: http://r.789695.n4.nabble.com/rgl-multiple-graphics-tp3047006p3048434.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] why help ignores some values
Please take a look at the values below . [31,] 30.000 30.000 [32,] 31.000 31.000 [33,] 32.000 32.000 [34,] 33.000 33.000 [35,] 34.000 34.000 [36,] 35.000 35.000 [37,] 35.872 35.872 These are entries in an array. These values are used as indexes inside a matrix. f[shweights[37,1],shweights[37,2]] works fine for me and returns correctly the value. but when I try f[shweights[,1],shweights[,2]] I only get 36 out of 37 results (seems that in that case ignores the last values, 37th) . [35,] 2.7245297165175781 [36,] 2.7245297165175781 Why this might be happening? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] why help ignores some values
Possibly because R has no idea what the 35.872-th element of a matrix is? However you are coming up with these elements, you are running into a floating-point arithmetic problem (FAQ 7.31). Using round() might help. Sarah On Thu, Nov 18, 2010 at 6:19 AM, Alaios ala...@yahoo.com wrote: Please take a look at the values below . [31,] 30.000 30.000 [32,] 31.000 31.000 [33,] 32.000 32.000 [34,] 33.000 33.000 [35,] 34.000 34.000 [36,] 35.000 35.000 [37,] 35.872 35.872 These are entries in an array. These values are used as indexes inside a matrix. f[shweights[37,1],shweights[37,2]] works fine for me and returns correctly the value. but when I try f[shweights[,1],shweights[,2]] I only get 36 out of 37 results (seems that in that case ignores the last values, 37th) . [35,] 2.7245297165175781 [36,] 2.7245297165175781 Why this might be happening? Regards Alex -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to catch warnings
Like this ? f - function() { # on first warning will print to console and return results so far out - c(1,2,3,4) extras - list(good=c(2,3,4,5), bad=c(9,9,9), ugly=c(9,9,9,9,9)) ok - TRUE for (ex in extras) { tryCatch(out - cbind(out, ex), warning=function(w) { cat(problem values:, ex, \n) ok - FALSE } ) if (!ok) break } out } Michael On 18 November 2010 22:14, Alaios ala...@yahoo.com wrote: The best would be the R when a warning stop. To issue a warnign at console stop the execution at the point it was and let your write commands in console to check what was going on. Is that possible? Regards Alex --- On Thu, 11/18/10, Michael Bedward michael.bedw...@gmail.com wrote: From: Michael Bedward michael.bedw...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 10:17 AM Sorry Alex, I don't quite follow what you want. What do you mean by it would be nicer if the execution is paused so to try to print more values ? Michael On 18 November 2010 21:11, Alaios ala...@yahoo.com wrote: Dear Michael, I would like to thank you for your reply. This line made things easier. One more question what If I want to halt or pause the program when a warning happens? Right now I get only a message printed but it would be nicer if the execution is paused so to try to print more values. Best REgards Alex --- On Thu, 11/18/10, Michael Bedward michael.bedw...@gmail.com wrote: From: Michael Bedward michael.bedw...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 1:26 AM Hi Alex, Something like this ? x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=function(w) cat(problem values: , yy, \n) ) } Michael On 18 November 2010 03:19, Alaios ala...@yahoo.com wrote: Hello when my code executes I receive the message that were some warnings. I want to catch warning messages at run time so to print some local variables and try to understand why this warning happens. I searched on internet and I tried withCallingHandlers( which seems to work but as I used Rkward the result is awful. I get a prompt to copy paste a value only while at the same time my background window with my code is not anymore accessible. Actually I get the warning that In f[cbind(shweights[, 1], shweights[, 2])] * shweights[, ... : longer object length is not a multiple of shorter object length and what I want is when the warning appear to be able to print the value shweights[,1] shweights[,2] to see what is going on. Any easier way to do that? Best REgards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to catch warnings
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 11/18/2010 11:11 AM, Alaios wrote: Dear Michael, I would like to thank you for your reply. This line made things easier. One more question what If I want to halt or pause the program when a warning happens? Right now I get only a message printed but it would be nicer if the execution is paused so to try to print more values. What about the following? Is that what x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=browser ) } Cheers, Rainer Best REgards Alex --- On Thu, 11/18/10, Michael Bedward michael.bedw...@gmail.com wrote: From: Michael Bedward michael.bedw...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 1:26 AM Hi Alex, Something like this ? x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=function(w) cat(problem values: , yy, \n) ) } Michael On 18 November 2010 03:19, Alaios ala...@yahoo.com wrote: Hello when my code executes I receive the message that were some warnings. I want to catch warning messages at run time so to print some local variables and try to understand why this warning happens. I searched on internet and I tried withCallingHandlers( which seems to work but as I used Rkward the result is awful. I get a prompt to copy paste a value only while at the same time my background window with my code is not anymore accessible. Actually I get the warning that In f[cbind(shweights[, 1], shweights[, 2])] * shweights[, ... : longer object length is not a multiple of shorter object length and what I want is when the warning appear to be able to print the value shweights[,1] shweights[,2] to see what is going on. Any easier way to do that? Best REgards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzlEBUACgkQoYgNqgF2egr9dgCfdkQYIpkzqAHw13KwszvNJfhe ttUAn0ckAcT1AS+RCeeDVc5wn7sVD9gU =CmU6 -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] classification question
Hi. Working with a data set like: age, demographic data (n fields), interests(n fields) has performed X actions for event Y. I want to ask how likely is it for another person with his/her age, demographic data and interests to perform actions for that event. My query set might be partial (eg just age or interests). Can R help me with this? If yes, could you point me in the right direction? -- Best, M. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where are my pspline knots?
Hello: I hope that someone more knowledgeable will confirm or correct what I'm about to say. I don't have time now to check this by studying the pspline code. From reading the pspline{survival} help page, I believe it uses standard B-splines, penalising the integrated second derivative, with theta being the penalty or weight used to multiply the integral of the square of the second derivative before adding it to the AIC to be minimized. The help page also suggests that the basis functions (i.e., the knots) are evenly spaced, though I'm not completely sure about any of this. A basic rule for B-splines is as follows: nbasis = order + n.knots where n.knots = the number of interior knots, nbasis = the number of basis functions, and order = the order of the spline = one more than the degree of the polynomial segments. With the default cubic splines, degree = 3, so order = 4. In a fit, nbasis = the number of coefficients estimated, I think. Consider the following modification of one of the examples in help('pspline'): coef(coxph(Surv(time, status) ~ ph.ecog + pspline(age,3), cancer)) ph.ecog ps(age)2 ps(age)3 ps(age)4 ps(age)5 ps(age)6 ps(age)7 ps(age)8 0.4480154 0.3221152 0.6470688 0.9342460 1.0289846 0.9639187 0.9004191 1.0119748 ps(age)9 ps(age)10 ps(age)11 1.2422085 1.6403940 2.0785682 This fit includes one coefficient for ph.ecog and 10 for pspline(age,3). I infer from this that there are 10 basis functions. Since degree = 3 (the default), order = 4, so the number of interior knots = 6 ( = 10-4). To find where they are located, I would guess that they are evenly spaced in range(cancer$age) = (39, 82): seq(39, 82, length=8) [1] 39.0 45.14286 51.28571 57.42857 63.57143 69.71429 75.85714 82.0 HOWEVER, these are only guesses; I hope someone else will either confirm what I've said or correct any errors. It would help to have a function as.fd.coxph.penal in the fda package, as fda includes functions to help clarify this question: knots.fd extracts the knots from an object of class fd, answering Federrico's question directly. Unfortunately, I don't have time to write such. It also includes a function TaylorSpline for converting a standard B-spline into the coefficients of a Taylor series approximation for each segment of the spline. Chapter 3 in Ramsay, Hooker, and Graves (2009) Functional Data Analysis with R and Matlab (Springer) includes code for plotting a B-spline basis set, and the fda package includes script files for working all but one of the 76 examples in that book. You can find that script file without obtaining the book as follows: fdaDir - system.file(package='fda') fdaDirs - dir(fdaDir, full=TRUE) fdaScripts - grep('scripts$', fdaDirs, value=TRUE) fdaCh - dir(fdaScripts, full=TRUE) fdaCh3 - grep('fdarm-ch03.R$', fdaCh, value=TRUE) You can then make a local copy of fdaCh3 and work through it line by line to see plots of the B-spline basis. This would help Federico more if fda included a as.fd.coxph.penal function, because then he could plot the spline basis used in his example. Hope this helps. Spencer On 11/17/2010 11:39 AM, David Winsemius wrote: On Nov 17, 2010, at 1:05 PM, Federico Calboli wrote: Hi All, I am trying to figure out how to get the position of the knots in a pspline used in a cox model. As far as I understand it, the term knot should be used with natural splines, but not for penalized smoothing splines. See p 124 of Therneau and Gramsch for better description and illustrations. If you want to see the weighting of a particular pspline then this example may help: nn=rnorm(20) matrix(pspline(nn), nrow=20)[order(nn), ] # sorts the spline basis weights so the overlap is visible my.model = coxph(Surv(agein, ageout, status) ~ pspline(x), mydata) # x being continuous How do I find out where the knot of the spline are? I would like to know to figure out how many cases are there between each knot. Best, Federico -- Federico C. F. Calboli Department of Epidemiology and Biostatistics Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] why help ignores some values
Just to update this f[35.99,36.22] works fine and returns the data from f[35,36] it does this rounding the R itself. the problem finally was a value f[0.99,3] that was returning numeric(0) which I understand as a matrix doesnot have any f[0,0] Regards Alex --- On Thu, 11/18/10, Sarah Goslee sarah.gos...@gmail.com wrote: From: Sarah Goslee sarah.gos...@gmail.com Subject: Re: [R] why help ignores some values To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 11:27 AM Possibly because R has no idea what the 35.872-th element of a matrix is? However you are coming up with these elements, you are running into a floating-point arithmetic problem (FAQ 7.31). Using round() might help. Sarah On Thu, Nov 18, 2010 at 6:19 AM, Alaios ala...@yahoo.com wrote: Please take a look at the values below . [31,] 30.000 30.000 [32,] 31.000 31.000 [33,] 32.000 32.000 [34,] 33.000 33.000 [35,] 34.000 34.000 [36,] 35.000 35.000 [37,] 35.872 35.872 These are entries in an array. These values are used as indexes inside a matrix. f[shweights[37,1],shweights[37,2]] works fine for me and returns correctly the value. but when I try f[shweights[,1],shweights[,2]] I only get 36 out of 37 results (seems that in that case ignores the last values, 37th) . [35,] 2.7245297165175781 [36,] 2.7245297165175781 Why this might be happening? Regards Alex -- Sarah Goslee http://www.functionaldiversity.org [[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 catch warnings
Thanks a lot. Unfortunately browser() works pretty bad for me. As I am using Rkward this gives me a prompt while at the same time R console is blocked which make things not very easy. Regards Alex --- On Thu, 11/18/10, Rainer M Krug r.m.k...@gmail.com wrote: From: Rainer M Krug r.m.k...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Michael Bedward michael.bedw...@gmail.com, Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 11:37 AM -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 11/18/2010 11:11 AM, Alaios wrote: Dear Michael, I would like to thank you for your reply. This line made things easier. One more question what If I want to halt or pause the program when a warning happens? Right now I get only a message printed but it would be nicer if the execution is paused so to try to print more values. What about the following? Is that what x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=browser ) } Cheers, Rainer Best REgards Alex --- On Thu, 11/18/10, Michael Bedward michael.bedw...@gmail.com wrote: From: Michael Bedward michael.bedw...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 1:26 AM Hi Alex, Something like this ? x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=function(w) cat(problem values: , yy, \n) ) } Michael On 18 November 2010 03:19, Alaios ala...@yahoo.com wrote: Hello when my code executes I receive the message that were some warnings. I want to catch warning messages at run time so to print some local variables and try to understand why this warning happens. I searched on internet and I tried withCallingHandlers( which seems to work but as I used Rkward the result is awful. I get a prompt to copy paste a value only while at the same time my background window with my code is not anymore accessible. Actually I get the warning that In f[cbind(shweights[, 1], shweights[, 2])] * shweights[, ... : longer object length is not a multiple of shorter object length and what I want is when the warning appear to be able to print the value shweights[,1] shweights[,2] to see what is going on. Any easier way to do that? Best REgards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel: +33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzlEBUACgkQoYgNqgF2egr9dgCfdkQYIpkzqAHw13KwszvNJfhe ttUAn0ckAcT1AS+RCeeDVc5wn7sVD9gU =CmU6 -END PGP SIGNATURE- [[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] rgl, multiple graphics ??
On 18/11/2010 5:55 AM, skan wrote: Hello I just get one plot How can I concoct several rgl plots? It's basically up to you to handle everything. demo(stereo) shows you one way. 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] Updata Rdata File
On 18/11/2010 1:49 AM, Jason Kwok wrote: How do I add data to a .rdata file? In my case, I have a time series that needs to get updated every day. Load it, update the variables, save them. 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 catch warnings
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 11/18/2010 12:54 PM, Alaios wrote: Thanks a lot. Unfortunately browser() works pretty bad for me. As I am using Rkward this gives me a prompt while at the same time R console is blocked which make things not very easy. First option: you know where the error occurs, so enlarge the script window, so that you can see the code you want to debug. Second option: Start a second rkward independent R session and debug from there. I would suggest to contact the rkward mailing list, as one should at least be able to scroll in the rkward windows while the prompt is shown. Cheers, Rainer Regards Alex --- On *Thu, 11/18/10, Rainer M Krug /r.m.k...@gmail.com/* wrote: From: Rainer M Krug r.m.k...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com Cc: Michael Bedward michael.bedw...@gmail.com, Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 11:37 AM On 11/18/2010 11:11 AM, Alaios wrote: Dear Michael, I would like to thank you for your reply. This line made things easier. One more question what If I want to halt or pause the program when a warning happens? Right now I get only a message printed but it would be nicer if the execution is paused so to try to print more values. What about the following? Is that what x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=browser ) } Cheers, Rainer Best REgards Alex --- On Thu, 11/18/10, Michael Bedward michael.bedw...@gmail.com /mc/compose?to=michael.bedw...@gmail.com wrote: From: Michael Bedward michael.bedw...@gmail.com /mc/compose?to=michael.bedw...@gmail.com Subject: Re: [R] How to catch warnings To: Alaios ala...@yahoo.com /mc/compose?to=ala...@yahoo.com Cc: Rhelp r-help@r-project.org /mc/compose?to=r-h...@r-project.org Date: Thursday, November 18, 2010, 1:26 AM Hi Alex, Something like this ? x - 1:4 y - list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x - cbind(x, yy), warning=function(w) cat(problem values: , yy, \n) ) } Michael On 18 November 2010 03:19, Alaios ala...@yahoo.com /mc/compose?to=ala...@yahoo.com wrote: Hello when my code executes I receive the message that were some warnings. I want to catch warning messages at run time so to print some local variables and try to understand why this warning happens. I searched on internet and I tried withCallingHandlers( which seems to work but as I used Rkward the result is awful. I get a prompt to copy paste a value only while at the same time my background window with my code is not anymore accessible. Actually I get the warning that In f[cbind(shweights[, 1], shweights[, 2])] * shweights[, ... : longer object length is not a multiple of shorter object length and what I want is when the warning appear to be able to print the value shweights[,1] shweights[,2] to see what is going on. Any easier way to do that? Best REgards Alex [[alternative HTML version deleted]] __ R-help@r-project.org /mc/compose?to=r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 /mc/compose?to=r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzlGnoACgkQoYgNqgF2ego/kQCeOdnA6RTOV8aRIREOnOuu7HH4 EMsAn1ZLGaibFByPYbMqYCJQgYiZReHI =mkOi -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Odp: Why some times R-halts?
Hi r-help-boun...@r-project.org napsal dne 18.11.2010 11:29:28: Alaios ala...@yahoo.com Odeslal: r-help-boun...@r-project.org Hello everyone. I have written a small function that returns a 3*n array where n is typicall between 5-55. I issued in R shweights-shadowing_weights(x,xr) and I got the result in less that one sec. then I tried to see what is inside the shweights array and thus I issued the edit(shweights) which 10 mins right now is busy and got no reply yet back. Well, what is the structure of shweights object? I have not find any shadowing_weights function so it is hard to tell what it does and how the object looks like. In case something takes a longer time then expected (usually nonsense commands issued by myself) I hit stop current computation or stop all computations on command window menu. Regards Petr As I am using rkward I tried from gui the same (workspace- double click on variable) this gives me the message fetching information. Please wait. Right now I can not do anything there is a interupt running command key in the gui which does not seem to be working. I also tried ctrl+c which broke the execution after 15mins. What do you do in such cases and why R sometimes looks like has problems with even simple tasks? ***I*** usually have problems with simple tasks, not R. It is always quicker than myself and if anything goes wrong it is 99.99% my fault. regards Petr I would like to thank you in advance for your help Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Give me all operator
works nice : lapply( Mystruct, [, xy) # should return a list with xy elements Thanks --- On Wed, 11/17/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Give me all operator To: Alaios ala...@yahoo.com Cc: r-help@r-project.org, ivan.calan...@uni-hamburg.de Date: Wednesday, November 17, 2010, 4:07 PM On Nov 17, 2010, at 9:26 AM, Alaios wrote: It seems that I am confusing something: List of 50 $ :List of 2 ..$ CRmap: logi [1:100, 1:100] NA NA NA NA NA NA ... ..$ xy : num [1:2] 21 11 $ :List of 2 ..$ CRmap: logi [1:100, 1:100] NA NA NA NA NA NA ... ..$ xy : num [1:2] 80 68 lapply( Mystruct, [, xy) # should return a list with xy elements Le 11/17/2010 14:56, Alaios a écrit : Thanks a lot for your helpful answer. In my case now I have implemented some struct with the following structure Mystruct.Map Mystruct.xy If I do Mystruct[2].$xy I get correctly the xy values of the second item. It shouldn't. That extra period should mess things up. There is no .$ operator. --David. I want now to print all the $xy fields of the Mystruct[[]] I tried Mystruct[data.frame(a=1:5)]]$xy which returns the following message: invalid subscript type 'list' I would like to thank you again for your support Regards Alex --- On *Wed, 11/17/10, Ivan Calandra /ivan.calan...@uni-hamburg.de/* wrote: From: Ivan Calandra ivan.calan...@uni-hamburg.de Subject: Re: [R] Give me all operator To: r-help@r-project.org Date: Wednesday, November 17, 2010, 1:44 PM Hi Alex, Is that what you're looking for: df - data.frame(a=LETTERS[1:5], b=rnorm(5)) df a b 1 A -0.2401323 2 B -0.9414998 3 C 0.4289836 4 D 1.9802749 5 E -0.6993612 df[3,2] [1] 0.4289836 df[3,] a b 3 C 0.4289836 df[,2] [1] -0.2401323 -0.9414998 0.4289836 1.9802749 -0.6993612 df[,2, drop=FALSE] b 1 -0.2401323 2 -0.9414998 3 0.4289836 4 1.9802749 5 -0.6993612 See ?[ for help. In short, in R you use [, not brackets as in matlab (from your example, I've never used it). You don't need the :, you just don't write anything in R. Ivan Le 11/17/2010 14:34, Alaios a écrit : Hello is there in R any operator that give you all the data of a matrix for example in matlab x(2,3) returns the 2ndth row and 3rdth column x(2,:) returns all the columns of the 2nd row. In R now I would like to print all the CRagent[[i]][2] CRagent[[:]][2] doesnot work of course. Other option is to make a loop with an index i that spans from 1:last element of CRagent[[]] but this is not that optimal. I would like to thank you in aavance for your help Best Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org /mc/compose?to=r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de /mc/compose?to=ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ R-help@r-project.org /mc/compose?to=r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. --Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org
Re: [R] randomForest parameters for image classification
1. Memory issue: You may want to try to increase nodesize (e.g., to 5, 11, or even 21) and see if that degrades performance. If not, you should be able to grow more trees with the larger nodesize. Another option is to use the sampsize argument to have randomForest() do the random subsampling for you (on a per tree basis, rather than one random subset for the entire forest). 2. predict() giving NA: Have no idea why you are calling predict() that way. The first argument of all predict() methods that I know about (not just for randomForest) needs to be a model object, then followed by the data you want to predict, not the other way around. Andy -Original Message- From: Deschamps, Benjamin [mailto:benjamin.descha...@agr.gc.ca] Sent: Tuesday, November 16, 2010 11:16 AM To: r-help@r-project.org Cc: Liaw, Andy Subject: RE: [R] randomForest parameters for image classification I have modified my code since asking my original question. The classifier is now generated correctly (with a good, low error rate, as expected). However, I am running into two issues: 1) I am getting an error at the prediction stage, I get only NA's when I try to run data down the forest; 2) I run out of memory when generating the forest with more than 200 trees due to the large block of memory already occupied by the training data Here is my code: library(raster) library(randomForest) # Set some user variables fn = image.pix outraster = output.pix training_band = 2 validation_band = 1 # Get the training data myraster = stack(fn) training_class = subset(myraster, training_band) training_class[training_class == 0] = NA training_class = Which(training_class != 0, cells=TRUE) training_data = extract(myraster, training_class) training_response = as.factor(as.vector(training_data[,training_band])) training_predictors = training_data[,3:nlayers(myraster)] remove(training_data) # Create and save the forest r_tree = randomForest(training_predictors, y=training_response, ntree = 200, keep.forest=TRUE) # Runs out of memory with ntree ~200 remove(training_predictors, training_response) # Classify the whole image predictor_data = subset(myraster, 3:nlayers(myraster)) layerNames(predictor_data) = layerNames(myraster)[3:nlayers(myraster)] predictions = predict(predictor_data, r_tree, filename=outraster, format=PCIDSK, overwrite=TRUE, progress=text, type=response) #All NA!? remove(predictor_data) See also a thread I started on http://stackoverflow.com/questions/4186507/rgdal-efficiently-r eading-lar ge-multiband-rasters about improving the efficiency of collecting the training data... Thanks, Benjamin -Original Message- From: Liaw, Andy [mailto:andy_l...@merck.com] Sent: November 11, 2010 7:02 AM To: Deschamps, Benjamin; r-help@r-project.org Subject: RE: [R] randomForest parameters for image classification Please show us the code you used to run randomForest, the output, as well as what you get with other algorithms (on the same random subset for comparison). I have yet to see a dataset where randomForest does _far_ worse than other methods. Andy -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Deschamps, Benjamin Sent: Tuesday, November 09, 2010 10:52 AM To: r-help@r-project.org Subject: [R] randomForest parameters for image classification I am implementing an image classification algorithm using the randomForest package. The training data consists of 31000+ training cases over 26 variables, plus one factor predictor variable (the training class). The main issue I am encountering is very low overall classification accuracy (a lot of confusion between classes). However, I know from other classifications (including a regular decision tree classifier) that the training and validation data is sound and capable of producing good accuracies). Currently, I am using the default parameters (500 trees, mtry not set (default), nodesize = 1, replace=TRUE). Does anyone have experience using this with large datasets? Currently I need to randomly sample my training data because giving it the full 31000+ cases returns an out of memory error; the same thing happens with large numbers of trees. From what I read in the documentation, perhaps I do not have enough trees to fully capture the training data? Any suggestions or ideas will be greatly appreciated. Benjamin [[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. Notice: This e-mail message, together with any attach...{{dropped:26}}
[R] Help me with R plotting
Hello everyone. I want some help with plots. I have some robots in an area. Every robot is placed on x,y coordinates and every robot has a power consumption of some watts. I would like to show where are the robots by showing in a map dots (where every dots is the x,y coordinate). Below that dot it would be nice to write the watt consumption but also use some colors to denote different classes of consumption. So 10-20watt should be denoted by blue 20-30 with red, 30-40 with pink and so on. Which is the appropriate plot function for that? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help me with R plotting
?plot Will give a good solution #Example: set.seed(5) xx - data.frame(x = runif(50), y = runif(50), z = sample(c(1:3), 50, T)) with(xx, plot(x, y, col = z, pch = 19)) Now you can start going into how to play with the colors, and how to add ?legend to the image... Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Thu, Nov 18, 2010 at 4:08 PM, Alaios ala...@yahoo.com wrote: Hello everyone. I want some help with plots. I have some robots in an area. Every robot is placed on x,y coordinates and every robot has a power consumption of some watts. I would like to show where are the robots by showing in a map dots (where every dots is the x,y coordinate). Below that dot it would be nice to write the watt consumption but also use some colors to denote different classes of consumption. So 10-20watt should be denoted by blue 20-30 with red, 30-40 with pink and so on. Which is the appropriate plot function for that? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sweep by levels of a factor
Hi, I'd appreciate help with this. I have a data matrix with one column, called f in the example below, a factor. I'd like to subtract the means from each of other columns for each level of the factor. That is, in the example, to go from the first matrix below to the second. I know SWEEP will take out means, but I want to do this for each level of the factor. fx 1 2 1 0 2 0 2 4 2 2 f xnew 11 1 -1 2 -2 22 2 0 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] format secondary axis for dates
Thanks for your help, David! Somehow I just could not find this information in the documentation! Jannis David Winsemius schrieb: On Nov 16, 2010, at 2:32 PM, Jannis wrote: Dear List, this may be a Newbi question and may have been asked several times, but i am too stupid to find the posts. I have a plot of values against POSIXct time steps. If I want to add a second x axis to the top margin of the plot, only numbers are at the tickmarks. Is there a straightforward way to specify the format to convert them to character representations (similar to the labels at the bottom)? x-as.POSIXct(1:1000*(60^2),origin='01-01-1970') The origin argument was incorrect and you got the wrong starting point: x[1] [1] 0001-01-19 01:00:00 EST y=rnorm(1000) plot(x,y) axis(3) This gives ticks at hourly intervals: axis(3, labels=format(x, %Y-%m-%d), at=x) Whereas this is probably what you want (after correcting the origin to 1970-01-01 axis.POSIXct(3, x=x, labels=TRUE ) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Mixed multinomial logit model (mlogit script)
Dear all, I am trying to run a mixed multinomial logit model in R since my response variable has 4 non-ordinal categories. I am using the package mlogit that estimates the parameters by maximum likelihood methods. First of all, I prepared my data using the mlogit.data command. In the mlogit command, one can introduce alternative-specific (fixed factors??) and individual-specific (random factors??) variables. Each of them is indicated before and after the | , respectively, in the formula script. My model has both types of predictor variables. As the author of the script indicated in the mlogit helps, I am using the mixed model script example: m-mlogit (mode ~ price + catch | income, data = Fish) but I obtain the next error: Error en drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) : rutina Lapack dgesv: sistema es exactamente singular The only syntax that I can run is: m-mlogit (mode ~ 1 | income, data = Fish) which I don not understant really well what is going on but I understand that here just individual-specific variables are being analyzed. So, I am a beginner pearson in R as well as in this kind of models. I would be really grateful any help. Thanks in advance, Maria. [[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] where are my pspline knots?
The pspline function uses P-splines (Eilers and Marx, Statistical Science, 1981), which are a spline basis using a regular set of knots. Looking at the code for pspline, which isn't so hard, let dx = (max(x) - min(x))/ ntermwhere nterm is round(2.5 * desired degrees of freedom) The knots go from min(x) -df*dx to max(x) + df*dx. The default df is 4. Once the knots are known, the bs() function generates the pspline basis for me. Terry T __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 Sampling question
This can of course be done, but before I make any attempt to do it I have to ask: why do you want this? On Wed, Nov 17, 2010 at 7:08 PM, wangwallace talentt...@gmail.com wrote: I have another question about drawing samples from a data frame. This might sound really tricky. Let me use a data frame I have posted earlier as an example: SubID CSE1 CSE2 CSE3 CSE4 WSE1 WSE2 WSE3 WSE4 1 6 5 6 2 6 2 2 4 2 6 4 7 2 6 6 2 3 3 5 5 5 5 5 5 4 5 4 5 4 3 4 4 4 5 2 5 5 6 7 5 6 4 4 1 6 5 4 3 6 4 3 7 3 7 3 6 6 3 6 5 2 1 8 3 6 6 3 6 5 4 7 this data frame have two sets of variables. each set simply represent one scale. as shown above, the first scale, say CSE, consists of four items: CSE1, CSE2, CSE3, and CSE4, whereas the second scale, say WSE, also has four items: WSE1, WSE2, WSE3, WSE4. the leftmost column lists the subjects' ID. I wanna create a new data frame through sampling random numbers from the data frame above. Below is the structure of the new data frame. SubID var var var var s c c c c s c c c c s c w w w s c w w w s c w w w s c w w w s c w w w s c w w w in the new data frame: s= SubID range from 1 to 8 var= variables c=CSE numbers w=WSE numbers some rules to construct the new data frame: 1. the top two rows have to be filled with CSE numbers; the numbers in the cells of each row should be randomized. for example, if the first row is an array of numbers from subject 4, they can follow the order: 4(CSE2), 5(CSE1), 3(CSE3), and 4(CSE4). Also, the numbers in the second row does not have to follow the order of the first row. for example, similarly, if the first row is an array of numbers from subject 4 in the order: 4(CSE2), 5(CSE1), 3(CSE3), and 4(CSE4), numbers in the second row (assuming it is from subject 8) does not have to be 6(CSE2), 3(CSE1), 6(CSE3), and 3(CSE4). numbers in these two rows should be drawn without replacement. 2. each of the rest of the rows should include a CSE number in the leftmost cell and three WSE numbers on the right. At the same time, in each row, the three WSE numbers on the right have to be only those numbers that are not corresponding to the CSE number in the leftmost cell. For example, if the CSE number in the leftmost cell is 4, a CSE2 number from subject 6, the three WSE numbers on the right side can only be 4(WSE1), 7(WSE3), and 3(WSE4) from subject 6. 3. the numbers in each row can only be drawn from the same subject. Also, Subjects should be randomized. Specifically, they does have to be in the following order: SubID 1 2 3 4 5 6 7 8 they can be: SubID 2 8 5 4 1 6 7 3 Any ideas? Thanks in advance!! :) -- View this message in context: http://r.789695.n4.nabble.com/New-Sampling-question-tp3047885p3047885.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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot does not work
Dear jim, just to update this. My problem is now fixed. Regards Alex --- On Mon, 10/25/10, jim holtman jholt...@gmail.com wrote: From: jim holtman jholt...@gmail.com Subject: Re: [R] plot does not work To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Monday, October 25, 2010, 12:59 PM try 'graphics.off()' to close any device that might be open and see if you see any output. On Mon, Oct 25, 2010 at 5:44 AM, Alaios ala...@yahoo.com wrote: Hello everyone The following two commands plot.default(seq(1,5),seq(2,6)) plot(seq(1,5),seq(2,6)) plot nothing. One day ago this would create a simple plot diagram but unfortunately right now no plot appears. ?plot returns Help on topic 'plot' was found in the following packages: Plot a Raster* object (in package raster in library /home/apa/R/x86_64-unknown-linux-gnu-library/2.11) Generic X-Y Plotting (in package graphics in library /usr/lib64/R/library) What do you think I should blame for that? Best Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] PS
Note that there is NOT an intercept term in my pspline basis. One of the features of psplines is that \sum beta_i f_i(x) (where f_i are the spline basis functions) is linear if and only if the coefficients beta are a linear sequence. This makes it easy to decompose the fit into linear and non-linear effects. Terry T __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sweep by levels of a factor
Hi: d$r - with(d, ave(x, f, FUN = function(u) u - mean(u))) d f x r 1 1 2 1 2 1 0 -1 3 2 0 -2 4 2 4 2 5 2 2 0 HTH, Dennis On Thu, Nov 18, 2010 at 6:02 AM, Lancaster, Anthony anthony_lancas...@brown.edu wrote: Hi, I'd appreciate help with this. I have a data matrix with one column, called f in the example below, a factor. I'd like to subtract the means from each of other columns for each level of the factor. That is, in the example, to go from the first matrix below to the second. I know SWEEP will take out means, but I want to do this for each level of the factor. fx 1 2 1 0 2 0 2 4 2 2 f xnew 11 1 -1 2 -2 22 2 0 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. [[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] problems subsetting
Dear all, I have searched the forums for an answer - and there is plenty of questions along the same line - but none of the paproaches shown worked to my problem: I have a data frame that I get from a csv: summarystats-as.data.frame(read.csv(file=f_summary)); where I have the columns Dataset, Class, Type, Category,.. Problem1: I want to find a subset of this frame, based on values in multiple columns What I do currently is: subset1 - summarystats subset1-subset1[subset1$Class == 1,] subset1-subset1[subset1$Type == 1,] subset1-subset1[subset1$Category == 1,] Now, this works, but is UGLY! I tried using or , for isntance : subset1-subset1[ (subset1$Class == 1) (subset1$Category == 1),] but it returns an empty data frame. Anyway, the main problem is Problem2: I have a second data frame - a square matrix (rownames == colnames), distm: distm-read.table(file=f_simmatrix, sep = ,); what I want is select ONLY the columns and rows entries matching the above subset1: subset2-distm[subset1$Dataset,subset1$Dataset] returns a matrix of correct size, but with incorrect entries (established by visual inspection). this is the same as: selectedrows-as.vector(subset1$Dataset) subset2-distm[selectedrows,selectedrows] also verified using: rownames(subset2)%in% selectedrows [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE What am I missing? Thanks Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems subsetting
Hi, I got a bit lost with your explanation for your second problem. A reproducible example would DEFINITELY help to understand what you have and what you're trying to get. For your first problem subset1 - summarystats[summarystats$Class == 1 summarystats$Type == 1 summarystats$Category == 1, ] should work. If not, maybe looking at str(summarystats) could help you figure out what the problem is (or could be) By the way in summarystats-as.data.frame(read.csv(file=f_summary)) as.data.frame() is useless since read.csv() outputs a data.frame For your second problem, it's difficult for me to understand anything because I don't know what summarystats$Dataset is. Could there be a problem with factors here? HTH, Ivan Le 11/18/2010 15:39, Martin Tomko a écrit : Dear all, I have searched the forums for an answer - and there is plenty of questions along the same line - but none of the paproaches shown worked to my problem: I have a data frame that I get from a csv: summarystats-as.data.frame(read.csv(file=f_summary)); where I have the columns Dataset, Class, Type, Category,.. Problem1: I want to find a subset of this frame, based on values in multiple columns What I do currently is: subset1 - summarystats subset1-subset1[subset1$Class == 1,] subset1-subset1[subset1$Type == 1,] subset1-subset1[subset1$Category == 1,] Now, this works, but is UGLY! I tried using or , for isntance : subset1-subset1[ (subset1$Class == 1) (subset1$Category == 1),] but it returns an empty data frame. Anyway, the main problem is Problem2: I have a second data frame - a square matrix (rownames == colnames), distm: distm-read.table(file=f_simmatrix, sep = ,); what I want is select ONLY the columns and rows entries matching the above subset1: subset2-distm[subset1$Dataset,subset1$Dataset] returns a matrix of correct size, but with incorrect entries (established by visual inspection). this is the same as: selectedrows-as.vector(subset1$Dataset) subset2-distm[selectedrows,selectedrows] also verified using: rownames(subset2)%in% selectedrows [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE What am I missing? Thanks Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plotting number of patients at risk below survival curve
Dear list, does anyone know of a R-package that has implemented the increasingly popular inclusion of the number of patients at risk below Kaplan-Meier curves like in http://bloodjournal.hematologylibrary.org/content/vol116/issue19/images/large/zh89991058760001.jpeg any hint (or negative answer) is much appreciated. Thanks Thorsten -- Thorsten Raff 2nd Medical Department, University Hospital Schleswig-Holstein, Campus Kiel Chemnitzstraße 33 24116 Kiel GERMANY phone: +49 431 1697-5234 fax: +49 431 1697-1264 email: t.raffatmed2.uni-kiel.de web: www.uk-sh.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help me with R plotting
Thanks a lot for your help I tried first this test-(myvalues)-mean(myvalues) so to put the values close to the 0...30 scale... then I passed this as an argument plot(x,y,col=test) which plots the places where the robots are with a small color. I think this is ok for now. What I want next is also to plot some color bar so the reader can by inspecting first this color bar to say Ah the read is for the range of 5-10 watts Also I tried legend... which creates small boxes below the dots which is Do not what I want exactly. I would like below every plot to write some text but not inside any box that will cover part of the image. Best Regards Alex --- On Thu, 11/18/10, Tal Galili tal.gal...@gmail.com wrote: From: Tal Galili tal.gal...@gmail.com Subject: Re: [R] Help me with R plotting To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 2:13 PM ?plotWill give a good solution #Example:set.seed(5)xx - data.frame(x = runif(50), y = runif(50), z = sample(c(1:3), 50, T))with(xx, plot(x, y, col = z, pch = 19)) Now you can start going into how to play with the colors, and how to add ?legend to the image... Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- Hello everyone. I want some help with plots. I have some robots in an area. Every robot is placed on x,y coordinates and every robot has a power consumption of some watts. I would like to show where are the robots by showing in a map dots (where every dots is the x,y coordinate). Below that dot it would be nice to write the watt consumption but also use some colors to denote different classes of consumption. So 10-20watt should be denoted by blue 20-30 with red, 30-40 with pink and so on. Which is the appropriate plot function for that? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems subsetting
Hi Gerrit, indeed, that works. Excellent tip! For reference, I did this: subset1-subset(summarystats,(Type==1)(Class==1)(Category==1)) I am still not totally sure when one uses amd when - I was under the impression that stands for logical AND Thanks a lot. Martin On 11/18/2010 3:58 PM, Gerrit Eichner wrote: Hello, Martin, as to your first problem, look at function subset(), and particularly at its argument subset. HTH, Gerrit On Thu, 18 Nov 2010, Martin Tomko wrote: Dear all, I have searched the forums for an answer - and there is plenty of questions along the same line - but none of the paproaches shown worked to my problem: I have a data frame that I get from a csv: summarystats-as.data.frame(read.csv(file=f_summary)); where I have the columns Dataset, Class, Type, Category,.. Problem1: I want to find a subset of this frame, based on values in multiple columns What I do currently is: subset1 - summarystats subset1-subset1[subset1$Class == 1,] subset1-subset1[subset1$Type == 1,] subset1-subset1[subset1$Category == 1,] Now, this works, but is UGLY! I tried using or , for isntance : subset1-subset1[ (subset1$Class == 1) (subset1$Category == 1),] but it returns an empty data frame. Anyway, the main problem is Problem2: I have a second data frame - a square matrix (rownames == colnames), distm: distm-read.table(file=f_simmatrix, sep = ,); what I want is select ONLY the columns and rows entries matching the above subset1: subset2-distm[subset1$Dataset,subset1$Dataset] returns a matrix of correct size, but with incorrect entries (established by visual inspection). this is the same as: selectedrows-as.vector(subset1$Dataset) subset2-distm[selectedrows,selectedrows] also verified using: rownames(subset2)%in% selectedrows [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE What am I missing? Thanks Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner - -- Martin Tomko Postdoctoral Research Assistant Geographic Information Systems Division Department of Geography University of Zurich - Irchel Winterthurerstr. 190 CH-8057 Zurich, Switzerland email: martin.to...@geo.uzh.ch site: http://www.geo.uzh.ch/~mtomko mob:+41-788 629 558 tel:+41-44-6355256 fax:+41-44-6356848 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Exporting Dataframe to Excel spreadsheet
Hi, I have a data frame contains 30,000 rows and 105 columns. How can i extract each of the columns as separate Excel spreadsheet of the same excel file. Regards, Pankaj Barah Department of Biology, Norwegian University of Science Technology (NTNU) Realfagbygget, N-7491 Trondheim, Norway [[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] Updata Rdata File
Thanks for the response Duncan. I'm sorry I wasn't clear in my question. I need to add an additional value every day to the data and not update it. I know how to load and save but I dont' know how to add data. load(file=C:\\datafile.rdata) save(data,file=C:\\datafile.rdata) Thanks. Jason On Thu, Nov 18, 2010 at 6:56 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 18/11/2010 1:49 AM, Jason Kwok wrote: How do I add data to a .rdata file? In my case, I have a time series that needs to get updated every day. Load it, update the variables, save them. Duncan Murdoch [[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] Help me with R plotting
Hi, Try this, robots - data.frame(id=letters[1:20], x=rnorm(20), y=rnorm(20), consumption=runif(20, 10, 100)) library(ggplot2) ggplot(robots) + geom_point(aes(x, y, colour=cut(consumption, c(0, 30, 50, 100 + geom_text(aes(x, y, colour=cut(consumption, c(0, 30, 50, 100)), label=round(consumption, 2)), vjust=1, legend=FALSE) + labs(colour=consumption) HTH, baptiste On Nov 18, 2010, at 4:18 PM, Alaios wrote: Thanks a lot for your help I tried first this test-(myvalues)-mean(myvalues) so to put the values close to the 0...30 scale... then I passed this as an argument plot(x,y,col=test) which plots the places where the robots are with a small color. I think this is ok for now. What I want next is also to plot some color bar so the reader can by inspecting first this color bar to say Ah the read is for the range of 5-10 watts Also I tried legend... which creates small boxes below the dots which is Do not what I want exactly. I would like below every plot to write some text but not inside any box that will cover part of the image. Best Regards Alex --- On Thu, 11/18/10, Tal Galili tal.gal...@gmail.com wrote: From: Tal Galili tal.gal...@gmail.com Subject: Re: [R] Help me with R plotting To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 2:13 PM ?plotWill give a good solution #Example:set.seed(5)xx - data.frame(x = runif(50), y = runif(50), z = sample(c(1:3), 50, T))with(xx, plot(x, y, col = z, pch = 19)) Now you can start going into how to play with the colors, and how to add ?legend to the image... Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- Hello everyone. I want some help with plots. I have some robots in an area. Every robot is placed on x,y coordinates and every robot has a power consumption of some watts. I would like to show where are the robots by showing in a map dots (where every dots is the x,y coordinate). Below that dot it would be nice to write the watt consumption but also use some colors to denote different classes of consumption. So 10-20watt should be denoted by blue 20-30 with red, 30-40 with pink and so on. Which is the appropriate plot function for that? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Exporting Dataframe to Excel spreadsheet
On Thu, Nov 18, 2010 at 10:26 AM, pankaj borah pankajborah...@yahoo.co.in wrote: I have a data frame contains 30,000 rows and 105 columns. How can i extract each of the columns as separate Excel spreadsheet of the same excel file. See: http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help me with R plotting
(Assuming you aren't going into ggplot2) You can have a look here, it might offer a nice solution: http://rgm2.lab.nig.ac.jp/RGM2/R_man-2.9.0/library/shape/man/colorlegend.html Also, you can use ?cut to change your coloring to specific chunks (although having a full gradient is probably nicer) Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Thu, Nov 18, 2010 at 5:18 PM, Alaios ala...@yahoo.com wrote: Thanks a lot for your help I tried first this test-(myvalues)-mean(myvalues) so to put the values close to the 0...30 scale... then I passed this as an argument plot(x,y,col=test) which plots the places where the robots are with a small color. I think this is ok for now. What I want next is also to plot some color bar so the reader can by inspecting first this color bar to say Ah the read is for the range of 5-10 watts Also I tried legend... which creates small boxes below the dots which is Do not what I want exactly. I would like below every plot to write some text but not inside any box that will cover part of the image. Best Regards Alex --- On *Thu, 11/18/10, Tal Galili tal.gal...@gmail.com* wrote: From: Tal Galili tal.gal...@gmail.com Subject: Re: [R] Help me with R plotting To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 2:13 PM ?plot Will give a good solution #Example: set.seed(5) xx - data.frame(x = runif(50), y = runif(50), z = sample(c(1:3), 50, T)) with(xx, plot(x, y, col = z, pch = 19)) Now you can start going into how to play with the colors, and how to add ?legend to the image... Tal Contact Details:--- Contact me: tal.gal...@gmail.comhttp://mc/compose?to=tal.gal...@gmail.com| 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Thu, Nov 18, 2010 at 4:08 PM, Alaios ala...@yahoo.comhttp://mc/compose?to=ala...@yahoo.com wrote: Hello everyone. I want some help with plots. I have some robots in an area. Every robot is placed on x,y coordinates and every robot has a power consumption of some watts. I would like to show where are the robots by showing in a map dots (where every dots is the x,y coordinate). Below that dot it would be nice to write the watt consumption but also use some colors to denote different classes of consumption. So 10-20watt should be denoted by blue 20-30 with red, 30-40 with pink and so on. Which is the appropriate plot function for that? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org http://mc/compose?to=r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ncdf4 for Windows/R-2.12.0
Hi David, This link looks like it points to the resources you need: http://www.unidata.ucar.edu/software/netcdf/docs/faq.html#windows_netcdf4 Perry -- View this message in context: http://r.789695.n4.nabble.com/ncdf4-for-Windows-R-2-12-0-tp3047807p3048935.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] problems subsetting
Hi, On Thu, Nov 18, 2010 at 10:25 AM, Martin Tomko martin.to...@geo.uzh.ch wrote: Hi Gerrit, indeed, that works. Excellent tip! For reference, I did this: subset1-subset(summarystats,(Type==1)(Class==1)(Category==1)) I am still not totally sure when one uses amd when - I was under the impression that stands for logical AND If you can't find the appropriate documentation, try to experiment in your workspace: R c(TRUE, TRUE, FALSE, TRUE) c(FALSE, TRUE, TRUE, TRUE) [1] FALSE TRUE FALSE TRUE R c(TRUE, TRUE, FALSE, TRUE) c(FALSE, TRUE, TRUE, TRUE) [1] FALSE The single logical operators ( , |) run over the entire length of your logical vectors. The doubles (, ||) just evaluate the first element of the vectors, and ignore the rest. -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems subsetting
Thanks Steve, that explains it... Unfortunately, I did nto get that from my R docs... I am still searching for a solution for matching the entries in my matrix by matching the rownames to the entires in a subset I got using Gerrit's method. Any idea? Thanks Martin On 11/18/2010 4:35 PM, Steve Lianoglou wrote: Hi, On Thu, Nov 18, 2010 at 10:25 AM, Martin Tomkomartin.to...@geo.uzh.ch wrote: Hi Gerrit, indeed, that works. Excellent tip! For reference, I did this: subset1-subset(summarystats,(Type==1)(Class==1)(Category==1)) I am still not totally sure when one uses amd when - I was under the impression that stands for logical AND If you can't find the appropriate documentation, try to experiment in your workspace: R c(TRUE, TRUE, FALSE, TRUE) c(FALSE, TRUE, TRUE, TRUE) [1] FALSE TRUE FALSE TRUE R c(TRUE, TRUE, FALSE, TRUE) c(FALSE, TRUE, TRUE, TRUE) [1] FALSE The single logical operators ( , |) run over the entire length of your logical vectors. The doubles (, ||) just evaluate the first element of the vectors, and ignore the rest. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems subsetting
On 2010-11-18 07:25, Martin Tomko wrote: Hi Gerrit, indeed, that works. Excellent tip! For reference, I did this: subset1-subset(summarystats,(Type==1)(Class==1)(Category==1)) I am still not totally sure when one uses amd when - I was under the impression that stands for logical AND This indicates that you haven't looked at (or absorbed) the help page for logic operators. It's pretty well explained there that both and perform AND, but the first is for elementwise comparison which is what your application clearly requires. -Peter Ehlers Thanks a lot. Martin On 11/18/2010 3:58 PM, Gerrit Eichner wrote: Hello, Martin, as to your first problem, look at function subset(), and particularly at its argument subset. HTH, Gerrit On Thu, 18 Nov 2010, Martin Tomko wrote: Dear all, I have searched the forums for an answer - and there is plenty of questions along the same line - but none of the paproaches shown worked to my problem: I have a data frame that I get from a csv: summarystats-as.data.frame(read.csv(file=f_summary)); where I have the columns Dataset, Class, Type, Category,.. Problem1: I want to find a subset of this frame, based on values in multiple columns What I do currently is: subset1- summarystats subset1-subset1[subset1$Class == 1,] subset1-subset1[subset1$Type == 1,] subset1-subset1[subset1$Category == 1,] Now, this works, but is UGLY! I tried using or , for isntance : subset1-subset1[ (subset1$Class == 1) (subset1$Category == 1),] but it returns an empty data frame. Anyway, the main problem is Problem2: I have a second data frame - a square matrix (rownames == colnames), distm: distm-read.table(file=f_simmatrix, sep = ,); what I want is select ONLY the columns and rows entries matching the above subset1: subset2-distm[subset1$Dataset,subset1$Dataset] returns a matrix of correct size, but with incorrect entries (established by visual inspection). this is the same as: selectedrows-as.vector(subset1$Dataset) subset2-distm[selectedrows,selectedrows] also verified using: rownames(subset2)%in% selectedrows [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE What am I missing? Thanks Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner - __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems subsetting
On Nov 18, 2010, at 10:25 AM, Martin Tomko wrote: Hi Gerrit, indeed, that works. Excellent tip! For reference, I did this: subset1-subset(summarystats,(Type==1)(Class==1)(Category==1)) I am still not totally sure when one uses amd when - I was under the impression that stands for logical AND Both stand for logical AND. is used for vectorized comparisons, while will only compare the first elements of the two sides (usually, but apparently not always) with a warning if there are longer objects than expected. c(1,0,1,0,1) c(0,0,1,1,-1) [1] FALSE FALSE TRUE FALSE TRUE c(1,0,1,0,1) c(0,0,1,1,-1) [1] FALSE c(1,0,1,0,1) c(1,0,1,1,-1) [1] TRUE -- David. Thanks a lot. Martin On 11/18/2010 3:58 PM, Gerrit Eichner wrote: Hello, Martin, as to your first problem, look at function subset(), and particularly at its argument subset. HTH, Gerrit On Thu, 18 Nov 2010, Martin Tomko wrote: Dear all, I have searched the forums for an answer - and there is plenty of questions along the same line - but none of the paproaches shown worked to my problem: I have a data frame that I get from a csv: summarystats-as.data.frame(read.csv(file=f_summary)); where I have the columns Dataset, Class, Type, Category,.. Problem1: I want to find a subset of this frame, based on values in multiple columns What I do currently is: subset1 - summarystats subset1-subset1[subset1$Class == 1,] subset1-subset1[subset1$Type == 1,] subset1-subset1[subset1$Category == 1,] Now, this works, but is UGLY! I tried using or , for isntance : subset1-subset1[ (subset1$Class == 1) (subset1$Category == 1),] but it returns an empty data frame. Anyway, the main problem is Problem2: I have a second data frame - a square matrix (rownames == colnames), distm: distm-read.table(file=f_simmatrix, sep = ,); what I want is select ONLY the columns and rows entries matching the above subset1: subset2-distm[subset1$Dataset,subset1$Dataset] returns a matrix of correct size, but with incorrect entries (established by visual inspection). this is the same as: selectedrows-as.vector(subset1$Dataset) subset2-distm[selectedrows,selectedrows] also verified using: rownames(subset2)%in% selectedrows [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE What am I missing? Thanks Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner - -- Martin Tomko Postdoctoral Research Assistant Geographic Information Systems Division Department of Geography University of Zurich - Irchel Winterthurerstr. 190 CH-8057 Zurich, Switzerland email: martin.to...@geo.uzh.ch site: http://www.geo.uzh.ch/~mtomko mob:+41-788 629 558 tel:+41-44-6355256 fax:+41-44-6356848 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking up the directory a file is located in
So it sounds like the best we can do in R is to keep track of the script in a sort of master file that runs the script, and set the working directory in the master. Is that accurate? In Python any time you run a script, there is a built-in __file__ variable that can tell you the file name of the script itself. It would be nice to have a feature like this in R. -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3048916.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] New Sampling question
Dear Ista Zahn-2, If you can give me some advice, I really appreciate it. I have been working on it for days. it seems hard for some novice of R like me to write flexible functions myself. This is for my dissertation. CSE and WSE are two scales of the same construct. The sampling strategy I wanted above allows me check how the items of these two scales vary within person and across person. Also, I added another rule: draw 1000 random samples... Again, Thanks! Wallace -- View this message in context: http://r.789695.n4.nabble.com/New-Sampling-question-tp3047885p3048948.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] Help me with R plotting
Thanks a lot :) nice one --- On Thu, 11/18/10, baptiste Auguié baptiste.aug...@googlemail.com wrote: From: baptiste Auguié baptiste.aug...@googlemail.com Subject: Re: [R] Help me with R plotting To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 3:34 PM Hi, Try this, robots - data.frame(id=letters[1:20], x=rnorm(20), y=rnorm(20), consumption=runif(20, 10, 100)) library(ggplot2) ggplot(robots) + geom_point(aes(x, y, colour=cut(consumption, c(0, 30, 50, 100 + geom_text(aes(x, y, colour=cut(consumption, c(0, 30, 50, 100)), label=round(consumption, 2)), vjust=1, legend=FALSE) + labs(colour=consumption) HTH, baptiste On Nov 18, 2010, at 4:18 PM, Alaios wrote: Thanks a lot for your help I tried first this test-(myvalues)-mean(myvalues) so to put the values close to the 0...30 scale... then I passed this as an argument plot(x,y,col=test) which plots the places where the robots are with a small color. I think this is ok for now. What I want next is also to plot some color bar so the reader can by inspecting first this color bar to say Ah the read is for the range of 5-10 watts Also I tried legend... which creates small boxes below the dots which is Do not what I want exactly. I would like below every plot to write some text but not inside any box that will cover part of the image. Best Regards Alex --- On Thu, 11/18/10, Tal Galili tal.gal...@gmail.com wrote: From: Tal Galili tal.gal...@gmail.com Subject: Re: [R] Help me with R plotting To: Alaios ala...@yahoo.com Cc: Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 2:13 PM ?plotWill give a good solution #Example:set.seed(5)xx - data.frame(x = runif(50), y = runif(50), z = sample(c(1:3), 50, T))with(xx, plot(x, y, col = z, pch = 19)) Now you can start going into how to play with the colors, and how to add ?legend to the image... Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- Hello everyone. I want some help with plots. I have some robots in an area. Every robot is placed on x,y coordinates and every robot has a power consumption of some watts. I would like to show where are the robots by showing in a map dots (where every dots is the x,y coordinate). Below that dot it would be nice to write the watt consumption but also use some colors to denote different classes of consumption. So 10-20watt should be denoted by blue 20-30 with red, 30-40 with pink and so on. Which is the appropriate plot function for that? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] problems subsetting
On Nov 18, 2010, at 10:42 AM, Martin Tomko wrote: Thanks Steve, that explains it... Unfortunately, I did nto get that from my R docs... I am still searching for a solution for matching the entries in my matrix by matching the rownames to the entires in a subset I got using Gerrit's method. OK. Looking back at your original question it appears you are confusing the actions of and | when setting up selection criteria. It may sound strange but if you want the union of the group that is A and the group the is B then the criteria needs to be A | B , not A B. So your original operation should have been: subset1-subset1[ subset1$Class == 1 | subset1$Type == 1 | subset1$Category == 1, ] -- David. Any idea? Thanks Martin On 11/18/2010 4:35 PM, Steve Lianoglou wrote: Hi, On Thu, Nov 18, 2010 at 10:25 AM, Martin Tomkomartin.to...@geo.uzh.ch wrote: Hi Gerrit, indeed, that works. Excellent tip! For reference, I did this: subset1-subset(summarystats,(Type==1)(Class==1)(Category==1)) I am still not totally sure when one uses amd when - I was under the impression that stands for logical AND If you can't find the appropriate documentation, try to experiment in your workspace: R c(TRUE, TRUE, FALSE, TRUE) c(FALSE, TRUE, TRUE, TRUE) [1] FALSE TRUE FALSE TRUE R c(TRUE, TRUE, FALSE, TRUE) c(FALSE, TRUE, TRUE, TRUE) [1] FALSE The single logical operators ( , |) run over the entire length of your logical vectors. The doubles (, ||) just evaluate the first element of the vectors, and ignore the rest. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking up the directory a file is located in
On Thu, Nov 18, 2010 at 10:26 AM, Cliff Clive cliffcl...@gmail.com wrote: In Python any time you run a script, there is a built-in __file__ variable that can tell you the file name of the script itself. It would be nice to have a feature like this in R. R has that feature. source(c:/myfullpath/myfile.r, chdir=TRUE) See ?source for details. Rich [[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] Looking up the directory a file is located in
On Thu, Nov 18, 2010 at 3:26 PM, Cliff Clive cliffcl...@gmail.com wrote: So it sounds like the best we can do in R is to keep track of the script in a sort of master file that runs the script, and set the working directory in the master. Is that accurate? Errr no. Maybe. What? Your script is somewhere. Something is calling it. The thing that calls it knows where it is. The thing that calls it is then responsible for telling the script where it is. For example: here = C:/Fnord/ source(C:/Fnord/script.R) now the script in C:\Fnord\script.R looks at 'here' and finds its data files by pasting 'data.txt' onto the value of 'here'. This is of course still a fairly bad way of doing things. Better to write functions that can live _anywhere_ and tell them where to find their data. So instead of the above, you should end up with: source(C:/MyLibrary/mycode.R) nowProcess(C:/Fnord) where nowProcess is a function that takes a directory to work on as its first parameter. But EVEN better still is to write a package. Then you do: library(myPackage) nowProcess(C:/Fnord) In Python any time you run a script, there is a built-in __file__ variable that can tell you the file name of the script itself. It would be nice to have a feature like this in R. Indeed. Also, I'd like to get rid of curly brackets from R and use indentation, and have a neater class mechanism... Perhaps decorators for functions... Hmm... Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking up the directory a file is located in
On Wed, Nov 17, 2010 at 4:08 PM, Cliff Clive cliffcl...@gmail.com wrote: Hello everyone, This should be an easy question, I think. I'd like to write a command in a program to set the working directory to whatever directory the file is currently stored in. Suppose I have a file called myRscript.r, and it's stored in C:\Rprojects\myRscript.r, and it references other R scripts and data files in the same directory. If I enter the command setwd(C:/Rprojects) I can then access all the files I need without typing the path. But suppose I want to move all of those files into another folder, say, C:\NewFolder. And suppose I might do this fairly often, or make copies of the script in several folders. Is there a command that looks something like this: setwd( look up current directory ) that will work no matter where I move my project, without having to go in and re-type the new directory path? For two solutions see: https://stat.ethz.ch/pipermail/r-help/2005-November/082347.html http://www.mail-archive.com/r-help@r-project.org/msg111871.html -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to find near neighbors?
I am looking for an efficient way to find near neighbors... More specifically... I have two sets of points: A B and I want to find points in set B which are closer to set A than some cutoff (or n-closest) I will appreciate very much any pointers... Ryszard -- Confidentiality Notice: This message is private and may ...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] aspect ratio 1 and blank space
Look at the squishplot function in the TeachingDemos package, it may do what you want, or if not quite then you could perhaps tweak the code to include the values you want and create the correct aspect ratio. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Silvia Cecere Sent: Wednesday, November 17, 2010 10:26 AM To: r-help@r-project.org Subject: [R] aspect ratio 1 and blank space Hi, I need to produce an ordinary scatter plot and it is vital that the aspect ratio equals 1. I set the axis as: plot(x, y, type=n, asp=1, ,ylim=c(-80,70),xlim=c(0,100)). The problem is that I get some 'additional' blank plot area (basically, the lower bound of xlim becomes quite negative). The xlim is not the range of the x-data, but I need the 0 there for further plotting. Any way to specify that even with asp=1, xlim=c(0,100)? 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] conditional mean between two data frames with different levels
Hi guys, I have two data frames: one referred to 2008 and one to 2009. Their structure is identical except for the different data in them. I need to create a vector alfa of the same length of the dataframe 2009 and fill each element with the mean of 2008$var1 conditional to the subgroup indicated by a factor variable in 2009$var2. In this case it would be easy to use the function alfa[i]-ave(2008$var1,2008$var2==2009$var2[i],FUN=mean). The problem is that 2008$var2 and 2009$var2 contain both 20 levels each but only 18 of them are shared. So for those 18 I need to find the result that I`d get applying the above formula (which in any case doesnt work if the levels are not identical in the two data frames colmns) and for those two different levels in 2009$var2 to use the average of the whole column 2008$var2. Anybody has some ideas? Please help me... Hope it`s clear enough what I need. Thanks! alberto -- View this message in context: http://r.789695.n4.nabble.com/conditional-mean-between-two-data-frames-with-different-levels-tp3049010p3049010.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] genralized linear regression - function glm - number of
Hello, Performing a linear regression through the function glm (yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10), I then edit the information about the coefficients: print(coefficients(summary(fit))) I note that the number of coefficients (7) is lower than the number of predictors (10). In this case, I work on simulated data for which I forced yi to be a linear function of the 10 predictors. intercept: 0.0180752965003802 predictor 1: -0.0111046268531608 predictor 2: -0.0185366138753851 predictor 3: 0.107341157096227 predictor 4: 0.00162924662836275 predictor 5: 0.00162924629403743 predictor 6: -0.0171999854554059 predictor 7: -0.0171999856835917 predictor 8: -0.057207682945982 predictor 9: -0.0171999856239631 predictor 10: 0.134643228957395 yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 Estimate Std. Error t value Pr(|t|) (Intercept) 0.018062134 5.624517e-17 3.211322e+140 X$V1-0.011104627 3.084989e-17 -3.599567e+140 X$V2-0.018536614 3.241635e-17 -5.718291e+140 X$V3 0.107341157 4.884358e-17 2.197651e+150 X$V4 0.003258493 3.286878e-17 9.913643e+130 X$V6-0.051599957 4.203840e-17 -1.227448e+150 X$V8-0.057207683 3.049835e-17 -1.875763e+150 X$V100.134643229 3.849911e-17 3.497308e+150 I am sure to have regressed the right number of variables, since I check that the formula is correct: yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 Could somebody explain to me 1) why there are mismatches between the true coefficients for predictors 4 and 6 and 2) why there is no information edited for predictors 5, 7 and 9 ? Thanks in advance for your kind help. C.S. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 Sampling question
Hi Wallace, Have you tried playing with sample()? Note that you can apply this function both to whole dataframes, as well as specific items within a vector. If you play with applying the function to different ways of indexing your sample data, you will likely arrive at your solution. for example: a-data.frame(c(1:10),c(21:30)) sample(a[,2],2) #randomly draw two numbers from a column sample(a[2,],2) #randomly draw two numbers from a row a[sample(nrow(a),5,replace=T),] #ranomly draw four whole rows with replacement You may also find subet() helpful, based on your description. HTH, Mike On Thu, Nov 18, 2010 at 9:43 AM, wangwallace talentt...@gmail.com wrote: Dear Ista Zahn-2, If you can give me some advice, I really appreciate it. I have been working on it for days. it seems hard for some novice of R like me to write flexible functions myself. This is for my dissertation. CSE and WSE are two scales of the same construct. The sampling strategy I wanted above allows me check how the items of these two scales vary within person and across person. Also, I added another rule: draw 1000 random samples... Again, Thanks! Wallace -- View this message in context: http://r.789695.n4.nabble.com/New-Sampling-question-tp3047885p3048948.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Rennie, Research Scientist Fisheries and Oceans Canada, Freshwater Institute Winnipeg, Manitoba, CANADA [[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 Sampling question
Also, I need some function at the end which would enable me to draw 1000 such random samples. thanks! :) -- View this message in context: http://r.789695.n4.nabble.com/New-Sampling-question-tp3047885p3048958.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] Odp: Sampling problem
I tried. yours works too. thanks a bounch!! Man -- View this message in context: http://r.789695.n4.nabble.com/Sampling-problem-tp3043804p3049013.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to find near neighbors?
Have a look at nncross() from the spatstat package. Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Czerminski, Ryszard Verzonden: donderdag 18 november 2010 17:10 Aan: r-help@r-project.org Onderwerp: [R] how to find near neighbors? I am looking for an efficient way to find near neighbors... More specifically... I have two sets of points: A B and I want to find points in set B which are closer to set A than some cutoff (or n-closest) I will appreciate very much any pointers... Ryszard -- Confidentiality Notice: This message is private and may ...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Updata Rdata File
?rbind Jason Kwok jayk...@gmail.com wrote: Thanks for the response Duncan. I'm sorry I wasn't clear in my question. I need to add an additional value every day to the data and not update it. I know how to load and save but I dont' know how to add data. load(file=C:\\datafile.rdata) save(data,file=C:\\datafile.rdata) Thanks. Jason On Thu, Nov 18, 2010 at 6:56 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 18/11/2010 1:49 AM, Jason Kwok wrote: How do I add data to a .rdata file? In my case, I have a time series that needs to get updated every day. Load it, update the variables, save them. Duncan Murdoch [[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. --- 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Updata Rdata File
Hi Jason, You can add as many objects as you want to save(). For instance: save(data1, data2, data3, data4, file = whatever). Once you have loaded the data, just add whatever data you want, and then save it (or edit your original object and resave it). Here is another example: ls() character(0) load(rhelp.RData) ls() [1] x ## Now I could edit, 'x' (e.g., rbind() in additional rows, etc.) ## or I could create a new variable, 'y' y - 1:10 # some new data ## from ?save save(x, y, file = rhelp.RData) ## clear space and show it is empty rm(list=ls()); ls() character(0) load(rhelp.RData) ls() [1] x y ## now both 'x' and 'y' are in the RData file ## if I had just edited x and resaved, it would be updated Cheers, Josh On Thu, Nov 18, 2010 at 7:26 AM, Jason Kwok jayk...@gmail.com wrote: Thanks for the response Duncan. I'm sorry I wasn't clear in my question. I need to add an additional value every day to the data and not update it. I know how to load and save but I dont' know how to add data. load(file=C:\\datafile.rdata) save(data,file=C:\\datafile.rdata) Thanks. Jason On Thu, Nov 18, 2010 at 6:56 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 18/11/2010 1:49 AM, Jason Kwok wrote: How do I add data to a .rdata file? In my case, I have a time series that needs to get updated every day. Load it, update the variables, save them. Duncan Murdoch [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] genralized linear regression - function glm - number of
On Nov 18, 2010, at 11:00 AM, Christine SINOQUET wrote: Hello, Performing a linear regression through the function glm (yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10), I then edit the information about the coefficients: print(coefficients(summary(fit))) I note that the number of coefficients (7) is lower than the number of predictors (10). In this case, I work on simulated data for which I forced yi to be a linear function of the 10 predictors. What code was used to make the simulation? intercept: 0.0180752965003802 predictor 1: -0.0111046268531608 predictor 2: -0.0185366138753851 predictor 3: 0.107341157096227 predictor 4: 0.00162924662836275 predictor 5: 0.00162924629403743 predictor 6: -0.0171999854554059 predictor 7: -0.0171999856835917 predictor 8: -0.057207682945982 predictor 9: -0.0171999856239631 predictor 10: 0.134643228957395 yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 Estimate Std. Error t value Pr(|t|) (Intercept) 0.018062134 5.624517e-17 3.211322e+140 X$V1-0.011104627 3.084989e-17 -3.599567e+140 X$V2-0.018536614 3.241635e-17 -5.718291e+140 X$V3 0.107341157 4.884358e-17 2.197651e+150 X$V4 0.003258493 3.286878e-17 9.913643e+130 X$V6-0.051599957 4.203840e-17 -1.227448e+150 X$V8-0.057207683 3.049835e-17 -1.875763e+150 X$V100.134643229 3.849911e-17 3.497308e+150 I am sure to have regressed the right number of variables, since I check that the formula is correct: yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 Could somebody explain to me 1) why there are mismatches between the true coefficients for predictors 4 and 6 and Your std errors are incredibly small (effectively zero from a numerical perspective) suggesting you have created a dataset with extremely small amounts of noise. The coefficients are different (than expected) because of the answer to the next question. 2) why there is no information edited for predictors 5, 7 and 9 ? You most likely had each of those set up as a linear combination of the retained predictors. Collinear variables are dropped and usually there is a warning, bust since you have not given a console session I cannot be sure. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems subsetting
Hi, On Thu, Nov 18, 2010 at 10:42 AM, Martin Tomko martin.to...@geo.uzh.ch wrote: Thanks Steve, that explains it... Unfortunately, I did nto get that from my R docs... I am still searching for a solution for matching the entries in my matrix by matching the rownames to the entires in a subset I got using Gerrit's method. Can you please provide a sample dataset with the code/questions you are trying to answer. I'm not sure what I get (if anything) from your problem 2. Make a toy matrix + data.frame. Say you have a data.frame df, call `dpaste(df)` and it will print a text representation of your object which you could paste into an email. We could then copy / paste it in an R session to recover your data objects and provide working code. The point is, make it easy for someone to help you and they will. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 Sampling question
You could try writing a loop a-data.frame(c(1:10),c(21:30)) M-10 #number of iterations- scale up to 1000 once you get your sampling function working res-NULL #place to store your results for i in (1:M) { ares-sample(a[,2],1) res-c(res, ares) } res It's up to you how to store your results- you can do it as a list if you want, then you can get at each of your 1000 results. I've provided a simple example where you just add each result to the end of your vector. Note also that someone will also take issue with the way I'm assigning results in the loop- I know I've seen it written elsewhere that this is not a very elegant way of approaching the problem (particularly in terms of efficiency), but it will work. I just can't recall the other way of doing things off the top of my head- if someone else would like to chime in, be my guest. Mike On Thu, Nov 18, 2010 at 9:46 AM, wangwallace talentt...@gmail.com wrote: Also, I need some function at the end which would enable me to draw 1000 such random samples. thanks! :) -- View this message in context: http://r.789695.n4.nabble.com/New-Sampling-question-tp3047885p3048958.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Rennie, Research Scientist Fisheries and Oceans Canada, Freshwater Institute Winnipeg, Manitoba, CANADA [[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] conditional mean between two data frames with different levels
Hi Alberto, It would help if you could provide a small example. I might break the problem down into three parts: 1) create a vector that has the final subgroupings you want 2) find the conditional means by subgroup 3) replicate the means as needed. My first guess would be start with: == or %in% to compare or find levels from 2008 %in% 2009 by(Data, GroupingVar, FUN = mean) This is probably not the best way, but since GroupingVar should be a factor, I would be tempted to do: tmp - (factor(GroupingVar, levels = levels(GroupingVar), labels = ResultsofByCall) YourMeans - as.numeric(levels(tmp))[tmp] as a way to map the means back to their appropriate subcondition replicated as many times as necessary. I'm sure you will get more detailed help if you can post a bit of sample data. HTH, Josh On Thu, Nov 18, 2010 at 8:10 AM, albechan alberto.case...@satt.biz wrote: Hi guys, I have two data frames: one referred to 2008 and one to 2009. Their structure is identical except for the different data in them. I need to create a vector alfa of the same length of the dataframe 2009 and fill each element with the mean of 2008$var1 conditional to the subgroup indicated by a factor variable in 2009$var2. In this case it would be easy to use the function alfa[i]-ave(2008$var1,2008$var2==2009$var2[i],FUN=mean). The problem is that 2008$var2 and 2009$var2 contain both 20 levels each but only 18 of them are shared. So for those 18 I need to find the result that I`d get applying the above formula (which in any case doesnt work if the levels are not identical in the two data frames colmns) and for those two different levels in 2009$var2 to use the average of the whole column 2008$var2. Anybody has some ideas? Please help me... Hope it`s clear enough what I need. Thanks! alberto -- View this message in context: http://r.789695.n4.nabble.com/conditional-mean-between-two-data-frames-with-different-levels-tp3049010p3049010.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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stacking consecutive columns
On Wed, Nov 17, 2010 at 10:37 AM, Graves, Gregory ggra...@sfwmd.gov wrote: Follows is the exact solution to this: v - NULL #note that decreasing is FALSE so preceding year preceeds for(i in 2:46) { kk - melt(yearmonth[, c(1, i, i+1)], id.vars=month, variable_name=year) v[[i-1]] - kk[order(kk$year, decreasing=FALSE),] } x - do.call(cbind, v) write.table(x,clipboard,sep= ,col.names=NA) #export to Excell via Ctrl-V I get an error when I run that code so I am not completely sure precisely what the order of columns etc. should be but here is a solution that can be tweaked that uses zoo's ability to use vector lags which seems reasonably straight forward. First we create a ts series, s and then cbind it with year and month giving s3. Then we use zoo's lag function together with the vector of lags 0, 12, 24, ... Finally use write table to create a csv file and run the csv file (which under the default set up in Windows launches Excel and reads it in). If yearmonth is a matrix rather than a data frame or if you want reversed rows or columns use the appropriate commented out lines. # create a ts series, s, and then cbind it with the year and month giving s3 # s - ts(c(yearmonth[, -seq(2)]), start = c(2001, 1), freq = 12) s - ts(unlist(yearmonth[, -seq(2)]), start = c(2001, 1), freq = 12) s3 - cbind(year = floor(time(s)), month = cycle(s), s) # use zoo's lag to create the desired layout library(zoo) numyears - length(s) / 12 # sl - na.omit(lag(as.zoo(s3), seq((numyears-2)*12, 0, -12))) sl - na.omit(lag(as.zoo(s3), seq(0, (numyears-2)*12, 12))) # time(sl) - - time(sl) write.table(sl, file = out.csv, row.names = FALSE, col.names = rep(c(year, month, value), length = ncol(sl)), sep = ,) shell(out.csv) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how exactly does 'identify' work?
I think that your problem comes from a misunderstanding. The general rule is that you give the plot command 2 vectors, x and y (though you can give it the vectors separately, or together in a list or matrix). If you give plot only a single vector then it will use this as the y vector and use the sequence of integers from 1 to the length of y as the x variable. Now in your example that matches your x exactly. In your working examples you either give the function both x and y, or only y and the generated sequence for x happens to match your x for this specific example, but not in general. For your non-working examples you give only the x variable, which is then used as the y variable and the sequence is generated for x, so it will only identify points along the diagonal. It does not know where to find your y variable. The fix, always give both x and y (the fact that your examples worked with only y is due to your specific example, not anything general). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of casperyc Sent: Tuesday, November 16, 2010 5:03 PM To: r-help@r-project.org Subject: [R] how exactly does 'identify' work? Hi all, # test=data.frame(x=1:26,y=-23.5+0.45*(1:26)+rnorm(26)) rownames(test)=LETTERS[1:26] attach(test) #test test.lm=lm(y~x) plot(test.lm,2) identify(test.lm$res,,row.names(test)) # not working plot(x,y) identify(x,y,row.names(test)) # works fine identify(y,,row.names(test)) # works fine identify(x,,row.names(test)) # not working identify(y,,y) # works identify(x,,y) # not working # My guess is that identify take the object 'x' ( the first argument ) is the thing that on the y axis. However, i have tried many many ways trying to get the LETTERS to be identified in the QQ-plot (plot(test.lm,2)) it never works. I have even tried to extract the standardized residual using library(MASS), the 'stdres' function, and put it as the first argument in identify, still failed... Is there any means to achieve this? Thanks! casper -- View this message in context: http://r.789695.n4.nabble.com/how- exactly-does-identify-work-tp3045953p3045953.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] problems subsetting
Hi Martin, I think Steve meant dput(df), as I already told you Ivan Le 11/18/2010 17:40, Steve Lianoglou a écrit : Hi, On Thu, Nov 18, 2010 at 10:42 AM, Martin Tomkomartin.to...@geo.uzh.ch wrote: Thanks Steve, that explains it... Unfortunately, I did nto get that from my R docs... I am still searching for a solution for matching the entries in my matrix by matching the rownames to the entires in a subset I got using Gerrit's method. Can you please provide a sample dataset with the code/questions you are trying to answer. I'm not sure what I get (if anything) from your problem 2. Make a toy matrix + data.frame. Say you have a data.frame df, call `dpaste(df)` and it will print a text representation of your object which you could paste into an email. We could then copy / paste it in an R session to recover your data objects and provide working code. The point is, make it easy for someone to help you and they will. -steve -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] kalman filter in sspir
To learn why sspir does not have a filter function, you need to ask the package maintainer, Claus Dethlefsen c...@rn.dk. My belief is that he, Soren Lundbye-Christensen and Anette Luther Christensen found other outlets for their time since they completed the package and the companion paper, C. Dethlefsen and S. Lundbye-Christensen. Formulating state space models in r with focus on longitudinal regression models. Journal of Statistical Software, 16(1), 2006. R works on volunteers. If you know someone willing and able to write such a function, I suggest you contact Dethlefsen to see if they are willing to put the package on R-Forge and permit others to contribute to the package. If they decline, you can create your own package, e.g., sspirPlus, that would add the desired filter function. Hope this helps. Spencer On 11/17/2010 11:49 AM, feder wrote: Hi, I used sspir for managing non-gaussian State space models but I observed that for such models only the smoother is gave while the filter is missing. Why? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] dmultinomial
Hello All, I'm trying to run a maximum likelihood analysis using dmultinomial (i'm avoiding dmultinom as I'd like to run it with vectors for the ML stuff). However, I'm having a hard time getting even the simplest example running. Any help would be greatly appreciated. library(mc2d) dmultinomial(x=c(0,0,1),prob=c(1,1,1),size=1,log=TRUE) Error in if (ncol(x) != K) stop(x[] and prob[] must be equal length vectors or equal col matrix.) : argument is of length zero # Once I get the simple stuff above running, I'd like to be able to do the following: testmat=rmultinomial(4, 1, prob) testmat [,1] [,2] [,3] [1,]100 [2,]001 [3,]001 [4,]001 dmultinomial(x=testmat,prob=prob,size=1,log=TRUE) Error in if (!is.null(size) nrow(size) != n) size - matrix(t(size), : missing value where TRUE/FALSE needed thanks, allie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems subsetting
On Nov 18, 2010, at 10:42 AM, David Winsemius wrote: On Nov 18, 2010, at 10:25 AM, Martin Tomko wrote: Hi Gerrit, indeed, that works. Excellent tip! For reference, I did this: subset1-subset(summarystats,(Type==1)(Class==1)(Category==1)) I am still not totally sure when one uses amd when - I was under the impression that stands for logical AND Both stand for logical AND. is used for vectorized comparisons, while will only compare the first elements of the two sides (usually, but apparently not always) with a warning if there are longer objects than expected. A little bird (actually more like an eagle in these parts) has suggested that I mention that the reason for two different types of logical operators is not just for confusing the unwary, but rather because the /|| versions will not evaluate its second argument if its first argument is TRUE. Since this form is mostly used within the if( ... ... ){} else{} construction, there can be increased efficiency when the second argument is an involved function. It won't need to be evaluated if the first argument to is FALSE or the first to || is TRUE. -- David. c(1,0,1,0,1) c(0,0,1,1,-1) [1] FALSE FALSE TRUE FALSE TRUE c(1,0,1,0,1) c(0,0,1,1,-1) [1] FALSE c(1,0,1,0,1) c(1,0,1,1,-1) [1] TRUE -- David. Thanks a lot. Martin On 11/18/2010 3:58 PM, Gerrit Eichner wrote: Hello, Martin, as to your first problem, look at function subset(), and particularly at its argument subset. HTH, Gerrit On Thu, 18 Nov 2010, Martin Tomko wrote: Dear all, I have searched the forums for an answer - and there is plenty of questions along the same line - but none of the paproaches shown worked to my problem: I have a data frame that I get from a csv: summarystats-as.data.frame(read.csv(file=f_summary)); where I have the columns Dataset, Class, Type, Category,.. Problem1: I want to find a subset of this frame, based on values in multiple columns What I do currently is: subset1 - summarystats subset1-subset1[subset1$Class == 1,] subset1-subset1[subset1$Type == 1,] subset1-subset1[subset1$Category == 1,] Now, this works, but is UGLY! I tried using or , for isntance : subset1-subset1[ (subset1$Class == 1) (subset1$Category == 1),] but it returns an empty data frame. Anyway, the main problem is Problem2: I have a second data frame - a square matrix (rownames == colnames), distm: distm-read.table(file=f_simmatrix, sep = ,); what I want is select ONLY the columns and rows entries matching the above subset1: subset2-distm[subset1$Dataset,subset1$Dataset] returns a matrix of correct size, but with incorrect entries (established by visual inspection). this is the same as: selectedrows-as.vector(subset1$Dataset) subset2-distm[selectedrows,selectedrows] also verified using: rownames(subset2)%in% selectedrows [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE What am I missing? Thanks Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/ eichner - -- Martin Tomko Postdoctoral Research Assistant Geographic Information Systems Division Department of Geography University of Zurich - Irchel Winterthurerstr. 190 CH-8057 Zurich, Switzerland email: martin.to...@geo.uzh.ch site: http://www.geo.uzh.ch/~mtomko mob:+41-788 629 558 tel:+41-44-6355256 fax:+41-44-6356848 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list
[R] lme Random Effects and Covariates
1. I'm attempting to test for Random Effects. I've grouped the data on subject (grid) but want to use lme to build the model without subject as a RE then add it and do anova between the 2 models. This is the result I get and it appears it's adding Random Effects. tmp.dat4 - groupedData(Trials ~ 1 | grid, data = tmp.dat4) mod2a - lme(Trials ~ factor(group_id) + reversal, data = tmp.dat4, na.action = na.omit, method = REML) summary(mod2a) Linear mixed-effects model fit by REML Data: tmp.dat4 AIC BIClogLik 4544.054 4587.718 -2262.027 Random effects: Formula: ~factor(group_id) + reversal | grid Structure: General positive-definite StdDevCorr (Intercept) 10.505303 (Intr) fc(_)2 factor(group_id)2 9.830679 -0.778 reversal2 7.106839 -0.275 0.023 Residual 9.995963 Fixed effects: Trials ~ factor(group_id) + reversal Value Std.Error DF t-value p-value (Intercept) 23.275874 1.876185 510 12.405960 0e+00 factor(group_id)2 -7.639842 2.151004 72 -3.551757 7e-04 reversal2 7.681495 1.206858 510 6.364869 0e+00 Correlation: (Intr) fc(_)2 factor(group_id)2 -0.785 reversal2 -0.308 -0.015 Standardized Within-Group Residuals: Min Q1Med Q3Max -2.6884393 -0.5059063 -0.1892908 0.4944976 2.8477377 Number of Observations: 585 Number of Groups: 74 2. Secondly is this the correct way to add covariates (such as age). mod2i - lme(Trials ~ factor(group_id)*factor(reversal) * age, data = tmp.dat4, random = ~ 1 | grid, na.action = na.omit, method = ML) -- View this message in context: http://r.789695.n4.nabble.com/lme-Random-Effects-and-Covariates-tp3049181p3049181.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] Logistic regression with factorial effect
Hello, I’d like to evaluate the temporal effect on the relationship between a continuous variable (e.g. size) and the probability of mate success. Initially I was trying to do a logistic regression model incorporating the temporal effect, but I don’t know if that is the best option. I simulated some data and that’s the problem: rep(c(Jan,Feb,Mar,Apr,May), each=20) - month as.factor(month) rep(LETTERS[seq(1:20)], 5) - ind rep(sort(rnorm(20, 5.5, 0.2)), 5) - size size c(c(rep(0,12), rep(1,8)), c(rep(0,12), rep(1,8)), c(rep(c(0,1), 10)), c(rep(1,8), rep(0,12)), c(rep(1,8), rep(0,12))) - success1 success1 With the object ‘success1’, only the highest values of size are successful at the two first months, but only the lowest values of size are successful at the two last months. So, the overall effect of size on the successful probability should not exist, but if we consider the interaction between size and time, we should be able to see that effect. glm(success1 ~ size, family=binomial) - test1.1 glmer(success1 ~ size + (1|ind), family=binomial) - test2.1 glmer(success1 ~ size + month + (1|ind), family=binomial) - test3.1 glmer(success1 ~ size : month + (1|ind), family=binomial) - test4.1 However, the expected result is not observed in the output of all these models. Using a model selection approach and comparing the AIC values of all models, it seems that ‘test1.1’ model is the most likely. All the deviances are almost at the same level and the differences in AIC values are due for the new parameters added. Given the data was simulated to generate differences between models and model ‘test4.1’ is supposed to be the best one, I’m probably doing something wrong. Has anyone faced this kind of problem? Or has anyone any idea how to solve that? Thanks and Regards Gustavo Requena PhD student - Laboratory of Arthropod Behavior and Evolution Universidade de São Paulo http://ecologia.ib.usp.br/opilio/gustavo.html -- View this message in context: http://r.789695.n4.nabble.com/Logistic-regression-with-factorial-effect-tp3049208p3049208.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] predict() an rpart() model: how to ignore missing levels in a factor
I am using an algorigm to split my data set into two random sections repeatedly and constuct a model using rpart() on one, test on the other and average out the results. One of my variables is a factor(crop) where each crop type has a code. Some crop types occur infrequently or singly. when the data set is randomly split, it may be that the first data set has a crop type which is not present in the second and so using predict() I get the error: Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = attr(object, : factor 'factor(c2001)' has new level(s) 13, 24, 35 where c2001 is the crop. I would like the predict function to ignore these records. is there a command which will allow this as part of the predict() function? With those with a small number of records (eg. 3-4), I would hope some of the models would have the right balance to allow a prediction to be made. -- View this message in context: http://r.789695.n4.nabble.com/predict-an-rpart-model-how-to-ignore-missing-levels-in-a-factor-tp3049218p3049218.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] Sample covariance matrix in R
Hello everyone. I would like to find the sample covariance matrix using R. So far I read on the wikipedia what a sample_covariance is http://en.wikipedia.org/wiki/Sample_covariance according to wikipedia one vector is enough to calculate the sample covariance matrix. In R I tried cov(myvector) and I get the reply that I need to pass either two argument or one matrix with x,y values . How can I find the sample covariance matrix? Best Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with lmer, nested data and repeated measures
Dear all, I'm discovering the somehow confusing (for me) world of linear mixed models after having been advised it could be the best option to analyze my dataset. After several days of reading, I'm not sure that what I ended up with makes some sense and I'd greatly appreciate any help and explanations. The dataset has been obtained as follows. In 15 different locations, I counted during 10 seconds the number of ants crossing a gap, before and after destroying a bridge that ants had previously built over the gap. I then waited for the ants to rebuild the bridge and repeated two more times the counting and destroying process. Therefore, for each gap observed, I have 3 replicates of the same experiment, each of them providing 1 count value for each treatment tested (before and after bridge destruction), i.e. 6 values in total per gap. I also measured for each gap its length. I now want to model the effect of the gap length (GapLength, continuous variable), the treatment (Treatment, categorical variable) and the replicate position (Replicate, categorical variable) on the number of ants crossing the gap (AntCount, count variable). As far as I understand, the gap (Gap) can be treated here as a random effect, the gap length, the treatment and the replicate position as fixed effects. Moreover, the treatment variable is nested in the replicate position variable that is also nested in the gap variable. Finally, since I have count data, a poisson distribution should be used for the model. With all this information in mind and some additional information from various sources, I ended up with the following R code: lmer(AntCount ~ Treatment + GapLength + (Treatment | Gap / Replicate) + (GapLength | Gap), data=dat, family=poisson(link=log)) The code runs fine and does not return any error. But of course this does not mean the model was correctly designed. Am I right when I'm doing this or am I (most likely) completely wrong? Thanks in advance for your help. Best, Simon. -- Dr. Simon Garnier Department of Ecology Evolutionary Biology Princeton University Guyot Hall e-mail: sgarn...@princeton.edu / simon.garn...@gmail.com website: http://www.simongarnier.com photoblog: http://www.simongarnier.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with lmer, nested data and repeated measures
You would be better off posting to R-sig-mixed-models or R-sig-ecology -- Bert On Thu, Nov 18, 2010 at 9:58 AM, Simon Garnier sgarn...@princeton.edu wrote: Dear all, I'm discovering the somehow confusing (for me) world of linear mixed models after having been advised it could be the best option to analyze my dataset. After several days of reading, I'm not sure that what I ended up with makes some sense and I'd greatly appreciate any help and explanations. The dataset has been obtained as follows. In 15 different locations, I counted during 10 seconds the number of ants crossing a gap, before and after destroying a bridge that ants had previously built over the gap. I then waited for the ants to rebuild the bridge and repeated two more times the counting and destroying process. Therefore, for each gap observed, I have 3 replicates of the same experiment, each of them providing 1 count value for each treatment tested (before and after bridge destruction), i.e. 6 values in total per gap. I also measured for each gap its length. I now want to model the effect of the gap length (GapLength, continuous variable), the treatment (Treatment, categorical variable) and the replicate position (Replicate, categorical variable) on the number of ants crossing the gap (AntCount, count variable). As far as I understand, the gap (Gap) can be treated here as a random effect, the gap length, the treatment and the replicate position as fixed effects. Moreover, the treatment variable is nested in the replicate position variable that is also nested in the gap variable. Finally, since I have count data, a poisson distribution should be used for the model. With all this information in mind and some additional information from various sources, I ended up with the following R code: lmer(AntCount ~ Treatment + GapLength + (Treatment | Gap / Replicate) + (GapLength | Gap), data=dat, family=poisson(link=log)) The code runs fine and does not return any error. But of course this does not mean the model was correctly designed. Am I right when I'm doing this or am I (most likely) completely wrong? Thanks in advance for your help. Best, Simon. -- Dr. Simon Garnier Department of Ecology Evolutionary Biology Princeton University Guyot Hall e-mail: sgarn...@princeton.edu / simon.garn...@gmail.com website: http://www.simongarnier.com photoblog: http://www.simongarnier.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Logistic regression with factorial effect
You would be better off posting to R-sig-mixed-models or R-sig-ecology -- Bert On Thu, Nov 18, 2010 at 9:32 AM, Billy.Requena billy.requ...@gmail.com wrote: Hello, I’d like to evaluate the temporal effect on the relationship between a continuous variable (e.g. size) and the probability of mate success. Initially I was trying to do a logistic regression model incorporating the temporal effect, but I don’t know if that is the best option. I simulated some data and that’s the problem: rep(c(Jan,Feb,Mar,Apr,May), each=20) - month as.factor(month) rep(LETTERS[seq(1:20)], 5) - ind rep(sort(rnorm(20, 5.5, 0.2)), 5) - size size c(c(rep(0,12), rep(1,8)), c(rep(0,12), rep(1,8)), c(rep(c(0,1), 10)), c(rep(1,8), rep(0,12)), c(rep(1,8), rep(0,12))) - success1 success1 With the object ‘success1’, only the highest values of size are successful at the two first months, but only the lowest values of size are successful at the two last months. So, the overall effect of size on the successful probability should not exist, but if we consider the interaction between size and time, we should be able to see that effect. glm(success1 ~ size, family=binomial) - test1.1 glmer(success1 ~ size + (1|ind), family=binomial) - test2.1 glmer(success1 ~ size + month + (1|ind), family=binomial) - test3.1 glmer(success1 ~ size : month + (1|ind), family=binomial) - test4.1 However, the expected result is not observed in the output of all these models. Using a model selection approach and comparing the AIC values of all models, it seems that ‘test1.1’ model is the most likely. All the deviances are almost at the same level and the differences in AIC values are due for the new parameters added. Given the data was simulated to generate differences between models and model ‘test4.1’ is supposed to be the best one, I’m probably doing something wrong. Has anyone faced this kind of problem? Or has anyone any idea how to solve that? Thanks and Regards Gustavo Requena PhD student - Laboratory of Arthropod Behavior and Evolution Universidade de São Paulo http://ecologia.ib.usp.br/opilio/gustavo.html -- View this message in context: http://r.789695.n4.nabble.com/Logistic-regression-with-factorial-effect-tp3049208p3049208.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sweep by levels of a factor
Thank you very much, Tony L. On 18 November 2010 14:02, Lancaster, Anthony anthony_lancas...@brown.eduwrote: Hi, I'd appreciate help with this. I have a data matrix with one column, called f in the example below, a factor. I'd like to subtract the means from each of other columns for each level of the factor. That is, in the example, to go from the first matrix below to the second. I know SWEEP will take out means, but I want to do this for each level of the factor. fx 1 2 1 0 2 0 2 4 2 2 f xnew 11 1 -1 2 -2 22 2 0 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] conditional mean between two data frames with different levels
Thank you very much Josh, I guess you`re right. So this is an example: data frame 1 has 2 columns and 10 rows. The first column is score a variable indicating the number of goals scored by a football team score-c(1,2,0,2,1,1,3,2,1,0), column 2 contains the football teams where teams-c(a,b,c,d,e,a,b,c,d,e). Data frame 2 has the following variables: score-c(2,3,1,0,0,0,4,2,1,2) and teams-c(b,c,d,e,f,b,c,d,e,f). What I need is to create a vector alfa-numeric(10) where the first element contains the mean of the number of goals scored by team b in the previous season, the second element contains the mean of the number of goals scored by team c in the previous season and so on. In correspondance of team f, the average of the whole score vector of the previous season. alfa should be (2.5, 1, 1.5, 0.5, 1.3, 2.5, 1, 1.5, 0.5, 1.3) The problem arises because f doesnt appear in the first data frame as it replaced a. Hope the issue is more understandable now. Thanks a lot! alberto -- View this message in context: http://r.789695.n4.nabble.com/conditional-mean-between-two-data-frames-with-different-levels-tp3049010p3049171.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] New Sampling question
Hi, Mike, thank you very much!!:) the following two functions are really helpful, which I didn't even know. Actually, I searched the forum for something like this, but failed. Now I am still trying to make up my own functions. :) sample(a[,2],2) #randomly draw two numbers from a column sample(a[2,],2) #randomly draw two numbers from a row -- View this message in context: http://r.789695.n4.nabble.com/New-Sampling-question-tp3047885p3049083.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] Looking up the directory a file is located in
Thanks, Gabor! So far I like this one best: https://stat.ethz.ch/pipermail/r-help/2005-November/082347.html So if my script is called myRscript.r, I can do the following: this.file = parent.frame(2)$ofile this.dir = gsub(/myRscript.r, , this.file) setwd(this.dir) This will set the working directory to the the directory that myRscript.r lives in, no matter where I move the script. It's nice that it can be done in only three lines of code, although it's not yet a perfect solution, since it won't work if I change the name of the script. But that's easy to take care of if I just do some slightly more sophisticated string manipulation (which I'm terrible at doing off the top of my head). -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3049113.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] RowSums Question
I have a question on RowSums. Lets say i have a timeSeries table A B C 1/1/90 NA 1 1 1/2/90 NA 1 1 1/3/90 NA 1 1 1/4/90 NA 1 1 1/5/901 1 1 1/6/901 1 1 if i use RowSums, i will get 1/5/903 1/6/903 but i want 1/1/90 2 1/2/90 2 1/3/90 2 1/4/90 2 1/5/90 3 1/6/90 3 I cant figure out a way without doing loop. Thanks Cameron -- View this message in context: http://r.789695.n4.nabble.com/RowSums-Question-tp3049261p3049261.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] sweep by levels of a factor
Try this also: x$x - ave(x$x, x$f) On Thu, Nov 18, 2010 at 12:02 PM, Lancaster, Anthony anthony_lancas...@brown.edu wrote: Hi, I'd appreciate help with this. I have a data matrix with one column, called f in the example below, a factor. I'd like to subtract the means from each of other columns for each level of the factor. That is, in the example, to go from the first matrix below to the second. I know SWEEP will take out means, but I want to do this for each level of the factor. fx 1 2 1 0 2 0 2 4 2 2 f xnew 11 1 -1 2 -2 22 2 0 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sample covariance matrix in R
Alex: ?cov -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios Sent: Thursday, November 18, 2010 12:54 PM To: Rhelp Subject: [R] Sample covariance matrix in R Hello everyone. I would like to find the sample covariance matrix using R. So far I read on the wikipedia what a sample_covariance is http://en.wikipedia.org/wiki/Sample_covariance according to wikipedia one vector is enough to calculate the sample covariance matrix. In R I tried cov(myvector) and I get the reply that I need to pass either two argument or one matrix with x,y values . How can I find the sample covariance matrix? Best Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RowSums Question
Try this: rowSums(tsObj, na.rm = TRUE) On Thu, Nov 18, 2010 at 3:58 PM, cameron raymond...@invesco.com wrote: I have a question on RowSums. Lets say i have a timeSeries table A B C 1/1/90 NA 1 1 1/2/90 NA 1 1 1/3/90 NA 1 1 1/4/90 NA 1 1 1/5/901 1 1 1/6/901 1 1 if i use RowSums, i will get 1/5/903 1/6/903 but i want 1/1/90 2 1/2/90 2 1/3/90 2 1/4/90 2 1/5/90 3 1/6/90 3 I cant figure out a way without doing loop. Thanks Cameron -- View this message in context: http://r.789695.n4.nabble.com/RowSums-Question-tp3049261p3049261.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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sample covariance matrix in R
The help and its examples are very comprehensive here. The usage you cite shows exactly what you need to do From: Alaios [mailto:ala...@yahoo.com] Sent: Thursday, November 18, 2010 1:30 PM To: Doran, Harold Subject: RE: [R] Sample covariance matrix in R Checked that Usage covr(x, y = NULL, na.rm = FALSE, use) as you can see expectes two inputs ,,, or one with two columns.. I also found intresting this The denominator n - 1 is used which gives an unbiased estimator of the (co)variance for i.i.d. observations\ but I do not know how to use this inside the cov to get wjhat I am lloking for. Regards Alex --- On Thu, 11/18/10, Doran, Harold hdo...@air.org wrote: From: Doran, Harold hdo...@air.org Subject: RE: [R] Sample covariance matrix in R To: Alaios ala...@yahoo.com, Rhelp r-help@r-project.org Date: Thursday, November 18, 2010, 6:26 PM Alex: ?cov -Original Message- From: r-help-boun...@r-project.org/mc/compose?to=r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org/mc/compose?to=r-help-boun...@r-project.org] On Behalf Of Alaios Sent: Thursday, November 18, 2010 12:54 PM To: Rhelp Subject: [R] Sample covariance matrix in R Hello everyone. I would like to find the sample covariance matrix using R. So far I read on the wikipedia what a sample_covariance is http://en.wikipedia.org/wiki/Sample_covariance according to wikipedia one vector is enough to calculate the sample covariance matrix. In R I tried cov(myvector) and I get the reply that I need to pass either two argument or one matrix with x,y values . How can I find the sample covariance matrix? Best Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org/mc/compose?to=r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Looking up the directory a file is located in
On 18/11/2010 11:56 AM, Cliff Clive wrote: Thanks, Gabor! So far I like this one best: https://stat.ethz.ch/pipermail/r-help/2005-November/082347.html So if my script is called myRscript.r, I can do the following: this.file = parent.frame(2)$ofile this.dir = gsub(/myRscript.r, , this.file) setwd(this.dir) This will set the working directory to the the directory that myRscript.r lives in, no matter where I move the script. It's nice that it can be done in only three lines of code, although it's not yet a perfect solution, since it won't work if I change the name of the script. But that's easy to take care of if I just do some slightly more sophisticated string manipulation (which I'm terrible at doing off the top of my head). You can use the dirname() function to remove the filename from the path, you don't need to know the filename. But you are making some strong assumptions in this code that may not hold: - that your script was invoked by source(), rather than piping into R, or using Rscript, or R CMD BATCH... - that source() has a local variable named ofile (which it does, but it might not in the future) I would say it's bad practice for your script to change directories and not restore the old one, but that's a matter of taste. I think the other solutions you were offered are better than this one. 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] predict() an rpart() model: how to ignore missing levels in a factor
I don't think that, considering the mechanism behind recursive partitioning, that there is any way for you to ignore the crop factor if it is not in the original test set. What decision should be made if, for instance, the next split in a decision tree were on crops and output was 5 for apples, 6 for bananas, and you had an instance of jicamas? It can't ignore the crop factor at that point since the next decision hinges on it. What I think you can do, however, is pre-trim your test set by testing whether each factor is present in the first set with something like (UNTESTED): test.set - test.set[test.set$crop %in% original.set$crop,] -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 11/18/2010 12:35:41 PM: [image removed] [R] predict() an rpart() model: how to ignore missing levels in a factor jamessc to: r-help 11/18/2010 12:37 PM Sent by: r-help-boun...@r-project.org I am using an algorigm to split my data set into two random sections repeatedly and constuct a model using rpart() on one, test on the other and average out the results. One of my variables is a factor(crop) where each crop type has a code. Some crop types occur infrequently or singly. when the data set is randomly split, it may be that the first data set has a crop type which is not present in the second and so using predict() I get the error: Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = attr(object, : factor 'factor(c2001)' has new level(s) 13, 24, 35 where c2001 is the crop. I would like the predict function to ignore these records. is there a command which will allow this as part of the predict() function? With those with a small number of records (eg. 3-4), I would hope some of the models would have the right balance to allow a prediction to be made. -- View this message in context: http://r.789695.n4.nabble.com/predict- an-rpart-model-how-to-ignore-missing-levels-in-a-factor-tp3049218p3049218.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] how exactly does 'identify' work?
Hi, I think the problem is 1 - when a linear model is fitted, ploting the qqnorm( test.lm$ res ) we dont 'know' what values are actually being used on the y-axis; and how do we refer to the ‘Index’ on the x-axis?? therefore, i dont know how to refer to the x and y coordinates in the identify function 2 - i have tried using the stdres function in the MASS library, to extract the standardised residuals and plot them manully, ( using the plot ) function. this way, the problem is we have to SORT the residuals first in increasing order to reproduce the same qqnorm plot, in that case, 'identify' function works, however, that CHANGES the order, i.e. it wont return the original A:Z ( row.names ) label. -- View this message in context: http://r.789695.n4.nabble.com/how-exactly-does-identify-work-tp3045953p3049357.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] generalized linear regression - function glm - dismissed predictors - more information about simulated data
Hello, a) Thanks a lot for the answer relative to the dismissed coefficients. However, the result below has been obtained in the R console and there was no warning (please, see the full display below (***) if you wish). yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 Estimate Std. Error t value Pr(|t|) (Intercept) 0.018062134 5.624517e-17 3.211322e+140 X$V1-0.011104627 3.084989e-17 -3.599567e+140 X$V2-0.018536614 3.241635e-17 -5.718291e+140 X$V3 0.107341157 4.884358e-17 2.197651e+150 X$V4 0.003258493 3.286878e-17 9.913643e+130 X$V6-0.051599957 4.203840e-17 -1.227448e+150 X$V8-0.057207683 3.049835e-17 -1.875763e+150 X$V100.134643229 3.849911e-17 3.497308e+150 b) Would it be wise to check if the predictors are colinear, prior to running the glm function ? How could it be performed, using the R language? In additoon, in the present case, I would like to check for colinearity, because I am puzzled by the absence of warning inthe R console. c) I now answer the question relative to the very low std errors and the way I generated the simulated data : I ran the following code : * drawRegressionCoefficientsAndUpdateY - function (target, marks, nbInd){ # X (individuals x marks) # y (nbTargets x individuals) l - length(marks) sigma - runif(1,0.03,0.08) # Values close to 0 are excluded from c0 simulation interval so that the effect of the predictors are detectable. c01- runif(1,-2,-0.5) c02- runif(1,0.5,2) i - runif(1,1:2) if (i==1) c0 - c01 else c0 - c02 coefficients - c() for(r in 1:l){ coefficient - runif(1,0.2+sigma,1+sigma) coefficients - c(coefficients, coefficient) } // TILL THAT POINT, I RELIED ON THE PROCESS DESCRIBED IN A THESIS. // THERE WAS NO INDICATION RELATIVE TO THE ADJUSTMENT OF EPSILON. epsilon - rnorm(1, mean = 0, sd = 0.002) for (ind in 1:nbInd){ y[target,ind]- c0 + coefficients %*% X[ind,SNPs] + epsilon } Thank you in advance for your kind help. C.S. yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 Estimate Std. Error t value Pr(|t|) (Intercept) 0.018062134 5.624517e-17 3.211322e+140 X$V1-0.011104627 3.084989e-17 -3.599567e+140 X$V2-0.018536614 3.241635e-17 -5.718291e+140 X$V3 0.107341157 4.884358e-17 2.197651e+150 X$V4 0.003258493 3.286878e-17 9.913643e+130 X$V6-0.051599957 4.203840e-17 -1.227448e+150 X$V8-0.057207683 3.049835e-17 -1.875763e+150 X$V100.134643229 3.849911e-17 3.497308e+150 I am sure to have regressed the right number of variables, since I check that the formula is correct: yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 Could somebody explain to me 1) why there are mismatches between the true coefficients for predictors 4 and 6 and 2) why there is no information edited for predictors 5, 7 and 9 ? Thanks in advance for your kind help. C.S. (***) Full console display ; inputoutputdir=/home/sinoquet/recherche/mcmc/output/sim_sat_02_10_10/ inputfilesnps=snps.txt inputfilepheno=pheno.txt X - read.table(file=paste(inputoutputdir,inputfilesnps,sep=),h=F) # data.frame #genotype file (individuals x SNPs); code: 0/1/2 : number of minor alleles y - read.table(file=paste(inputoutputdir,inputfilepheno,sep=),h=F) # data.frame #fit - glm(yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10, family = gaussian) #coefficients( summary(fit)) #* # BEGIN check real solution: target - 1 inputfilepredictors=predictor_descript.txt f0 - file(paste(inputoutputdir,inputfilepredictors,sep=), open = r) # format of file f0: #target predictors #1 1 2 3 4 5 6 7 8 9 10 line - readLines(f0, n = 1) # header line - readLines(f0, n = 1) v - unlist(strsplit(line, split= )) predictorsForThisTarget - v[-1] # dismiss target number print(paste(!,v,!,sep= )) [1] ! 1 ! ! 1 ! ! 2 ! ! 3 ! ! 4 ! ! 5 ! ! 6 ! ! 7 ! [9] ! 8 ! ! 9 ! ! 10 ! nbPredictors - length(predictorsForThisTarget) ch-paste(X$V,predictorsForThisTarget[1],sep=) for (i in 2:nbPredictors){ + item-paste(X$V,predictorsForThisTarget[i],sep=) + ch-paste(ch,item,sep= + ) + } formulaString - paste(yi,ch,sep= ~ ) print(formulaString) [1] yi ~ X$V1 + X$V2 + X$V3 + X$V4 + X$V5 + X$V6 + X$V7 + X$V8 + X$V9 + X$V10 formula - as.formula(formulaString) yi - unlist(y[target,]) fit - glm(formula, family =
Re: [R] odfWeave/XML Windows issue
Dave_F friedenbergd at battelle.org writes: I am getting the following error when using odfWeave Error in xmlEventParse(infile, handlers = handlers, trim = FALSE, state = state) : File content_1.xml does not exist Thanks, Dave Dear Dave! I was getting the same message while trying to weave my own files, while the files from example directory of the package worked. That led me to believe that the problem is at lest partly in my code. What I found out is that the problem was caused by me changing the working directory in the source odf file. Once I removed that, everything worked. It's still a minor annoyance, but not a major problem (at lest for me). Best regards, Ales __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 exactly does 'identify' work?
On 18/11/2010 1:50 PM, casperyc wrote: Hi, I think the problem is 1 - when a linear model is fitted, ploting the qqnorm( test.lm$ res ) we dont 'know' what values are actually being used on the y-axis; and how do we refer to the ‘Index’ on the x-axis?? therefore, i dont know how to refer to the x and y coordinates in the identify function You could look at qqnorm.default to figure those things out, but it is probably difficult to do. You'd be better off using locator() to find the coordinates of a mouse click, and plotting the label using text(). For a simple example, x - rnorm(100, mean=10, sd=2) qqnorm(x) repeat { pt - locator(1) if (!length(pt$x)) break text(pt, labels=which.min( abs(x - pt$y) ) ) } Duncan Murdoch 2 - i have tried using the stdres function in the MASS library, to extract the standardised residuals and plot them manully, ( using the plot ) function. this way, the problem is we have to SORT the residuals first in increasing order to reproduce the same qqnorm plot, in that case, 'identify' function works, however, that CHANGES the order, i.e. it wont return the original A:Z ( row.names ) label. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 exactly does 'identify' work?
yes, i tried to modify the 2L part in plot.lm ### if (show[2L]) { ylim - range(rs, na.rm = TRUE) ylim[2L] - ylim[2L] + diff(ylim) * 0.075 qq - qqnorm(rs, main = main, ylab = ylab23, ylim = ylim, ...) if (qqline) qqline(rs, lty = 3, col = gray50) if (one.fig) title(sub = sub.caption, ...) mtext(getCaption(2), 3, 0.25, cex = cex.caption) if (id.n 0) text.id(qq$x[show.rs], qq$y[show.rs], rs) ### but didnt go very far, I could just use text to add the label, I just dont understand why identify does not 'identify' the residuals in a linear model in the qqnorm plot ... Thanks. -- View this message in context: http://r.789695.n4.nabble.com/how-exactly-does-identify-work-tp3045953p3049385.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] R Courses***Fundamentals Advanced Programming ***December 2010 - in San Francisco, New York City and Washington DC by XLSolutions Corporation
Check out our Fundamentals and Advanced Programming R courses for December 2010 in Washington DC, San Francisco and New York City http://www.xlsolutions-corp.com/Rcourses *** R Fundamentals and Programming Techniques New York, Dec 13-14, 2010 Washington DC, Dec 16-17, 2010 San Francisco, Dec 16-17 *** R/S Systems: Advanced Programming New York, Dec 16-17, 2010 Washington DC, Dec 13-14, 2010 San Francisco, Dec 13-14 More on website http://www.xlsolutions-corp.com/Rcourses Ask for group discount and reserve your seat Now - Earlybird Rates. Payment due after the class! Email Sue Turner: sue at xlsolutions-corp.com Phone: 206-686-1578 Please let us know if you and your colleagues are interested in this class to take advantage of group discount. Register now to secure your seat. Cheers, Elvis Miller, PhD Manager Training. XLSolutions Corporation 206 686 1578 www.xlsolutions-corp.com elvis at xlsolutions-corp.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.