[R] how to solve error in precict( ) while using with rpart?
Hello, I am working with rpart function but geting some error in prediction. the same code works fine with iris dataset. but applying other dataset it doesn't work. sample code is given for reference. acc_model-rpart(V1~V2+V3+V4+V5+V6+V7+V8, data=accEx.train) plotcp(acc_model) acc_find_cp-(acc_model$cptable)[,CP][which.min(acc_model$cptable[,xerror])] acc_prune_model-prune(acc_model,acc_find_cp) acc_predict_tree-predict(acc_prune_model,newdata=accEx.test, type=class) Error in predict.rpart(acc_prune_model, newdata = accEx.test, type = class) : Invalid prediction for rpart object #conf.mat #function(true, new) { t - table(true, new) s - sum(t) acc - round((sum(diag(t)))/s, 2) res - list(conf = t, accuracy = acc) } # I thought the Error is in match.arg(type) : # 'arg' should be one of vector, prob, class, matrix # accEx.test # V1 is response V2 to V8 are predictors V1 V2V3 V4 V5V6 V7 V8 1 3.66356 7.74414 -4.4 4.2 0.0 18.0 19 116 2 3.04452 8.03398 -5.7 4.8 -0.3 69.1 9 506 3 3.71357 4.70048 -13.5 4.3 0.2 80.0 3 95 4 2.9 7.52510 1.4 3.0 0.1 177.0 22 161 5 4.06044 7.76260 4.1 5.6 1.1 287.0 7 80 6 3.6 7.88683 5.8 2.3 -0.1 200.0 9 33 7 3.33220 7.81521 2.7 1.9 0.4 228.0 7 129 8 3.36730 7.9 7.1 8.9 0.2 220.0 15 155 9 2.07944 6.89163 4.1 2.0 0.1 183.0 9 132 10 1.94591 7.67740 1.1 5.2 0.1 43.1 10 480 .. .. .. acc_predict_tree-predict(acc_prune_model,newdata=accEx.test, type=vector) acc_conf-conf.mat(accEx.train,acc_predict_tree) Error in sort.list(unique.default(x), na.last = TRUE) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? how to solve this problem? [[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] Bold greek letters using plotmath
Plotmath does not have a bold symbol font -- R's plotting system has only 5 fonts (see 'font' in ?par), and bold symbol fonts are not commonly installed in plotting systems. Strictly the symbols such as mu used in mathematical notation differ from the letters used in Greek. You may get a good substitute using a Greek letter, depending on the device -- which you have not told us but I would guess() was windows(). Try replating mu by \u03bc. (I am not using Windows, but this works on X11() and quartz() for example.) On Tue, 23 Mar 2010, Jim Price wrote: I'm trying to annotate some graphics using plotmath and finding out that the code I'm using isn't bolding the greek letters - it bolds the rest (once I adjusted the numerics to characters), it's just failing on the greek characters. Any suggestions welcomed. Jim Price. Cardiome Pharma Corp. Test code: plot(1:5, type = 'n') # The not bold version text(2, 2:4, cex = 2, labels = do.call(expression, unlist(list('Placebo', lapply(c(3, 6), function(.x) substitute(.x ~~ mu * g / kg / hr, list(.x = .x, recur = F))) # The bold version - note that the greek letter doesn't change text(4, 2:4, cex = 2, labels = do.call(expression, unlist(list(substitute(bold(Placebo)), lapply(as.character(c(3, 6)), function(.x) substitute(bold(.x ~~ mu * g / kg / hr), list(.x = .x, recur = F))) sessionInfo() R version 2.10.0 (2009-10-26) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] graphics grDevices utils datasets methods stats base other attached packages: [1] foreign_0.8-38 latticeExtra_0.6-1 RColorBrewer_1.0-2 lattice_0.17-26 loaded via a namespace (and not attached): [1] grid_2.10.0 tools_2.10.0 -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] R and/or REngine kills Java
Hi all, I am using R and JRI under Windows XP Pro. I am posting this question here since the reason might be R related (since I am running an R script) but there is also a very good chance that it is JRI only (since I am using the JRI interface to activate the script) -- in which case I want to apologize for misplacing this message. I have a method that instantiates an REngine object every time it is called. It runs a script provided by a file name and closes REngine afterward. The script works fine, the png file is successfully generated and the PNG file is released so that I can delete it if I want ( but I don't in that case). For some strange reason, when running this code twice I get the following error: upon which the Java Virtual machine dies on me. Any explanation would be greatly appreciated! Best, Ralf Here the Java code, the R code, and the Java VM error: START JAVA CODE ++ /** Helper method */ private static void eval(Rengine r, String s) { r.eval(s, false); } /** Assigns the given java value to the given R variable name */ private static void assign(Rengine r, String rVariableName, String javaValue) { r.assign(rVariableName, javaValue); } public void run() throws Exception { String filepath = this.path; if (filepath != null) { File rFile = new File(filepath ); if (rFile.exists()) { // run R script // start R engine if (!Rengine.versionCheck()) { System.err.println(** Version mismatch - Java files don't match library version.); System.exit(1); } // creating R engine Rengine rEngine = new Rengine(null, false, new EmptyCallbacks()); // the engine creates R is a new thread, so we should wait until it's ready if (!rEngine.waitForR()) { System.out.println(Cannot load R for + this.getClass().getName()); return; } // executing logic try { assign(rEngine, filename, filepath); eval(rEngine, source(filename)); } catch (Exception e) { System.out.println(this.getClass().getName() + : Error in R code: + e); e.printStackTrace(); // stopping R engine System.out.println(Error when running script - rEngine stopped!); if (rEngine != null){ rEngine.end(); } } // stopping R engine rEngine.end(); } else { throw new Exception(getClass().getName() + not run - missing R file - location: + rFile.getAbsolutePath()); } } } + END JAVA CODE + + START R Code library(RJDBC) # db connection driver - JDBC(com.mysql.jdbc.Driver,lib/mysql-connector-java-5.0.6-bin.jar) con - dbConnect(driver, jdbc:mysql://localhost/mydb, xxx, yyy) # list tables dbListTables(con) # user, task and event information result = dbGetQuery(con, SELECT x,y from mytable;) png(file=output.png) plot(result$x, result$y) dev.off() + START R Code ERROR: # # An unexpected error has been detected by Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc005) at pc=, pid=5400, tid=3204 # # Java VM: Java HotSpot(TM) Client VM (11.2-b01 mixed mode, ) # Problematic frame: # C [R.dll+0x1136fe] # # An error report file with more information is saved as: # [WARN] 404 - GET /output.png (127.0.0.1) 1402 bytes Request headers Host: localhost: User-Agent: Accept: image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://localhost Response headers Content-Length: 1402 Content-Type: text/html; charset=iso-8859-1 # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the
Re: [R] Plot ``freezes''.
On Wed, 24 Mar 2010, Rolf Turner wrote: In an elderly version of ``plotSymbols'' (now in the cwhmisc package) that I had lying around, there was the example plot(1:10,xlab=\374) which the comments said would give a u-umlaut as the x-axis label. In a Latin-1 encoding, which R gave up as default in 2.1.0. You should just be able to use plot(1:10,xlab=ü) or failing that (and the mailer may trash that line) plot(1:10,xlab=\u00fc) When I execute this plot (a) I get no x-axis label at all, and (b) the plot ``freezes'' in that further plotting commands (e.g. plot(runif(42))) produce no results. The plot window (X11) remains as it was after the ``plot(1:10,xlab=\374)'' command. No error message is given, but no new plot is produced. If I do dev.off(), then normal plotting recommences. Can anyone explain to me what is going on here? My session info is given below. I run R from the command line, from a terminal window. My guess is that this is your 'elderly' Mac OS X11 plotting system. Does X11(type=Xlib) behave? If so, this suggests that the Mac OS X implementation of cairo (supplied by Simon Urbanek) is not too robust (which in a several ways we already know). On Linux I get warnings (process:14674): Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text() and a 'broken char' symbol on the plot. cheers, Rolf Turner sessionInfo() R version 2.10.1 (2009-12-14) i386-apple-darwin8.11.1 locale: [1] en_NZ.UTF-8/en_NZ.UTF-8/C/C/en_NZ.UTF-8/en_NZ.UTF-8 attached base packages: [1] datasets utils stats graphics grDevices methods base other attached packages: [1] misc_0.0-12fortunes_1.3-7 MASS_7.3-4 -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] how to make a histogram with non-numeric x's?
Hello, I need to make a histogram with variable x bin ranges. For example my bins are 0-15, 15-25, 25-40 etc. Any suggestions? Thanks! -- View this message in context: http://n4.nabble.com/how-to-make-a-histogram-with-non-numeric-x-s-tp1680093p1680093.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] Affymetrix Cancer Dataset
I am looking for an online (easily accessible) form of the samples of genetic data for those with cancer and those without cancer. Can anyone direct me in the right place? Thanks, Jim [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Affymetrix Cancer Dataset
You might find something of interest via this page: http://www.aroma-project.org/node/51 /Henrik On Wed, Mar 24, 2010 at 9:32 AM, Jim Silverton jim.silver...@gmail.com wrote: I am looking for an online (easily accessible) form of the samples of genetic data for those with cancer and those without cancer. Can anyone direct me in the right place? Thanks, Jim [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing axis origin for plot
On 03/24/2010 11:08 AM, Ralf B wrote: Hi all, I am plotting data using the simple plot function: plot(data$x, data$y) which results in a standard plot with the axis origin in the lower left corner. ^ | | | | | O O | O O -- Since my data are screen coordinates I need mirrored axis so that the origin for both axis is in the upper left corner; like this: | | O O | O O | | | | | v Anybody know how? I did not find any parameter when consulting the help file. I assume its a more general parameter but where is that documented? Hi Ralf, I don't know of any options or call to par that will change which axes are displayed. You can do what you want like this: plot(...,xaxt=n) axis(3,...) unless you want to reverse the direction of the ordinate (y-axis). In that case, have a look at the revaxis function in the plotrix package. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to make a histogram with non-numeric x's?
On 03/24/2010 04:36 PM, cbarcelo wrote: Hello, I need to make a histogram with variable x bin ranges. For example my bins are 0-15, 15-25, 25-40 etc. Any suggestions? Thanks! Hi cbarcelo, You can just do this: x-sample(0:40,100,TRUE) hist(x,breaks=c(0,15,25,40)) which will produce densities, or: hist(x,breaks=c(0,15,25,40),freq=TRUE) which will display counts, but complain about it, or: barplot(hist(x,breaks=c(0,15,25,40))$counts, names.arg=c((0-15],(15-25],(25-40])) which may be what you want. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Monte Carlo simulation in R
On 24-Mar-10 01:05:56, Hongwei Dong wrote: Hi, R-helpers, I'm trying to use R to do a Monte Carlo simulation and need the help. What I have is a matrix that consists of the probabilities for the persons to choose zones. For example, in the matrix shown below, each column represents a person, and each row represents a zone. So, the probability that the first person will choose the 2nd zone is 30%. 25% 30% 10% 30% 20% 0% 20% 50% 60% 50% 0% 10% 20% 0% 20% Based on this matrix, I want to locate the persons to zones based on the probability using a Monte Carlo method. The result I want to see is like this: 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 Could anyone please give some help? Thanks. You will need to state (and probably formulate) the problem better. You have presented your matrix as a single line of 5 blocks of 3. 25% 30% 10% 30% 20% 0% 20% 50% 60% 50% 0% 10% 20% 0% 20% It is ambiguous as to whether a block of 3 is a row or a column. So this could represent Person = 1 2 3 -- Zone = 1 25% 30% 10% 2 30% 20% 0% 3 20% 50% 60% 4 50% 0% 10% 5 20% 0% 20% in which Person=1 and Zone=3 gets 30% (as you state). Or it could represent Person = 1 2 3 4 5 -- Zone = 1 25% 30% 20% 50% 20% 2 30% 20% 50% 0% 0% 3 10% 0% 60% 10% 20% Once again, Person=1 and Zone=2 gets 30%. So your example does not identify which of these two representations is the one you intend. I suspect you mean the first, since in that you have columns 2 and 3 adding up to 100% (which, as probabilities over the choices each Person could make, they have to do), and this does not occur for any column of the second. But column 1 in the first does not add up to 100% -- so what would you then mean by the percentages in column 1? Or do you intend an interpretation of your statement according to which the percentages in the columns do not represent probabilities which add to 1? In that case, the second representation could also be valid. But then what do your percentages mean? More details, please! Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 24-Mar-10 Time: 10:20:22 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R Full Screen
Hello all, I'm new user with R and just completed a five day course on the program. Somehow, a few basic questions remain unanswered. I'm working on a Mac Os X system and have my laptop connected to a large, flat- screen monitor. I can't make any of the Quartz windows fill the monitor's screen; I'd like to make them full screen to identify points in a dense scatterplot. Thank you for any suggestions. Yours, Simon Kiss * Simon J. Kiss, PhD SSHRC and DAAD Post-Doctoral Fellow John F. Kennedy Institute of North America Studies Free University of Berlin Lansstraße 7-9 14195 Berlin, Germany Cell: +49 (0)1525-300-2812, Web: http://www.jfki.fu-berlin.de/index.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help needed with boxplot
On 03/24/2010 06:08 AM, kathy_BJ wrote: Thank you so much for help, Jim. But I didn't get any plot after I submit the job except below, which indicating the number of lines for the two inputs. What's the problem? Read 3360 records Read 3360 records I know I didn't confuse you. Okay, let's make up some data and produce a set of boxplots. file1-data.frame( col1=sample(c(05000:05200,22000:22900),1000), col2=sample(0:270,1000,TRUE), col3=runif(1000,50,80),col4=runif(1000,50,80), col5=sample(c(RED,GREEN,BLUE),1000,TRUE)) file2-data.frame( col1=sample(c(05000:05200,22000:22900),1000), col2=sample(0:270,1000,TRUE), col3=runif(1000,50,80),col4=runif(1000,50,80), col5=sample(c(RED,GREEN,BLUE),1000,TRUE)) file1$col_group-cut(file1$col2,breaks=c(0,20,50,70,271), right=FALSE) file2$col_group-cut(file2$col2,breaks=c(0,20,50,70,271), right=FALSE) reds1-file1$col5==RED reds2-file2$col5==RED greens1-file1$col5==GREEN greens2-file2$col5==GREEN blues1-file1$col5==BLUE blues2-file2$col5==BLUE file1$col43-file1$col4-file1$col3 file2$col43-file2$col4-file2$col3 col_group11-as.numeric(file1$col_group)==1 col_group12-as.numeric(file1$col_group)==2 col_group13-as.numeric(file1$col_group)==3 col_group14-as.numeric(file1$col_group)==4 col_group21-as.numeric(file2$col_group)==1 col_group22-as.numeric(file2$col_group)==2 col_group23-as.numeric(file2$col_group)==3 col_group24-as.numeric(file2$col_group)==4 x11(width=9) boxplot(file1$col43[reds1col_group11], file2$col43[reds2col_group21], file1$col43[reds1col_group12], file2$col43[reds2col_group22], file1$col43[reds1col_group13], file2$col43[reds2col_group23], file1$col43[reds1col_group14], file2$col43[reds2col_group24], main=Comparison of RED col4 and col3 differences across col2 groups, names=rep(,8)) require(plotrix) staxlab(at=1:8, labels=paste(c(file1,file2),rep(levels(file1$col_group),each=2))) This should produce a set of 8 boxplots comparing the medians, etc. of the differences of col4 and col3 between file1 and file 2 for all of the entries with col5=RED across the levels of col_group. I don't know whether this is what you want, but it might get you started. 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 in matlab - r code
Dear list members, I need to translate 3 lines of matlab code to R (a loop, to be specific), and I don't know what would be the results in matlab or how to do it in R-- I don't realise if they are doing to the col, vector or what. if the results are a vector or a value or a matrix :-( Anyone with matlab, can run it and give me the result? Any ideias what am I doing wrong? The code is bellow...I have put the matlab code, followed by what I think would be the R code . Any help would be greatly appreciated, Thank you very much in advance, Best wishes, Marta * # from Rubin 2004: The following example opens an image (line 1), displays the image (line 2), # converts the image to grayscale data (line 3), and calculates the autocorrelation curve # for offset distances of one pixel to 99 pixels (lines 710). This code can be used to # perform steps (4) and (6) listed above in the Summary of Steps to Calculate Grain # Size of Natural Sediment. ColorData = imread(ImageName.jpg); x - read.jpeg(sed2.jpg)# opens the image imshow(ColorData); plot(x) # plot image data = double(rgb2gray(ColorData)); x=rgb2grey(x) # transform in grayscale, the image ; # example of a similar data matrix: data = double(0.54878431372549,0.468,0.553411764705882,0.663529411764706, 0.440156862745098,0.330313725490196,0.473843137254902,0.690980392156863, 0.483,0.344862745098039,0.458156862745098,0.647843137254902) ImageWidth = size(data,2); dim(A)[2] # i.e. number of col MaxOffset = 99; # defined variable, =2R ImageWidthToProcess = ImageWidth-MaxOffset; # =2R defined variable for Offset = 1:MaxOffset ; loop to calculate the autocorrelation. basicly, they do cor2, which I think is Spearman correlation, between every column and store it in the vector position??? OffsetPlaquette = data(:,1+Offset:ImageWidthToProcess+Offset); AutoCData(Offset) = corr2(data(:,1:ImageWidthToProcess), OffsetPlaquette) end # IN R would be... but it is not correct! What would be the results in matlab? and how to do it in R? for(Offset in 1:MaxOffset){ OffsetPlaquette = x[,1+Offset:ImageWidthToProcess+Offset] AutoCData[Offset] = cor(c(x[,1:ImageWidthToProcess]), c(OffsetPlaquette)) } * [[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] Converting date format
The following functions may help; strptime() ISOdate() Muhammad Hosack, Michael wrote: R community: Hello, I would to like to convert a character date variable from %m/%d/%Y to %m/%d/%y. Any advice would be greatly appreciated. I have tried functions for changing the formatting and removing the unnecessary digits without success. 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bulk editing of mySQL tables
Hello, I have started to use RMySQL and I would like to use R to make batch changes to data. What it the best way to do this? Is it to download the table using dbGetQuery, manipulate the data in R and then dbWriteTable to delete the existing table and replace it with the local data. What I am concerned about this is that it might lose some mySQL table configuration options and it isn't a very effective way to do it. An example of the sort of thing I am doing is to try and update a column based on a CSV file stored locally. Thanks Dan -- ** Daniel Brewer, Ph.D. Institute of Cancer Research Molecular Carcinogenesis Email: daniel.bre...@icr.ac.uk ** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the a...{{dropped:2}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Full Screen
On Mar 24, 2010, at 6:57 AM, Simon Kiss wrote: Hello all, I'm new user with R and just completed a five day course on the program. Somehow, a few basic questions remain unanswered. I'm working on a Mac Os X system and have my laptop connected to a large, flat-screen monitor. I can't make any of the Quartz windows fill the monitor's screen; I'd like to make them full screen to identify points in a dense scatterplot. If you are using the GUI, then the preferences for Quartz width/height parameters can be set off R menu. You could also override them with a call to quartz. You should have been able to resize the plot as well. Thank you for any suggestions. Yours, Simon Kiss -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nls function
Hi everybody, would like to ask if there is any possibility to get SOME BEST result for nls fitting if the function itself doesn't produce it. I already increased number of iterations, reduced minfactor and still it doesn't give me the solution. Thanks a lot. [[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] barplot (stacked)
Hi Jens! 23.03.2010 17:18, koj wrote: The problem is: I want to group the data. I want to have ten groups. The first two bars should be [1,1] and [2,1] together in one bar and in the second bar of the first obervation should be [1,2] and [2,2] (stacked with beside =TRUE). Therefore the first observation is [1,1],[1,2],[2,1] and [2,2]. I am not sure that I wholly understood what You want :) But why not use lattice 'barchart' instead: Let's suppose 'dm' is your data matrix. Please try the following command and let us know, if the output is what you are looking for: barchart(~dm[,1]+dm[,2], stacked=T) HTH, Kimmo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] with data in the form of an R data objecte: Monte Carlo simulation in R
On Mar 23, 2010, at 11:00 PM, Hongwei Dong wrote: Hi, please use the following the matrix z as the example: x-c(2,4,5,7,6,9,8,2,0) y-matrix(x,3,3) z-apply(y,2,function(x)x/sum(x)) z [,1] [,2] [,3] [1,] 0.1818182 0.3181818 0.8 [2,] 0.3636364 0.2727273 0.2 [3,] 0.4545455 0.4090909 0.0 require(Hmisc) # rMultinomial expects its subject probs to be in rows rather than in columns # here is twenty realizations of three subjects rMultinom(t(z), 20) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [, 13] [,14] [1,]332213333 2 2 2 2 3 [2,]231233312 1 1 1 3 3 [3,]111211111 1 1 1 1 1 [,15] [,16] [,17] [,18] [,19] [,20] [1,] 3 2 3 3 3 2 [2,] 1 1 3 3 3 3 [3,] 2 1 1 1 1 1 On Tue, Mar 23, 2010 at 6:59 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 23, 2010, at 9:05 PM, Hongwei Dong wrote: Hi, R-helpers, I'm trying to use R to do a Monte Carlo simulation and need the help. What I have is a matrix that consists of the probabilities for the persons to choose zones. For example, in the matrix shown below, each column represents a person, and each row represents a zone. So, the probability that the first person will choose the 2nd zone is 30%. 25% 30% 10% 30% 20% 0% 20% 50% 60% 50% 0% 10% 20% 0% 20% As Alex Trebeck would say: Can you put that in the form of an R data object? Based on this matrix, I want to locate the persons to zones based on the probability using a Monte Carlo method. The result I want to see is like this: 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 Could anyone please give some help? Thanks. You cannot specify what the result _will_ be and call the process simulation of results at the same time. The sample function should work for a vector. Why not use it? -- David. David Winsemius, MD West Hartford, CT David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] optimize a joint lieklihood with mle2
Hi I'm trying to maximize a joint likelihood of 2 likelihoods (Likelihood 1 and Likelihood 2) in mle2, where the parameters I estimate in Likelihood 2 go into the likelihood 1. In Likelihood 1 I estimate the vector logN with length 37, and for the Likelihood 2 I measure a vector s of length 8. The values of s in Lieklihood 2 are used in the Likelihood 1. I have 2 questions: ##1 I manage to write the joint lieklihood (it's very long which is why I don't put it here), but I don't know how to write the correct argument for the mle2 function. Here is what I've tried: ## the lieklihood function to be optimized is called mfun(logN, s, h=h, cohort=cohort). I want to maximize the vectors logN and s. I define the starting values for logN as svec1 and for s as svec2 then I write for the optimization: m1 = mle2(mfun,start=list(svec1=logN,svec2=s), method=L-BFGS-B,lower=lower,upper=10, vecpar=TRUE, data=list(h=h,cohort=cohort)) but I get the error: Error in mle2(mfun, start = list(svec1 = logN, svec2 = s), method = L-BFGS-B, : some named arguments in 'start' are not arguments to the specified log-likelihood function How can I correctly write the fucntion for this? # ##2 Besides I'm using constrained optim method L-BFGS-B. But I would only like to use it for logN and not for s. Is that at all possible? I guess I could use the same limits also for s because s falls in the range of logN values, but how can I tell mle2 that I measure 2 likelihoods. thanks so much for the help Benedikt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] no predict function in lme4 ?
There is a very nice paper that illustrates a flexible approach that allows the user to specify nearly any possible prediction he or she may desire. A flexible system is critical since one man's fixed effect is another man's random effect to quote Schabenberger. @article{welham2004prediction, title={{Prediction in linear mixed models}}, author={Welham, S. and Cullis, B. and Gogel, B. and Gilmour, A. and Thompson, R.}, journal={Australian \ New Zealand Journal of Statistics}, volume={46}, number={3}, pages={325--347}, year={2004}, publisher={John Wiley \ Sons} } Kevin Wright On Tue, Mar 23, 2010 at 8:15 PM, Ben Bolker bol...@ufl.edu wrote: Douglas Bates bates at stat.wisc.edu writes: It is not easy to decide what predict should return for a linear mixed model, let alone the more complicated cases. Do you want predictions based on the fixed-effects only or based on a combination of the fixed-effects and the random-effects? For the lme function in the nlme package we allowed levels of predictions but that won't work for all models that can be fit with lme4. I do actually think there's a reasonable way to specify this -- an indicator specifying which random effects should have their conditional modes included in the prediction (the default could be either 'none' or 'all'). Further discussion should presumably move to r-sig-mixed-models. On Tue, Mar 23, 2010 at 9:18 AM, Markus Loecher wrote: Dear mixed effects modelers, I seem unable to find a predict method for mer objects in the package lme4. Am I not seeing the forest for the trees ? In the meantime you can construct your own model matrices and use them to generate the predictions by hand -- see http://glmm.wikidot.com/local--files/examples/Owls.pdf http://glmm.wikidot.com/local--files/examples/Owls.Rnw for a bit of a worked example. 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. [[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] likelihood profiles for multiple parameters
Hi I'm using mle2 for optimization of a multinomial likelihood. The model fit is not very good and I would like to look at the likelihood profiles. However I'm optimizing many parameters (~40) so using the function profile() takes forever and is not practical. How can I calculate approximate likelihood profiles? Is there a function for this in R? thanks a lot for the help Beni __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ordinal regression
Dear colleagues, i am carrying out an ordinal regression model. I try it on SPSS but I flirt with R as well. I have a few questions. 1. What is the most reliable/tested/trusted package for ordinal regression in the R world? 2. Also, I have a statistical question. What is the danger of having to many 'empty cells' in ordinal regression? How many empty cells are too many? Do you have a reference for me to read? Thank you for the support Dr. Iasonas Lamprianou Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.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] pca error message
Hi All, I have been running pca smoothly for some time now. However, the error message below makes progress difficult for me. It will be much appreciated if anybody can hint me on the possible source of this error. Thanks Ogbos The error: Error in pca$rotation %*% sqrt(data.cor.eigen.matrix) : non-conformable arguments In addition: Warning message: In sqrt(data.cor.eigen.matrix) : NaNs produced [[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] barplot (stacked)
Hi Kimmo, thank you for your answer, but this is not the thing I am searching for. Unfortunately, I have not described the problem very good. But just in this moment I have a good idea: I use add=TRUE and paint two plots. And so I am sure that I can solve the problem. -- View this message in context: http://n4.nabble.com/barplot-stacked-tp1679227p1680485.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help in matlab - r code
Dear list members, I need to translate 3 lines of matlab code to R (a loop, to be specific), and I don't know what would be the results in matlab or how to do it in R-- I don't realise if they are doing to the col, vector or what. if the results are a vector or a value or a matrix :-( Anyone with matlab, can run it and give me the result? Any ideias what am I doing wrong? The code is bellow...I have put the matlab code, followed by what I think would be the R code . Any help would be greatly appreciated, Thank you very much in advance, Best wishes, Marta * # from Rubin 2004: The following example opens an image (line 1), displays the image (line 2), # converts the image to grayscale data (line 3), and calculates the autocorrelation curve # for offset distances of one pixel to 99 pixels (lines 710). This code can be used to # perform steps (4) and (6) listed above in the Summary of Steps to Calculate Grain # Size of Natural Sediment. ColorData = imread(ImageName.jpg); x - read.jpeg(sed2.jpg)# opens the image imshow(ColorData); plot(x) # plot image data = double(rgb2gray(ColorData)); x=rgb2grey(x) # transform in grayscale, the image ; # example of a similar data matrix: data = double(0.54878431372549,0.468,0.553411764705882,0.663529411764706, 0.440156862745098,0.330313725490196,0.473843137254902,0.690980392156863, 0.483,0.344862745098039,0.458156862745098,0.647843137254902) ImageWidth = size(data,2); dim(A)[2] # i.e. number of col MaxOffset = 99; # defined variable, =2R ImageWidthToProcess = ImageWidth-MaxOffset; # =2R defined variable for Offset = 1:MaxOffset ; loop to calculate the autocorrelation. basicly, they do cor2, which I think is Spearman correlation, between every column and store it in the vector position??? OffsetPlaquette = data(:,1+Offset:ImageWidthToProcess+Offset); AutoCData(Offset) = corr2(data(:,1:ImageWidthToProcess), OffsetPlaquette) end # IN R would be... but it is not correct! What would be the results in matlab? and how to do it in R? for(Offset in 1:MaxOffset){ OffsetPlaquette = x[,1+Offset:ImageWidthToProcess+Offset] AutoCData[Offset] = cor(c(x[,1:ImageWidthToProcess]), c(OffsetPlaquette)) } * -- LNEG_VS_Poli_CMYK_300dpi Laboratório Nacional de Energia e Geologia, I.P. Estrada da Portela, Zambujal - Alfragide Apartado 7586, 2720-866 Amadora www.lneg.pt [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to use the paste function to create an already used variable
Hi there, I have the following problem Four data frames exist: data1 data2 data3 data4 Now I want to write a loop and temporarily store the data1, data2, data3, data4 in a variable called data. I tried the following... for (i in 1:4) { Data - paste(data,i,sep=) ... .. } but it doesn't function. I think the problem is the definition of the mode of the pasted variable. Could anyone help me? Thanks Greetings Jürgen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] multiple line plots from ncdf files
How can I create a multi-line plot from a netCDF files that containes the following fields: time [MM] 195301 195302 195303 [.] 195312 [..] 200112 data [float] mm1 mm2 mm3 [...] (monthly mean value for each months in the time series.) I want to plot the annual cycle of sis for each year into one plot. The result should be a multi-line plot (x-axis: sis-values; y-axes: month; one line for each year), with a seperate color/style for each line. How can I do this in R? I found some hints in various documentations (including the graph gallery) and mailing lists that are close to the problem. However, I could not find a solution for this particular problem. __ z gegen Massenmails. [[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 use the paste function to create an already used variable
Try: for (i in 1:4) { Data - eval(parse(text = paste(data,i,sep=))) ... .. } (and if there are other solutions - I would love to know) Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- 2010/3/24 Biedermann, Jürgen juergen.biederm...@charite.de Hi there, I have the following problem Four data frames exist: data1 data2 data3 data4 Now I want to write a loop and temporarily store the data1, data2, data3, data4 in a variable called data. I tried the following... for (i in 1:4) { Data - paste(data,i,sep=) ... .. } but it doesn't function. I think the problem is the definition of the mode of the pasted variable. Could anyone help me? Thanks Greetings Jürgen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] isdst warning when rounding a range of time data: fix or suppress?
Hi, I'm working with timeseries data. The values are every 5 seconds and each series can last up to 4-5 days. To generate the x-axis labels, I'm doing the following: = # Variable for displaying hours on the x-axis rtime - as.POSIXct(round(range(timedata), hours)) # Variable for displaying days on the x-axis stime - as.POSIXct(round(range(timedata), days)) # Plot the hours on the x-axis axis.POSIXct(1, at=seq(rtime[1], rtime[2], by=hour), format=%H, cex.axis=.6, lwd=0, lwd.ticks=1, hadj=0.2, las=2, tck=-0.02) # Plot the days on the x-axis axis.POSIXct(1, at=seq(stime[1], stime[2], by=day), format=%A, cex.axis=.7, line=1, lty=0, padj=-1.4) = The data generated and the plots look fine. R issues a warning on the round() function when rtime is set, though. It looks like this: round(range(cgmtime), hours) [1] 2003-11-04 14:00:00 EST 2003-11-07 11:00:00 EST Warning message: In if (isdst == -1) { : the condition has length 1 and only the first element will be used Am I approaching this incorrectly? Is there another way to achieve the same result without the warning? Or is there a way I can suppress the warning? Thanks in advance, Clay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 use the paste function to create an already used variable
On Mar 24, 2010, at 9:25 AM, Tal Galili wrote: Try: for (i in 1:4) { Data - eval(parse(text = paste(data,i,sep=))) ... .. } (and if there are other solutions - I would love to know) Well, it's not actually a solution since the first three fetched values would have been overwritten. Instead: Data - list() for (i in 1:4) { Data[[i]] - eval(parse(text = paste(data,i,sep=))) } Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- 2010/3/24 Biedermann, Jürgen juergen.biederm...@charite.de Hi there, I have the following problem Four data frames exist: data1 data2 data3 data4 Now I want to write a loop and temporarily store the data1, data2, data3, data4 in a variable called data. I tried the following... for (i in 1:4) { Data - paste(data,i,sep=) ... .. } but it doesn't function. I think the problem is the definition of the mode of the pasted variable. Could anyone help me? Thanks Greetings Jürgen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R and/or REngine kills Java
Hi Ralf -- On 03/23/2010 11:53 PM, Ralf B wrote: Hi all, I am using R and JRI under Windows XP Pro. I am posting this question here since the reason might be R related (since I am running an R script) but there is also a very good chance that it is JRI only (since I am using the JRI interface to activate the script) -- in which case I want to apologize for misplacing this message. I have a method that instantiates an REngine object every time it is called. It runs a script provided by a file name and closes REngine afterward. The script works fine, the png file is successfully generated and the PNG file is released so that I can delete it if I want ( but I don't in that case). For some strange reason, when running this code twice I get the following error: upon which the Java Virtual machine dies on me. Any explanation would be greatly appreciated! A bit of a shot in the dark, but it might be related to signal handling http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/signals.html with the solution being use of -Xrs when starting the JVM. Martin Best, Ralf Here the Java code, the R code, and the Java VM error: START JAVA CODE ++ /** Helper method */ private static void eval(Rengine r, String s) { r.eval(s, false); } /** Assigns the given java value to the given R variable name */ private static void assign(Rengine r, String rVariableName, String javaValue) { r.assign(rVariableName, javaValue); } public void run() throws Exception { String filepath = this.path; if (filepath != null) { File rFile = new File(filepath ); if (rFile.exists()) { // run R script // start R engine if (!Rengine.versionCheck()) { System.err.println(** Version mismatch - Java files don't match library version.); System.exit(1); } // creating R engine Rengine rEngine = new Rengine(null, false, new EmptyCallbacks()); // the engine creates R is a new thread, so we should wait until it's ready if (!rEngine.waitForR()) { System.out.println(Cannot load R for + this.getClass().getName()); return; } // executing logic try { assign(rEngine, filename, filepath); eval(rEngine, source(filename)); } catch (Exception e) { System.out.println(this.getClass().getName() + : Error in R code: + e); e.printStackTrace(); // stopping R engine System.out.println(Error when running script - rEngine stopped!); if (rEngine != null){ rEngine.end(); } } // stopping R engine rEngine.end(); } else { throw new Exception(getClass().getName() + not run - missing R file - location: + rFile.getAbsolutePath()); } } } + END JAVA CODE + + START R Code library(RJDBC) # db connection driver - JDBC(com.mysql.jdbc.Driver,lib/mysql-connector-java-5.0.6-bin.jar) con - dbConnect(driver, jdbc:mysql://localhost/mydb, xxx, yyy) # list tables dbListTables(con) # user, task and event information result = dbGetQuery(con, SELECT x,y from mytable;) png(file=output.png) plot(result$x, result$y) dev.off() + START R Code ERROR: # # An unexpected error has been detected by Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc005) at pc=, pid=5400, tid=3204 # # Java VM: Java HotSpot(TM) Client VM (11.2-b01 mixed mode, ) # Problematic frame: # C [R.dll+0x1136fe] # # An error report file with more information is saved as: # [WARN] 404 - GET /output.png (127.0.0.1) 1402 bytes Request headers Host: localhost: User-Agent: Accept: image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://localhost
Re: [R] How to use the paste function to create an already used variable
On 24/03/2010 9:25 AM, Tal Galili wrote: Try: for (i in 1:4) { Data - eval(parse(text = paste(data,i,sep=))) ... .. } (and if there are other solutions - I would love to know) The get() function is simpler if you're just retrieving a variable: Data - get(paste(data, i, sep=)) Duncan Murdoch Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- 2010/3/24 Biedermann, Jürgen juergen.biederm...@charite.de Hi there, I have the following problem Four data frames exist: data1 data2 data3 data4 Now I want to write a loop and temporarily store the data1, data2, data3, data4 in a variable called data. I tried the following... for (i in 1:4) { Data - paste(data,i,sep=) ... .. } but it doesn't function. I think the problem is the definition of the mode of the pasted variable. Could anyone help me? Thanks Greetings Jürgen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use the paste function to create an already used variable
Try this: Data - lapply(ls(pattern = 'data[0-9]'), get) Data[[1]] is data1 Data[[2]] is data2 etc. 2010/3/24 Biedermann, Jürgen juergen.biederm...@charite.de: Hi there, I have the following problem Four data frames exist: data1 data2 data3 data4 Now I want to write a loop and temporarily store the data1, data2, data3, data4 in a variable called data. I tried the following... for (i in 1:4) { Data - paste(data,i,sep=) ... .. } but it doesn't function. I think the problem is the definition of the mode of the pasted variable. Could anyone help me? Thanks Greetings Jürgen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] removing fields of the same group from a data frame
Dear all, I'm trying to find a a way to remove certain fields belonging to the same group from a data frame structure. I have a data frame like this: foo v1 v2 v3 1 1 a 6 2 a 3 8 a 4 4 b 4 4 b 2 1 c 1 6 d Each row can then be grouped according to the third column: a, b, c, d. Then I would like to remove all fields that belong to a group with less than X members, for example less than 3 members, then the resulting data frame structure would look like: foo v1 v2 v3 1 1 a 6 2 a 3 8 a Is there some simple way to do this in R? Thanks in advance. /Oscar [[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] flexible alternative to subsetting dataframe inside nested loops
I have a dataFrame variable: L1 L2 L3 ... v1 v2 ... 1 2 3 4 ... I want to process subsets of it as defined by combinations of L1-L2-L3. I do it successfully using nested loops: for (i in valuesOfL1 { for (j in valuesOfL2) { for (k in valuesOfL3) { tempData - subset(dataFrame, (L1 == i L2 == j L3 == k, select=c(v1,v2) )) if (dim(tempData)[1]0) # does this combination of L1-L2-L3 contain any data? { process(tempData) } } } } It works fine but: 1. I'm sure there can be more efficient solution 2. each time I want to change criteria (i.e. subset by less or more Ls) I have to manually change number of nested loops in my code. Is there a more flexible way to do it? Thanks -- View this message in context: http://n4.nabble.com/flexible-alternative-to-subsetting-dataframe-inside-nested-loops-tp1680580p1680580.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] flexible alternative to subsetting dataframe inside nested loops
On Wed, Mar 24, 2010 at 8:52 AM, mgierdal mgier...@gmail.com wrote: I have a dataFrame variable: L1 L2 L3 ... v1 v2 ... 1 2 3 4 ... I want to process subsets of it as defined by combinations of L1-L2-L3. I do it successfully using nested loops: for (i in valuesOfL1 { for (j in valuesOfL2) { for (k in valuesOfL3) { tempData - subset(dataFrame, (L1 == i L2 == j L3 == k, select=c(v1,v2) )) if (dim(tempData)[1]0) # does this combination of L1-L2-L3 contain any data? { process(tempData) } } } } It works fine but: 1. I'm sure there can be more efficient solution 2. each time I want to change criteria (i.e. subset by less or more Ls) I have to manually change number of nested loops in my code. ?split library(plyr) ?ddply Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] removing fields of the same group from a data frame
Try this: subset(foo, v3 %in% names(which(!table(foo$v3) 3))) On Wed, Mar 24, 2010 at 10:38 AM, Oscar Franzén oscar.franz...@gmail.com wrote: Dear all, I'm trying to find a a way to remove certain fields belonging to the same group from a data frame structure. I have a data frame like this: foo v1 v2 v3 1 1 a 6 2 a 3 8 a 4 4 b 4 4 b 2 1 c 1 6 d Each row can then be grouped according to the third column: a, b, c, d. Then I would like to remove all fields that belong to a group with less than X members, for example less than 3 members, then the resulting data frame structure would look like: foo v1 v2 v3 1 1 a 6 2 a 3 8 a Is there some simple way to do this in R? Thanks in advance. /Oscar [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] removing fields of the same group from a data frame
On Mar 24, 2010, at 8:38 AM, Oscar Franzén wrote: Dear all, I'm trying to find a a way to remove certain fields belonging to the same group from a data frame structure. I have a data frame like this: foo v1 v2 v3 1 1 a 6 2 a 3 8 a 4 4 b 4 4 b 2 1 c 1 6 d Each row can then be grouped according to the third column: a, b, c, d. Then I would like to remove all fields that belong to a group with less than X members, for example less than 3 members, then the resulting data frame structure would look like: foo v1 v2 v3 1 1 a 6 2 a 3 8 a Is there some simple way to do this in R? Thanks in advance. /Oscar DF v1 v2 v3 1 1 1 a 2 6 2 a 3 3 8 a 4 4 4 b 5 4 4 b 6 2 1 c 7 1 6 d subset(DF, !v3 %in% names(which(table(v3) 3))) v1 v2 v3 1 1 1 a 2 6 2 a 3 3 8 a The use of table() gets us: table(DF$v3) 3 a b c d FALSE TRUE TRUE TRUE followed by: names(which(table(DF$v3) 3)) [1] b c d which gives us the values of v3 that don't have at least 3 entries. When using subset(), the variables are evaluated first within the data frame, hence we can drop the 'DF$' in the function call. The use of %in% in subset() allows us to include or exclude certain values from a set comparison. We could also reverse the logic, yielding the same result: subset(DF, v3 %in% names(which(table(v3) = 3))) v1 v2 v3 1 1 1 a 2 6 2 a 3 3 8 a See ?table, ?subset and ?%in% for more information. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Predict from glm
Dear list members, I fitted a glm model (See output below). My outcome is death, and weight (continuous), ClutchSize (3-level factor), EggVolume (continuous), Sex (obviously 2-level factor), and SiblingCompetence (2-level factor) are my covariates. I'd like to obtain the odds of death for a range of Weights, EggVolumes, and different combinations of ClutchSize. I've tried using the predict function but I just can't seem to get it right. Could anyone give me some guidance? I am not including codes with predict function in my message because I got it totally wrong (lots of errors) and I'd rather start from scratch with some fresh guidance from the list. Thank you very much. Luciano Call: glm(formula = Death ~ Weight + ClutchSize + EggVolume + Sex + SibComp, family=binomial) Deviance Residuals: Min 1Q Median 3Q Max -1.7205 -0.8476 -0.5362 0.9769 2.3132 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 5.905432.60526 2.267 0.0234 * Weight -0.025210.01709 -1.475 0.1402 ClutchSizeTwo-eggs1.617010.65699 2.461 0.0138 * ClutchSizeThree-eggs 1.077750.66945 1.610 0.1074 EggVolume-0.082000.03375 -2.430 0.0151 * SexMale 0.778820.35374 2.202 0.0277 * SibCompPresente 0.723330.40077 1.805 0.0711 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 238.12 on 182 degrees of freedom Residual deviance: 200.09 on 176 degrees of freedom (84 observations deleted due to missingness) AIC: 214.09 Number of Fisher Scoring iterations: 4 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
Hi, I have this data set: obitoss = c( 5.8,17.4,5.9,17.6,5.8,17.5,4.7,15.8, 3.8,13.4,3.8,13.5,3.7,13.4,3.4,13.6, 4.4,17.3,4.3,17.4,4.2,17.5,4.3,17.0, 4.4,13.6,5.1,14.6,5.7,13.5,3.6,13.3, 6.5,19.6,6.4,19.4,6.3,19.5,6.0,19.7) (dados = data.frame( regiao = factor(rep(c('Norte', 'Nordeste', 'Sudeste', 'Sul', 'Centro-Oeste'), each=8)), ano = factor(rep(c('2000','2001','2002','2003'), each=2)), sexo = factor(rep(c('F','M'), 4)), resp=obitoss)) I would like to make a mosaic to represent the numeric variable depending on 3 variables. Does anyone know how to do? -- Silvano Cesar da Costa Departamento de Estatística Universidade Estadual de Londrina Fone: 3371-4346 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rpad ?
Erich, I use Rpad actively so I am disappointed to hear it is no longer being updated. Would you be willing to share your modifications with the list, or at least with me? Thanks, Roger -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erich Neuwirth Sent: Tuesday, March 23, 2010 4:47 PM To: r-help@r-project.org Subject: Re: [R] rpad ? We are using RPad for a teaching application here. But we had to find many things the hard way, and additionally, it did not survive the latest R release change. There is a minimal repair, but the maintainer does not answer any email any more. We did the repair and are giving a modified version to our students, but we do not have enough resource to take over maintenance. On 3/23/2010 8:00 PM, sjaffe wrote: Is anyone using rpad? Is there any documentation or examples beyond that in the 'man' directory of the source? -- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** This message is for the named person's use only. It may\...{{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] barplot (stacked)
Hi Jens! 24.03.2010 14:48, koj wrote Hi Kimmo, thank you for your answer, but this is not the thing I am searching for. Unfortunately, I have not described the problem very good. But just in this moment I have a good idea: I use add=TRUE and paint two plots. And so I am sure that I can solve the problem. Just to satisfy my curiosity: does the following code solve Your problem (once again, dm refers to your data matrix): --- cut here --- barplot(dm[,seq(1,20,2)], col=grey, space=2) barplot(dm[,seq(2,20,2)], add=T, col=c(blue,green), space=c(3,rep(2,9))) --- cut here --- Regards, Kimmo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 text form the graph(outer region)
Dear R communities, when i do a calibration plot i have text inside the graph bottom left and right (outer region) saying x resampling added B=200, i want to get rid of this texts please advise me how can i do it Thanks very much Paaveen _ Take your contacts everywhere [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sample size for proportion, not binomial
Dear Marc, Thank you very much for the advice and the papers, it helps. Regards, Paul From: Marc Schwartz marc_schwa...@me.com To: Prew, Paul paul.p...@ecolab.com Cc: r-help@r-project.org Subject: Re: [R] Sample size for proportion, not binomial Message-ID: c56551a0-fce8-4ffe-8857-d16dd3827...@me.com Content-Type: text/plain; charset=windows-1252 On Mar 23, 2010, at 11:05 AM, Prew, Paul wrote: Hello, I am looking for a sample size function for samples sizes, to test proportions that are not binomial proportions. The proportions represent a ratio of (final measure) / (baseline measure) on the same experimental unit. Searches using RSeek and such bring multiple hits for binomial proportions, but that doesn't seem to fit my situation. Perhaps there's some standard terminology from a different field that would provide better hits than deeming this a 'rate' or a 'proportion'. Of course, most sample size functions assume a normal distribution, while this data will be bounded between 0 and 1. The scientist I'm working with feels it's important to make fair comparisons, any weight loss must account for the baseline weight. A logistic transformation seems appropriate, but that term also didn't yield hits I recognized as useful. Loss of weight --- compare treatments: Treatment A: 1 - Final weight / Initial weight Treatment B: 1 - Final weight / Initial weight This appears to be a situation that would be common, but I'm not framing it in a way that matches an R package. Any guidance is appreciated. Regards, Paul If you and the scientist are in a position of being open to better options of analyzing change from baseline data, I would recommend that you both read the following two papers: Statistics notes: analysing controlled trials with baseline and follow up measurements. Vickers AJ, Altman DG. BMJ 2001;323:1123?4. http://www.bmj.com/cgi/content/full/323/7321/1123 http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1121605/pdf/1123.pdf The use of percentage change from baseline as an outcome in a controlled trial is statistically inefficient: a simulation study. Vickers AJ. BMC Med Res Methodol 2001;1:6. http://www.biomedcentral.com/1471-2288/1/6 http://www.biomedcentral.com/content/pdf/1471-2288-1-6.pdf and review an additional web site: http://biostat.mc.vanderbilt.edu/wiki/Main/MeasureChange Once you are hopefully in a position of adopting a regression based approach (eg. FinalWeight ~ BaseWeight + Treatment), there are various options for calculating sample sizes. The key advantage of this approach is that you get the baseline adjusted between-group comparison (the regression beta coefficient and confidence intervals for Treatment) which is the key outcome of interest in comparing treatments in a parallel design. The easiest, albeit conservative approach for sample size, is to use power.t.test() on your assumptions of the inter-group delta for actual weight change (not percent change), the std dev for actual change, desired power and target alpha. I am not aware off-hand of any power/sample size functions in R for regular linear regression, though they may exist. There are third party programs that do provide that functionality. If you are willing to code and experiment a bit, you could construct a monte carlo simulation with a linear model, using data generated with rnorm() based upon reasonable assumptions about the distribution of your data in each group for the baseline and final values. Once you get your actual data collected and ready for analysis, you will also need to test for a baseline*treatment interaction (FinalWeight ~ BaseWeight * Treatment), which can make the interpretation of treatment effects more complicated, since the treatment effect will be conditional upon the baseline weight, rather than being able to report a mean treatment effect. HTH, Marc Schwartz Paul Prew ⪠Statistician 651-795-5942 ⪠fax 651-204-7504 Ecolab Research Center ⪠Mail Stop ESC-F4412-A 655 Lone Oak Drive ⪠Eagan, MN 55121-1560 [[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] Bulk editing of mySQL tables
Hello Daniel, although I am not completely sure what you mean with 'batch changes to data'. Assuming that you want to modify the data in your tables, I would first try to do it in MySQL without exporting it to R and the importing it back. If it is to difficult to do in MySQL, for example a complex calculation, then I would get it into R, change it and place it back in the database. In that case you would need to update your tables and not simply use dbWriteTable. Albart -- View this message in context: http://n4.nabble.com/Bulk-editing-of-mySQL-tables-tp1680417p1680776.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] lattice: defining graphical parameters
Dears, could anyone give me some advice how to change some plotting parameters for a lattice graph? I need to adjust the following: -reduce outer margins (like par(mar=c(0,0,0,0)) with base graphs) -modify positions of labels (like par(mpg=c(0,0,0)) with base graphs) I already did some research, but got confused by the huge amount of settings with the lattice objects. I know that the road to success goes in this direction: trellis.par.set(list(fontsize=list(text=8))) But how are my specific arguments called? First tries like: trellis.par.set(list(top.padding=0.5)) did not seem to have any effect. Thanks for your help! _ ügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.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] Summing with NA
Slightly longer method, but works as well. z - c(-12,-9) e - c(-2,0) k - c(NA,NA) x - c(z,e,k) x1 - which(x!=NA,arr.ind=TRUE) # get elements which are not NA x2 - x[x1] sum(x2) [1] -23 -- Muhammad tj wrote: Hi all, May I request for your help if you have time and if you have an idea on how to do this. I want to add three vectors... And my goal is to obtain the sum of the vectors, ignoring the vector of na... Here is what i did in R.. I'm adding the three vectors, e,z,k, and my objective is to get an answer = -23. I tried putting the na.omit but it did not work. Thanks. z [1] -12 -9 e [1] -2 0 k [1] NA NA sum(z+e+k) [1] NA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] install ncdf package
Dear R users I am attempting to add lncdf_1.6.tar.gz libraries within R, and have failed. I have R version 2.8.1, and are running on fedora 10 Kernel Linux 2.6.293.-60.fc10.x86_64. I've run R CMD INSTALL ncdf_1.6.tar.gz and I have the following --- * Installing to library '/usr/lib64/R/library' * Installing *source* package 'ncdf' ... checking for gcc... gcc -m64 -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -m64 -std=gnu99 accepts -g... yes checking for gcc -m64 -std=gnu99 option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -m64 -std=gnu99 -E checking for egrep... grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking netcdf.h usability... yes checking netcdf.h presence... yes checking for netcdf.h... yes Found netcdf.h in: . checking for nc_open in -lnetcdf... yes Found netcdf library file libnetcdf.a in directory . configure: creating ./config.status config.status: creating R/load.R config.status: creating src/Makevars ** libs gcc -m64 -std=gnu99 -I/usr/include/R -I. -I/usr/local/include-fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c ncdf2.c -o ncdf2.o gcc -m64 -std=gnu99 -I/usr/include/R -I. -I/usr/local/include-fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c ncdf3.c -o ncdf3.o ncdf3.c: In function ‘R_nc_get_vara_charvarid’: ncdf3.c:221: warning: assignment discards qualifiers from pointer target type ncdf3.c: In function ‘R_nc_get_vara_numvarid’: ncdf3.c:267: warning: assignment discards qualifiers from pointer target type ncdf3.c:249: warning: ‘rv_data’ may be used uninitialized in this function gcc -m64 -std=gnu99 -I/usr/include/R -I. -I/usr/local/include-fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c ncdf.c -o ncdf.o ncdf.c: In function ‘R_nc_get_vara_double’: ncdf.c:196: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c:202: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c: In function ‘R_nc_get_vara_int’: ncdf.c:239: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c:245: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c: In function ‘R_nc_get_vara_text’: ncdf.c:296: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c:302: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c: In function ‘R_nc_ttc_to_nctype’: ncdf.c:424: warning: implicit declaration of function ‘exit’ ncdf.c:424: warning: incompatible implicit declaration of built-in function ‘exit’ ncdf.c: In function ‘R_nc_put_vara_double’: ncdf.c:582: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ ncdf.c:585: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ gcc -m64 -std=gnu99 -shared -L/usr/local/lib64 -o ncdf.so ncdf2.o ncdf3.o ncdf.o -L. -lnetcdf -L/usr/lib64/R/lib -lR /usr/bin/ld: /usr/local/lib/libnetcdf.a(attr.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libnetcdf.a: could not read symbols: Bad value collect2: ld returned 1 exit status make: *** [ncdf.so] Error 1 chmod: cannot access `/usr/lib64/R/library/ncdf/libs/*': No such file or directory ERROR: compilation failed for package 'ncdf' ** Removing '/usr/lib64/R/library/ncdf' --- Any help is strongly appreciated, thank you in advance -- View this message in context: http://n4.nabble.com/install-ncdf-package-tp1680818p1680818.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] Summing with NA
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Muhammad Rahiz Sent: Wednesday, March 24, 2010 9:21 AM To: tj Cc: r-help@r-project.org Subject: Re: [R] Summing with NA Slightly longer method, but works as well. z - c(-12,-9) e - c(-2,0) k - c(NA,NA) x - c(z,e,k) x1 - which(x!=NA,arr.ind=TRUE) # get elements which are not NA Instead of x!=NA, which works here more or less by accident, use !is.na(x) Your code works because x!=NA is NA for any value of x that is NA and which() considers NA to be the same as FALSE. However, which(x!=String that a numeric will not be converted to) will do the same. Most functions do distinguish between NA and FALSE in logical vectors so you will run into fewer surprises if you use is.na(x) (rather than x!=NA) to see where the NA's in x are. (You will also save the time and memory involved in converting x to a character vector.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com x2 - x[x1] sum(x2) [1] -23 -- Muhammad tj wrote: Hi all, May I request for your help if you have time and if you have an idea on how to do this. I want to add three vectors... And my goal is to obtain the sum of the vectors, ignoring the vector of na... Here is what i did in R.. I'm adding the three vectors, e,z,k, and my objective is to get an answer = -23. I tried putting the na.omit but it did not work. Thanks. z [1] -12 -9 e [1] -2 0 k [1] NA NA sum(z+e+k) [1] NA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ordinal regression
Iasonas Lamprianou wrote: Dear colleagues, i am carrying out an ordinal regression model. I try it on SPSS but I flirt with R as well. I have a few questions. 1. What is the most reliable/tested/trusted package for ordinal regression in the R world? 2. Also, I have a statistical question. What is the danger of having to many 'empty cells' in ordinal regression? How many empty cells are too many? Do you have a reference for me to read? Thank you for the support Dr. Iasonas Lamprianou Not sure what is the most trusted but the lrm function in the rms package does proportional odds and continuation ratio models (the latter with a trick to expand the dataset). Nearly empty cells are not a problem unless you allow for non-proportionality (e.g., interaction between X and Y). Frank Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.uk -- Frank E Harrell Jr Professor and ChairmanSchool 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] Summing with NA
Hi, Do help(sum) to find more information about the option na.rm=T sum(c(z,e,k),na.rm=T) [1] -23 Alain On 24-Mar-10 17:21, Muhammad Rahiz wrote: Slightly longer method, but works as well. z - c(-12,-9) e - c(-2,0) k - c(NA,NA) x - c(z,e,k) x1 - which(x!=NA,arr.ind=TRUE) # get elements which are not NA x2 - x[x1] sum(x2) [1] -23 -- Muhammad tj wrote: Hi all, May I request for your help if you have time and if you have an idea on how to do this. I want to add three vectors... And my goal is to obtain the sum of the vectors, ignoring the vector of na... Here is what i did in R.. I'm adding the three vectors, e,z,k, and my objective is to get an answer = -23. I tried putting the na.omit but it did not work. Thanks. z [1] -12 -9 e [1] -2 0 k [1] NA NA sum(z+e+k) [1] NA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] splitting word
Hi all, Could someone tell me how to split a word. c(AA) to c(A,A) Thanks! Phoebe [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Export R dataframe to STA with Variable Labels
I've successfully imported a Stata file (dta) into R with the read.dta (function) (i.e., data, variable labels, and value labels import correctly). After working in R, I use write.dta to export the data frame back to a *.dta file. The data and value labels convert fine, but the variable labels do not - the variable labels are written as the variable name(e.g., the variable label for f1sn1 is listed as f1sn1 instead of students academic grade). write.dta(d,immigration.dta,version=7L,convert.factor=labels) Are there any suggestions for maintaining the variable labels between a Stata--R--Stata import/export. My apologies for imprecise language. I'm new to R and am not familiar with its vocabulary. IF this goes well, I hope to convince my collegues to migrate from Stata to R. Mike -- View this message in context: http://n4.nabble.com/Export-R-dataframe-to-STA-with-Variable-Labels-tp1680841p1680841.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] splitting word
Dear Phoebe, If I understand correctly that you always want to split a word into individual letters, then strsplit(AA, )[[1]] will do the trick -- and help.search(split) turns up strsplit(). I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of phoebe kong Sent: March-24-10 12:46 PM To: r-help Subject: [R] splitting word Hi all, Could someone tell me how to split a word. c(AA) to c(A,A) Thanks! Phoebe [[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] splitting word
strsplit(x,split=) --- phoebe kong sityeek...@gmail.com schrieb am Mi, 24.3.2010: Von: phoebe kong sityeek...@gmail.com Betreff: [R] splitting word An: r-help r-help@r-project.org Datum: Mittwoch, 24. März, 2010 16:46 Uhr Hi all, Could someone tell me how to split a word. c(AA) to c(A,A) Thanks! Phoebe [[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. __ herausragenden Schutz gegen Massenmails. http://mail.yahoo.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: defining graphical parameters
Jannis: I understand your confusion, but you need to read and follow the lattice documentation more carefully. You may also wish to consider getting Deepayan's book, which provides a gentler, less terse, and more organized guide to lattice's complexities with many more examples. Anyway, names(trellis.par.get()) shows you that there is NO component named top.padding Rather, top.padding is one of the components of the layout.heights list which IS one of the components of the trellis.par.get() settings list. To change the top.padding component of THIS list you therefore should do: trellis.par.set(layout.heights = list(top.padding = .5)) (I'm not sure this will do what you want, but at least the call will be correct.) All this is explained in ?trellis.par.set. Bert Gunter Genentech Nonclinical Biostatistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jannis Sent: Wednesday, March 24, 2010 8:50 AM To: r-help@r-project.org Subject: [R] lattice: defining graphical parameters Dears, could anyone give me some advice how to change some plotting parameters for a lattice graph? I need to adjust the following: -reduce outer margins (like par(mar=c(0,0,0,0)) with base graphs) -modify positions of labels (like par(mpg=c(0,0,0)) with base graphs) I already did some research, but got confused by the huge amount of settings with the lattice objects. I know that the road to success goes in this direction: trellis.par.set(list(fontsize=list(text=8))) But how are my specific arguments called? First tries like: trellis.par.set(list(top.padding=0.5)) did not seem to have any effect. Thanks for your help! _ ügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plotting Zero Inflated Poisson regression lines
Dear All, I'm using zeroinfl() from the pscl-package for zero inflated Poisson regression. I have a continuous variable that interacts with a dichotomous variable to predict my outcome. I want to plot the relationship predicted by the count model in my ZIP regression between my continuous IV and the DV for each group of my dichotomous variable (so as to illustrate the interaction). Any suggestions as to how I can do this will be appreciated. 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] Zelig: Error message for 'mlogit'
I'm running a multinomial logit in R using the Zelig package. However I get the following error. HELP anes96two - zelig(trade962a ~ age962 + education962 + personal962 + economy962 + partisan962 + employment962 + union962 + home962 + market962 + race962 + income962, model=mlogit, data=data96) #Error in attr(tt, depFactors)$depFactorVar : # $ operator is invalid for atomic vectors __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Deleting duplicate rows in a matrix at random
Hello, I am relatively new to R, and I've run into a problem formatting my data for input into the package RankAggreg. I have a matrix of gene titles and P-values (weights) in two columns: KCTD12 4.06904E-22 UNC93A 9.91852E-22 CDKN3 1.24695E-21 CLEC2B 4.71759E-21 DAB21.12062E-20 HSPB1 1.23125E-20 ... The data contains many, many duplicate gene titles, and I need to remove all but one of each, which must be chosen at random. I have looked for quite some time, and I've been unable to find a way to do this. Any help would be greatly appreciated! Thanks, Jeff -- View this message in context: http://n4.nabble.com/Deleting-duplicate-rows-in-a-matrix-at-random-tp1680730p1680730.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] Using svm function
Hello, I'm a newbie in this language, and I'm using svm to predict events using R, and would like to know what are the arguments that can be sent to the svm function, the only example I have about this is about the iris example and goes like this data(iris) model - svm(Species ~ ., data = iris, method = C-classification, kernel = radial, cost = 10, gamma = 0.1) summary(model) I really don't know how this svm function works, and don't know how to obtain the data properly from a data file that I got from this site http://archive.ics.uci.edu/ml/datasets.html I know that I have to obtain data, classificate it, and then model it using the svm method, but I think documentation regarding this function is very scarce Thanks in advance -- View this message in context: http://n4.nabble.com/Using-svm-function-tp1680707p1680707.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R warning and error messages taking a long time and generating pop-up windows
Hi all, thanks for your help in advance. I was running some scripts and suddenly R began taking a very long time to process mundane errors, which I often generate since I am new to R...such as forgetting to add in my quote getOption(warn) Error in options(x) : object 'warn' not found Not only does the warning message print in the R console when it finally writes the error, but it also generates a warning pop up box in windows reiterating the error. Is this a setting that got accidently turned on? It never did this before, but its making code debugging take a LONG time. Thanks, Justin Justin M. Balko, Pharm.D., Ph.D. Research Fellow, Arteaga Lab Vanderbilt-Ingram Cancer Center 691 Preston Research Building Nashville, TN 37232-6307 Tel: 615-936-1495 Email: justin.ba...@vanderbilt.edumailto:justin.ba...@vanderbilt.edu [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Converting a data set from 'long' format to 'interval' format
Hi, I have a data set in which the variable 'dose' is time-varying. Currently, the data set is in a long format, with 1 row for each time unit of follow-up for each individual Id. It looks like this: orig.data - cbind(Id = c(rep(1,4), rep(2,5)), time = c(1:4, 1:5), dose = c(1,1,1,0,1,0,1,1,0)) orig.data Id time dose [1,] 111 [2,] 121 [3,] 131 [4,] 140 [5,] 211 [6,] 220 [7,] 231 [8,] 241 [9,] 250 What I would like to do is to convert the data set into an interval format. By that I mean a data set in which each row has a 'Start' and a 'Stop' value that indicates the time units in which the 'dose' is constant. For example, my orig.data example would now be: int.data - cbind(Id = c(rep(1,2), rep(2,4)), Start = c(1,4,1,2,3,5), Stop = c(3,4,1,2,4,5), dose = c(1,0,1,0,1,0)) int.data Id Start Stop dose [1,] 1 131 [2,] 1 440 [3,] 2 111 [4,] 2 220 [5,] 2 341 [6,] 2 550 Basically, this implies collapsing rows that have the same Id and dose and creating Start and Stop to index the time. While I can write a clumsy routine with multiple loops to do it, it will be inefficient and will not work for large data set. I wonder if people know of a function that would reshape my data set from 'long' to 'interval'? Best, MP [[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] Recall: vcov.nlminb
Johnson, Brian P. would like to recall the message, vcov.nlminb. [[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] vcov.nlminb
Hello all, I am trying to get the variance-covariance (VCOV) matrix of the parameter estimates produced from the nlminb minimizing function, using vcov.nlminb, but it seems to have been expunged from the MASS library. The hessian from nlminb is also producing NaNs, although the estimates seems to be right, so I can't VCOV that way either. I also tried using the vcov function after minimizing the function with the nlm function and that produced the following error: Error in UseMethod(vcov) : no applicable method for 'vcov' applied to an object of class list Any thoughts on this would be welcome. Thanks, Brian Essentia Institute of Rural Health Duluth, MN 55805 [[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] install ncdf package
Pinto wrote: Dear R users I am attempting to add lncdf_1.6.tar.gz libraries within R, and have failed. I have R version 2.8.1, and are running on fedora 10 Kernel Linux 2.6.293.-60.fc10.x86_64. I've run R CMD INSTALL ncdf_1.6.tar.gz and I have the following --- * Installing to library '/usr/lib64/R/library' * Installing *source* package 'ncdf' ... checking for gcc... gcc -m64 -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -m64 -std=gnu99 accepts -g... yes checking for gcc -m64 -std=gnu99 option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -m64 -std=gnu99 -E checking for egrep... grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking netcdf.h usability... yes checking netcdf.h presence... yes checking for netcdf.h... yes Found netcdf.h in: . checking for nc_open in -lnetcdf... yes Found netcdf library file libnetcdf.a in directory . configure: creating ./config.status config.status: creating R/load.R config.status: creating src/Makevars ** libs gcc -m64 -std=gnu99 -I/usr/include/R -I. -I/usr/local/include-fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c ncdf2.c -o ncdf2.o gcc -m64 -std=gnu99 -I/usr/include/R -I. -I/usr/local/include-fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c ncdf3.c -o ncdf3.o ncdf3.c: In function ‘R_nc_get_vara_charvarid’: ncdf3.c:221: warning: assignment discards qualifiers from pointer target type ncdf3.c: In function ‘R_nc_get_vara_numvarid’: ncdf3.c:267: warning: assignment discards qualifiers from pointer target type ncdf3.c:249: warning: ‘rv_data’ may be used uninitialized in this function gcc -m64 -std=gnu99 -I/usr/include/R -I. -I/usr/local/include-fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c ncdf.c -o ncdf.o ncdf.c: In function ‘R_nc_get_vara_double’: ncdf.c:196: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c:202: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c: In function ‘R_nc_get_vara_int’: ncdf.c:239: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c:245: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c: In function ‘R_nc_get_vara_text’: ncdf.c:296: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c:302: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘size_t’ ncdf.c: In function ‘R_nc_ttc_to_nctype’: ncdf.c:424: warning: implicit declaration of function ‘exit’ ncdf.c:424: warning: incompatible implicit declaration of built-in function ‘exit’ ncdf.c: In function ‘R_nc_put_vara_double’: ncdf.c:582: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ ncdf.c:585: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ gcc -m64 -std=gnu99 -shared -L/usr/local/lib64 -o ncdf.so ncdf2.o ncdf3.o ncdf.o -L. -lnetcdf -L/usr/lib64/R/lib -lR /usr/bin/ld: /usr/local/lib/libnetcdf.a(attr.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libnetcdf.a: could not read symbols: Bad value collect2: ld returned 1 exit status make: *** [ncdf.so] Error 1 chmod: cannot access `/usr/lib64/R/library/ncdf/libs/*': No such file or directory ERROR: compilation failed for package 'ncdf' ** Removing '/usr/lib64/R/library/ncdf' --- Any help is strongly appreciated, thank you in advance Based on the error: /usr/bin/ld: /usr/local/lib/libnetcdf.a(attr.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC I would guess that R is complaining about libnetcdf.a was not compiled to use position independent code, hence the request for -fPIC. However, my expertise in these areas is amateur at best-- someone else may be able to provide a more informed opinion. Also, you stated you are using R 2.8.1 which is out of date by two, soon to be three, major releases. It is highly recommended to keep your version of R as current as possible. A newer
[R] vcov.nlminb
Hello all, I am trying to get the variance-covariance (VCOV) matrix of the parameter estimates produced from the nlminb minimizing function, using vcov.nlminb, but it seems to have been expunged from the MASS library. I also tried using the vcov function after minimizing the function with the nlm function and that produced the following error: Error in UseMethod(vcov) : no applicable method for 'vcov' applied to an object of class list The hessian from nlm is also producing NaNs, although the estimates seems to be right, so I can't get the VCOV that way either. Any potential solutions on this would be welcome. Thanks, Brian Essentia Institute of Rural Health Duluth, MN 55805 [[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] methods with * how to see
Dear R-gurus, When I use methods(general method) I sometimes get 'sub-methods marked with a *. How can see the code of such *-marked methods? Sincerly Fredrik Fredrik Lundgren fredrik.bg.lundg...@gmail.com Engelbrektsgatan 31 582 21 Linköping tel 013 - 47 30 117 mob 0706 - 86 39 29 Sommarhus: Ljungnäs 158 380 30 Rockneby 0480 - 650 98 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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
I've typically used mosaic plots with categorical data - not sure what the numerical values represent. This fits a mosaic plot by rounding the values: library(vcd) t - xtabs(resp ~ sexo + regiao + ano, data = dados) ft - ftable(round(t)) cotabplot(ft, panel = cotab_coindep, type = mosaic) Sam Thomas -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Silvano Sent: Wednesday, March 24, 2010 11:01 AM To: r-help@r-project.org Subject: [R] Mosaic Hi, I have this data set: obitoss = c( 5.8,17.4,5.9,17.6,5.8,17.5,4.7,15.8, 3.8,13.4,3.8,13.5,3.7,13.4,3.4,13.6, 4.4,17.3,4.3,17.4,4.2,17.5,4.3,17.0, 4.4,13.6,5.1,14.6,5.7,13.5,3.6,13.3, 6.5,19.6,6.4,19.4,6.3,19.5,6.0,19.7) (dados = data.frame( regiao = factor(rep(c('Norte', 'Nordeste', 'Sudeste', 'Sul', 'Centro-Oeste'), each=8)), ano = factor(rep(c('2000','2001','2002','2003'), each=2)), sexo = factor(rep(c('F','M'), 4)), resp=obitoss)) I would like to make a mosaic to represent the numeric variable depending on 3 variables. Does anyone know how to do? -- Silvano Cesar da Costa Departamento de Estatística Universidade Estadual de Londrina Fone: 3371-4346 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Filling a grid based on existing data
Dear all, I currently have a data frame of dimensions 18556 rows by 19 columns. I want to convert this into a grid of dimensions 720 rows by 360 columns. The problem in this case is that not all rows in the initial data frame are complete (there are gaps). Therefore I am perhaps looking for a way of filling a 720 x 360 grid by reading in all values in each row until one is encountered which does not have 19 columns. In these cases, the row in the new grid should be filled (as the gaps occur every 720 values), and filling should re-start on the next row of the new grid. I hope this is reasonably clear! Many thanks for any help, Steve _ Got a cool Hotmail story? Tell us now __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] methods with * how to see
Try ?getAnywhere Fredrik Lundgren wrote: Dear R-gurus, When I use methods(general method) I sometimes get 'sub-methods marked with a *. How can see the code of such *-marked methods? Sincerly Fredrik Fredrik Lundgren fredrik.bg.lundg...@gmail.com Engelbrektsgatan 31 582 21 Linköping tel013 - 47 30 117 mob 0706 - 86 39 29 Sommarhus: Ljungnäs 158 380 30 Rockneby 0480 - 650 98 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
When you click search on the R homepage, type mosaic into the box, and click the button, do the top 3 links seem relevant ? Your previous 2 requests for help : 26 Feb : Response was SuppDists. Yet that is the first hit returned by the subject line you posted : Hartleys table 22 Feb : Response was shapiro.test. Yet that is in the second hit returned by the subject line you posted : normality in split plot design Spot the pattern ? Silvano silv...@uel.br wrote in message news:a9322645c4f846a3a6a9daaa8b5a2...@ccepc... Hi, I have this data set: obitoss = c( 5.8,17.4,5.9,17.6,5.8,17.5,4.7,15.8, 3.8,13.4,3.8,13.5,3.7,13.4,3.4,13.6, 4.4,17.3,4.3,17.4,4.2,17.5,4.3,17.0, 4.4,13.6,5.1,14.6,5.7,13.5,3.6,13.3, 6.5,19.6,6.4,19.4,6.3,19.5,6.0,19.7) (dados = data.frame( regiao = factor(rep(c('Norte', 'Nordeste', 'Sudeste', 'Sul', 'Centro-Oeste'), each=8)), ano = factor(rep(c('2000','2001','2002','2003'), each=2)), sexo = factor(rep(c('F','M'), 4)), resp=obitoss)) I would like to make a mosaic to represent the numeric variable depending on 3 variables. Does anyone know how to do? -- Silvano Cesar da Costa Departamento de Estatística Universidade Estadual de Londrina Fone: 3371-4346 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] string problems in R
Hello all I have been working on my thesis using R. I am a newbie to R and met a problem that bothered me for a while due to my lack of acquaintance of R. I am using R to query from SQL. I got a list of crsp_fundno of G-style mutual funds which is still alive. I use the following codes and got what I want: library(RODBC) channel-odbcConnect(CRSPFUND) g.crspfundno-sqlQuery(channel,select crsp_fundno from Fund_style where wbrger_obj_cd = 'G'order by crsp_fundno) g.crspfundno (got crsp_fundno of G-style fund from Fund_style table) y.crspfundno-sqlQuery(channel,select crsp_fundno from Fund_hdr where dead_flag = 'N'and end_dt=20091231 order by crsp_fundno) y.crspfundno (got crsp_fundno of still alive fund from Fund_hdr table) g$key-paste(g.crspfundno$crsp_fundno) y$key-paste(y.crspfundno$crsp_fundno) v.fundno-intersect(g$key,y$key) (using intersect to get crsp_fundno of G-style mutual funds which is still alive.) v.fundno What i need to do next is using the v.fundno I got to query from another table Monthly_return to get the mret coresponding to every v.fundno. I have only a basic idea of the code: for (i in 1:length(v.fundno)){ gmret-sqlQuery(channel,select mret from Monthly_returns where crsp_fundno = toString(v.fundno[i])) } gmret R gave me an error with undefined function toString I know there should be some details added in to get it right,like define an object or how to convert number to string.. I would be appreciated if anyone gives me any clue about it. Muting __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] string problems in R
Muting Zhang wrote: Hello all I have been working on my thesis using R. I am a newbie to R and met a problem that bothered me for a while due to my lack of acquaintance of R. I am using R to query from SQL. I got a list of crsp_fundno of G-style mutual funds which is still alive. I use the following codes and got what I want: library(RODBC) channel-odbcConnect(CRSPFUND) g.crspfundno-sqlQuery(channel,select crsp_fundno from Fund_style where wbrger_obj_cd = 'G'order by crsp_fundno) g.crspfundno (got crsp_fundno of G-style fund from Fund_style table) y.crspfundno-sqlQuery(channel,select crsp_fundno from Fund_hdr where dead_flag = 'N'and end_dt=20091231 order by crsp_fundno) y.crspfundno (got crsp_fundno of still alive fund from Fund_hdr table) g$key-paste(g.crspfundno$crsp_fundno) y$key-paste(y.crspfundno$crsp_fundno) v.fundno-intersect(g$key,y$key) (using intersect to get crsp_fundno of G-style mutual funds which is still alive.) v.fundno What i need to do next is using the v.fundno I got to query from another table Monthly_return to get the mret coresponding to every v.fundno. I have only a basic idea of the code: for (i in 1:length(v.fundno)){ gmret-sqlQuery(channel,select mret from Monthly_returns where crsp_fundno = toString(v.fundno[i])) } gmret R gave me an error with undefined function toString I know there should be some details added in to get it right,like define an object or how to convert number to string.. I would be appreciated if anyone gives me any clue about it. Muting I'm going to take a wild guess and say that the following might work: gmret-sqlQuery(channel, paste( select mret from Monthly_returns where crsp_fundno =, v.fundno[i] ) ) If you could post example data, say the results of: head( v.fundno ) I could provide more than a wild guess. Hope it helps! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/string-problems-in-R-tp1685419p1685837.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] vcov.nlminb
Try the `hessian' function in numDeriv package. It can produce very accurate hessians. Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Johnson, Brian P. Sent: Wednesday, March 24, 2010 12:14 PM To: r-help@r-project.org Cc: Brian Johnson Subject: [R] vcov.nlminb Hello all, I am trying to get the variance-covariance (VCOV) matrix of the parameter estimates produced from the nlminb minimizing function, using vcov.nlminb, but it seems to have been expunged from the MASS library. I also tried using the vcov function after minimizing the function with the nlm function and that produced the following error: Error in UseMethod(vcov) : no applicable method for 'vcov' applied to an object of class list The hessian from nlm is also producing NaNs, although the estimates seems to be right, so I can't get the VCOV that way either. Any potential solutions on this would be welcome. Thanks, Brian Essentia Institute of Rural Health Duluth, MN 55805 [[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] Suggestions for synchronizing multisite R use?
In the past, I have been using various rsync scripts for synchronizing, but just realized that I could upload the contents of my .Rprofile to google docs (to maintain a single copy with revision history), and then having each of my local .Rprofiles source the url. (Haven't tried it). Does anybody have any experience with this issue? I'm sure one could write some external code for .First and .Last to load/save their Rhistory/Rdata to the cloud, for example using the google api. Thoughts? Best, Blair __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Multi-panel Pie Charts.
Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 R Code: as it is from the book, library(lattice) library(grid) library(gridBase) panel.piechart - function(x, y, labels = as.character(y), edges = 200, radius = 0.8, clockwise = FALSE, init.angle = if(clockwise) 90 else 0, density = NULL, angle = 45, col = superpose.polygon$col, border = superpose.polygon$border, lty = superpose.polygon$lty, ...) { stopifnot(require(gridBase)) superpose.polygon - trellis.par.get(superpose.polygon) opar - par(no.readonly = TRUE) on.exit(par(opar)) if (panel.number() 1) par(new = TRUE) par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0)) pie(as.numeric(x), labels = labels, edges = edges, radius = radius, clockwise = clockwise, init.angle = init.angle, angle = angle, density = density, col = col, border = border, lty = lty) } piechart - function(x, data = NULL, panel = panel.piechart, ...) { ocall - sys.call(sys.parent()) ocall[[1]] - quote(piechart) ccall - match.call() ccall$data - data ccall$panel - panel ccall$default.scales - list(draw = FALSE) ccall[[1]] - quote(lattice::barchart) ans - eval.parent(ccall) ans$call - ocall ans } ## Figure 14.5 par(new = TRUE) piechart(foo) Thanks in advance, Gurmeet [[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] removing text form the graph(outer region)
You have to look at the documentation for the function you used to create the calibration plot. Find out what options it has for controlling what text appears, and use them. If there are no options, then maybe there is a graphics parameter [ see help('par') ] that will prevent them. Otherwise, you will probably have to reconstruct the plot yourself using basic plotting functions. Or, assuming you used a plotting function from some package, contact the package author or maintainer. -Don At 11:27 AM -0400 3/24/10, paaventhan jeyaganth wrote: Dear R communities, when i do a calibration plot i have text inside the graph bottom left and right (outer region) saying x resampling added B=200, i want to get rid of this texts please advise me how can i do it Thanks very much Paaveen _ Take your contacts everywhere [[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. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] shading an area of a graphic
Colleagues OS 10.5 R: 2.10.1 I have a simple x-y plot for which I would like to shade the lower (or upper) part of the interior region (i.e., the area bounded by the axes). If the delineation between top and bottom were linear, it would be use to use the polygon function. However, the delineation is a curve (which I can describe by an equation). In theory, I could divide the x-axis into a large number of regions, then draw a series of polygons side by side, the top / bottom borders of which are lines. Is there a more elegant solution? Dennis Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help needed with boxplot
Jim, I really appreciate your hlep. You almost solve my problem, I had tried both of your suggestions, but both of them only solve part of problem, and how can I combine their functions? your second sample can't give the axis (like 0-20, 20-50 etc), btw, we don't have plotrix function on our machine. What I want looks like the second plot from http://www.statmethods.net/graphs/boxplot.html, I want to compare the MB between the two dataset, so the first/third/fifth box should from file1(MB) with same color (black), second/fourth/sixth box from file2(MB) with same color(red). Of course, the first (black) box and second(red) box share the same data range (eg 0-20), and so on for other group of box. Thank you a bunch for help. -- View this message in context: http://n4.nabble.com/help-needed-with-boxplot-tp1677678p1687165.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] Multi-panel Pie Charts.
Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Would paneled bar charts not suffice? I don't mean to be harsh, but the only situation I can think of where I would consider a pie chart would be if I wanted to take advantage of the fact that people are worse at judging differences in area than they are at judging differences in length in order to hide some trend in my data. Anyway, the following code uses ggplot2 to produce a paneled bar plot from your data: require( ggplot2 ) productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA, ProdB, ProdC, ProdD), class = factor), month = structure(c(3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label = c(Apr, Feb, Jan, Mar), class = factor), value = c(25, 30, 25, 10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names = c(variable, month, value), class = data.frame, row.names = c(NA, -16L)) productPlot - qplot( variable, value, data = productData, geom = 'bar', xlab = 'Product', ylab = 'Percentage' ) + facet_wrap( ~ month ) + theme_bw() print( productPlot ) I know it's not what you want, but I personally need a strong argument for generating pie charts before I would perpetuate their use. Gurmeet wrote: 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 {SNIP} Thanks in advance, Gurmeet Providing data as a printed table, like you did, is not the most effective way to transmit example data on this list. There are two major disadvantages: * Tabulated data often gets mangled in email * Tabulated data can not be copied and pasted directly into R to regenerate the example data.frame- it takes me ~4 minutes of mucking around with Excel to regenerate a .csv file that R can ingest. This added time will limit the number of people who will attempt to investigate your problem. The best way to transmit the contents of a data frame is to paste the output of the dput() function. This function dumps the data frame to an R command that can be simply copied and pasted into a R session to regenerate the data.frame. The results of dput is the structure() command I used in my example above. Hope this helps in some way! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.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] Multi-panel Pie Charts.
Thanks for your reply Sharpie. I completely understand that it may not be the best to go with muti-panel pie charts, but my group would like to have this utility along with barplot/dotplot (may be, using it for proportions data). Thanks, ~Gurmeet On Wed, Mar 24, 2010 at 3:38 PM, Sharpie ch...@sharpsteen.net wrote: Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Would paneled bar charts not suffice? I don't mean to be harsh, but the only situation I can think of where I would consider a pie chart would be if I wanted to take advantage of the fact that people are worse at judging differences in area than they are at judging differences in length in order to hide some trend in my data. Anyway, the following code uses ggplot2 to produce a paneled bar plot from your data: require( ggplot2 ) productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA, ProdB, ProdC, ProdD), class = factor), month = structure(c(3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label = c(Apr, Feb, Jan, Mar), class = factor), value = c(25, 30, 25, 10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names = c(variable, month, value), class = data.frame, row.names = c(NA, -16L)) productPlot - qplot( variable, value, data = productData, geom = 'bar', xlab = 'Product', ylab = 'Percentage' ) + facet_wrap( ~ month ) + theme_bw() print( productPlot ) I know it's not what you want, but I personally need a strong argument for generating pie charts before I would perpetuate their use. Gurmeet wrote: 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 {SNIP} Thanks in advance, Gurmeet Providing data as a printed table, like you did, is not the most effective way to transmit example data on this list. There are two major disadvantages: * Tabulated data often gets mangled in email * Tabulated data can not be copied and pasted directly into R to regenerate the example data.frame- it takes me ~4 minutes of mucking around with Excel to regenerate a .csv file that R can ingest. This added time will limit the number of people who will attempt to investigate your problem. The best way to transmit the contents of a data frame is to paste the output of the dput() function. This function dumps the data frame to an R command that can be simply copied and pasted into a R session to regenerate the data.frame. The results of dput is the structure() command I used in my example above. Hope this helps in some way! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Multi-panel Pie Charts.
Gurmeet and I are looking for such utility. It could be helpful! On Wed, Mar 24, 2010 at 3:46 PM, Gary Miller mail2garymil...@gmail.comwrote: Thanks for your reply Sharpie. I completely understand that it may not be the best to go with muti-panel pie charts, but my group would like to have this utility along with barplot/dotplot (may be, using it for proportions data). Thanks, ~Gurmeet On Wed, Mar 24, 2010 at 3:38 PM, Sharpie ch...@sharpsteen.net wrote: Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Would paneled bar charts not suffice? I don't mean to be harsh, but the only situation I can think of where I would consider a pie chart would be if I wanted to take advantage of the fact that people are worse at judging differences in area than they are at judging differences in length in order to hide some trend in my data. Anyway, the following code uses ggplot2 to produce a paneled bar plot from your data: require( ggplot2 ) productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA, ProdB, ProdC, ProdD), class = factor), month = structure(c(3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label = c(Apr, Feb, Jan, Mar), class = factor), value = c(25, 30, 25, 10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names = c(variable, month, value), class = data.frame, row.names = c(NA, -16L)) productPlot - qplot( variable, value, data = productData, geom = 'bar', xlab = 'Product', ylab = 'Percentage' ) + facet_wrap( ~ month ) + theme_bw() print( productPlot ) I know it's not what you want, but I personally need a strong argument for generating pie charts before I would perpetuate their use. Gurmeet wrote: 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 {SNIP} Thanks in advance, Gurmeet Providing data as a printed table, like you did, is not the most effective way to transmit example data on this list. There are two major disadvantages: * Tabulated data often gets mangled in email * Tabulated data can not be copied and pasted directly into R to regenerate the example data.frame- it takes me ~4 minutes of mucking around with Excel to regenerate a .csv file that R can ingest. This added time will limit the number of people who will attempt to investigate your problem. The best way to transmit the contents of a data frame is to paste the output of the dput() function. This function dumps the data frame to an R command that can be simply copied and pasted into a R session to regenerate the data.frame. The results of dput is the structure() command I used in my example above. Hope this helps in some way! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Multi-panel Pie Charts.
Gary Miller wrote: Thanks for your reply Sharpie. I completely understand that it may not be the best to go with muti-panel pie charts, but my group would like to have this utility along with barplot/dotplot (may be, using it for proportions data). Thanks, Well, if the management trolls *DEMAND* pie, then these sites provide a good start with ggplot2: http://learnr.wordpress.com/2009/08/20/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-13-2/ http://had.co.nz/ggplot2/coord_polar.html Using the data I posted before, you could apply those approach with: productPie - qplot( factor(1), value/100, data = productData, geom = 'bar', fill = variable, xlab = '', ylab = '' ) + facet_wrap( ~ month, scales = 'free_y' ) + coord_polar( theta = 'y' ) + scale_y_continuous( formatter = 'percent' ) + theme_bw() print( productPie ) The beauty of ggplot2 is that that is basically the same chart I posted last time, the bars have just been bent into a pie through the use of coord_polar(). It probably needs some fine-tuning, but I'll leave that up to you. Good luck! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689591.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] shading an area of a graphic
Dennis, If I understand correctly, you should be able to do something like this (example with exponential decay): these.x - (1:10)/10 plot(these.x,exp(-these.x),type=l) # create a basic plot for starting point this.usr - par(usr)# get the plotting region limits # they are xleft, xright, ybottom, ytop # for shading lower region these.x2 - c(this.usr[1],these.x,this.usr[2]) # an updated x-axis vector polygon(x=c(this.usr[1],these.x2,this.usr[2]), y=c(this.usr[3],exp(-these.x2),this.usr[3]), col=gray,border=NA) # for shading upper region these.x2 - c(this.usr[1],these.x,this.usr[2]) polygon(x=c(these.x2,this.usr[2]), y=c(exp(-these.x2),this.usr[4]), col=gray,border=NA) # to make the plot frame more clear you may want to add box() Basically polygon() is able to draw a shape that has your desired curve for one side, you just have to give it enough points to get a smooth curve (all it took in this case was 10). In reality it is drawing little line segments between all the points, similar in a way to your proposal, but much faster and simpler. Exactly what you assign to x and y in polygon() will depend on if you curve increases or decreases with x, or is some kind of paraboloid type thing. but the same basic idea applies. You don't need to use a bunch of polygons, one will do. Hope that helps, Andy On Wed, Mar 24, 2010 at 3:23 PM, Dennis Fisher fis...@plessthan.com wrote: Colleagues OS 10.5 R: 2.10.1 I have a simple x-y plot for which I would like to shade the lower (or upper) part of the interior region (i.e., the area bounded by the axes). If the delineation between top and bottom were linear, it would be use to use the polygon function. However, the delineation is a curve (which I can describe by an equation). In theory, I could divide the x-axis into a large number of regions, then draw a series of polygons side by side, the top / bottom borders of which are lines. Is there a more elegant solution? Dennis Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a data set from 'long' format to 'interval' format
Try this: foo - function(x) { data.frame(Id = unique(x$Id), rbind(range(x$time)), dose = unique(x$dose)) } t(sapply(split(as.data.frame(orig.data), with(rle(orig.data[,'dose']), rep(seq_along(lengths), lengths))), foo)) On Wed, Mar 24, 2010 at 12:27 PM, Marie-Pierre Sylvestre mp.sylves...@gmail.com wrote: Hi, I have a data set in which the variable 'dose' is time-varying. Currently, the data set is in a long format, with 1 row for each time unit of follow-up for each individual Id. It looks like this: orig.data - cbind(Id = c(rep(1,4), rep(2,5)), time = c(1:4, 1:5), dose = c(1,1,1,0,1,0,1,1,0)) orig.data Id time dose [1,] 1 1 1 [2,] 1 2 1 [3,] 1 3 1 [4,] 1 4 0 [5,] 2 1 1 [6,] 2 2 0 [7,] 2 3 1 [8,] 2 4 1 [9,] 2 5 0 What I would like to do is to convert the data set into an interval format. By that I mean a data set in which each row has a 'Start' and a 'Stop' value that indicates the time units in which the 'dose' is constant. For example, my orig.data example would now be: int.data - cbind(Id = c(rep(1,2), rep(2,4)), Start = c(1,4,1,2,3,5), Stop = c(3,4,1,2,4,5), dose = c(1,0,1,0,1,0)) int.data Id Start Stop dose [1,] 1 1 3 1 [2,] 1 4 4 0 [3,] 2 1 1 1 [4,] 2 2 2 0 [5,] 2 3 4 1 [6,] 2 5 5 0 Basically, this implies collapsing rows that have the same Id and dose and creating Start and Stop to index the time. While I can write a clumsy routine with multiple loops to do it, it will be inefficient and will not work for large data set. I wonder if people know of a function that would reshape my data set from 'long' to 'interval'? Best, MP [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] translating SQL statements into data.table operations
I've recently stumbled across data.table, Matthew Dowle's package. I'm impressed by the speed of the package in handling operations with large data.frames, but am a bit overwhelmed with the syntax. I'd like to express the SQL statement below using data.table operations rather than sqldf (which was incredibly slow for a small subset of my financial data) or import/export with a DBMS, but I haven't been able to figure out how to do it. I would be grateful for your suggestions. nick My aim is to join events (trades) from two datasets (edt and cdt) where, for the same stock, the events in one dataset occur between 15 and 75 days before the other, and within the same time window. I can only see how to express the WHERE e.SYMBOL = c.SYMBOL part in data.table syntax. I'm also at a loss at whether I can express the remainder using data.table's %between% operator or not. ctqm - sqldf(SELECT e.*, c.DATE 'DATEctrl', c.TIME 'TIMEctrl', c.PRICE 'PRICEctrl', c.SIZE 'SIZEctrl' FROM edt e, ctq c WHERE e.SYMBOL = c.SYMBOL AND julianday(e.DATE) - julianday(c.DATE) BETWEEN 15 AND 75 AND strftime('%H:%M:%S',c.TIME) BETWEEN strftime('%H:%M:%S',e.BEGTIME) AND strftime('%H:%M:%S',e.ENDTIME)) [[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] Using R to analyze limesurvey data
Hello everyone, I have a survey on LimeSurvey ( https://www.limeservice.com/ ) going and I am preparing data analysis. Data exports to R dumps are completed and works. I have slowly started learning R but would really appreciate some assistance in helping me fly faster. I do understand that this attitude may not be entirely compliant with the philosophy of R. Still, please appreciate the survey is on management and the author has never been rewarded for his patience. If anyone have any R scripts from a Lime Survey or analysis of such a thing, I would be very grateful if you would share it on this list or publish a link to such scripts. Best regards ottar [[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] write: write array to file without NAs
Dears, does anyone know, how I can get R to save the values of an array in a csv like file using write(), but without printing NA to the file? I use ';' to seperate the elements, so : a=c(1,NA,2,3,3) write(a) should produce 1;;2;3;3 in the file. Thanks in advance! __ Do You enden Schutz gegen Massenmails. http://mail.yahoo.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] LDL matrix factorization
Hello, I would like to do Block LDL' factorization for Hermitian indefinite matrices, where D is a block diagonal matrix and L a psychologically lower triangular matrix (i.e a product of unit lower triangular and permutation matrices) in L such that A = L*D*L'. The block diagonal matrix D has 1-by-1 and 2-by-2 blocks on its diagonal. Does anybody know how to do this in R? Thank you Felipe Parra [[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] GGPLOT2: Reverse order of legend to match order of x-axis
How do I reverse the order of the legend in a bar plot to match order of the x-axis? In other words, I want the stacked colors of the legend to match the stacked colors of the bar plot. I tried this, but it didn't work. colors - c(5 = red,4 = blue,3 = darkgreen) p - qplot(factor(cyl), data=mtcars, geom=bar, fill=factor(gear)) p + scale_colour_manual(name = gear,values = colors,breaks = c(5,4,3),labels = c(5 speed,4 speed,3 speed)) http://n4.nabble.com/file/n1689526/plot.jpeg -- View this message in context: http://n4.nabble.com/GGPLOT2-Reverse-order-of-legend-to-match-order-of-x-axis-tp1689526p1689526.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] write: write array to file without NAs
jannis-2 wrote: Dears, does anyone know, how I can get R to save the values of an array in a csv like file using write(), but without printing NA to the file? I use ';' to seperate the elements, so : a=c(1,NA,2,3,3) write(a) should produce 1;;2;3;3 in the file. Thanks in advance! When using Nabble to post questions, it would be best to use the New Topic button at the top left of the forum view rather than posting in a random thread. Your question is completely unrelated to creating multi-paneled pie charts and this: * Confuses those who are following the pie chart thread. * Makes your question invisible to people browsing the Nabble forum unless they happen to look at the pie chart question. In which case they may get confused. Anyway, the answer to your question can be found in the help pages for write.table(): ?write.table Specifically, you may want to play with the arguments sep and na. Good luck! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689863.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help needed with boxplot
On 03/25/2010 06:03 AM, kathy_BJ wrote: Jim, I really appreciate your hlep. You almost solve my problem, I had tried both of your suggestions, but both of them only solve part of problem, and how can I combine their functions? your second sample can't give the axis (like 0-20, 20-50 etc), btw, we don't have plotrix function on our machine. That's okay, I have rewritten the x axis tick labelling so that you don't have to use staxlab. That's why you didn't get the axis labels. What I want looks like the second plot from http://www.statmethods.net/graphs/boxplot.html, Great! We finally have an example of what you want. I want to compare the MB between the two dataset, so the first/third/fifth box should from file1(MB) with same color (black), second/fourth/sixth box from file2(MB) with same color(red). Of course, the first (black) box and second(red) box share the same data range (eg 0-20), and so on for other group of box. The attached code does this for the values in the made-up data that have col5 equal to RED (in your original post you indicated that you wanted to separate these colors). You will probably want to change this somewhat, but it is what I understand by the example and your explanation above. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help needed with boxplot
Oops! I sent before attaching the code. On 03/25/2010 06:03 AM, kathy_BJ wrote: Jim, I really appreciate your hlep. You almost solve my problem, I had tried both of your suggestions, but both of them only solve part of problem, and how can I combine their functions? your second sample can't give the axis (like 0-20, 20-50 etc), btw, we don't have plotrix function on our machine. That's okay, I have rewritten the x axis tick labelling so that you don't have to use staxlab. That's why you didn't get the axis labels. What I want looks like the second plot from http://www.statmethods.net/graphs/boxplot.html, Great! We finally have an example of what you want. I want to compare the MB between the two dataset, so the first/third/fifth box should from file1(MB) with same color (black), second/fourth/sixth box from file2(MB) with same color(red). Of course, the first (black) box and second(red) box share the same data range (eg 0-20), and so on for other group of box. The attached code does this for the values in the made-up data that have col5 equal to RED (in your original post you indicated that you wanted to separate these colors). You will probably want to change this somewhat, but it is what I understand by the example and your explanation above. Jim file1-data.frame( col1=sample(c(50:52,220:229),1000,TRUE)*100, col2=sample(0:270,1000,TRUE), col3=runif(1000,50,80),col4=runif(1000,50,80), col5=sample(c(RED,GREEN,BLUE),1000,TRUE)) file2-data.frame( col1=sample(c(50:52,220:229),1000,TRUE)*100, col2=sample(0:270,1000,TRUE), col3=runif(1000,50,80),col4=runif(1000,50,80), col5=sample(c(RED,GREEN,BLUE),1000,TRUE)) file1$col_group-cut(file1$col2,breaks=c(0,20,50,70,271), right=FALSE) file2$col_group-cut(file2$col2,breaks=c(0,20,50,70,271), right=FALSE) # get logical vectors that will pick out the different colors reds1-file1$col5==RED reds2-file2$col5==RED greens1-file1$col5==GREEN greens2-file2$col5==GREEN blues1-file1$col5==BLUE blues2-file2$col5==BLUE # calculate the differences between col4 and col3 file1$col43-file1$col4-file1$col3 file2$col43-file2$col4-file2$col3 col_group11-as.numeric(file1$col_group)==1 col_group12-as.numeric(file1$col_group)==2 col_group13-as.numeric(file1$col_group)==3 col_group14-as.numeric(file1$col_group)==4 col_group21-as.numeric(file2$col_group)==1 col_group22-as.numeric(file2$col_group)==2 col_group23-as.numeric(file2$col_group)==3 col_group24-as.numeric(file2$col_group)==4 # need a wide display for this x11(width=9) # display the boxplots without boxplot(file1$col43[reds1col_group11], file2$col43[reds2col_group21], file1$col43[reds1col_group12], file2$col43[reds2col_group22], file1$col43[reds1col_group13], file2$col43[reds2col_group23], file1$col43[reds1col_group14], file2$col43[reds2col_group24], main=Comparison of RED col4 and col3 differences across col2 groups, ylab=MB,names=rep(,8),notch=TRUE,col=c(black,red)) # add the x axis labels, staggered to avoid overlap mtext(text=paste(c(file1,file2),rep(levels(file1$col_group),each=2)), side=1,line=c(0.5,1.5),at=1:8) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nls object -- how to edit?
Hi, I recently used columns of a matrix as inputs to nls(), which works just fine, but then I get, for example, (assuming nls(stuff)-nl30 was the original command) nl30$call nls(dr[,2]~apowr^(dr[,1])/(b*sqrt(dr[,1]))) Now, I can build a new matrix with same dimensions as dr and use that to run predict, as in predict(nl30,list(dr=newdr)) , but I was wondering if there's a way to edit the contents of nl30 itself? I changed the contents of nl30$call just fine (using expression() on an edited version of the formula itself), but that does not change whatever items in nl30 are used by predict(). Again, I recognize that I'm much better off running nls() with more sensible independent and dependent variables to begin with. I just would like some help to learn how to read the guts of the class variable that nls() produces. (yes, I know how to do nl30$m and so on; those lists don't show me any of the variables or formulas I can get using formula(nl30) and other commands with methods for this type of class variable). Thanks Carl __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using dev.copy
Hi Dan Davison wrote: I'm working over an ssh connection without X11 graphics. I'm making a plot, the first stage of drawing which takes a long time. I want to experiment with adding details. Here is what I was hoping to do, which results in error. ## Draw the master plot on png dev 2 png(file=master.png) plot(1:10) ## Save a copy on png dev 3 png(file=copy1.png) dev.set(2) dev.copy(which=3) ## Add details to copy, write to disk and view abline(v=5) Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet Can someone tell me how to do this correctly? The problem is that the display list is turned off by default for png() devices, so there is no record of what has been drawn, so when you do dev.copy(), there is nothing to copy. If you turn the display list on, it should work much better ... png(file=master.png) ## TURN DISPLAY LIST ON dev.control(enable) plot(1:10) ## Save a copy on png dev 3 png(file=copy1.png) dev.set(2) dev.copy(which=3) ## Add details to copy, write to disk and view abline(v=5) ... hope that helps. Paul Thanks a lot, 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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~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.
Re: [R] GGPLOT2: Reverse order of legend to match order of x-axis
See here: http://learnr.wordpress.com/2010/03/23/ggplot2-changing-the-default-order-of-legend-labels-and-stacking-of-data/ Hadley On Wed, Mar 24, 2010 at 2:40 PM, Ryan Garner ryan.steven.gar...@gmail.com wrote: How do I reverse the order of the legend in a bar plot to match order of the x-axis? In other words, I want the stacked colors of the legend to match the stacked colors of the bar plot. I tried this, but it didn't work. colors - c(5 = red,4 = blue,3 = darkgreen) p - qplot(factor(cyl), data=mtcars, geom=bar, fill=factor(gear)) p + scale_colour_manual(name = gear,values = colors,breaks = c(5,4,3),labels = c(5 speed,4 speed,3 speed)) http://n4.nabble.com/file/n1689526/plot.jpeg -- View this message in context: http://n4.nabble.com/GGPLOT2-Reverse-order-of-legend-to-match-order-of-x-axis-tp1689526p1689526.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. -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rpad ?
I found the repair by googling. You have to get the source and buld the package. The change needed is in HtmlTree.R You have to add return(str) at the end of the function definition. The reason is that for loops now return NULL, they returned (I think) the value of the last interation if the looped statement before. HTMLargs - function(x) { # returns a string with the arguments as a=arg1, b=arg2, and so on names - names(x) if (length(x) 0) str - else str - for (i in seq(along = x)) str - paste(str, names[i], =, jsQuote(x[[i]]), , sep = ) # next code line added by EN, necessary under under R 2.10 # due to changes how for works return(str) } I found the solution here http://code.google.com/p/rpad/issues/detail?id=5#c0 On 3/24/2010 4:18 PM, Bos, Roger wrote: Erich, I use Rpad actively so I am disappointed to hear it is no longer being updated. Would you be willing to share your modifications with the list, or at least with me? Thanks, Roger -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erich Neuwirth Sent: Tuesday, March 23, 2010 4:47 PM To: r-help@r-project.org Subject: Re: [R] rpad ? We are using RPad for a teaching application here. But we had to find many things the hard way, and additionally, it did not survive the latest R release change. There is a minimal repair, but the maintainer does not answer any email any more. We did the repair and are giving a modified version to our students, but we do not have enough resource to take over maintenance. On 3/23/2010 8:00 PM, sjaffe wrote: Is anyone using rpad? Is there any documentation or examples beyond that in the 'man' directory of the source? -- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** This 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 an error in transmission. If you have received this message in error, please immediately notify the 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. __ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email __ -- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 grob
Hi baptiste auguie wrote: Thanks Felix and Paul. I had overlooked grid.grabExpr, assuming that one had to draw on a device before grabbing the output. Now I'm not sure if there's any difference between either solution, I'll go for the shortest. As Felix pointed out, one possible problem with the grid.gradExpr() approach is that you get a copy of what was drawn on the current device, which may be dependent on things like how big the current device is, what fonts it uses, etc. The drawDetails() approach means that 'lattice' will calculate what to draw every time you want to draw, so it should adapt to different device sizes and different device properties more gracefully. On the other hand, the drawDetails() approach only records a VERY high-level description of what you are drawing (a 'lattice' object), so you cannot fiddle about with the low-level details of what you draw. For example, following ... latticeGrob - function(p, ...){ grob(p=p, ..., cl=lattice) } drawDetails.lattice - function(x, recording=FALSE){ lattice:::plot.trellis(x$p, newpage=FALSE) } p1 - xyplot(1:10 ~ 1:10) g1 - latticeGrob(p1) grid.draw(g1) ... grid.ls() gives you ... grid.ls() GRID.lattice.53 ... whereas the grid.gradExpr() approach records all of the bits and pieces of the drawing, e.g., following ... p1 - xyplot(1:10 ~ 1:10) g1 - grid.grabExpr(print(p1)) grid.draw(g1) ... grid.ls() gives you ... grid.ls() GRID.gTree.94 GRID.rect.85 plot1.xlab plot1.ylab GRID.segments.86 GRID.segments.87 GRID.text.88 GRID.segments.89 GRID.text.90 GRID.segments.91 GRID.points.92 GRID.rect.93 So it's a bit of a trade-off. Paul Best, baptiste On 22 March 2010 00:18, Felix Andrews fe...@nfrac.org wrote: What's wrong with using grid.grabExpr? p1 - xyplot(1:10 ~ 1:10) g1 - grid.grabExpr(print(p1)) I can imagine there would be potential problems to do with the plot-time aspect and layout calculations... On 19 March 2010 21:51, baptiste auguie baptiste.aug...@googlemail.com wrote: Dear list, I'm trying to arrange various grid objects on a page using a frameGrob. It works fine with basic grobs (textGrob, gTree, etc.), and also with ggplot2 objects using the ggplotGrob() function. I am however stuck with lattice. As far as I understand, lattice produces a list of class trellis, which is eventually displayed using the plot.trellis method. I am not sure if/how one can convert this list into a high-level grob. I tried the following, latticeGrob - function(p, ...){ grob(p=p, ..., cl=lattice) } drawDetails.lattice - function(x, recording=FALSE){ lattice:::plot.trellis(x$p) } p1 - xyplot(1:10 ~ 1:10) g1 - latticeGrob(p1) grid.draw(g1) # works fine but, fg - frameGrob(layout = grid.layout(1,1)) fg - placeGrob(fg, g1, row = 1, col = 1) grid.draw(fg) Error in UseMethod(depth) : no applicable method for 'depth' applied to an object of class NULL Ideas are most welcome, Best regards, baptiste sessionInfo() R version 2.10.1 RC (2009-12-06 r50690) i386-apple-darwin9.8.0 locale: [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] grid tools stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.8.7 digest_0.4.1reshape_0.8.3 plyr_0.1.9 proto_0.3-8 gridExtra_0.5 lattice_0.17-26 gtools_2.6.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Felix Andrews / 安福立 Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andr...@anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~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] Trying to create R dataframe with JRI
Hi all, I am writing here because the JRI mailing list seems abandoned... maybe some of you guys know an answer or has a pointer into the right direction. I am quite confused by the jars that exist between rServe, JRI and rJava. What I want to do is simply using a local R instance from Java and I thought (and still think) JRI is the way forward. I did the following steps: 1) Installed R-2.10.0-win32.exe 2) Got rJava_0.8-3.zip (from http://www.rforge.net/rJava ) 3) Start Eclipse a) created an example project 'RTest' b) create a folder /lib within the project directory and copied jri.dll and JRI.jar from rJava/jri (the unzipped JRI package) into /lib d) copied R.dll from the /bin folder of the R installation into /lib (now /lib contains jri.dll, JRI.jar and R.dll) and wrote an simple test application that simply calls a command and does not do much parameter assignment (except strings and simple integers) -- all worked fine. Now I want to feed data as a dataframe to R. I thought I can make RVector objects, create RList objects from that and create REXP dataframes from those lists. I found an example here: http://code.google.com/p/jamsim/source/browse/trunk/JAMSIM/src/org/jamsim/r/RInterfaceHL.java?spec=svn52r=52 ... RList rlist = new RList(vectors.size(), true); ... // turn the rlist into a dataframe REXP dataframe = REXP.createDataFrame(rlist); both of these constructors do not exist in JRI (apparently). They must use a different set of libraries (?) and I am now puzzeled. How can I create a dataframe from Strings and integers? I managed to create RVectors: ArrayListRVector vectors = new ArrayListRVector(); for (Feature feature : freqFeatures){ RVector rVector = new RVector(); rVector.addAll(feature.getParameters().values()); vectors.add(rVector); } but I miss the next steps. Anybody can give some example code? (JRI source code documentation is mostly abandoned.) What are you guys using? Are there better alternatives for what I wanna do? Thanks a lot, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.