Re: [R] R tcl/tk
Try: R.home() This is the directory in which R is installed, for me R_HOME is /usr/lib/R. I don't have a /usr/lib/R/Tcl/doc though, perhaps you do ... I do have a /usr/lib/R/doc, but there's no Tcl inside there either. For Tcl documentation I can suggest wiki.tcl.tk, it's a great site. Then, you need to learn the interface between R and Tcl for which there's a nice (easy to find with Google) pdf document. If you really cannot find it, I'll look it up for you. JeeBee. On Mon, 23 Oct 2006 12:11:40 -0200, Alberto Monteiro wrote: This must be dumbest question ever asked, but... When I ask help.search(tcltk), I get a reference to tcltk-package. When I ask help(tcltk-package), I get rtfm(s) in 'R_HOME/Tcl/doc'. But then when I ask help.search(R_HOME), I get nothing. Is something missing here in those help pages? Alberto Monteiro __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] variables with dynamic names?
You can use list.files to obtain the file names, see ?list.files Read the comma seperated values files with read.cvs, see ?read.csv JeeBee. On Tue, 24 Oct 2006 13:33:42 +0200, Antje wrote: Hello, I have the following problem. I have a set of CSV files and they are named for a special position in a matrix (e.g. A01.csv, F06.csv, H11.csv) Now, I would like to read in the data of all these files and eveluate something for each set (and write it at the position in a result matrix). How can I realize this with R? Ciao, Antje __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] tcltk: multiple listboxes, selection
Dear list, I have multiple (BWidget) listboxes in the same toplevel window. The problem is, if I select (by left clicking) on one of those listbox elements, the current selection in the *other* listboxes is cleared! Anybody knows how I can prevent this? Here's my code (sorry not complete): (E.g. If I select an X value, I'd lose the Y value I selected before) gui.create.tab.general - function(tt) { # Network topology frame.1 - tkframe(tt) combo_topology - tkwidget(frame.1, ComboBox, values = infras, editable = FALSE) tcl(combo_topology, setvalue, first) tkgrid(tklabel(frame.1, text=Network topology), combo_topology) tkgrid(frame.1, sticky = w) # X values frame.x - tkwidget(tt, labelframe, text = X value) tl.x - tklistbox(frame.x, height = length(xvals) / 2, width = 50, selectmode = browse, background = white) for(i in seq(from=1, to=length(xvals), by=2)) { tkinsert(tl.x, end, xvals[[i]]) } tkselection.set(tl.x, 0) tkgrid(tl.x, sticky=news) # Y values frame.y - tkwidget(tt, labelframe, text = Y value(s)) tl.y - tklistbox(frame.y, height = 20, #length(yvals) / yvals.field.count, yscrollcommand=function(...) tkset(scr.y,...), width = 50, selectmode = extended, background = white) scr.y - tkscrollbar(frame.y, repeatinterval = 5, command = function(...) tkyview(tl.y, ...)) for(i in seq(from=1, to=length(yvals), by=yvals.field.count)) { tkinsert(tl.y, end, yvals[[i]]) } tkselection.set(tl.y, 0) tkgrid(tl.y, scr.y, sticky=news) # Packing tkgrid(frame.x, frame.y, sticky=news) #side = left, fill = both, expand = TRUE) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] set linetype with plotCI
Sorry, the plot_linetypes[1] is a debugging leftover. It's plot_linetypes[graph_idx] in my actual code ... And plot_linetypes is just the sequence 1,2,3,4... etc plotCI( x = xvals.f[sorted], y = yvals.f[sorted], xlim = c(xmin, xmax), ylim = c(ymin, ymax), pch = plot_symbols[graph_idx], type = b, lty = plot_linetypes[1], col = plot_colors[graph_idx], barcol = plot_colors[graph_idx], uiw = NA, xlab = , ylab = , add = (plot_cnt 0) ) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] set linetype with plotCI
Thanks, I tried using plotCI in the plotrix library. This, however, gives me the below error. CODE:: cat(x = ); print(xvals.f[sorted]) cat(y = ); print(yvals.f[sorted]) cat(pch = ); print(plot_symbols[graph_idx]) cat(lty = ); print(plot_linetypes[graph_idx]) cat(col = ); print(plot_colors[graph_idx]) print(paste(graph_idx =, graph_idx, and plot_cnt =, plot_cnt)) plotCI( x = xvals.f[sorted], y = yvals.f[sorted], xlim = c(xmin, xmax), ylim = c(ymin, ymax), pch = plot_symbols[graph_idx], type = b, lty = plot_linetypes[graph_idx], col = plot_colors[graph_idx], barcol = plot_colors[graph_idx], uiw = NA, xlab = , ylab = , add = (plot_cnt 0) ) print(plotCI succeeeded...) OUTPUT:: x = [1] 160 160 160 160 160 160 160 160 160 160 320 320 320 320 320 320 320 320 320 [20] 480 480 480 480 480 480 480 480 480 640 640 640 640 640 640 640 640 800 800 [39] 800 800 800 800 800 800 800 960 960 960 960 960 960 960 960 960 y = [1] 0.062263829 0.062263829 0.062263829 0.062263829 0.062263829 0.062263829 [7] 0.062263829 0.062263829 0.062263829 0.062263829 0.029483948 0.029483948 [13] 0.029483948 0.029483948 0.029483948 0.029483948 0.029483948 0.029483948 [19] 0.029483948 0.018035707 0.018035707 0.018035707 0.018035707 0.018035707 [25] 0.018035707 0.018035707 0.018035707 0.018035707 0.009895540 0.009895540 [31] 0.009895540 0.009895540 0.009895540 0.009895540 0.009895540 0.009895540 [37] 0.008534913 0.008534913 0.008534913 0.008534913 0.008534913 0.008534913 [43] 0.008534913 0.008534913 0.008534913 0.007301515 0.007301515 0.007301515 [49] 0.007301515 0.007301515 0.007301515 0.007301515 0.007301515 0.007301515 pch = [1] 0 lty = [1] 1 col = [1] #FF [1] graph_idx = 1 and plot_cnt = 0 Error in plot.default(c(160, 160, 160, 160, 160, 160, 160, 160, 160, 160, : formal argument type matched by multiple actual arguments __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] set linetype with plotCI
Great, why didn't I think of that. Thanks :) If you want to add lines as well as points, I think you will have to use lines(x,y,type=b,lty = plot_linetypes[graph_idx]) in addition to plotCI, __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What is the matrix version of min()
see ?apply min.row - apply(X, 1, min) min.col - apply(X, 2, min) JeeBee On Wed, 06 Sep 2006 01:37:22 -0700, Tong Wang wrote: Hi, Is there a function which operates on a matrix and return a vector of min/max of each rol/col ? say, X= 2, 1 3, 4 min.col(X)=c(2,1) thanks a lot. tong __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] winDialog UNIX equivalent?
Yes, there are many. To give one example, you could consider using tcltk. library(tcltk) tkmessageBox(title=This is terrible, message=What did you do?\nPromise not to do this again!, icon=error, type=ok) On Tue, 05 Sep 2006 23:10:41 +0200, Richard Müller wrote: Hi all, I'm using winDialog and winDialogString in scripts running on a XP-machine. Since we're using some Linux-machines (Suse 10.0 and 10.1 on x86) I'm interested in equivalents of the above functions usable under Linux-OS. Are there any? Thanks, Richard __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] histogram in the background?
How about this? http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=78 JeeBee On Wed, 06 Sep 2006 18:19:28 +0800, gallon li wrote: I intend to draw a plot of y against x. In the background of this graph I wish to creat a histogram of the horizontal variable x. Does any expert know how to produce such a plot? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot axises on both sides of a graph
Look at: ?axis (try the examples) Further, a nice example I found on this mailing lists archive, from somebody who says this has been asked many times already :) x - 1:10 y1 - 1:10 y2 - rev(seq(1,1000, length=10)) plot(x,y1,ann=FALSE) axis(2, at=c(2,4,6,8), labels=as.character(c(2,4,6,8))) points(x,y2/100,col=red) axis(4, at=c(2,4,6,8), labels=as.character(c(200, 400, 600, 800))) On Wed, 06 Sep 2006 18:10:33 +0800, gallon li wrote: Usually the y-axis is shown on the left-hand-side of a graph, is it possible to artifically creat one more y-axis on the right-hand-side in R? What is the main reference? Thank you in advance. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] histogram in the background?
gallon li wrote: I have found this one before. However, my intension is slightly differing from this plot: I wish to plot the histogram in the backgroun instead of in the margin. Thanks anyway! On Wed, 06 Sep 2006 12:29:51 +0200, JeeBee wrote: How about this? http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=78 JeeBee __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: plot axises on both sides of a graph
See these two examples. plot(1:2) axis(4) mtext(right y axis, side=4, line=-1.5) par(mar=c(5,4,4,5)+.1) plot(1:2) axis(4) mtext(right y axis, side=4, line=3) Good luck finding the right combination again ;) On Wed, 06 Sep 2006 20:08:43 +0800, gallon li wrote: -- Forwarded message -- From: gallon li [EMAIL PROTECTED] Date: Sep 6, 2006 7:48 PM Subject: Re: [R] plot axises on both sides of a graph To: Jim Lemon [EMAIL PROTECTED] Both of your suggestions are so helpful. By combining what you told me, now I am able to produce a second y-axis on the right-hand-side. Still one problem remains: how can I put a definition of this y-axis in the space left? Clearly there is enough room and I have to check some functions for defining the margin of a plot. Moreoever, it seems not straight forward to put some vertical text directly on the plot for this second ylab. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tk combobox question
I think you want something like this: require(tcltk) || stop(Package tcltk is not available.) version.BWidget - tclvalue(tclRequire(BWidget)) modify_command - function() { print(Hey, I'm modified...) } tt - tktoplevel() values = c(foo, bar, jeebee) combo - tkwidget(tt, ComboBox, -modifycmd, modify_command, values=values) tkgrid(combo) How can I get the index of the selected item in an Iwidgets combobox? Till now I am only able to get the contents of the selected combobox item. For BWidget: as.numeric(tclvalue(tcl(combo,getvalue)))+1 I haven't used Iwdigets yet... JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Interpretation of call to aov()
Hi all, I've been reading about aov() at http://www.psych.upenn.edu/~baron/rpsych/rpsych.html and http://davidmlane.com/hyperstat/intro_ANOVA.html and I try to use this test in experiments with my simulator. What I would like Anova to tell me is whether the differences I see when plotting the means of performance per method are significant. And also, whether this is dependent on the problem size (bigger is more complex). I would be very grateful if there's somebody more mathematically skilled on this list who could tell me whether I'm drawing correct conclusions. data performance method problem 1 146780. -f 960 2 4654. -f 160 345840. -f 320 454750. -f 320 591750. -f 480 6 7452. -f 160 7 8866. -f 160 8 8513. -f 160 9 139520. -f 960 10 85380. -f 480 snip str(data) `data.frame': 419 obs. of 3 variables: $ performance: num 146780 4654 45840 54750 91750 ... $ method : Factor w/ 7 levels -f,-f -q,-h0 -r0,..: 1 1 1 1 1 1 1 1 1 1 ... $ problem: int 960 160 320 320 480 160 160 160 960 480 ... summary(aov(performance ~ method * problem, data=data)) Df Sum SqMean Sq F valuePr(F) method 6 3.3185e+11 5.5308e+10 416.91 2.2e-16 *** problem 1 5.7141e+11 5.7141e+11 4307.26 2.2e-16 *** method:problem 6 9.8891e+10 1.6482e+10 124.24 2.2e-16 *** Residuals 405 5.3728e+10 1.3266e+08 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 I interpret this data as follows: -1- The performance depends on the chosen method. If I compute the overall performance means for each method, this will give me numbers that are significantly different. This means, the method with the greatest mean is significantly better than at least some other methods (and not worse than any other method). -2- The performance depends on the problem complexity. This is not so interesting. In my setting it is trivial that performance is worse for more complex problems. -3- There is interaction between method and complexity, in other words, when trying to order the methods from bad to good, one cannot simply do this without taking the problem complexity into account. (for simple problems method A might be the best, for complex problems, another method might be the better). I have not used Error() in my call to aov(). I've seen this one being used: Error(subj/(shape * color) But I do not have subjects. Or in fact, I believe I have only 1, which is my simulator. Am I correct about that? Or should I use something like Error(method * problem) ? Thanks in advance, JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interpretation of call to aov()
Or, perhaps I can use Error(subject/(method * problem)) where subject = paste(method, problem) Because I repeated each simulation several times for different problems of the same problem. This gives me the following output: summary(aov(performance ~ method * problem + Error(subj/(method * problem)), data=data)) Error: subj Df Sum SqMean Sq F valuePr(F) method6 3.3185e+11 5.5308e+10 46.179 3.020e-13 *** problem1 5.7141e+11 5.7141e+11 477.094 2.2e-16 *** method:problem6 9.8891e+10 1.6482e+10 13.761 3.123e-07 *** Residuals 28 3.3535e+10 1.1977e+09 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Error: Within Df Sum SqMean Sq F value Pr(F) Residuals 377 2.0193e+10 5.3562e+07 Warning message: Error() model is singular in: aov(performance ~ method * problem + Error(subj/(method * problem)), data = data) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question
Hi Jessica, I think you want to use names() See: ?names ?colnames (or rownames) If not, it's perhaps a good idea to send us a more complete example. JeeBee. On Fri, 04 Aug 2006 17:12:24 +0200, Jessica G. wrote: How to convert a rowname vector of numbers into a real column of the matrix, My problem is that I applied a rowsum function on a matrix. Then I get a matrix in which the names of the columns are the values of the group (numbers) Now I need to make calculation on the groups row. How to convert this vector of (rownames) into a real column in the matrix ? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting a row number from a matrix
so in the following example (single column, but my real data has multiple columns) how do I get the row number of the last row of x beyond which there are 10 or more 0's (which in this case is row#100). x - as.matrix(c(rep(seq(1:20),5),rep(0,20))) max( which(x 0) ) JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 convert two-dimensional function to matrix?
On Tue, 01 Aug 2006 16:23:46 +0200, Lothar Schmid wrote: I'd like to convert a two-dimensional function f(x,y) to a matrix m, so that m[x,y] = f [x,y]. How can I achieve this? Maybe this helps. I create an empty matrix first, then apply f to the indices. f - function(x, y) { 1000*x + y } ( m - matrix( data = NA, nrow = 5, ncol = 4 ) ) ( m - f(row(m), col(m)) ) JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] convert decimals to fractions - sorted
Ah I see, I did not read your story well enough. You want to sort after applying table() Well, the idea I suggested was to keep the real numbers in, because the fractions are sorted as characters strings (alphabetically), which is not what you want. So, now I suggest the following: # First apply table() tmp1 - as.data.frame(table(df)) # Note that table() turned your numeric data into factors, # this might not be a handy approach, anyways, it is possible I guess. # You have to convert back using as.numeric(as.character(tmp1$V2)) # or, more efficiently, as.numeric(levels(tmp1$V2))[tmp1$V2] # Add the column with the fractions tmp2 - cbind(tmp1, fracs=as.character(as.fractions(as.numeric(as.character(tmp1$V2) # Finally hide that sort colum if you want ( tmp2[-2] ) # Everybody happy? JeeBee __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] convert decimals to fractions - sorted
Hi Muhammad, How about this? at - read.table(textConnection(a)) at2 - cbind(at, jeebee=as.character(as.fractions(as.numeric(at[,2] sort.order - order(at2$V2) at2[sort.order,] at2[sort.order,c(1,3)] JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] tkbutton command - how to know which button was clicked?
In the below code fragment, print(arg) always prints the last element of rekeningen$rekening. Is this because of lazy evaluation? I.e. arg is evaluated at the time the button is pressed? And, if so, how can I avoid this? I tried function() {force(arg); print(arg)} but that didn't work either. Thanks, Jeebee. for(rek in seq(1,nrow(rekeningen))) { arg - rekeningen$rekening[rek] tkgrid(tkbutton(frame.1, text=paste(Saldo historie, arg), command=function() print(arg)), sticky=news) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] apply a function to several lists' components
Maybe this helps ( data1 = list(a=c(1,2), b=c(3,4), c=c(5,6,7)) ) ( data2 = list(a=c(10,11), b=c(30,40), c=c(70,80)) ) cc - NULL for(data in ls(pattern=^data[0-9]+$)) { cc - c(cc, with(get(data), c)) } mean(cc) JeeBee. On Fri, 30 Jun 2006 09:50:51 -0500, Taka Matzmoto wrote: Dear R-user I have 100 lists. Each list has several components. For example, data1 $a [1] 1 2 $b [1] 3 4 $c [1] 5 There are data1, data2,, data100. All lists have the same number and the same name of components. Is there any function I can use for applying to only a specific component across 100 lists? (e.g., taking mean of $c acorss 100 lists) or do I need to write my own function for that? Thank you. Taka, __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Basic NA handling problem
Try this: help.search(interpolate) Then find this: library(zoo) na.approx(x) [1] 1.0 4.0 5.0 8.0 6.0 4.0 4.5 5.0 5.0 1.0 2.0 7.0 8.0 9.0 10.5 [16] 12.0 13.5 15.0 6.0 8.0 Hth, JeeBee. On Thu, 22 Jun 2006 06:54:53 +0100, Sumanta Basak wrote: Hi All, I need your help in NA handling. I've following data series. x-c(1,4,5,8,NA,4,NA,5,5,1,2,7,8,9,NA,NA,NA,15,6,8) Now i want to interpolate where NA value persists. Like, between 9 and 5 there are three NA's. So, that should be interpolated like, 1st NA- (15-9)/4 2nd NA- 1st NA value + (15-9)/4 Can i get help on this using a 'for' loop. Actually i have huge daily time series with lots of NA values where i need to make these values. Please help. Thanks, Sumanta Basak. - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Some R-Tcl/Tk-BWidget newbie questions.
Dear list, Could somebody who is more experienced with the Tcl/Tk interface from R please help me clarify the issues I've put below with ### -- tags? Several things go wrong, and it's probably because of messy code, but I have a difficult time finding out what is the cause. Thanks very much, JeeBee. require(tcltk) || stop(Package tcltk is not available.) # Add path to BWidgets addTclPath(.) version.BWidget - tclvalue(tclRequire(BWidget)) start.gui - function() { # Toplevel tt - tktoplevel() tkwm.title(tt, MyTitle) # Notebook ### -- The following line makes R hang with 100% cpu forever #tkpack(tn - tkwidget(tt, NoteBook), fill=both, expand=TRUE) ### -- This works, but not sticky=news, ### -- the notebook does not resize together with the window tn - tkwidget(tt, NoteBook) tkgrid(tn, sticky=news) ### -- I guess there is a simpler way to do this ... tbn - tclvalue(tkinsert(tn, end, Algemeen, -text, Algemeen)) tkpack(tbw.algemeen - .Tk.newwin(tbn)) tkpack(tab.algemeen - tkframe(tbw.algemeen)) tbn - tclvalue(tkinsert(tn, end, Relaties, -text, Relaties)) tkpack(tbw.relaties - .Tk.newwin(tbn)) tkpack(tab.relaties - tkframe(tbw.relaties)) tbn - tclvalue(tkinsert(tn, end, Posten, -text, Posten)) tkpack(tbw.posten - .Tk.newwin(tbn)) tkpack(tab.posten - tkframe(tbw.posten)) tbn - tclvalue(tkinsert(tn, end, Instellingen, -text, Instellingen)) tkpack(tbw.instellingen - .Tk.newwin(tbn)) tkpack(tab.instellingen - tkframe(tbw.instellingen)) gui.maak.tab(tab.algemeen) gui.maak.tab(tab.relaties) gui.maak.tab(tab.posten) gui.maak.tab(tab.instellingen) tkgrid(tkbutton(tt, text=GUI bijwerken, command=function() verwerk.button(GUIBijwerken, tt))) # FIXME: add cleanup handler? #tkbind(tt, Destroy, function() tkdestroy(tn)) ### -- Don't understand this ... if I do the last raise only, ### -- then I see all tabs in the first tab, until I go to another ### -- tab and back. With all these raises, it works tcl(tn, raise, Instellingen) tcl(tn, raise, Posten) tcl(tn, raise, Relaties) tcl(tn, raise, Algemeen) } gui.maak.tab - function(tt) { tkgrid(tklabel(tt, text=Instellingen), sticky=news) test.button - tclVar(one two) tkgrid(tkcheckbutton(tt,variable=test.button)) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R with tcl/tk 8.5
Hi List, Is it possible to tell R to use tcl/tk 8.5? My R package seems to depend on libtcl8.4.so. However, in Windows it seems to be possible to set TCL_LIBRARY and MY_TCLTK. Is there something similar possible in Linux? I have installed: $ rpm -q R R-2.3.1-1.fc5 $ locate libtcl8 /usr/lib/libtcl8.4.so /usr/local/lib/libtcl8.5.so __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Compact sums in functions definitions
Hi Alessandro, The problem is that arr/x isn't quite doing what you thought it was. arr / x is something like c(arr[1] / x[1], arr[2] / x[2], arr[1] / x[3], ...) What I mean is, it divides arr[i] by x[i] and tries to lengthen arr by repeating itself (because it is shorter than x). It warns in case length(x) is not a multiple of length(arr). (or the other way around if arr was longer than x) I made a nice one for you: g - function(x) rowSums( t(t(1/x)) %*% arr ) It is likely someone else can do it much nicer (shorter), my R knowledge still has to be increased ... JeeBee. On Thu, 15 Jun 2006 18:55:15 +0200, Alessandro Antonucci wrote: I'm trying to make more compact the definition of a function as for example: f - function(x) 2/x+3/x by simply defining the array of coefficients arr = c(2,3) and setting: g - function(x) sum((arr/x)) Everything seems to work fine because the values returned by f and g result coincident for different values of their argument, but when I try to plot the function g using: x = seq(-1,1,.01) plot(x,g(x)) I receive the errors/warnings: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ In addition: Warning message: longer object length is not a multiple of shorter object length in: b/t Execution halted Any idea about that? Thanks. Alessandro __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Compact sums in functions definitions
Slightly better: h - function(x) rowSums( as.matrix(1/x) %*% arr ) On Thu, 15 Jun 2006 19:41:12 +0200, JeeBee wrote: Hi Alessandro, The problem is that arr/x isn't quite doing what you thought it was. arr / x is something like c(arr[1] / x[1], arr[2] / x[2], arr[1] / x[3], ...) What I mean is, it divides arr[i] by x[i] and tries to lengthen arr by repeating itself (because it is shorter than x). It warns in case length(x) is not a multiple of length(arr). (or the other way around if arr was longer than x) I made a nice one for you: g - function(x) rowSums( t(t(1/x)) %*% arr ) It is likely someone else can do it much nicer (shorter), my R knowledge still has to be increased ... JeeBee. On Thu, 15 Jun 2006 18:55:15 +0200, Alessandro Antonucci wrote: I'm trying to make more compact the definition of a function as for example: f - function(x) 2/x+3/x by simply defining the array of coefficients arr = c(2,3) and setting: g - function(x) sum((arr/x)) Everything seems to work fine because the values returned by f and g result coincident for different values of their argument, but when I try to plot the function g using: x = seq(-1,1,.01) plot(x,g(x)) I receive the errors/warnings: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ In addition: Warning message: longer object length is not a multiple of shorter object length in: b/t Execution halted Any idea about that? Thanks. Alessandro __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] case insensitive regular expression
Can anybody fix the following, to match a string disregarding case? I tried: with(my.data.frame, regexpr(pattern = '(?i)J\. Test', text=TARGET_COLUMN), perl=T) != -1) R yields: invalid regular expression with(my.data.frame, regexpr(pattern = 'J\. Test', text=TARGET_COLUMN), perl=T) != -1) works, but it does not match J. TEST. It does match J. Test correctly. I have the feeling I'm not reading the documentation good enough, but cannot seem to figure this out, sorry. Thanks in advance, JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] case insensitive regular expression
Found the problem already. Without the 'with' it works, so I know where to look for the problem now. Thanks anyways, JeeBee. On Mon, 05 Jun 2006 15:16:34 +0200, JeeBee wrote: Can anybody fix the following, to match a string disregarding case? I tried: with(my.data.frame, regexpr(pattern = '(?i)J\. Test', text=TARGET_COLUMN), perl=T) != -1) R yields: invalid regular expression with(my.data.frame, regexpr(pattern = 'J\. Test', text=TARGET_COLUMN), perl=T) != -1) works, but it does not match J. TEST. It does match J. Test correctly. I have the feeling I'm not reading the documentation good enough, but cannot seem to figure this out, sorry. Thanks in advance, JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] several plots in one
Can anyone tell me how I can supply more than one graph to plotCI (gplots) at once? Below is what I tried, also with rbind instead of cbind. What is the way to do this (in general, I think)? Problem is that lines of 1-st and 2-nd series are mixed, while they have nothing to do with each other. I also tried calling plotCI with argument add=TRUE, which didn't seem to work (that is actually what I wanted I think). (It should look the same as if I called plotCI twice with same labels/xlim/ylim/etc.) plotCI(x = cbind(x1,x2), y = cbind(means1,means2), # means1 == ci1[Estimate,] xlim = c(0,100), #ylim = c(0.2,0.5), ylab = System welfare, pch = 7, col = c(red,blue), type = b, uiw = cbind(uiw1,uiw2)) Thanks in advance, JeeBee. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] date handling
D = as.POSIXlt(c(2005-07-01, 2005-07-02, 2005-07-03, 2005-07-04, 2005-07-05)) (Years = 1900+D$year) [1] 2005 2005 2005 2005 2005 (Months = D$mon+1) [1] 7 7 7 7 7 weekdays(D) [1] Friday Saturday Sunday Monday Tuesday # you better check this one carefully !!! (Weeknumbers = floor((D$yday+7)/7)) JeeBee On Mon, 12 Dec 2005 12:59:11 +0100, Richard van Wingerden wrote: Hi, Given a frame with calendar date's: 2005-07-01, 2005-07-02,2005-07-03,2005-07-04,2005-07-05,etc. I want to extract the following from these dates: week number month number year number Any ideas how to accomplish this? Many thanks. Regards, Richard __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to make a plot?
That can be done very easy using a program that can deal with layers, for example the Gimp. Just make one layer containing the barplot and one layer containing the background image. Then you can do all kind of nice things. Directly in R, I don't have a clue, but it wouldn't surprise me if someone will show you an example ;) JeeBee. On Tue, 13 Dec 2005 08:32:15 -0500, Gabor Grothendieck wrote: Does anyone have an idea of how to make a chart in R like the ones here that use a graphic: http://bigpicture.typepad.com/comments/images/slide1.gif __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] sample matrix as a new object
You mean writing to a file? Maybe you should read the R Data Import/Export Manual http://cran.r-project.org/doc/manuals/R-data.html or as pdf http://cran.r-project.org/doc/manuals/R-data.pdf You might also want to read the manual pages of these two commands: help('dump') help('write.table') JeeBee. On Tue, 13 Dec 2005 11:31:33 -0300, Carlos Mauricio Cardeal Mendes wrote: Please, I´d like to store this sample matrix as a new object. How can I do this ? pulse - c(67, 67, 68, 68, 68, 69, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 72, 72, 73, 74) m - NULL x - 0 for (i in 1:5) { x - sample(pulse,3) m - mean(x) cat(x,m,\n) } Thanks, Mauricio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Help on a matrix task
Here is one possible solution: for(cr in seq(1, dim(combin_mat)[2])) { W = which(input_mat[,combin_mat[1,cr]] == 1 input_mat[,combin_mat[2,cr]] == 1) cat(Combination, cr, (, combin_mat[,cr], ) :, W, \n) } JeeBee. --- Full program: N = 4 input_numbers = seq((2^N)-1, 0, -1) # convert to binary matrix input_mat = NULL for(i in seq(N-1,0,-1)) { new_col = input_numbers %% 2 input_mat = cbind(new_col, input_mat) input_numbers = (input_numbers - new_col) / 2 } colnames(input_mat) = NULL library(gtools) combin_mat = t(combinations(n=N, r=2, v=1:N, set=TRUE, repeats.allowed=FALSE)) for(cr in seq(1, dim(combin_mat)[2])) { W = which(input_mat[,combin_mat[1,cr]] == 1 input_mat[,combin_mat[2,cr]] == 1) cat(Combination, cr, (, combin_mat[,cr], ) :, W, \n) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] hamming distance
You could install.packages(e1071) and see help(hamming.distance) JeeBee. hamming.distancepackage:e1071R Documentation Hamming Distances of Vectors Description: If both 'x' and 'y' are vectors, 'hamming.distance' returns the Hamming distance (number of different bytes) between this two vectors. If 'x' is a matrix, the Hamming distances between the rows of 'x' are computed and 'y' is ignored. Usage: hamming.distance(x, y) Arguments: x: a vector or matrix. y: an optional vector. Examples: x - c(1, 0, 0) y - c(1, 0, 1) hamming.distance(x, y) z - rbind(x,y) rownames(z) - c(Fred, Tom) hamming.distance(z) On Thu, 24 Nov 2005 11:33:45 +0100, Ana Conesa wrote: Hi, Does anyone know an R function to impute hamming distance? Thanks Ana O@ nb @@@O@@O@ Centro de Genómica @OO@ Instituto Valenciano de Investigaciones Agrarias (IVIA) @@@O Carretera Moncada - Naquera, Km. 4,5 O@46113 Moncada (Valencia) SPAIN || || __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] write.table read.table with Dates
I've found several similar issues with write.table/read.table with Dates on this list, but trying to follow this advice I still get an error. First, I read in data from several files, constructing several date/time columns using ISOdatetime str(Tall$Begin) 'POSIXct', format: chr [1:40114] 2005-10-02 00:00:00 2005-10-02 00:00:00 ... length(Tall$Begin) [1] 40114 class(Tall$Begin) [1] POSIXt POSIXct This looks good (time is not always 00:00:00 ...) This data came from several files, now I want to store the result I have in data.frame Tall and be able to retrieve this quickly some other time. This is what I do: write.table(Tall, file=somefile.csv, sep=,, qmethod=double, row.names=FALSE) Later, I do this to read the file again: fieldnames=c(Begin,test-a,test-b,Eind) T=read.table(file = somefile.csv, col.names = fieldnames, header = TRUE, sep = ,, quote=\, fill=FALSE) I understand T$Begin now is a factor. I tried to simply convert it again using (as I read on this mailinglist ...): Q = strptime(as.character(T$Begin),format=%Y-%m-%d %H:%M:%S) Q is looking good, though its length I don't understand .. is it a list or something? It seems there are 40114 values in there somewhere... class(Q) [1] POSIXt POSIXlt length(Q) [1] 9 str(Q) 'POSIXlt', format: chr [1:40114] 2005-10-02 00:00:00 2005-10-02 00:00:00 ... T$Begin = Q ### yields this error Error in $-.data.frame(`*tmp*`, Begin, value = list(sec = c(0, 0, : replacement has 9 rows, data has 40114 Could somebody explain me how to convert the date column? Or perhaps there is an easier way? Thanks in advance for your time. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] write.table read.table with Dates
I see that strptime returns a list of year, mon, mday, hour, min, sec, etc. The following works for me (for each column that is a date/time field in my imported file) cat(Converting date/time fields...\n) Q = strptime(as.character(data$myfield), format=%Y-%m-%d%H:%M:%S) data$myfield = ISOdatetime(year = Q$year + 1900, month = Q$mon + 1, day = Q$mday, hour =Q$hour, min = Q$min, sec = Q$sec, tz = ) ISOdatetime does return a vector, which is, I guess, what I want. It is quite slow like this though, and I don't think it's the best way. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html