Re: [R] howto import .xls and .ods
There is a *manual* on R Data Import/Export, not just an FAQ. This is the first request I have seen for .ods (whatever that is -- please don't assume that a file type is determined by an extension, and we not infrequently get asked about CSV files with extension .xls). On Thu, 1 May 2008, Abhijit Dasgupta wrote: I've written a little python script that converts ods and xls to csv, and a wrapper in R that imports a sheet of the ods and/or xls into a data.frame in R. If this is a FAQ and there is an existing solution, great. Actually, for xls, the library gdata has a read.xls function that uses a perl function underneath. Abhijit Dasgupta, Ph.D Assistant Professor | Division of Biostatistics Dept of Pharmacology and Experimental Therapeutics | Thomas Jefferson University 1015 Chestnut St | Suite M100 | Philadelphia PA 19107 Ph: (215) 503-9201 | Fax: (215) 503-3804 adasgupt (at) mail (dot) jci (dot) tju (dot) edu The documents accompanying this transmission may contain confidential health or business information. This information is intended for the use of the individual or entity named above. If you have received this information in error, please notify the sender immediately and arrange for the return or destruction of these documents. Jonas Stein wrote: Hi, i want to import data from .ods and .xls files in R on a linux system. Seems it was a faq in the past, but i found only solutions for Windows. Is there a handy solution for linux? The best would be something like mytab -read.ods(...) Any hints? Thanks a lot for reading so far, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fCopulae
My problem in a few words is as folow: I used the fCopulae packages because i have 2 series which are already transformed in the uniform domain (the space of the copulas functions) and i estimated with type archmList() from 1 to 22, but i don't know their names:for exemple the type=4 is the Gumbel Copula...and for the others i can't have any idea about how can i find their names explicitly? Please can you help me in this point? Thank you. __ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Locale problem with umlauts in factor levels in 2.7.0 (patched) from grid or lattice
The bug is in grid, in some layout calculations which need the string width. There was a 'FIXME' in the sources, and I've fixed this now. (svn r45579/80). Many other grid examples worked so it took me a while to track this down. On Thu, 1 May 2008, Dieter Menne wrote: With 2.7.0 patched (not tested with 2.0.0), I get an error message in a program that ran correctly in R 2.6.2 when the grouping factor of a stripplot contains an Umlaut: I am aware that there are a few locale-changes in R 2.7.0, but I could not easily locate who's at fault Dieter library(lattice) dt = data.frame(x=rnorm(100),y=1:100,levs= as.factor(c(Gru,Grü))) stripplot(x ~ y|levs, data = dt) #Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, : # invalid input 'Grü' in 'utf8towcs' # Works as.graphicsAnnot(as.factor(c(Gru,Grü))) R version 2.7.0 Patched (2008-04-30 r45572) i386-pc-mingw32 locale: LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252; LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.17-6 loaded via a namespace (and not attached): [1] grid_2.7.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Optimal knot locations for splines
Mike Dugas mikedugas77 at gmail.com writes: Thanks for the help. I tried out the one promising lead, curfit.free.knot, and it doesn't work for linear or quadratic splines. The documentation says it should, but when I specify a linear spline, it returns a cubic. Could you demonstrate this with a self-running example? Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error while making R package
No idea, can you make the package available for us (after R CMD build)? Uwe Ligges Vidhu Choudhary wrote: Hi All, I am trying to make R package using R 2.6.2 And I am getting following error. When I give R CMD check t1\ -- Making package t1 adding build stamp to DESCRIPTION making DLL ... making CGHseg_rewrite.d from CGHseg_rewrite.c making rowMedians.d from rowMedians.c making runavg.d from runavg.c gcc-sjlj -std=gnu99 -Ic:/R/R-2.6.2/include -O3 -Wall -c CGHseg_rewrite.c -o CGHseg_rewrite.o gcc-sjlj -std=gnu99 -Ic:/R/R-2.6.2/include -O3 -Wall -c rowMedians.c -o rowMedians.o gcc-sjlj -std=gnu99 -Ic:/R/R-2.6.2/include -O3 -Wall -c runavg.c -o runavg.o windres --preprocessor=gcc-sjlj -E -xc -DRC_INVOKED -I c:/R/R-2.6.2/include -i t1_res.rc -o t1_res.o gcc-sjlj -std=gnu99 -shared -s -o t1.dll t1.def CGHseg_rewrite.o rowMedians.o runavg.o t1_res.o -Lc:/R/R-2.6.2/bin-lR ... DLL made installing DLL installing R files installing data files rm: failed to get attributes of `/': No such file or directory make[2]: *** [C:/Vidhu/CGH/RPackage/t1.Rcheck/t1/data] Error 1 make[1]: *** [all] Error 2 make: *** [pkg-t1] Error 2 *** Installation of t1 failed *** Can you please suggest what could be the probable cause of the error Thank you Vidhu [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with apply and split...
I'm trying to drop all rows except for the ones with the most recent year. So I split the data frame by NPERMNO and keep just the last record of all groups. datg=t(sapply(split(datgic, datgic$NPERMNO, drop=TRUE), function(x){return( x[nrow(x),] )})) I get something like this... GVKEY NPERMNO GIC year 10001 12994 10001 55102010 2007 10002 19049 10002 40101015 2007 10009 16739 10009 40101010 1999 Has this been made into a proper data frame. How come the row numbers are not 1,2,3,4...? Thank you so much, and I would really appreciate any help! Mike __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 plot wind direction and strength field
Thanks Greg, I'll give it a whirl and let you know how it goes (although it might not be till after the bank holiday weekend now sorry for delay!) Thanks for replying and spending time on this problem. All the best, Jenny On Thu, 1 May 2008, Greg Snow wrote: Does the following do what you want (or at least move in that direction)? u - array(NA,c(5,8)) t - seq(from=0.5, to=0.11,length=15) t2 - seq(from=(-0.7),to=(-0.1),length=25) u[1:15] - t u[16:40] - t2 v - array(NA,c(5,8)) y - seq(from=(-0.9), to=(-0.01),length=40) v[1:40] - y library(TeachingDemos) library(maps) map('state',col='grey') lats - seq( 27.5, 48.7, length=5 ) longs - seq( -123, -73, length=8 ) x - longs[ col(u) ] y - lats[ row(u) ] speed - sqrt( u*u+v*v ) dir - atan2(v,u) my.symbols(x,y,ms.arrows, angle=dir, r=speed, add=TRUE, length=.05) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jenny Barnes Sent: Tuesday, April 29, 2008 6:26 AM To: Jim Lemon Cc: r-help@r-project.org Subject: Re: [R] How to plot wind direction and strength field Thanks Jim - here is some data: u - array(NA,c(5,8)) t - seq(from=0.5, to=0.11,length=15) t2 - seq(from=(-0.7),to=(-0.1),length=25) u[1:15] - t u[16:40] - t2 v - array(NA,c(5,8)) y - seq(from=(-0.9), to=(-0.01),length=40) v[1:40] - y I've made up the data but it's similar magnitude and the longitude direction is u and latitude direction is v as in the real data. I really appreciate your help! Jenny On Tue, 29 Apr 2008, Jim Lemon wrote: Jenny Barnes wrote: Hi Jim, I would like to plot something like figure 2 on this webpage: http://www.cnrfc.noaa.gov/storm_summaries/jan1997storms.php My data is very large - covering the whole globe at 2.5deg resolution so longitude=144 girds, latitude=73 grids and time=32 years - hard to give you that data..Would it help to give you a couple of grid squares worth of data for one year? Okay, Figures 2 and 3 look like 5 degree squares, and given a larger plot, 2.5 degree should be okay. Do you want curved arrows? That would take some programming as the standard arrows are straight. Also, the arrows in the figures all seem to be the same length. I can make the lengths proportional to wind speed. Yes, some data would be helpful, as getting the right plot usually involves trying out real data. Doesn't matter if it's faked as long as it has the same format and similar numbers to the real thing. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] removing rows from matrix
Hi, I have a problem regarding matrix handeling. I am working with a serie of matrixes containing several columns. Now I would like to delete those rows of the matrixes,that in one of the columns contain values less than 50 or greater than 1000. How would this be possible, I have tried to create a simple function for this, but I just don't seem to get it right.Thank you so much for your help, Monna _ [[elided Hotmail spam]] PLink [[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 with apply and split...
datg=t(sapply(split(datgic, datgic$NPERMNO, drop=TRUE), function(x){return( x[nrow(x),] )})) I get something like this... GVKEY NPERMNO GIC year 10001 12994 10001 55102010 2007 10002 19049 10002 40101015 2007 10009 16739 10009 40101010 1999 Has this been made into a proper data frame. How come the row numbers are not 1,2,3,4...? You can check if a variable is a 'proper data frame' using is.data.frame(datg) or class(datg). The row numbers are preserved from the original data frame to make it easier to check that you've extracted the correct rows. You can renumber them using rownames(datg) - seq_len(nrow(datg)) Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] to cairo or not to cairo
I have installed R 2.7.0 in a Linux x64 computer and everything seems to be ok but, when I am trying to plot something, say plot(x=1:10), I am getting the following message: unable to load shared library '/usr/local/lib/R/modules//R_X11.so ...(and libpangocairo-1.0.so.0, as well)... If I use configure --without-cairo the problem is gone... but I would like to test cairo. How can I work with cairo and get rid of this problem? -- View this message in context: http://www.nabble.com/to-cairo-or-not-to-cairo-tp17014848p17014848.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] to extract particular date/data
If I have this daily rainfall data, how do call a particular day? Year,Month,Day,Amount 1900,12,22,1.3 1900,12,23,0 1900,12,24,0 1900,12,25,0 1900,12,26,0 1900,12,27,0 1900,12,28,0 1900,12,29,4.8 1900,12,30,0.3 1900,12,31,0.5 1901,1,1,0 1901,1,2,3 1901,1,3,0 1901,1,4,0.5 1901,1,5,0 1901,1,6,0 ... I used to use julian.date in S-Plus. I read your data in as the following data frame: rainfall Year Month Day Amount 1 190012 221.3 2 190012 230.0 3 190012 240.0 4 190012 250.0 5 190012 260.0 6 190012 270.0 7 190012 280.0 8 190012 294.8 9 190012 300.3 10 190012 310.5 11 1901 1 10.0 12 1901 1 23.0 13 1901 1 30.0 14 1901 1 40.5 15 1901 1 50.0 16 1901 1 60.0 You can access only the days with rainfall$Day, but you might also like to convert all the dates to POSIX format. This code will do the trick: posixdates - with(rainfall, ISOdate(Year, Month, Day)) posixdates is a vector of class POSIXct, which means it is the number of seconds since the start of 1970, with some methods to make it print nicely and behave itself in time series plots. See also ?julian, and the chron package. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice book
I too have been studying the book and it is indeed outstanding. For my purposes the only topic missing is the straightforward drawing of error bars and bands, for which I've been using Hmisc::xYplot (where error bands seem to be broken for R) or gplots::barplot2. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ On May 1, 2008, at 7:26 PM, Deepayan Sarkar wrote: On 4/30/08, Charilaos Skiadas [EMAIL PROTECTED] wrote: Actually it's been out for a couple of weeks now at least. Yes, it's been out since March 12, actually. I just finished my first reading of it, and I must say it was spectacular. Congratulations Deepayan, the book gave me exactly the kind of lattice knowledge I needed, and then some. The graphics are really impressive and good illustrations of what lattice can do, and I found the writing very clear, with the complexity increasing at just the right speed. I definitely recommend it to anyone who wants to learn how to use lattice, at any level they desire. Thanks for the great review :-) As Karl mentioned, there is a website with code and figures from the book at http://lmdvr.r-forge.r-project.org/ I also hope to eventually write some short vignettes on topics not covered in the book, and put them up here. Feel free to suggest topics to me. And of course, please report any typos and errors. -Deepayan [[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] Cant resolve Error Message
Hi, Im having trouble creating the following graph. Here is my code: library(plotrix) library(prettyR) female_improvement -read.table(C://project/graphs/gender/breakdown/gender-improvement/female-improvement.csv, sep=,, header=TRUE) barp(rbind(rep(length(female_improvement$gender),2),freq(female_improvement$reason)[[1]]), ylab=22 Males participated in the survey, col=4:5,names.arg=c(FemalesInfo entered is relevant(4), Males Room for Improvement(18))) legend(topright,c(Females,Reason),fill=4:5) Here is the error: Error in axis(1, at = 1:ngroups, labels = names.arg, cex.axis = cex.axis) : 'at' and 'labels' lengths differ, 3 != 2 In addition: Warning messages: 1: package 'prettyR' was built under R version 2.7.0 2: In rbind(rep(length(female_improvement$gender), 2), freq(female_improvement$reason)[[1]]) : number of columns of result is not a multiple of vector length (arg 1) Here is the file: gender,reason Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Info entered is all relevant Female,Room for Improvement Female,Room for Improvement Female,Room for improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Info entered is all relevant Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement I use the exact same code when creating the same chart for male and it works fine.(change female variable to male) Any suggestions as to how to resolve the problem? Thanks in advance. Hope to hear from someone soon. Jack. -- View this message in context: http://www.nabble.com/Cant-resolve-Error-Message-tp17016312p17016312.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] Lattice book
Michael Kubovy wrote: I too have been studying the book and it is indeed outstanding. For my purposes the only topic missing is the straightforward drawing of error bars and bands, for which I've been using Hmisc::xYplot (where error bands seem to be broken for R) or gplots::barplot2. If these are broken in xYplot we need to have a bug report with a small reproducible example. Frank _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ On May 1, 2008, at 7:26 PM, Deepayan Sarkar wrote: On 4/30/08, Charilaos Skiadas [EMAIL PROTECTED] wrote: Actually it's been out for a couple of weeks now at least. Yes, it's been out since March 12, actually. I just finished my first reading of it, and I must say it was spectacular. Congratulations Deepayan, the book gave me exactly the kind of lattice knowledge I needed, and then some. The graphics are really impressive and good illustrations of what lattice can do, and I found the writing very clear, with the complexity increasing at just the right speed. I definitely recommend it to anyone who wants to learn how to use lattice, at any level they desire. Thanks for the great review :-) As Karl mentioned, there is a website with code and figures from the book at http://lmdvr.r-forge.r-project.org/ I also hope to eventually write some short vignettes on topics not covered in the book, and put them up here. Feel free to suggest topics to me. And of course, please report any typos and errors. -Deepayan [[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. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] removing rows from matrix
Hi, I have a problem regarding matrix handeling. I am working with a serie of matrixes containing several columns. Now I would like to delete those rows of the matrixes,that in one of the columns contain values less than 50 or greater than 1000. Try this: m - matrix(runif(150, 0, 1050), nrow=10); m cols.to.remove - apply(m, 2, function(x) any(x 50 | x 1000)) m[,!cols.to.remove] It's well worth learning how to use apply, and its variants (tapply, sapply etc.); they come in very useful. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in downViewport.vpPath(vpPathDirect(name)
Hi, I am having trouble plotting a series of dendrograms using lattice and grid code as found in Paul Murrells book R Graphics. This is the error message I recieve: Error in downViewport.vpPath(vpPathDirect(name), strict, recording = recording) : Viewport 'plot1.panel.1.1.off.vp' was not found I have attached the code and also my data file. Should anyone have any suggestions then your help would be gratefully appreciated. Thank you Andrew http://www.nabble.com/file/p17017801/dend4c.txt dend4c.txt http://www.nabble.com/file/p17017801/gL2.csv gL2.csv -- View this message in context: http://www.nabble.com/Error-in-downViewport.vpPath%28vpPathDirect%28name%29-tp17017801p17017801.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] Cant resolve Error Message
It appears that you have a problem in your data. Here is just the rbind in the call: rbind(rep(length(female_improvement$gender),2),freq(female_improvement$reason)[[1]]) Info entered is all relevant Room for improvement Room for Improvement [1,] 20 20 20 [2,]21 17 Warning message: In rbind(rep(length(female_improvement$gender), 2), freq(female_improvement$reason)[[1]]) : number of columns of result is not a multiple of vector length (arg 1) It is the one producing the error message. Is this normal? On Fri, May 2, 2008 at 7:48 AM, hoogeebear [EMAIL PROTECTED] wrote: Hi, Im having trouble creating the following graph. Here is my code: library(plotrix) library(prettyR) female_improvement -read.table(C://project/graphs/gender/breakdown/gender-improvement/female-improvement.csv, sep=,, header=TRUE) barp(rbind(rep(length(female_improvement$gender),2),freq(female_improvement$reason)[[1]]), ylab=22 Males participated in the survey, col=4:5,names.arg=c(FemalesInfo entered is relevant(4), Males Room for Improvement(18))) legend(topright,c(Females,Reason),fill=4:5) Here is the error: Error in axis(1, at = 1:ngroups, labels = names.arg, cex.axis = cex.axis) : 'at' and 'labels' lengths differ, 3 != 2 In addition: Warning messages: 1: package 'prettyR' was built under R version 2.7.0 2: In rbind(rep(length(female_improvement$gender), 2), freq(female_improvement$reason)[[1]]) : number of columns of result is not a multiple of vector length (arg 1) Here is the file: gender,reason Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Info entered is all relevant Female,Room for Improvement Female,Room for Improvement Female,Room for improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Info entered is all relevant Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement Female,Room for Improvement I use the exact same code when creating the same chart for male and it works fine.(change female variable to male) Any suggestions as to how to resolve the problem? Thanks in advance. Hope to hear from someone soon. Jack. -- View this message in context: http://www.nabble.com/Cant-resolve-Error-Message-tp17016312p17016312.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] to extract particular date/data
Have a look at the zoo package which has three vignettes and R News 4/1. On Fri, May 2, 2008 at 12:27 AM, Roslina Zakaria [EMAIL PROTECTED] wrote: Hi R-expert, If I have this daily rainfall data, how do call a particular day? Year,Month,Day,Amount 1900,12,22,1.3 1900,12,23,0 1900,12,24,0 1900,12,25,0 1900,12,26,0 1900,12,27,0 1900,12,28,0 1900,12,29,4.8 1900,12,30,0.3 1900,12,31,0.5 1901,1,1,0 1901,1,2,3 1901,1,3,0 1901,1,4,0.5 1901,1,5,0 1901,1,6,0 ... I used to use julian.date in S-Plus. Thank you so much for your kind attention and help. [[elided Yahoo spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Errors bar in barchart
Hi, I user barplot2 to make a plot bar with errors bars. In old times I needed to use a sequence of segments commands to make this. Now I try to make the same but using lattice. Is possible to use barplot2 in barchart function? If not, what is the simplest way to put errors bar in barchart? I try to find an example in Lattice book, but dont find anythink like this. Thanks a lot Inté Ronaldo -- You have a tendency to feel you are superior to most computers. -- Prof. Ronaldo Reis Júnior | .''`. UNIMONTES/Depto. Biologia Geral/Lab. de Biologia Computacional | : :' : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil | `- Fone: (38) 3229-8187 | [EMAIL PROTECTED] | [EMAIL PROTECTED] | http://www.ppgcb.unimontes.br/ | ICQ#: 5692561 | LinuxUser#: 205366 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] stdFit
Hi, I am using the stdFit function (fGarch package) to get estimates for a fitted location, scale, and degrees of freedom of a dataset. I have no errors with the code however the estimates are not identical to the estimates I am getting when using SAS and MatLab (both give me the same estimates). Can someone comment on it? Here is the simple two lines I am using t_fit - stdFit(independent) est - t_fit$est where independent is my data to be fitted. Thanks! Alex -- View this message in context: http://www.nabble.com/stdFit-tp17018969p17018969.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] Data manipulation for random intercept GLMM
Giovanni Petris GPetris at uark.edu writes: ## Example: Ratings of prime minister (Agresti, Table 12.1, p.494) rating - matrix(c(794, 86, 150, 570), 2, 2) dimnames(rating) - list(First = c(approve, disapprove), + Second = c(approve, disapprove)) rating Second Firstapprove disapprove approve794150 disapprove 86570 [snip] approval - factor(c(Approve, Disapprove), +levels = c(Disapprove, Approve)) survey - factor(c(First, Second)) tmp - data.frame(approval = unlist(expand.grid(approval, approval)), + survey = rep(survey, each = 4)) rat.df - cbind(tmp[rep(1:8, rep(rating, 2)), ], + id = factor(rep(1:sum(rating), 2))) row.names(rat.df) - NULL That does the job, since now I can call lmer: m1 - lmer(approval ~ survey + (1 | id), family = binomial, data = rat.df, +method = Laplace) [snip] Consider also that the next simplest example is the following, in which there are three items on a questionnaire and gender is included in the model: ### Example: Support for legalizing abortion (Agresti, Table 10.13, p.441) legalize - matrix(c(342, 440, 26, 25, 6, 14, 21, 18, 11, 14, + 32, 47, 19, 22, 356, 457), nr = 2) dimnames(legalize) - list(Gender = c(Male, Female), +Three = c(111, 112, 211, 212, 121, +122, 221, 222)) legalize Three Gender 111 112 211 212 121 122 221 222 Male 342 26 6 21 11 32 19 356 Female 440 25 14 18 14 47 22 457 (Here '111' means (Yes, Yes, Yes) on the three items, etc.) How can I tranform elegantly this table into a dataframe that I can feed to lmer? I would like to know the answers to this as well. I thought I was going to be able to get away with as.data.frame.table() [which is handy and underappreciated], but it doesn't expand counts. I hope you get an elegant solution: in the meantime, I guess my advice is to try to write a reasonably general (if not necessarily absolutely elegant) function that you can supply your students with. If they have an expand.table() function, they won't care how complex it is internally ... Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] xYplot error bands not working, was: Re: Lattice book
On R version 2.7.0 (2008-04-22) i386-apple-darwin8.10.1 locale: C/C/en_US/C/C/C attached base packages: [1] splines grid grDevices datasets graphics stats utils methods base other attached packages: [1] Design_2.1-1 survival_2.34-1 Hmisc_3.4-3 languageR_0.92coda_0.13-1 lme4_0.99875-9 [7] Matrix_0.999375-9 zipfR_0.6-0 lattice_0.17-6 MASS_7.2-41 JGR_1.5-18iplots_1.1-2 [13] JavaGD_0.5-1 rJava_0.5-1 loaded via a namespace (and not attached): [1] cluster_1.11.10 tools_2.7.0 From the xYplot() help page (as you can see from the comment, the problem had been noted---although works differently seems to be a euphemism for doesn't work--- reported by me, among others, a while ago): dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month; year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) # filled bands: default fill = pastel colors matching solid colors # in superpose.line (this works differently in R) xYplot ( Cbind ( y, Lower, Upper ) ~ month, groups=year, method=filled bands , data=s, type=l) # this produces a bright red band at the top and a black band at the bottom I'll be happy to submit a bug report if this doesn't count and if you tell me how. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ On May 2, 2008, at 7:50 AM, Frank E Harrell Jr wrote: Michael Kubovy wrote: I too have been studying the book and it is indeed outstanding. For my purposes the only topic missing is the straightforward drawing of error bars and bands, for which I've been using Hmisc::xYplot (where error bands seem to be broken for R) or gplots::barplot2. If these are broken in xYplot we need to have a bug report with a small reproducible example. Frank [[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] points size in plots
Dear list, I would like to produce a plot of variables where the size of the points will be indicative of their standard errors. How is that possible? Thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error in using by + median
The help says A data frame is split by row into data frames subsetted by the values of one or more factors, and function 'FUN' is applied to each subset in turn. You attempting to apply median() to a data frame -- it does no work, unlike mean() On Fri, 2 May 2008, vito muggeo wrote: dear all, Could anyone explain me the behaviour of median() within by()? (I am running R.2.7.0) thanks, vito H-cbind(rep(0:1,l=20),matrix(rnorm(20*2),20,2)) by(H[,-1],H[,1],mean) INDICES: 0 V1 V2 -0.2101069 0.2954377 - INDICES: 1 V1 V2 -0.23682173 -0.01225147 by(H[,-1],H[,1],median) Error in median.default(data[x, , drop = FALSE], ...) : need numeric data -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Università di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612 http://dssm.unipa.it/vmuggeo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Accesing data frame members from within functions
I am writing a simple R program to execute a t-test repeatedly on data contained in a data frame. My data looks like this: Category Value1 Value2 1 .5 .8 1 .3 .9 . . . . . . . . . 2 1.4 1.3 2 1.3 1.3 . . . . . . . . . 15.2 .3 15.5 .1 So in all there are 15 categories, and each category contains two sets of observations which I want to compare. I only want to compare Value1 and Value2 within each category, but I need to do it 15 times (once for each category), so I wanted to write an R function to make it easier. Right now I am using a for() loop to do the comparison. My loop looks like this: for(i in 1:21) { x - t.test(Value1[Category == i], Value2[Category == i]) y - c(y, x$p.value) } The loop runs and everything is working well. However, I am not sure how to translate this code into a function. In particular, I'm not sure how to write a function that passes a data frame ds (containing Category, Value1, and Value2 as members) as an argument, and then accessing these members within the body of the function. I've tried the following: repeated_test - function(data) { for(i in 1:21) { x - t.test(ds$Value1[ds$Category == i], ds$Value2[ds$Category == i]) y - c(y, x$p.value) } This will run, but only if the members of the data frame I am passing as an argument are in fact named Value1, Value2, and Category. This is fine for now, but in the future I will have to run this function on data where I cannot be sure this is the case. Rather than change the member names by hand, I would like to make the function generic to work with any data frame. How do I do this? Or is there a better way to do this without the for() loop (for example, using apply())? [[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] error in using by + median
dear all, Could anyone explain me the behaviour of median() within by()? (I am running R.2.7.0) thanks, vito H-cbind(rep(0:1,l=20),matrix(rnorm(20*2),20,2)) by(H[,-1],H[,1],mean) INDICES: 0 V1 V2 -0.2101069 0.2954377 - INDICES: 1 V1 V2 -0.23682173 -0.01225147 by(H[,-1],H[,1],median) Error in median.default(data[x, , drop = FALSE], ...) : need numeric data -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Università di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612 http://dssm.unipa.it/vmuggeo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] isotonic/ordered heterogeneity tests
dear R-help: one of my students is struggling to test an ordered alternative hypothesis on a set of groups (e.g., mu_a = mu_b = mu_c). There has been some literature on this topic -- a lot of this goes back to Bartholomew (1961); Gaines and Rice (see refs below) are the ones who've popularized it in the ecology community. The topic is closely related to isotonic regression, but all of the isotonic-regression stuff we've been able to discover in R so far (isoreg, the Iso and cir packages, etc.) are geared towards estimating smooth (or non-smooth) monotone relationships rather than towards testing ordered hypotheses. Computing p-values based on the Gaines and Rice (1990) algorithm is actually fairly hairy, because one has to calculate probabilities of amalgamating k groups into m ... the later Rice and Gaines ordered hypothesis algorithms look easier to code, but still not completely trivial. Does anyone have any hints toward implementations of these or similar methods, or do we have to do it ourselves ... ? (We're not proud -- pointers to straightforward ways to this on other platforms [cough]SAS[cough] would be great too.) thanks, Ben Bolker Gaines, Steven D., and William R. Rice. 1990. Analysis of Biological Data When there are Ordered Expectations. The American Naturalist 135, no. 2:310-317. Rice, William R., and Steven D. Gaines. 1994a. Extending Nondirectional Heterogeneity Tests to Evaluate Simply Ordered Alternative Hypotheses. Proceedings of the National Academy of Sciences of the United States of America 91, no. 1:225-226. Rice, William R., and Steven D. Gaines. 1994b. The Ordered-Heterogeneity Family of Tests. Biometrics 50, no. 3:746-752. signature.asc Description: OpenPGP digital 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.
Re: [R] Accesing data frame members from within functions
Try: foo - function(data, ...) { res - unlist(lapply(split(data, data$Category), function(.x)t.test(.x$Value1, .x$Value2)$p.value)) test - merge(data, as.data.frame(res), by.x=Category, by.y = 0) return(test) } x - data.frame(Category = rep(1:15, each = 10), Value1 = rnorm(150), Value2 = rnorm(150)) foo(x) On Fri, May 2, 2008 at 11:19 AM, David Schwab [EMAIL PROTECTED] wrote: I am writing a simple R program to execute a t-test repeatedly on data contained in a data frame. My data looks like this: Category Value1 Value2 1 .5 .8 1 .3 .9 . . . . . . . . . 2 1.4 1.3 2 1.3 1.3 . . . . . . . . . 15.2 .3 15.5 .1 So in all there are 15 categories, and each category contains two sets of observations which I want to compare. I only want to compare Value1 and Value2 within each category, but I need to do it 15 times (once for each category), so I wanted to write an R function to make it easier. Right now I am using a for() loop to do the comparison. My loop looks like this: for(i in 1:21) { x - t.test(Value1[Category == i], Value2[Category == i]) y - c(y, x$p.value) } The loop runs and everything is working well. However, I am not sure how to translate this code into a function. In particular, I'm not sure how to write a function that passes a data frame ds (containing Category, Value1, and Value2 as members) as an argument, and then accessing these members within the body of the function. I've tried the following: repeated_test - function(data) { for(i in 1:21) { x - t.test(ds$Value1[ds$Category == i], ds$Value2[ds$Category == i]) y - c(y, x$p.value) } This will run, but only if the members of the data frame I am passing as an argument are in fact named Value1, Value2, and Category. This is fine for now, but in the future I will have to run this function on data where I cannot be sure this is the case. Rather than change the member names by hand, I would like to make the function generic to work with any data frame. How do I do this? Or is there a better way to do this without the for() loop (for example, using apply())? [[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] A plot of factor data?
Thank you, Bert! I have a question one more. I have found out that mosaic function of vcd package is more interesting since I want to color different cells. The question is how to make x axis label to be vertical not horizontal. I tried las or some other options in par but I could not change it. Here is an example. == library(vcd) music = c(10, 5, 15, 20) dim(music) = c(2,2) dimnames(music) = list(Age=c(old, young), Listen=c(yes,no)) mosaic(music, split_vertical=TRUE) == The Age names are old, and young. I want them to be vertical rather than horizontal since I have too many columns. Thank you, Sang Chul On May 1, 2008, at 7:27 PM, Bert Gunter wrote: ?mosaicplot -- Bert Gunter -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ] On Behalf Of Sang Chul Choi Sent: Thursday, May 01, 2008 4:09 PM To: r-help@r-project.org Subject: [R] A plot of factor data? Hi, I am wondering if there is a way to plot proportions of factors. I tried to find plot functions for those but in vain. For example, I have a data like this where column a has 10 of 0s and 15 of 1s, and column b has 5 and 20. x - data .frame (a=factor(c(rep(0,10),rep(1,15))),b=factor(c(rep(0,5),rep(1,20 summary(x) a b 0:10 0: 5 1:15 1:20 I want to have a plot like: |-| | | --- proportion of 0 | | |-| | | | | --- proportion of 1 | | |-| column a |-| | | --- proportion of 0 |-| | | | | | | --- proportion of 1 | | |-| column b Is there anybody who can do this easily? I appreciate any help. Thank you, Sang Chul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] need help on ICC for a questionnaire
Dear All, I am trying to get ICC (Intra class correlation coefficient) for a questionnaire. The questionnaire has about 25 questions and was administered to 50 subjects on two occasions. I want to calculate the reproducibility of the questionnaire administered to the same group of subjects on two occasions. I need to calculate reproducibility of each question administered and not a summary/total score. Each question is not always measured on a same scale. I read the psy and psychometric packages, however, I do not understand as to how should I organize my data. Each subject has two scores for each question. Is there any other package I can use for this? I am a R novice, so sorry for very obvious questions... Please help. Sincerely, Dr. Smita Pakhale_ [[elided Yahoo spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[elided Yahoo spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 parse XML
I would like to learn how to parse a mixed text/xml document I downloaded from the sec.gov website (see example below). I would like to parse this to get the value for each xml tag and then access it within R, but I don't know much about xml so I don't even know where to start debugging the errors I am getting in this example code. Can anyone help me get started? Thanks, Roger ftp - ftp://anonymous:[EMAIL PROTECTED]/edgar/data/1317493/0001144204-08-02122 1.txt download.file(url=ftp, destfile=test2.txt) xmlTreeParse(test2.txt) ** * This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No right to confidential or privileged treatment of this message is waived or lost by any error in transmission. If you have received this message in error, please immediately notify the sender by e-mail, delete the message and all copies from your system and destroy any hard copies. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message if you are not the intended recipient. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mosaic plot of vcd package does not stretch with 2-dimension?
Hi, I like mosaic function of vcd package. I have played around it. I have found out that mosaic plot data table is 2-dimension does not stretch when you enlarge a mosaic plot. It is okay when data table is 3 or more dimension. The first one is of 3-dimension table case, and the second one is 2-dimension. With the first plot, you can drag window to enlarge a plot. With the second, I cannot. I have gone through the document, but I could not find any specific to solve this problem. Thank you, Sang Chul === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 2, 2) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low), Listen = c(Yes, No)) mosaic(music) === === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 4) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low, Upper, Lower)) mosaic(music) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] efficiency profiling?
esmail bonakdarian [EMAIL PROTECTED] wrote: Yes, I have been reading the list, the amount of messages per day is simply amazing, I can hardly keep up. Do most of you read this on the web or get it as digest? I am getting them as individual e-mails (thank god for filters) ... :-) I used filters for a while. Now, I read the R list through the gmane Usenet interface. It appears to me to be a newsgroup, rather than a huge collection of emails. I find that much easier. See http://gmane.org/ -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Accesing data frame members from within functions
Hi David, Try this: # Data set set.seed(123) Category=as.factor(rep(1:15,each=10)) Value1 = rnorm(150) Value2= rnorm(150) yourdata=data.frame(Category,Value1,Value2) # Global function TTEST=function(mydata){ # Internal function tt=function(x,y) t.test(x,y)$p.value # p-values for(i in 1:length(levels(mydata$Category))){ mydatai=mydata[mydata$Category==i,][,-1] res[i]=tt(mydatai[,1],mydatai[,2]) } # Result data.frame(Category=levels(Category),pvalue=res) } TTEST(yourdata) Category pvalue 1 1 0.88699832 2 2 0.87711367 3 3 0.26075787 4 4 0.30382321 5 5 0.59213871 6 6 0.83755043 7 7 0.47836246 8 8 0.37509850 9 9 0.26132601 10 10 0.29195145 11 11 0.24169206 12 12 0.25594943 13 13 0.34882014 14 14 0.8574 15 15 0.04556924 HTH, Jorge On Fri, May 2, 2008 at 10:19 AM, David Schwab [EMAIL PROTECTED] wrote: I am writing a simple R program to execute a t-test repeatedly on data contained in a data frame. My data looks like this: Category Value1 Value2 1 .5 .8 1 .3 .9 . . . . . . . . . 2 1.4 1.3 2 1.3 1.3 . . . . . . . . . 15.2 .3 15.5 .1 So in all there are 15 categories, and each category contains two sets of observations which I want to compare. I only want to compare Value1 and Value2 within each category, but I need to do it 15 times (once for each category), so I wanted to write an R function to make it easier. Right now I am using a for() loop to do the comparison. My loop looks like this: for(i in 1:21) { x - t.test(Value1[Category == i], Value2[Category == i]) y - c(y, x$p.value) } The loop runs and everything is working well. However, I am not sure how to translate this code into a function. In particular, I'm not sure how to write a function that passes a data frame ds (containing Category, Value1, and Value2 as members) as an argument, and then accessing these members within the body of the function. I've tried the following: repeated_test - function(data) { for(i in 1:21) { x - t.test(ds$Value1[ds$Category == i], ds$Value2[ds$Category == i]) y - c(y, x$p.value) } This will run, but only if the members of the data frame I am passing as an argument are in fact named Value1, Value2, and Category. This is fine for now, but in the future I will have to run this function on data where I cannot be sure this is the case. Rather than change the member names by hand, I would like to make the function generic to work with any data frame. How do I do this? Or is there a better way to do this without the for() loop (for example, using apply())? [[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 parse XML
Hi Roger -- Bos, Roger [EMAIL PROTECTED] writes: I would like to learn how to parse a mixed text/xml document I downloaded from the sec.gov website (see example below). I would like I'm not sure of a more robust way to extract the XML, but from inspection I wrote ftp - ftp://anonymous:[EMAIL PROTECTED]/edgar/data/1317493/0001144204-08-021221.txt txt - readLines(ftp) xmlInside - grep(/*XML, txt) xmlTxt - txt[seq(xmlInside[1]+1, xmlInside[2]-1)] so that xmlTxt contains the part of the message that is XML to parse this to get the value for each xml tag and then access it within R, but I don't know much about xml so I don't even know where to There are several ways to proceed. I personally like the xpath query language. to do this, one might xml - xmlTreeParse(xmlTxt, useInternal=TRUE) head(unlist(xpathApply(xml, //*, xmlName))) [1] ownershipDocument schemaVersion documentType [4] periodOfReportnotSubjectToSection16 issuer xpathApply takes an xml document and performs a query. The query '//*' says find all nodes mataching any character string (that's the *) that are located anywhere (that's the //) below the current (in this case root) node. This gives a list of nodes; xmlName extracts the name of the node. If I wanted all nodes not subject to section 16 (sounds ominmous) I'd extract all the nodes (a list0 node - xpathApply(xml, //notSubjectToSection16) and then do something with them, e.g., look at them lapply(node, saveXML) [[1]] [1] notSubjectToSection160/notSubjectToSection16 (not so bad, looks like nothing is not subject to section 16, that's a relief) and extract their value lapply(node, xmlValue) In one step: xpathApply(xml, //notSubjectToSection16, xmlValue) ?xpathApply is a good starting place, as is http://www.w3.org/TR/xpath, especially http://www.w3.org/TR/xpath#path-abbrev Martin start debugging the errors I am getting in this example code. Can anyone help me get started? Thanks, Roger ftp - ftp://anonymous:[EMAIL PROTECTED]/edgar/data/1317493/0001144204-08-02122 1.txt download.file(url=ftp, destfile=test2.txt) xmlTreeParse(test2.txt) ** * This message is for the named person's use only. It ma...{{dropped:26}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A plot of factor data?
This depends entirely one what the version in vcd allows you to do. Since I don't use it, I have no idea. Read the docs there, or perhaps someone else familiar with it can help. -- Bert -Original Message- From: Sang Chul Choi [mailto:[EMAIL PROTECTED] Sent: Friday, May 02, 2008 8:06 AM To: Bert Gunter Cc: r-help@r-project.org Subject: Re: [R] A plot of factor data? Thank you, Bert! I have a question one more. I have found out that mosaic function of vcd package is more interesting since I want to color different cells. The question is how to make x axis label to be vertical not horizontal. I tried las or some other options in par but I could not change it. Here is an example. == library(vcd) music = c(10, 5, 15, 20) dim(music) = c(2,2) dimnames(music) = list(Age=c(old, young), Listen=c(yes,no)) mosaic(music, split_vertical=TRUE) == The Age names are old, and young. I want them to be vertical rather than horizontal since I have too many columns. Thank you, Sang Chul On May 1, 2008, at 7:27 PM, Bert Gunter wrote: ?mosaicplot -- Bert Gunter -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ] On Behalf Of Sang Chul Choi Sent: Thursday, May 01, 2008 4:09 PM To: r-help@r-project.org Subject: [R] A plot of factor data? Hi, I am wondering if there is a way to plot proportions of factors. I tried to find plot functions for those but in vain. For example, I have a data like this where column a has 10 of 0s and 15 of 1s, and column b has 5 and 20. x - data .frame (a=factor(c(rep(0,10),rep(1,15))),b=factor(c(rep(0,5),rep(1,20 summary(x) a b 0:10 0: 5 1:15 1:20 I want to have a plot like: |-| | | --- proportion of 0 | | |-| | | | | --- proportion of 1 | | |-| column a |-| | | --- proportion of 0 |-| | | | | | | --- proportion of 1 | | |-| column b Is there anybody who can do this easily? I appreciate any help. Thank you, Sang Chul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mosaic plot of vcd package does not stretch with 2-dimension?
On Fri, 2 May 2008, Sang Chul Choi wrote: Hi, I like mosaic function of vcd package. I have played around it. I have found out that mosaic plot data table is 2-dimension does not stretch when you enlarge a mosaic plot. It is okay when data table is 3 or more dimension. The first one is of 3-dimension table case, and the second one is 2-dimension. With the first plot, you can drag window to enlarge a plot. With the second, I cannot. You need to set keep_aspect_ratio = FALSE This is described on the man page for strucplot() (which is the workhorse function behind mosaic()): keep_aspect_ratio: logical indicating whether the aspect ratio should be fixed or not. If unspecified, the default is 'TRUE' for two-dimensional tables and 'FALSE' otherwise. hth, Z I have gone through the document, but I could not find any specific to solve this problem. Thank you, Sang Chul === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 2, 2) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low), Listen = c(Yes, No)) mosaic(music) === === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 4) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low, Upper, Lower)) mosaic(music) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mosaic plot of vcd package does not stretch with 2-dimension?
Sang Chul Choi choi at biology.rutgers.edu writes: I like mosaic function of vcd package. I have played around it. I have found out that mosaic plot data table is 2-dimension does not stretch when you enlarge a mosaic plot. It is okay when data table is 3 or more dimension. The first one is of 3-dimension table case, and the second one is 2-dimension. With the first plot, you can drag window to enlarge a plot. With the second, I cannot. === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 2, 2) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low), Listen = c(Yes, No)) mosaic(music) === === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 4) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low, Upper, Lower)) mosaic(music) Not really: note that the images resizes correctly, it just keeps its square aspect-ratio. vcd is so strongly modularized that it can be difficult to find the information required. Check strucplot, where it says: strucplot keep_aspect_ratio logical indicating whether the aspect ratio should be fixed or not. If unspecified, the default is TRUE for two-dimensional tables and FALSE otherwise. So try mosaic(music, keep_aspect_ratio=FALSE) but think over if that's really what you want. In most cases it makes sense to keep the square aspect for 2x2 cases Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Transform values from one column into column names of new dataframe
Hi, I have a question about reformatting data. It looks like it should be simple, but I've been working at it for awhile now and it's about time I ask for help. My data look like this: ITEM VALUE STEP item1 A first item2 C first item2 D second item1 A second item3 A first item3 B second item3 A third I just want to transform it so they look like this: ITEM FIRST SECOND THIRD item1 A ANA item2 C DNA item3 A BA Basically taking the values of the STEP column and using those as the column names and merging together the items. I appreciate your help, -Matt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Transform values from one column into column names of new dataframe
On Fri, May 2, 2008 at 11:05 AM, Matt [EMAIL PROTECTED] wrote: Hi, I have a question about reformatting data. It looks like it should be simple, but I've been working at it for awhile now and it's about time I ask for help. My data look like this: ITEM VALUE STEP item1 A first item2 C first item2 D second item1 A second item3 A first item3 B second item3 A third I just want to transform it so they look like this: ITEM FIRST SECOND THIRD item1 A ANA item2 C DNA item3 A BA Basically taking the values of the STEP column and using those as the column names and merging together the items. Have a look at the reshape package (http://had.co.nz/reshape): install.packages(reshape) library(reshape) names(mydf) - tolower(names(mydf)) cast(mydf, item ~ step, length) cast(mydf, item ~ step, function(x) x[1]) Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] wrong path to helpfiles
hi, since lately i receive an error message when prompting ?help: help will not be available. path not found. It is not possible to get help for any command. I don`t know why but it seems that i need to tell R the right path for the helpfiles. How can i do that? thanks a lot cheers michael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Transform values from one column into column names of new dataframe
Try this also: noquote(with(x, tapply(VALUE, list(ITEM, STEP), paste))) On Fri, May 2, 2008 at 1:05 PM, Matt [EMAIL PROTECTED] wrote: Hi, I have a question about reformatting data. It looks like it should be simple, but I've been working at it for awhile now and it's about time I ask for help. My data look like this: ITEM VALUE STEP item1 A first item2 C first item2 D second item1 A second item3 A first item3 B second item3 A third I just want to transform it so they look like this: ITEM FIRST SECOND THIRD item1 A ANA item2 C DNA item3 A BA Basically taking the values of the STEP column and using those as the column names and merging together the items. I appreciate your help, -Matt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mosaic plot of vcd package does not stretch with 2-dimension?
Thank you very much! Sang Chul On May 2, 2008, at 12:06 PM, Dieter Menne wrote: Sang Chul Choi choi at biology.rutgers.edu writes: I like mosaic function of vcd package. I have played around it. I have found out that mosaic plot data table is 2-dimension does not stretch when you enlarge a mosaic plot. It is okay when data table is 3 or more dimension. The first one is of 3-dimension table case, and the second one is 2-dimension. With the first plot, you can drag window to enlarge a plot. With the second, I cannot. === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 2, 2) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low), Listen = c(Yes, No)) mosaic(music) === === music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 4) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low, Upper, Lower)) mosaic(music) Not really: note that the images resizes correctly, it just keeps its square aspect-ratio. vcd is so strongly modularized that it can be difficult to find the information required. Check strucplot, where it says: strucplot keep_aspect_ratio logical indicating whether the aspect ratio should be fixed or not. If unspecified, the default is TRUE for two- dimensional tables and FALSE otherwise. So try mosaic(music, keep_aspect_ratio=FALSE) but think over if that's really what you want. In most cases it makes sense to keep the square aspect for 2x2 cases Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] A horizontal or vertical line draw on mosaic plot?
Hi, I want to have a horizontal line on a mosaic plot with vcd package. This would give me an idea where is 0.5 proportion in a cell. Using mosaicplot function of graphics package, I can draw a line using abline. But, with mosaic function of vcd package, I have tried to use abline function, which complains plot.new has not been called yet. Is there a way to draw lines across a mosaic plot? library(vcd) music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 4) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low, Upper, Lower)) mosaic(music, keep_aspect_ratio=FALSE) abline(h=0.5) Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet Thank you, Sang Chul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] png misbehaving with levelplot when inside a loop
I want to use spplot inside a loop to itteratively produce png files. for (i in 1:5){ png(file=paste(myPlot,i,.png,sep=),bg=white,height=500,width=500) library(lattice) trellis.par.set(sp.theme()) # sets bpy.colors() ramp data(meuse) coordinates(meuse) - ~x+y l2 = list(SpatialPolygonsRescale, layout.north.arrow(), offset = c(181300,329800), scale = 400) l3 = list(SpatialPolygonsRescale, layout.scale.bar(), offset = c(180500,329800), scale = 500, fill=c(transparent,black)) l4 = list(sp.text, c(180500,329900), 0) l5 = list(sp.text, c(181000,329900), 500 m) spplot(meuse, c(ffreq), sp.layout=list(l2,l3,l4,l5),col.regions=black,pch=c(1,2,3), key.space=list(x=0.1,y=.95,corner=c(0,1))) dev.off() } The above example fails to write the output to the file. When the loop is finished the file size of each file is 0Kb. If I perform the work of the loop manually, ie. setting i - 1, i - 2 etc before manually running the loop contents then there is no problem. There is also no problem if I replace all the spplot stuff with say hist(rnorm(100)). The same behaviour is reproduced with levelplot too so is not sp specific. for (i in 1:5){ png(file=paste(sillyPlot,i,.png,sep=),bg=white,height=500,width=500) x - seq(pi/4, 5 * pi, length = 100) y - seq(pi/4, 5 * pi, length = 100) r - as.vector(sqrt(outer(x^2, y^2, +))) grid - expand.grid(x=x, y=y) grid$z - cos(r^2) * exp(-r/(pi^3)) levelplot(z~x*y, grid, cuts = 50, scales=list(log=e), xlab=, ylab=, main=Weird Function, sub=with log scales, colorkey = FALSE, region = TRUE) dev.off() } How should I correctly write these loops to do as intended? cheers David -- David Pleydell Laboratoire de Biologie Environnementale USC INRA-EA 3184 Université de Franche-Comté Place Leclerc F 25030 Besançon France (0033) 0381665763 [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data manipulation for random intercept GLMM
Is this what you are trying to do? tt - matrix( 5:10, ncol=2 ) df - as.data.frame.table(tt) df2 - df[ rep( 1:nrow(df), df$Freq ), ] And is that elegant enough? -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Bolker Sent: Friday, May 02, 2008 7:36 AM To: [EMAIL PROTECTED] Subject: Re: [R] Data manipulation for random intercept GLMM Giovanni Petris GPetris at uark.edu writes: ## Example: Ratings of prime minister (Agresti, Table 12.1, p.494) rating - matrix(c(794, 86, 150, 570), 2, 2) dimnames(rating) - list(First = c(approve, disapprove), + Second = c(approve, disapprove)) rating Second Firstapprove disapprove approve794150 disapprove 86570 [snip] approval - factor(c(Approve, Disapprove), +levels = c(Disapprove, Approve)) survey - factor(c(First, Second)) tmp - data.frame(approval = unlist(expand.grid(approval, approval)), + survey = rep(survey, each = 4)) rat.df - cbind(tmp[rep(1:8, rep(rating, 2)), ], + id = factor(rep(1:sum(rating), 2))) row.names(rat.df) - NULL That does the job, since now I can call lmer: m1 - lmer(approval ~ survey + (1 | id), family = binomial, data = rat.df, +method = Laplace) [snip] Consider also that the next simplest example is the following, in which there are three items on a questionnaire and gender is included in the model: ### Example: Support for legalizing abortion (Agresti, Table 10.13, p.441) legalize - matrix(c(342, 440, 26, 25, 6, 14, 21, 18, 11, 14, + 32, 47, 19, 22, 356, 457), nr = 2) dimnames(legalize) - list(Gender = c(Male, Female), +Three = c(111, 112, 211, 212, 121, +122, 221, 222)) legalize Three Gender 111 112 211 212 121 122 221 222 Male 342 26 6 21 11 32 19 356 Female 440 25 14 18 14 47 22 457 (Here '111' means (Yes, Yes, Yes) on the three items, etc.) How can I tranform elegantly this table into a dataframe that I can feed to lmer? I would like to know the answers to this as well. I thought I was going to be able to get away with as.data.frame.table() [which is handy and underappreciated], but it doesn't expand counts. I hope you get an elegant solution: in the meantime, I guess my advice is to try to write a reasonably general (if not necessarily absolutely elegant) function that you can supply your students with. If they have an expand.table() function, they won't care how complex it is internally ... Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] partial residuals
Dear all, I am trying to estimate partial residuals for the multiple regression lm model: a.lm=lm(y~x1+x2) I use the function residuals(a.lm, type=partial) However, the results are much different when I use the manual method to get partial residuals for x2 (or for x1): residuals(a.lm) +b1*x1 Where b1 is the estimated coefficient for x1 in the lm model and x1 is the vector of the first predictor. What is the difference (or my error) in these methods? Thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A horizontal or vertical line draw on mosaic plot?
Sang Chul Choi Choi at biology.rutgers.edu writes: I want to have a horizontal line on a mosaic plot with vcd package. This would give me an idea where is 0.5 proportion in a cell. Using mosaicplot function of graphics package, I can draw a line using abline. But, with mosaic function of vcd package, I have tried to use abline function, which complains plot.new has not been called yet. Is there a way to draw lines across a mosaic plot? library(vcd) music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 4) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low, Upper, Lower)) mosaic(music, keep_aspect_ratio=FALSE) abline(h=0.5) Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet Not that easy. vcd uses grid graphics, which is a medium-to-low level package; for example, lattice also uses grid graphics, and abline would not help. You could draw directly using grid graphics, but it may be a bit of reading. Use the example on the bottom of the strucplot page as a starter, which changes color. Also see page 17 of strucplot.pdf in the doc-directory of vcd for an example how to draw a frame around a rectangle. grid.edit(rect:Class=1st,Sex=Male,Age=Adult,Survived=Yes, gp = gpar(fill = red)) Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Post-hoc repeated measures ANOVA
Hello. I am looking for a multiple comparisons test to follow up a repeated mesures ANOVA i have conducted. Im not an expert in statistics or in R but i have managed to produce this: START fit5.lme-lme(logfaa~segment,random=~+1|fish) anova(fit5.lme) numDF denDF F-value p-value (Intercept) 1 8 14.553052 0.0051 segment 4 8 4.198819 0.0402 summary(fit3.lme) Linear mixed-effects model fit by REML Data: NULL AIC BIClogLik 34.53912 36.65722 -10.26956 Random effects: Formula: ~+1 | fish (Intercept) Residual StdDev: 7.073225e-06 0.5134332 Fixed effects: logufr ~ segment Value Std.Error DF t-value p-value (Intercept) -1.2899434 0.2964308 8 -4.351584 0.0024 segmentS21.0399190 0.4192164 8 2.480625 0.0381 segmentS31.1002549 0.4192164 8 2.624551 0.0304 segmentS40.3346369 0.4192164 8 0.798244 0.4478 segmentS5 -0.1543765 0.4192164 8 -0.368250 0.7222 Correlation: (Intr) sgmnS2 sgmnS3 sgmnS4 segmentS2 -0.707 segmentS3 -0.707 0.500 segmentS4 -0.707 0.500 0.500 segmentS5 -0.707 0.500 0.500 0.500 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -1.54451640 -0.23806358 -0.01628289 0.20255062 1.56079929 Number of Observations: 15 Number of Groups: 3 END Anyone know how i can follow this up to find out which segment(s) causes the significant difference? Snor __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] my first post to the list
Hello R-listers! My first post to the list is a very simple one for those who use the software continuosly. I am trying to understand the fixed-x resampling and random-x-resampling method proposed by Fox about Bootstrapping. The doubt that I have is on the side of the model run in one of the functions expressed for fixed-x resampling. What I don't understand is: X=model.matrix, and the -1 under mod= rlm. Please see below: #fixed x-resampling fit - fitted(mod.duncan.hub) e - residuals(mod.duncan.hub) X - model.matrix(mod.duncan.hub) boot.huber.fixed - function(data, indices, maxit=20){ y - fit + e[indices] mod - rlm(y ~ X - 1, maxit=maxit) coefficients(mod) } duncan.fix.boot - boot(Duncan, boot.huber.fixed, 1999, maxit=100) duncan.fix.boot I just need a quick explanation about WHAT the functions mean or do in this context. 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.
[R] expand.grid using a repeated vector as a parameter
Hello. I'm trying to do this (not necessarily 0:1) : expand.grid ( 0:1, 0:1, 0:1, 0:1, 0:1) etc..etc. but I want to have control over how many 0:1 are included. Any ideas please ? Thankyou. Simon Parker Imperial College - A Smarter Email. [[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] Loading large files in R
Hello, I'm attempting to load a ~110 MB text file with ~500,000 rows and 200 columns using read.table . R hangs and seems to give up. Can anyone tell me an efficient way to load a file of this size? Thank you! Alex -- View this message in context: http://www.nabble.com/Loading-large-files-in-R-tp17025045p17025045.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] WGEE
Hi! I am using geeglm (in geepack) and I need to use weights. There is in R a function that calculates the weights like in SAS PROC GENMOD . Any help would be sincerely appreciated. Thanks Salomé __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] expand.grid using a repeated vector as a parameter
?do.call On Fri, 2 May 2008, Simon Parker wrote: Hello. I'm trying to do this (not necessarily 0:1) : expand.grid ( 0:1, 0:1, 0:1, 0:1, 0:1) etc..etc. but I want to have control over how many 0:1 are included. Any ideas please ? Thankyou. Simon Parker Imperial College - A Smarter Email. [[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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loading large files in R
On 5/2/2008 2:13 PM, ajoyner wrote: Hello, I'm attempting to load a ~110 MB text file with ~500,000 rows and 200 columns using read.table . R hangs and seems to give up. Can anyone tell me an efficient way to load a file of this size? It will help a lot if you specify the column types (using the colClasses argument), so that R doesn't have to determine them from the data. It will also help if you've got lots of physical memory available for R; depending on the data, that could take several hundred MB of memory, and if the OS needs to use swap space to get it, you'll find it very slow. If you want to limit the memory footprint, don't read all of the data at once: specify some columns to be skipped (set their class to NULL) or some rows (using skip and/or nrow). 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] Loading large files in R
Hi Alex, Perhaps http://www.nabble.com/How-to-read-HUGE-data-sets--td15729830.html#a15746400can helps. HTH, Jorge On Fri, May 2, 2008 at 2:13 PM, ajoyner [EMAIL PROTECTED] wrote: Hello, I'm attempting to load a ~110 MB text file with ~500,000 rows and 200 columns using read.table . R hangs and seems to give up. Can anyone tell me an efficient way to load a file of this size? Thank you! Alex -- View this message in context: http://www.nabble.com/Loading-large-files-in-R-tp17025045p17025045.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extract lags from a formula
Hi folks! How do I extract lags from a formula? An example: mod.eq-formula(x~lag(x,-1)+lag(x,-2)) mod.eq x ~ lag(x, -1) + lag(x, -2) mod.eq[1] ~() mod.eq[2] x() mod.eq[3] lag(x, -1) + lag(x, -2)() I'm trying to extract the lags into a vector that would be simply [1,2]. How do I do this? I'm using the dyn package to do dynamic regression. John [[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] expand.grid using a repeated vector as a parameter
Try: tmp - rep( list( 0:1 ), 5 ) out - do.call(expand.grid, tmp) Then change the 5 to whatever you want. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Simon Parker Sent: Friday, May 02, 2008 11:50 AM To: r-help@r-project.org Subject: [R] expand.grid using a repeated vector as a parameter Hello. I'm trying to do this (not necessarily 0:1) : expand.grid ( 0:1, 0:1, 0:1, 0:1, 0:1) etc..etc. but I want to have control over how many 0:1 are included. Any ideas please ? Thankyou. Simon Parker Imperial College - A Smarter Email. [[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] Extract lags from a formula
On Fri, May 2, 2008 at 1:35 PM, Kerpel, John [EMAIL PROTECTED] wrote: Hi folks! How do I extract lags from a formula? An example: mod.eq-formula(x~lag(x,-1)+lag(x,-2)) mod.eq x ~ lag(x, -1) + lag(x, -2) mod.eq[1] ~() mod.eq[2] x() mod.eq[3] lag(x, -1) + lag(x, -2)() I'm trying to extract the lags into a vector that would be simply [1,2]. How do I do this? I'm using the dyn package to do dynamic regression. Maybe something like: f - formula(x~lag(x,-1)+lag(x,-2)) lags - function(x) { if (length(x) != 3) return() if (x[[1]] == as.name(lag)) { return(eval(x[[3]])) } else { return(c(lags(x[[2]]), lags(x[[3]]))) } } R expressions are preorder trees. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] New package: profr 0.1 - an alternative display for profiling information
profr 0.1 profr provides an alternative data structure and display for profiling data. It still uses Rprof() to collect the data, but outputs a data.frame which should be easier to manipulate. It also implements a novel visualisation which allows you to see the length of each call, as well as the context in which it was called. To get started, try: install.packages(profr) library(profr) p - profr(my.slow.function()) plot(p) Two built in examples are: plot(nesting_prof) plot(reshape_prof) (and the second has helped me to considerably speed up (5-20x) the development version of reshape) Regards, Hadley PS. If you'd like to contribute to the development of profr, the source code is available from http://github.com/hadley/profr. -- http://had.co.nz/ ___ R-packages mailing list [EMAIL PROTECTED] 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] re moving rows from matrix
you could do it using apply like the first two replies mentioned or you could just use the index way for example: (assuming your matrix name is ym and the values are greater than 25 and less than 50 and the column is column 3).. if you mean any column use the first two replies. ym-array(runif(10,20,100),c(6,5)); ym [,1] [,2] [,3] [,4] [,5] [1,] 97.57168 52.22471 41.23411 91.78960 22.57583 [2,] 41.17106 23.73572 55.77120 27.47041 37.94204 [3,] 41.23411 91.78960 22.57583 97.57168 52.22471 [4,] 55.77120 27.47041 37.94204 41.17106 23.73572 [5,] 22.57583 97.57168 52.22471 41.23411 91.78960 [6,] 37.94204 41.17106 23.73572 55.77120 27.47041 ym-ym[(ym[,3]25) (ym[,3] 50),]; ym [,1] [,2] [,3] [,4] [,5] [1,] 97.57168 52.22471 41.23411 91.78960 22.57583 [2,] 55.77120 27.47041 37.94204 41.17106 23.73572 thanks Monna Nygård wrote: Hi, I have a problem regarding matrix handeling. I am working with a serie of matrixes containing several columns. Now I would like to delete those rows of the matrixes,that in one of the columns contain values less than 50 or greater than 1000. How would this be possible, I have tried to create a simple function for this, but I just don't seem to get it right.Thank you so much for your help, Monna _ [[elided Hotmail spam]] PLink [[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. -- View this message in context: http://www.nabble.com/removing-rows-from-matrix-tp17016646p17025836.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] Fwd: my first post to the list
Hello R-listers! My first post to the list is a very simple one for those who use the software continuosly. I am trying to understand the fixed-x resampling and random-x-resampling method proposed by Fox about Bootstrapping. The doubt that I have is on the side of the model run in one of the functions expressed for fixed-x resampling. What I don't understand is: X=model.matrix, and the -1 under mod= rlm. Please see below: #fixed x-resampling fit - fitted(mod.duncan.hub) e - residuals(mod.duncan.hub) X - model.matrix(mod.duncan.hub) boot.huber.fixed - function(data, indices, maxit=20){ y - fit + e[indices] mod - rlm(y ~ X - 1, maxit=maxit) coefficients(mod) } duncan.fix.boot - boot(Duncan, boot.huber.fixed, 1999, maxit=100) duncan.fix.boot I just need a quick explanation about WHAT the functions mean or do in this context. Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loading large files in R
On 5/2/2008 2:52 PM, Alex Joyner wrote: Duncan, Thank you for your response. I actually am using colClasses, but the first column is a character column, and the rest are numeric. Is there any way to specify that all columns are numeric except for the first one? I couldn't find this in the documentation. Also, I can't remove the first column until I read the file in right? If you set colClasses = c(NULL, rep(numeric, 199)) you should get what you want. Duncan Murdoch Thanks again! Alex Date: Fri, 2 May 2008 14:34:39 -0400 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] CC: r-help@r-project.org Subject: Re: [R] Loading large files in R On 5/2/2008 2:13 PM, ajoyner wrote: Hello, I'm attempting to load a ~110 MB text file with ~500,000 rows and 200 columns using read.table . R hangs and seems to give up. Can anyone tell me an efficient way to load a file of this size? It will help a lot if you specify the column types (using the colClasses argument), so that R doesn't have to determine them from the data. It will also help if you've got lots of physical memory available for R; depending on the data, that could take several hundred MB of memory, and if the OS needs to use swap space to get it, you'll find it very slow. If you want to limit the memory footprint, don't read all of the data at once: specify some columns to be skipped (set their class to NULL) or some rows (using skip and/or nrow). Duncan Murdoch With Windows Live for mobile, your contacts travel with you. Connect on the go. http://www.windowslive.com/mobile/overview.html?ocid=TXT_TAGLM_WL_Refresh_mobile_052008 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cor.test like cor?
Hi, Is there a simple way to do correlation coefficient tests with cor.test like I would do with cor function? I have a data frame where each column is a list. y - data.frame(a=sample(30, 20), b=sample(30, 20), c=sample(30,20)) cor(y) But, cor.test does not take y alone, and it needs two vectors. We may do each test by iterating a pair of columns by loop. Is there a simple way to do it? I will appreciate your help. Thank you, Sang Chul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 parse XML
Martin, I can't thank you enough for taking the time to help and providing the detailed examples of how to get started. Now I know exactly how to proceed. Thanks again, Roger -Original Message- From: Martin Morgan [mailto:[EMAIL PROTECTED] Sent: Friday, May 02, 2008 12:02 PM To: Bos, Roger Cc: r-help@r-project.org Subject: Re: [R] How to parse XML Hi Roger -- Bos, Roger [EMAIL PROTECTED] writes: I would like to learn how to parse a mixed text/xml document I downloaded from the sec.gov website (see example below). I would like I'm not sure of a more robust way to extract the XML, but from inspection I wrote ftp - ftp://anonymous:[EMAIL PROTECTED]/edgar/data/1317493/0001144204-08-02122 1.txt txt - readLines(ftp) xmlInside - grep(/*XML, txt) xmlTxt - txt[seq(xmlInside[1]+1, xmlInside[2]-1)] so that xmlTxt contains the part of the message that is XML to parse this to get the value for each xml tag and then access it within R, but I don't know much about xml so I don't even know where to There are several ways to proceed. I personally like the xpath query language. to do this, one might xml - xmlTreeParse(xmlTxt, useInternal=TRUE) head(unlist(xpathApply(xml, //*, xmlName))) [1] ownershipDocument schemaVersion documentType [4] periodOfReportnotSubjectToSection16 issuer xpathApply takes an xml document and performs a query. The query '//*' says find all nodes mataching any character string (that's the *) that are located anywhere (that's the //) below the current (in this case root) node. This gives a list of nodes; xmlName extracts the name of the node. If I wanted all nodes not subject to section 16 (sounds ominmous) I'd extract all the nodes (a list0 node - xpathApply(xml, //notSubjectToSection16) and then do something with them, e.g., look at them lapply(node, saveXML) [[1]] [1] notSubjectToSection160/notSubjectToSection16 (not so bad, looks like nothing is not subject to section 16, that's a relief) and extract their value lapply(node, xmlValue) In one step: xpathApply(xml, //notSubjectToSection16, xmlValue) ?xpathApply is a good starting place, as is http://www.w3.org/TR/xpath, especially http://www.w3.org/TR/xpath#path-abbrev Martin start debugging the errors I am getting in this example code. Can anyone help me get started? Thanks, Roger ftp - ftp://anonymous:[EMAIL PROTECTED]/edgar/data/1317493/0001144204-08-021 22 1.txt download.file(url=ftp, destfile=test2.txt) xmlTreeParse(test2.txt) ** * This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No right to confidential or privileged treatment of this message is waived or lost by any error in transmission. If you have received this message in error, please immediately notify the sender by e-mail, delete the message and all copies from your system and destroy any hard copies. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message if you are not the intended recipient. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (206) 667-2793 ** * This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No right to confidential or privileged treatment of this message is waived or lost by any error in transmission. If you have received this message in error, please immediately notify the sender by e-mail, delete the message and all copies from your system and destroy any hard copies. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message if you are not the intended recipient. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] plot size vs. text size
Hello: I am using plot() in rpart, making a decision tree plot. I use plot() first, then text() followed, but I think due to the figure vs. text size, the bottom of the text always gets cut off. I can only see the text of the bottom of the tree if I make the font size REALLY small. I think is shouldnt be a specific rpart question, but rather a general plotting technique question. Thanks, Karen _ [[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] GLMM and data manipulation (2nd try)
Hello, I posted a question yesterday but I got no replies, so I'll try to reformulate it in a more concise way. I have the following data, summarizing approval ratings on two different surveys for a random sample of 1600 individuals: ## Example: Ratings of prime minister (Agresti, Table 12.1, p.494) rating - matrix(c(794, 86, 150, 570), 2, 2) dimnames(rating) - list(First = c(approve, disapprove), + Second = c(approve, disapprove)) rating Second Firstapprove disapprove approve794150 disapprove 86570 I would like to fit a logit model with approve/disapprove as response, survey (first/second) as a fixed effect, and subject as a random effect. 1) Is it possible to fit such a model directly using lmer? or 2) Should I unroll the table above into a dataframe containing also fictitious subject id's? If this is the case, what is a clean way of doing it? Thank you in advance, Giovanni Petris -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A horizontal or vertical line draw on mosaic plot?
Thank you, Dieter, very much for your answer. I'd rather avoid using mosaic. I think that I need to read more about vcd manual you mentioned. One quick question? Is it possible to color each cells with all different colors with mosaicplot? I have used mosaic function to do coloring each cells depending on my favor. I mean, I can color any cell with any color with mosaic but I could not figure it out with mosaicplot. Is it possible to color any cell with any color with mosaicplot function? I will greatly appreciate any help. Thank you, Sang Chul On May 2, 2008, at 1:41 PM, Dieter Menne wrote: Sang Chul Choi Choi at biology.rutgers.edu writes: I want to have a horizontal line on a mosaic plot with vcd package. This would give me an idea where is 0.5 proportion in a cell. Using mosaicplot function of graphics package, I can draw a line using abline. But, with mosaic function of vcd package, I have tried to use abline function, which complains plot.new has not been called yet. Is there a way to draw lines across a mosaic plot? library(vcd) music = c(210, 194, 170, 110, 190, 406, 730, 290) dim(music) = c(2, 4) dimnames(music) = list(Age = c(Old, Young), Education = c(High, Low, Upper, Lower)) mosaic(music, keep_aspect_ratio=FALSE) abline(h=0.5) Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet Not that easy. vcd uses grid graphics, which is a medium-to-low level package; for example, lattice also uses grid graphics, and abline would not help. You could draw directly using grid graphics, but it may be a bit of reading. Use the example on the bottom of the strucplot page as a starter, which changes color. Also see page 17 of strucplot.pdf in the doc-directory of vcd for an example how to draw a frame around a rectangle. grid.edit(rect:Class=1st,Sex=Male,Age=Adult,Survived=Yes, gp = gpar(fill = red)) Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Errors using nlme's gls with autocorrelation
Hi, I am trying out a generalized least squares method of forecasting that corrects for autocorrelation. I downloaded daily stock data from Yahoo Finance, and am trying to predict Close (n=7903). I have learned to use date functions to extract indicator variables for Monday - Friday (and Friday is missing in the model to prevent it from becoming full rank). When I run the following code... library(nlme) MyModel - gls(Close ~ Monday + Tuesday + Wednesday + Thursday, correlation=corARMA(p=2), data=MyData, method=ML) ...I get the following error... Error in corFactor.corARMA(object) : Calloc could not allocate (62457409 of 8) memory ...Does anybody know what I'm doing wrong? I appreciate any help. Thanks. -- View this message in context: http://www.nabble.com/Errors-using-nlme%27s-gls-with-autocorrelation-tp17026417p17026417.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] adjusting plot vs font size in a plot
Hello: I am using plot() in rpart, making a decision tree plot. I use plot() first, then text() followed, but I think due to the figure vs. text size, the bottom of the text always gets cut off. I can only see the text of the bottom of the tree if I make the font size REALLY small. I think is shouldn't be a specific rpart question, but rather a general plotting technique question. Thanks, Karen [[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] .Rprofile is being executed twice
Hi, After updating to R 2.7, my .Rprofile executes twice on startup. I confirmed this by putting in the following line: print(starting .Rprofile...) When I start R, I see: [1] starting .Rprofile... [1] starting .Rprofile... This seems like the obverse of the following FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f But in my case .Rprofile is working, just working twice as much as it should. Even if there is nothing in my .Rprofile except that print() statement, it still executes twice. What could be causing this? Thanks Dan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cor.test like cor?
Try this: y - data.frame(a=sample(30, 20), b=sample(30, 20), c=sample(30,20)) x - diag(1, length(names(y)) cors - combn(names(y), 2, FUN = function(x)cor.test(y[,x[1]], y[,x[2]])$p.value) x[lower.tri(x)] - cors x[upper.tri(x)] - cors On 5/2/08, Sang Chul Choi [EMAIL PROTECTED] wrote: Hi, Is there a simple way to do correlation coefficient tests with cor.test like I would do with cor function? I have a data frame where each column is a list. y - data.frame(a=sample(30, 20), b=sample(30, 20), c=sample(30,20)) cor(y) But, cor.test does not take y alone, and it needs two vectors. We may do each test by iterating a pair of columns by loop. Is there a simple way to do it? I will appreciate your help. Thank you, Sang Chul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Errors using nlme's gls with autocorrelation
You're running out of RAM. Your options are 1) run code on a machine with more RAM 2) try the model on fewer observations 3) try a simpler model. Andrew On Fri, May 02, 2008 at 12:37:15PM -0700, zerfetzen wrote: Hi, I am trying out a generalized least squares method of forecasting that corrects for autocorrelation. I downloaded daily stock data from Yahoo Finance, and am trying to predict Close (n=7903). I have learned to use date functions to extract indicator variables for Monday - Friday (and Friday is missing in the model to prevent it from becoming full rank). When I run the following code... library(nlme) MyModel - gls(Close ~ Monday + Tuesday + Wednesday + Thursday, correlation=corARMA(p=2), data=MyData, method=ML) ...I get the following error... Error in corFactor.corARMA(object) : Calloc could not allocate (62457409 of 8) memory ...Does anybody know what I'm doing wrong? I appreciate any help. Thanks. -- View this message in context: http://www.nabble.com/Errors-using-nlme%27s-gls-with-autocorrelation-tp17026417p17026417.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. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GLMM and data manipulation (2nd try)
On Fri, May 02, 2008 at 03:06:31PM -0500, Giovanni Petris wrote: Hello, I posted a question yesterday but I got no replies, so I'll try to reformulate it in a more concise way. I have the following data, summarizing approval ratings on two different surveys for a random sample of 1600 individuals: ## Example: Ratings of prime minister (Agresti, Table 12.1, p.494) rating - matrix(c(794, 86, 150, 570), 2, 2) dimnames(rating) - list(First = c(approve, disapprove), + Second = c(approve, disapprove)) rating Second Firstapprove disapprove approve794150 disapprove 86570 I would like to fit a logit model with approve/disapprove as response, survey (first/second) as a fixed effect, and subject as a random effect. 1) Is it possible to fit such a model directly using lmer? or 2) Should I unroll the table above into a dataframe containing also fictitious subject id's? If this is the case, what is a clean way of doing it? Unroll it. Asking for a clean way to do something is a disincentive because it implies that you know how to do it but not cleanly. In the future I would suggest that you do one of two things a) post your on dirty version and ask for a cleaner one, or b) just ask for something that works. Something like ... ratings - data.frame( response = c( rep(c(1,1), 794), rep(c(1,0), 150), rep(c(0,1), 86), rep(c(0,0), 570)), time = rep(c(1,2), 1600), subject=rep(1:1600, each=2)) test.lmer - lmer(response ~ time + (1|subject), data=ratings, family=binomial) but I don't know if you think that's clean or not. Andrew Thank you in advance, Giovanni Petris -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GLMM and data manipulation (2nd try)
On Sat, May 03, 2008 at 06:43:22AM +1000, Andrew Robinson wrote: On Fri, May 02, 2008 at 03:06:31PM -0500, Giovanni Petris wrote: Hello, I posted a question yesterday but I got no replies, so I'll try to reformulate it in a more concise way. I have the following data, summarizing approval ratings on two different surveys for a random sample of 1600 individuals: ## Example: Ratings of prime minister (Agresti, Table 12.1, p.494) rating - matrix(c(794, 86, 150, 570), 2, 2) dimnames(rating) - list(First = c(approve, disapprove), + Second = c(approve, disapprove)) rating Second Firstapprove disapprove approve794150 disapprove 86570 I would like to fit a logit model with approve/disapprove as response, survey (first/second) as a fixed effect, and subject as a random effect. 1) Is it possible to fit such a model directly using lmer? or 2) Should I unroll the table above into a dataframe containing also fictitious subject id's? If this is the case, what is a clean way of doing it? Unroll it. Asking for a clean way to do something is a disincentive because it implies that you know how to do it but not cleanly. In the future I would suggest that you do one of two things a) post your on dirty version and ask for a cleaner one, or b) just ask for something that works. Something like ... Or (possibly better) make time a factor. ratings - data.frame( response = c( rep(c(1,1), 794), rep(c(1,0), 150), rep(c(0,1), 86), rep(c(0,0), 570)), time = factor(rep(c(1,2), 1600)), subject=rep(1:1600, each=2)) test.lmer - lmer(response ~ time + (1|subject), data=ratings, family=binomial) Andrew but I don't know if you think that's clean or not. Andrew Thank you in advance, Giovanni Petris -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] points size in plots
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Irene Mantzouni Sent: Friday, May 02, 2008 7:52 AM To: [EMAIL PROTECTED] Subject: [R] points size in plots Dear list, I would like to produce a plot of variables where the size of the points will be indicative of their standard errors. How is that possible? Thank you! Do you mean (a) the larger the standard error, the bigger the point, or (b) the larger the standard error, the smaller the point? (b) makes more statistical sense. Anyways, you can use cex. An example with two variables, u and v, in the case of (a) u - rnorm(10,2,3) v - rnorm(10,5,4) se.u - runif(10,1,4) se.v - runif(10,4,7) x - 2:11 plot(x,u,cex=se.u/max(se.u)) points(x,v,cex=se.v/max(se.v),pch=19) And in the case of (b) u - rnorm(10,2,3) v - rnorm(10,5,4) se.u - runif(10,1,4) se.v - runif(10,4,7) x - 2:11 plot(x,u,cex=(1/se.u)/max(1/se.u)) points(x,v,cex=(1/se.v)/max(1/se.v),pch=19) If you have NAs in your variables, use the na.rm=TRUE argument of max(). If the standard errors are very different, you can multiply the quantity evaluated for cex with a positive constant, say u - rnorm(10,2,3) v - rnorm(10,5,4) se.u - runif(10,1,4) se.v - runif(10,4,7) x - 2:11 w=2.5 plot(x,u,cex=w*(1/se.u)/max(1/se.u)) points(x,v,cex=w*(1/se.v)/max(1/se.v),pch=19) HTH Ruben __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GLMM and data manipulation (2nd try)
Andrew, Thank you for your reply. In fact, I had a way of unrolling the table but I think yours look much nicer - much readable to me. Below is what I did, but I was afraid I would scare my students away from R! approval - factor(c(Approve, Disapprove), +levels = c(Disapprove, Approve)) survey - factor(c(First, Second)) tmp - data.frame(approval = unlist(expand.grid(approval, approval)), + survey = rep(survey, each = 4)) rat.df - cbind(tmp[rep(1:8, rep(rating, 2)), ], + id = factor(rep(1:sum(rating), 2))) row.names(rat.df) - NULL Thank you again, Giovanni Date: Sat, 03 May 2008 06:43:22 +1000 From: Andrew Robinson [EMAIL PROTECTED] Cc: r-help@r-project.org User-Agent: Mutt/1.4.2.3i On Fri, May 02, 2008 at 03:06:31PM -0500, Giovanni Petris wrote: Hello, I posted a question yesterday but I got no replies, so I'll try to reformulate it in a more concise way. I have the following data, summarizing approval ratings on two different surveys for a random sample of 1600 individuals: ## Example: Ratings of prime minister (Agresti, Table 12.1, p.494) rating - matrix(c(794, 86, 150, 570), 2, 2) dimnames(rating) - list(First = c(approve, disapprove), + Second = c(approve, disapprove)) rating Second Firstapprove disapprove approve794150 disapprove 86570 I would like to fit a logit model with approve/disapprove as response, survey (first/second) as a fixed effect, and subject as a random effect. 1) Is it possible to fit such a model directly using lmer? or 2) Should I unroll the table above into a dataframe containing also fictitious subject id's? If this is the case, what is a clean way of doing it? Unroll it. Asking for a clean way to do something is a disincentive because it implies that you know how to do it but not cleanly. In the future I would suggest that you do one of two things a) post your on dirty version and ask for a cleaner one, or b) just ask for something that works. Something like ... ratings - data.frame( response = c( rep(c(1,1), 794), rep(c(1,0), 150), rep(c(0,1), 86), rep(c(0,0), 570)), time = rep(c(1,2), 1600), subject=rep(1:1600, each=2)) test.lmer - lmer(response ~ time + (1|subject), data=ratings, family=binomial) but I don't know if you think that's clean or not. Andrew Thank you in advance, Giovanni Petris -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Aggregate() questions
You need seet the FUN argument: X - with( FDP0D, ave( IAC, list( Key), FUN = mean)) On 5/1/08, Chip Barnaby [EMAIL PROTECTED] wrote: Henrique, thanks for the response. As a new user, I was unaware of with() and ave(), those are both very helpful. However, I don't think your method is quite right. I for all rows in each Key, I want the mean( IAC) where ProfA = 0. To simplify the problem, I have made a subset dataframe that contains only the rows required for the mean (data frame names changed from the original email) ... FDP0D-subset( FD, abs( FD$ProfA) .01 FD$IncA 70, select=c(Key,IAC)) The first few rows of FDP0D look like this (note row names) ... FDP0D KeyIAC 11 B6-VB000.VB00045.3.12.3.0 0.889 12 B6-VB000.VB00045.3.12.3.0 0.889 13 B6-VB000.VB00045.3.12.3.0 0.890 14 B6-VB000.VB00045.3.12.3.0 0.890 15 B6-VB000.VB00045.3.12.3.0 0.891 16 B6-VB000.VB00045.3.12.3.0 0.892 17 B6-VB000.VB00045.3.12.3.0 0.893 83 B6-VB020.VB02045.3.12.3.0 0.852 84 B6-VB020.VB02045.3.12.3.0 0.852 85 B6-VB020.VB02045.3.12.3.0 0.852 (etc ... 630 rows) Now I do the ave( ) X-with( FDP0D, ave( IAC, list( Key), mean)) And I get ... function (x, ...) UseMethod(mean) environment: namespace:base Error in unique.default(x) : unique() applies only to vectors What's up? unique() seems to work OK on Key ... with( FDP0D, unique( Key)) [1] B6-VB000.VB00045.3.12.3.0 B6-VB020.VB02045.3.12.3.0 [3] B6-VB040.VB04045.3.12.3.0 B6-VB060.VB06045.3.12.3.0 [5] B6-VB080.VB08045.3.12.3.0 B6-VB100.VB10045.3.12.3.0 [7] BC6-VB000.VB00045.3.12.3.0 BC6-VB020.VB02045.3.12.3.0 [9] BC6-VB040.VB04045.3.12.3.0 BC6-VB060.VB06045.3.12.3.0 (etc, 90 values which is correct) Thanks, Chip Barnaby At 03:09 PM 4/30/2008, Henrique Dallazuanna wrote: If I understand your question: x$IAC0 - with(x, ave(IAC, list(ProfA, Key), FUN = mean)) On Wed, Apr 30, 2008 at 3:52 PM, Chip Barnaby mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote: Dear all -- I have a data frame containing data related to heat gain through windows. The general form is ... Key ProfAIAC many other numeric columns AAA0.7 AAA 10.6 AAA0 .66 AAA 20 .45 (more AAA rows) (then AAB rows) 'Key' identifies the physical configuration ... rows with a given Key contain data for same window under various conditions. I want to add a column IAC0 containing, for each Key, the mean IAC of all rows with ProfA == 0. The general approach I think I need is approximately (the following is not known to run) -- 1) XS-subset( X, ProfA .01) to get the ProfA == 0 rows. This could be done implicitly as part of step 2, I suppose. 2) X0-aggregate( XS[,IAC], by=list( Key=XS$Key), mean) 3) XF-merge( X, X0, by=Key) 4) Change new col name to IAC0 (see Question 2). Question 1: Is this a reasonable way to solve my problem? Question 2: The aggregate() result has 2 columns: Key and x. Can the name of the mean column be specified (short of renaming after the fact)? All the aggregate() examples (e.g. in help()) elegantly produce the right result with nicely named columns etc. I can't seem to make things work so smoothly. Thanks! Chip Barnaby - Chip Barnaby mailto:[EMAIL PROTECTED][EMAIL PROTECTED] Vice President of Research Wrightsoft Corp. 781-862-8719 x118 voice 131 Hartwell Ave 781-861-2058 fax Lexington, MA 02421 http://www.wrightsoft.comwww.wrightsoft.com __ mailto:R-help@r-project.orgR-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O - Chip Barnaby [EMAIL PROTECTED] Vice President of Research Wrightsoft Corp. 781-862-8719 x118 voice 131 Hartwell Ave 781-861-2058 fax Lexington, MA 02421 www.wrightsoft.com - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version
[R] data transformation
Dear all, how can I, with R, transform a presence-absence (0/1) matrix of species occurrences into a presence-only table (3 columns) with the names of the species (1st column), the lat information of the sites (2nd column) and the lon information of the sites (3rd column), as given in the below example? Thanks a lot for your help! Christian my dataframe: sitelat lon spec1 spec2 spec3 spec4 site1 10 11 1 0 1 0 site2 20 21 1 1 1 0 site3 30 31 0 1 1 1 my desired new dataframe: species lat lon spec1 10 11 spec1 20 21 spec2 20 21 spec2 30 31 spec3 10 11 spec3 20 21 spec3 30 31 spec4 30 31 -- Christian Hof, PhD student Center for Macroecology Evolution University of Copenhagen www.macroecology.ku.dk Biodiversity Global Change Lab Museo Nacional de Ciencias Naturales, Madrid www.biochange-lab.eu mobile ES .. +34 697 508 519 mobile DE .. +49 176 205 189 27 mail .. [EMAIL PROTECTED] mail2 .. [EMAIL PROTECTED] blog .. www.vogelwart.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.
[R] barplot with log base 2 scale or shift the x-axis
Hi, I have data that is on a log base 2 scale. It goes from negative factors of 2 to positive ones. I am using barplot. However, I don't want the data centered at 0 - I want the min of the yaxis to be just below the lowest value in the data. The plots are kind of deceptive switching between positive and negative. I see that barplot has a log option, but that doesn't seem to be adjustable for a log base 2 scale. Does anyone know how to adjust the x-axis, so it's at y= -value rather than at y=0? I''d rather not add a factor to the data, unless I can have accurate labels on the y-axis. Any ideas? Thanks, Summer [[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] data transformation
Christian, You need to use reshape to convert to the 'long' format. Check the help page ?reshape for details. dat - read.table('clipboard', header=TRUE) dat site lat lon spec1 spec2 spec3 spec4 1 site1 10 11 1 0 1 0 2 site2 20 21 1 1 1 0 3 site3 30 31 0 1 1 1 dat.long - reshape(dat, varying = list(names(dat)[4:7]), timevar=species, times=names(dat)[4:7], direction=long) dat.long site lat lon species spec1 id 1.spec1 site1 10 11 spec1 1 1 2.spec1 site2 20 21 spec1 1 2 3.spec1 site3 30 31 spec1 0 3 1.spec2 site1 10 11 spec2 0 1 2.spec2 site2 20 21 spec2 1 2 3.spec2 site3 30 31 spec2 1 3 1.spec3 site1 10 11 spec3 1 1 2.spec3 site2 20 21 spec3 1 2 3.spec3 site3 30 31 spec3 1 3 1.spec4 site1 10 11 spec4 0 1 2.spec4 site2 20 21 spec4 0 2 3.spec4 site3 30 31 spec4 1 3 dat.long[dat.long$spec1 == 1, ] site lat lon species spec1 id 1.spec1 site1 10 11 spec1 1 1 2.spec1 site2 20 21 spec1 1 2 2.spec2 site2 20 21 spec2 1 2 3.spec2 site3 30 31 spec2 1 3 1.spec3 site1 10 11 spec3 1 1 2.spec3 site2 20 21 spec3 1 2 3.spec3 site3 30 31 spec3 1 3 3.spec4 site3 30 31 spec4 1 3 -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christian Hof Sent: Friday, May 02, 2008 5:28 PM To: r-help@r-project.org Subject: [R] data transformation Dear all, how can I, with R, transform a presence-absence (0/1) matrix of species occurrences into a presence-only table (3 columns) with the names of the species (1st column), the lat information of the sites (2nd column) and the lon information of the sites (3rd column), as given in the below example? Thanks a lot for your help! Christian my dataframe: site lat lon spec1 spec2 spec3 spec4 site1 10 11 1 0 1 0 site2 20 21 1 1 1 0 site3 30 31 0 1 1 1 my desired new dataframe: species lat lon spec1 10 11 spec1 20 21 spec2 20 21 spec2 30 31 spec3 10 11 spec3 20 21 spec3 30 31 spec4 30 31 -- Christian Hof, PhD student Center for Macroecology Evolution University of Copenhagen www.macroecology.ku.dk Biodiversity Global Change Lab Museo Nacional de Ciencias Naturales, Madrid www.biochange-lab.eu mobile ES .. +34 697 508 519 mobile DE .. +49 176 205 189 27 mail .. [EMAIL PROTECTED] mail2 .. [EMAIL PROTECTED] blog .. www.vogelwart.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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data transformation
Hi Christian, Here's a way using the reshape package: dfr site lat lon spec1 spec2 spec3 spec4 1 site1 10 11 1 0 1 0 2 site2 20 21 1 1 1 0 3 site3 30 31 0 1 1 1 library(reshape) dfr - melt(dfr[, -1], id=1:2, variable_name='species') dfr - dfr[dfr$value0,] dfr lat lon species value 1 10 11 spec1 1 2 20 21 spec1 1 5 20 21 spec2 1 6 30 31 spec2 1 7 10 11 spec3 1 8 20 21 spec3 1 9 30 31 spec3 1 12 30 31 spec4 1 The 'value', variable is not interesting here, but if you had counts rather than presence/absence it could be. best, Kingsford Jones On Fri, May 2, 2008 at 2:27 PM, Christian Hof [EMAIL PROTECTED] wrote: Dear all, how can I, with R, transform a presence-absence (0/1) matrix of species occurrences into a presence-only table (3 columns) with the names of the species (1st column), the lat information of the sites (2nd column) and the lon information of the sites (3rd column), as given in the below example? Thanks a lot for your help! Christian my dataframe: sitelat lon spec1 spec2 spec3 spec4 site1 10 11 1 0 1 0 site2 20 21 1 1 1 0 site3 30 31 0 1 1 1 my desired new dataframe: species lat lon spec1 10 11 spec1 20 21 spec2 20 21 spec2 30 31 spec3 10 11 spec3 20 21 spec3 30 31 spec4 30 31 -- Christian Hof, PhD student Center for Macroecology Evolution University of Copenhagen www.macroecology.ku.dk Biodiversity Global Change Lab Museo Nacional de Ciencias Naturales, Madrid www.biochange-lab.eu mobile ES .. +34 697 508 519 mobile DE .. +49 176 205 189 27 mail .. [EMAIL PROTECTED] mail2 .. [EMAIL PROTECTED] blog .. www.vogelwart.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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] .Rprofile is being executed twice
On 02/05/2008 4:24 PM, Dan Tenenbaum wrote: Hi, After updating to R 2.7, my .Rprofile executes twice on startup. I confirmed this by putting in the following line: print(starting .Rprofile...) When I start R, I see: [1] starting .Rprofile... [1] starting .Rprofile... This seems like the obverse of the following FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f But in my case .Rprofile is working, just working twice as much as it should. Even if there is nothing in my .Rprofile except that print() statement, it still executes twice. What could be causing this? It doesn't for me, so I think we need more details, such as sessionInfo(), and exactly where you put your .Rprofile, and how you started R. 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] data transformation
Try this: newx - with(x, cbind(stack(x, select = grep(spec, names(x))), lat, lon)) newx[newx$values 0, -1] On 5/2/08, Christian Hof [EMAIL PROTECTED] wrote: Dear all, how can I, with R, transform a presence-absence (0/1) matrix of species occurrences into a presence-only table (3 columns) with the names of the species (1st column), the lat information of the sites (2nd column) and the lon information of the sites (3rd column), as given in the below example? Thanks a lot for your help! Christian my dataframe: sitelat lon spec1 spec2 spec3 spec4 site1 10 11 1 0 1 0 site2 20 21 1 1 1 0 site3 30 31 0 1 1 1 my desired new dataframe: species lat lon spec1 10 11 spec1 20 21 spec2 20 21 spec2 30 31 spec3 10 11 spec3 20 21 spec3 30 31 spec4 30 31 -- Christian Hof, PhD student Center for Macroecology Evolution University of Copenhagen www.macroecology.ku.dk Biodiversity Global Change Lab Museo Nacional de Ciencias Naturales, Madrid www.biochange-lab.eu mobile ES .. +34 697 508 519 mobile DE .. +49 176 205 189 27 mail .. [EMAIL PROTECTED] mail2 .. [EMAIL PROTECTED] blog .. www.vogelwart.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. -- 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] Lattice book
On 5/2/08, Michael Kubovy [EMAIL PROTECTED] wrote: I too have been studying the book and it is indeed outstanding. For my purposes the only topic missing is the straightforward drawing of error bars and bands, for which I've been using Hmisc::xYplot (where error bands seem to be broken for R) or gplots::barplot2. That's a useful topic; I'll write something up (I do have some code around for error bars, but not bands). -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Errors bar in barchart
On 5/2/08, Ronaldo Reis Junior [EMAIL PROTECTED] wrote: Hi, I user barplot2 to make a plot bar with errors bars. In old times I needed to use a sequence of segments commands to make this. Now I try to make the same but using lattice. Is possible to use barplot2 in barchart function? If not, what is the simplest way to put errors bar in barchart? I try to find an example in Lattice book, but dont find anythink like this. No there isn't. I don't like the idea of error bars on bar charts, and I would suggest you use them with dot plots instead. There is a demo of this that you can run using demo(intervals, package = lattice) -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] png misbehaving with levelplot when inside a loop
Hi David, Putting a print statement around your spplot command solves your problem. This behaviour is common for trellis graphics plot methods (such as spplot). This is the command including print: print(spplot(meuse, c(ffreq), sp.layout=list(l2,l3,l4,l5),col.regions=black,pch=c(1,2,3), key.space=list(x=0.1,y=.95,corner=c(0,1 These kinds of questions maybe are not specific to sp, but still might generate more response from the r-sig-geo mailing list. cheers, Paul David wrote: I want to use spplot inside a loop to itteratively produce png files. for (i in 1:5){ png(file=paste(myPlot,i,.png,sep=),bg=white,height=500,width=500) library(lattice) trellis.par.set(sp.theme()) # sets bpy.colors() ramp data(meuse) coordinates(meuse) - ~x+y l2 = list(SpatialPolygonsRescale, layout.north.arrow(), offset = c(181300,329800), scale = 400) l3 = list(SpatialPolygonsRescale, layout.scale.bar(), offset = c(180500,329800), scale = 500, fill=c(transparent,black)) l4 = list(sp.text, c(180500,329900), 0) l5 = list(sp.text, c(181000,329900), 500 m) spplot(meuse, c(ffreq), sp.layout=list(l2,l3,l4,l5),col.regions=black,pch=c(1,2,3), key.space=list(x=0.1,y=.95,corner=c(0,1))) dev.off() } The above example fails to write the output to the file. When the loop is finished the file size of each file is 0Kb. If I perform the work of the loop manually, ie. setting i - 1, i - 2 etc before manually running the loop contents then there is no problem. There is also no problem if I replace all the spplot stuff with say hist(rnorm(100)). The same behaviour is reproduced with levelplot too so is not sp specific. for (i in 1:5){ png(file=paste(sillyPlot,i,.png,sep=),bg=white,height=500,width=500) x - seq(pi/4, 5 * pi, length = 100) y - seq(pi/4, 5 * pi, length = 100) r - as.vector(sqrt(outer(x^2, y^2, +))) grid - expand.grid(x=x, y=y) grid$z - cos(r^2) * exp(-r/(pi^3)) levelplot(z~x*y, grid, cuts = 50, scales=list(log=e), xlab=, ylab=, main=Weird Function, sub=with log scales, colorkey = FALSE, region = TRUE) dev.off() } How should I correctly write these loops to do as intended? cheers David -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +31302535773 Fax:+31302531145 http://intamap.geo.uu.nl/~paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Phil Spector's book
Since we're on the topic of book reviews, I just received Phil Spector's new R book called Data Manipulation with R and it is also quite a nice book. I haven't gone through it all and I won't give a detailed review but I have gotten a lot out of the first 100 pages that I have read. Note that I've been using R for almost 1.5 years so , for me, it's a really useful book. For someone who's used it for longer than that or is just really, really great at using R in an efficient manner and knows all the neat tricks already, they of course may not need the book. Great job Phil. On Fri, May 2, 2008 at 4:20 PM, Mark Wardle wrote: Sorry. I received a very exciting email from Springer and placed my order and felt compelled to advertise it. Didn't see any previous postings about it. Hope no offence taken! Best wishes, and well done with book. Looking forward to receiving it... Mark 2008/5/2 Deepayan Sarkar [EMAIL PROTECTED]: On 4/30/08, Charilaos Skiadas [EMAIL PROTECTED] wrote: Actually it's been out for a couple of weeks now at least. Yes, it's been out since March 12, actually. I just finished my first reading of it, and I must say it was spectacular. Congratulations Deepayan, the book gave me exactly the kind of lattice knowledge I needed, and then some. The graphics are really impressive and good illustrations of what lattice can do, and I found the writing very clear, with the complexity increasing at just the right speed. I definitely recommend it to anyone who wants to learn how to use lattice, at any level they desire. Thanks for the great review :-) As Karl mentioned, there is a website with code and figures from the book at http://lmdvr.r-forge.r-project.org/ I also hope to eventually write some short vignettes on topics not covered in the book, and put them up here. Feel free to suggest topics to me. And of course, please report any typos and errors. -Deepayan __ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email __ -- Dr. Mark Wardle Specialist registrar, Neurology Cardiff, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] interactive rotatable 3d scatterplot
I would like to create a 3d scatterplot that is interactive in the sense that I can spin it on its axes to better visualize some PCA results I have. What are the options in R? I've looked at RGL and perhaps it will suffice but it wasn't apparent from the documentation I found. Any demo scripts available for a package that will work? Mark -- Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail (317) 663-0513 Home (no voice mail please) ** [[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] Summarize data for MCA (FactoMineR)
On Sun, Apr 27, 2008 at 10:10 AM, David Winsemius [EMAIL PROTECTED] wrote: Nelson Castillo [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: (cut) That is, from: x weight var1 var2 1 1AB 2 1AB 3 2AB 4 1AB 5 2CD to: y weihgt var1 var2 1 5AB 2 2CD Does this suffice? s.wt - with(x, aggregate(weight, by=list(var1=var1,var2=var2), sum) ) # s.wt # var1 var2 x #1AB 5 #2CD 2 #then fix names names(s.wt)[3] - weight # s.wt # var1 var2 weight #1AB 5 #2CD 2 That was exactly what I needed :-) Thanks a lot. I tried to make the list that you have to pass as by from colnames(edom)[2:14] : [1] VB21 VB17_NEV VB17_LAV VB17_EQS VB17_CAL VB17_DEL [7] VB17_LIC VB17_HEL VB17_AIR VB17_VEN VB17_TVC VB17_PC [13] VB17_HMI But I couldn't do it. So, I did the list by hand. edom2 = with(edom,aggregate(FACT_EXP_CAL_H, by=list(Income=VB21,VB17_NEV=VB17_NEV, VB17_LAV=VB17_LAV, VB17_EQS=VB17_EQS, VB17_CAL=VB17_CAL, VB17_DEL=VB17_DEL, VB17_LIC=VB17_LIC, VB17_HEL=VB17_HEL, VB17_AIR=VB17_AIR, VB17_VEN=VB17_VEN, VB17_TVC=VB17_TVC, VB17_PC=VB17_PC, VB17_HMI=VB17_HMI), sum)) nrow(edom2) [1] 9817 And the row count matches what I did before with Perl :-) I believe that the reshape or reShape packages could do this in one step. I skimmed over the paper and reshape seems to be very powerful. I didn't know how to use it in this case but I guess I'll get back to the paper some other time. Regards, Nelson.- -- http://arhuaco.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.
[R] Excluding/removing row and column names on text output files
Dear R users, I've had no joy finding a solution to this online or in any of my R books. Many thanks in advance for any help you can give. I'm seeking to output a data frame (or matrix - it doesn't matter which for my purposes) to a .txt file, but omit any row or column names. The data frame that I'm using doesn't actually have column or row names to start with as it has been coerced into its present form from a matrix. When I use: capture.output(x, file=/Users/Desktop/Data.txt, append=TRUE) I get the following (this is a small fraction of the actual data frame): 1 2 3 4 5 X1 0 0 0 0 2 X2 0 0 0 2 0 X3 1 1 2 0 0 If the data frame is transformed into a matrix, I still get row and column 'names' (or at least numbers like v1, etc.). Using the sink function also produces the exact same result. I've tried using row.names=FALSE (as you would when writing to a .csv file), in the capture.output function, but it doesn't work. I would also like the remove the horizontal spaces between numbers on the same row, to produce: 2 00020 11200 But, I want each row to remain a separate entity (not be concatenated with the others). I know I can remove the blank spaces by doing Find and Replace in a text editor, but is it possible to remove the row and column names, and the row spaces, directly in R so that it outputs like the above example? Thanks, Steve ~~ Steven Worthington Ph.D. Candidate New York Consortium in Evolutionary Primatology Department of Anthropology New York University 25 Waverly Place New York, NY 10003 U.S.A. ~~ -- View this message in context: http://www.nabble.com/Excluding-removing-row-and-column-names-on-text-output-files-tp17030424p17030424.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] Excluding/removing row and column names on text output files
try: write.table(x, file=/Users/Desktop/Data.txt, row.names= FALSE, col.names= FALSE, sep=, append=TRUE) this should do it. If you don't want to append, just turn that opion off. Stropharia wrote: Dear R users, I've had no joy finding a solution to this online or in any of my R books. Many thanks in advance for any help you can give. I'm seeking to output a data frame (or matrix - it doesn't matter which for my purposes) to a .txt file, but omit any row or column names. The data frame that I'm using doesn't actually have column or row names to start with as it has been coerced into its present form from a matrix. When I use: capture.output(x, file=/Users/Desktop/Data.txt, append=TRUE) I get the following (this is a small fraction of the actual data frame): 1 2 3 4 5 X1 0 0 0 0 2 X2 0 0 0 2 0 X3 1 1 2 0 0 If the data frame is transformed into a matrix, I still get row and column 'names' (or at least numbers like v1, etc.). Using the sink function also produces the exact same result. I've tried using row.names=FALSE (as you would when writing to a .csv file), in the capture.output function, but it doesn't work. I would also like the remove the horizontal spaces between numbers on the same row, to produce: 2 00020 11200 But, I want each row to remain a separate entity (not be concatenated with the others). I know I can remove the blank spaces by doing Find and Replace in a text editor, but is it possible to remove the row and column names, and the row spaces, directly in R so that it outputs like the above example? Thanks, Steve ~~ Steven Worthington Ph.D. Candidate New York Consortium in Evolutionary Primatology Department of Anthropology New York University 25 Waverly Place New York, NY 10003 U.S.A. ~~ -- View this message in context: http://www.nabble.com/Excluding-removing-row-and-column-names-on-text-output-files-tp17030424p17030476.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] interactive rotatable 3d scatterplot
Hi Mark, Try using ggobi via Rggobi. ggobi is aimed at higher dimension multivariate data but it does a very useful service in 3-D projections, do a manually controlled tour ... I've used this to tweak PCA results and find fine structure, Richard Mark Kimpel wrote: I would like to create a 3d scatterplot that is interactive in the sense that I can spin it on its axes to better visualize some PCA results I have. What are the options in R? I've looked at RGL and perhaps it will suffice but it wasn't apparent from the documentation I found. Any demo scripts available for a package that will work? Mark -- Dr Richard Rowe Zoology Tropical Ecology School of Marine Tropical Biology James Cook University Townsville 4811 AUSTRALIA ph +61 7 47 81 4851 fax +61 7 47 25 1570 JCU has CRICOS Provider Code 00117J __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Excluding/removing row and column names on text output files
Steve, I think you can use: write.table(x, file = /Users/Desktop/Data.txt, sep = , append=T, row.names = F, col.names = F) I used that for the data PERSHRUB DISTX AGE RODENTSP 166 2100 501 290 914 201 375 1676 341 475 243 341 560 822 161 650 121 141 7 5 1554 790 820 1219 580 930 2865 360 10 52 670 310 and got 662100501 90914201 751676341 75243341 60822161 50121141 51554790 201219580 302865360 52670310 Hope this helps, Bob On Fri, 2008-05-02 at 18:02 -0700, Stropharia wrote: Dear R users, I've had no joy finding a solution to this online or in any of my R books. Many thanks in advance for any help you can give. I'm seeking to output a data frame (or matrix - it doesn't matter which for my purposes) to a .txt file, but omit any row or column names. The data frame that I'm using doesn't actually have column or row names to start with as it has been coerced into its present form from a matrix. When I use: capture.output(x, file=/Users/Desktop/Data.txt, append=TRUE) I get the following (this is a small fraction of the actual data frame): 1 2 3 4 5 X1 0 0 0 0 2 X2 0 0 0 2 0 X3 1 1 2 0 0 If the data frame is transformed into a matrix, I still get row and column 'names' (or at least numbers like v1, etc.). Using the sink function also produces the exact same result. I've tried using row.names=FALSE (as you would when writing to a .csv file), in the capture.output function, but it doesn't work. I would also like the remove the horizontal spaces between numbers on the same row, to produce: 2 00020 11200 But, I want each row to remain a separate entity (not be concatenated with the others). I know I can remove the blank spaces by doing Find and Replace in a text editor, but is it possible to remove the row and column names, and the row spaces, directly in R so that it outputs like the above example? Thanks, Steve ~~ Steven Worthington Ph.D. Candidate New York Consortium in Evolutionary Primatology Department of Anthropology New York University 25 Waverly Place New York, NY 10003 U.S.A. ~~ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extract lags from a formula
If x is a zoo object note that zoo (and therefore dyn) allows the more compact form lag(x, -(1:2)) so if we write: mod.eq - x ~ lag(x, -(1:2)) then mod.eq[[3]][[3]] is the vector -(1:2) or if you like you can define Lag - function(x, k) lag(x, -k) in which case you can write it: mod.eq - x ~ Lag(x, 1:2) and the same expression extracts 1:2. On Fri, May 2, 2008 at 2:35 PM, Kerpel, John [EMAIL PROTECTED] wrote: Hi folks! How do I extract lags from a formula? An example: mod.eq-formula(x~lag(x,-1)+lag(x,-2)) mod.eq x ~ lag(x, -1) + lag(x, -2) mod.eq[1] ~() mod.eq[2] x() mod.eq[3] lag(x, -1) + lag(x, -2)() I'm trying to extract the lags into a vector that would be simply [1,2]. How do I do this? I'm using the dyn package to do dynamic regression. John [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help with subset
Dear list: I have a problem using the subset function: dat- data.frame(treatment=c(A, B, A, C, C, D, A, D, C, D), response=rnorm(10)) I am interested in treatments A, B and D vec- c(A, B, D) But I can only obtain what I want with: subset(dat, treatment==A | treatment==B | treatment==D) What's wrong with subset(dat, treatment==vec) It would be much more simple to compute the latter in a rather complex dataframe. Thanks in advance Justin -- [EMAIL PROTECTED] -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 subset
Try %in% subset(dat, treatment %in% vec) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Friday, May 02, 2008 11:41 PM To: r-help@r-project.org Subject: [R] help with subset Dear list: I have a problem using the subset function: dat- data.frame(treatment=c(A, B, A, C, C, D, A, D, C, D), response=rnorm(10)) I am interested in treatments A, B and D vec- c(A, B, D) But I can only obtain what I want with: subset(dat, treatment==A | treatment==B | treatment==D) What's wrong with subset(dat, treatment==vec) It would be much more simple to compute the latter in a rather complex dataframe. Thanks in advance Justin -- [EMAIL PROTECTED] -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with subset
Justin, try subset(dat, treatment %in% vec) I guess thats what you want. On Fri, May 2, 2008 at 8:40 PM, [EMAIL PROTECTED] wrote: Dear list: I have a problem using the subset function: dat- data.frame(treatment=c(A, B, A, C, C, D, A, D, C, D), response=rnorm(10)) I am interested in treatments A, B and D vec- c(A, B, D) But I can only obtain what I want with: subset(dat, treatment==A | treatment==B | treatment==D) What's wrong with subset(dat, treatment==vec) It would be much more simple to compute the latter in a rather complex dataframe. Thanks in advance Justin -- [EMAIL PROTECTED] -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- HTH/Best, Jim Porzak Responsys, Inc. San Francisco, CA http://www.linkedin.com/in/jimporzak [[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 with subset
Thank you Christos and Jim: That is precisely what I was after. On Sat, 3 May 2008 00:01:58 -0400, Christos Hatzis [EMAIL PROTECTED] said: Try %in% subset(dat, treatment %in% vec) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Friday, May 02, 2008 11:41 PM To: r-help@r-project.org Subject: [R] help with subset Dear list: I have a problem using the subset function: dat- data.frame(treatment=c(A, B, A, C, C, D, A, D, C, D), response=rnorm(10)) I am interested in treatments A, B and D vec- c(A, B, D) But I can only obtain what I want with: subset(dat, treatment==A | treatment==B | treatment==D) What's wrong with subset(dat, treatment==vec) It would be much more simple to compute the latter in a rather complex dataframe. Thanks in advance Justin -- [EMAIL PROTECTED] -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- [EMAIL PROTECTED] -- wherever you are __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] interactive rotatable 3d scatterplot
#Install library rgl #here is the is the function: rgl.plot3d-function(z, x, y, cols=red,axes=T,new=T) {xr-range(x) x01-(x-xr[1])/(xr[2]-xr[1]) yr-range(y) y01-(y-yr[1])/(yr[2]-yr[1]) zr-range(z) z01-(z-zr[1])/(zr[2]-zr[1]) if(new) rgl.clear() if(axes) {xlab-pretty(x) ylab-pretty(y) zlab-pretty(z) xat-(xlab-xr[1])/(xr[2]-xr[1]) yat-(ylab-yr[1])/(yr[2]-yr[1]) zat-(zlab-zr[1])/(zr[2]-zr[1]) rgl.lines(c(0,1.1),0,0) rgl.lines(0,c(0,1.1),0) rgl.lines(0,0,c(0,1.1)) rgl.texts(xat,-.05,-.05,xlab) rgl.texts(-.05,yat,-.05,ylab) rgl.texts(-.05,-.05,zat,zlab) rgl.texts(c(0.5,-.15,-.15),c(-.15,.5,-.15),c(-.15,-.15,.5), c(deparse(substitute(x)),deparse(substitute(y)),deparse(substitute(z } rgl.spheres(x01,y01,z01,.01,color=cols) } #and here is how you call it library(rgl) data(iris) iris.pc-prcomp(iris[,1:4],scale=T) rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3]) # different colors rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3],col=unclass(iris[,5])+1) #you could also change the labels and everything else. Enjoy! Mark W Kimpel wrote: I would like to create a 3d scatterplot that is interactive in the sense that I can spin it on its axes to better visualize some PCA results I have. What are the options in R? I've looked at RGL and perhaps it will suffice but it wasn't apparent from the documentation I found. Any demo scripts available for a package that will work? Mark -- Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail (317) 663-0513 Home (no voice mail please) ** [[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. -- View this message in context: http://www.nabble.com/interactive-rotatable-3d-scatterplot-tp17030023p17030164.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.