Re: [R] merge
One other option during the import is to set 'strip.white = TRUE' in read.csv(). See ?read.csv for more information. Bear in mind that this will strip both leading and trailing white space in all columns, which may have unintended consequences. Yet another post-import option, would be to use sub() on specific columns: df - data.frame(A = c(ST , ST, ST , ST , ST ), B = letters[1:5]) df A B 1 ST a 2 ST b 3STc 4 ST d 5 ST e df$A - sub('[[:space:]]+$', '', as.character(df$A)) df A B 1 ST a 2 ST b 3 ST c 4 ST d 5 ST e See ?sub for more information. Be cautious in this case, as you will need to coerce any factors to character vectors as I have done above, and then possibly re-coerce to a factor as you may require. HTH, Marc Schwartz On Fri, 2005-07-08 at 20:10 -0400, Gabor Grothendieck wrote: trim in package gdata will trim spaces off the beginning and end. On 7/8/05, Ling Jin [EMAIL PROTECTED] wrote: Hi all, I have two data frames to merge by a column containing the site names (as characters). However, somehow, one of the site names of one data frame have fixed length, say 8, so the names sometimes have spaces at the end. For example, the site name is ST, but in one data frame, it is ST. Therefore, the merge function won't recognize that ST and STare the same, so won't merge accordingly. Is there a easy way to deal with it? Or I should do something during data import? (BTW, I imported the data using read.csv) Thanks! Ling __ 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-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] Overlying a Normal Dist in a Barplot
On Fri, 2005-07-08 at 21:58 -0400, Gabor Grothendieck wrote: On 7/8/05, Bret Collier [EMAIL PROTECTED] wrote: R-Users, Hopefully someone can shed some light on these questions as I had little luck searching the archives (although I probably missed something in my search due to the search phrase). I estimated multinomial probabilities for some count data (number successful offspring) ranging from 0 to 8 (9 possible response categories). I constructed a barplot (using barplot2) and I want to overlay a normal distribution on the figure (using rnorm (1000, mean, sd)). My intent is to show that using a mean(and associated sd) estimated from discrete count data may not be a valid representation of the distribution of successful offspring. Obviously the x and y axes (as structured in barplot2) will not be equivalent for these 2 sets of information and this shows up in my example below. 1) Is it possible to somehow reconcile the underlying x-axis to the same scale as would be needed to overly the normal distribution (e.g. where 2.5 would fall on the normal density, I could relate it to 2.5 on the barplot)? Then, using axis (side=4) I assume I could insert a y-axis for the normal distribution. 2) Is lines(density(x)) the appropriate way to insert a normal distribution into this type of figure? Should I use 'curve'? If someone could point me in the right direction, I would appreciate it. TIA, Bret Example: testdata 00.196454948 10.063515510 20.149187592 30.237813885 40.282127031 50.066469719 60.001477105 70.001477105 80.001477105 x-rnorm(1000, 2.84, 1.57) barplot2(testdata, xlab=Fledgling Number, ylab=Probability, ylim=c(0, 1), col=black, border=black, axis.lty=1) lines(density(x)) Maybe something like this using rect and curve: # data from your post testdata - c(0.196454948, 0.06351551, 0.149187592, 0.237813885, 0.282127031, 0.066469719, 0.001477105, 0.001477105, 0.001477105) x - 0:9 # setup plot ranges noting max of normal density is at mean xrange - range(x) + c(-0.5,+0.5) yrange - range(c(testdata, dnorm(2.84, 2.84, 1.57), 0)) plot(xrange, yrange, type = n, xlab = X, ylab = Probability, xaxt = n) axis(1, x) # draw bars using rect and density using curve rect(x - 0.5, 0, x + 0.5, testdata, col = lightgrey) curve(dnorm(x, 2.84, 1.57), min(xrange), max(xrange), add = TRUE) Nice solution Gabor. I had to think about this one for a bit, and think I may have it using barplot[2](): testdata V1 V2 1 0 0.196454948 2 1 0.063515510 3 2 0.149187592 4 3 0.237813885 5 4 0.282127031 6 5 0.066469719 7 6 0.001477105 8 7 0.001477105 9 8 0.001477105 # Change 'space = 0' so that bars are adjacent to each other # This also puts each bar center at seq(0.5, 8.5, 1) mp - barplot2(testdata[, 2], xlab=Fledgling Number, ylab=Probability, ylim=c(0, .3), axis.lty = 1, names.arg = testdata[, 1], space = 0) mp [,1] [1,] 0.5 [2,] 1.5 [3,] 2.5 [4,] 3.5 [5,] 4.5 [6,] 5.5 [7,] 6.5 [8,] 7.5 [9,] 8.5 x - testdata[, 1] # Now do the curve and shift the mean by +0.5 # To coincide with the bar centers curve(dnorm(x, 2.84 + 0.5, 1.57), add = TRUE) I think that does it. HTH, Marc Schwartz __ 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] not supressing leading zeros when reading a table?
On Sun, 2005-07-10 at 18:13 +, Adrian Dusa wrote: Dear R list, I have a dataset with a column which should be read as character, like this: name surname answer 1 xx yyy 00100 2 rrr hhh 01 When reading this dataset with read.table, I get 1 xx yyy 100 2 rrr hhh 1 The string column consists in answers to multiple choice questions, not all having the same number of answers. I could format the answers using formatC but there are over a hundred different questions in there. I tried with quote=\' without any luck. Googling after this take me nowhere either. It should be simple but I seem to miss it... Can anybody point me to the right direction? TIA, Adrian With your example data saved in a file called test.txt: df - read.table(test.txt, header = TRUE, colClasses = character) df name surname answer 1 xx yyy 00100 2 rrr hhh 01 str(df) `data.frame': 2 obs. of 3 variables: $ name : chr xx rrr $ surname: chr yyy hhh $ answer : chr 00100 01 See the colClasses argument in ?read.table. HTH, Marc Schwartz __ 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: how to change the size of a window after it has been created
On Thu, 2005-07-14 at 14:38 +0200, wu sz wrote: Hello, I wish to plot some figures in a window in turn, but the size of these figures is different, so how can I change the size of the window by resetting the parameters before each plotting? Thank you, Shengzhe Other than dragging a plot window with a mouse, I do not think that there is a way to change the size of an open display device via code (though somebody will no doubt correct me if I am wrong). See ?Devices Depending upon your OS, there is likely a 'width' and 'height' argument for the screen display device for newly opened devices. For example, under systems using X, where X11() is the screen device: X11(width = 11, height = 8) plot(1:10) X11(width = 5, height = 5) barplot(1:5) In the above example, two separate plot windows will be created. If you want to only have one open at a time, you can close the device first using dev.off() before the subsequent plots. However, you lose the current plot as soon as you close it. X11(width = 11, height = 8) plot(1:10) dev.off() X11(width = 5, height = 5) barplot(1:5) dev.off() HTH, Marc Schwartz __ 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] .gct file
On Tue, 2005-07-19 at 13:08 -0500, Marc Schwartz (via MN) wrote: For the TAB delimited columns, adjust the 'sep' argument to: read.table(data.gct, skip = 2, header = TRUE, sep = \t) The 'quote' argument is by default: quote = \' which should take care of the quoted strings and bring them in as a single value. The above presumes that the header row is also TAB delimited. If not, you may have to set 'skip = 3' to skip over the header row and manually set the column names. One correction. If the final para applies and you need to use 'skip = 3', you would also need to leave out the 'header = TRUE' argument, which defaults to FALSE. Marc __ 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] Question about 'text'
On Sun, 2005-07-24 at 18:19 +0100, Dan Bolser wrote: On Sun, 24 Jul 2005, John Wilkinson wrote: Dan, Another tweak ! If you want the 'legend' to look pretty you can resize it by adding,say, 'cex=0.6' into the legend code; try--- legend(topleft, #inset=-1, legend = do.call(expression, L), bg='white', ncol = 2, pch=c('','','',':',':',':'), x.intersp = 0.4, title=Yay! Thank You!, cex=0.6 ) Thats cool, but my biggest problem is using monospaced fonts in a postscript output. It dosn't seem to work! Also, anybody else have the inset= problem? Cheers for the tweek! Dan. Dan, Try this: my.slope.1 - 3.22 my.slope.2 - 0.13 my.inter.1 - -10.66 my.inter.2 - 1.96 my.Rsqua - 0.97 # Include Courier font in the PS device postscript(file = LM.ps, font = Courier) plot(1:5) L - list(Intercept, Slope, bquote(paste(R^2)), bquote(.(my.inter.1) %+-% .(my.inter.2)), bquote(.(my.slope.1) %+-% .(my.slope.2)), bquote(.(my.Rsqua))) # Set font to Courier for mono spacing par(family = Courier) legend(topleft, inset = .10, legend = do.call(expression, L), bg = 'white', ncol = 2, pch = rep(c('', ':'), each = 3), x.intersp = 0.1, title = Yay! Thank You!) dev.off() Note that the 'inset' argument is to be a fraction of the plot region in the range of 0 - 1. The above setting moves the legend to the right and down from the upper left hand corner by 10% of the plot region width/height. One more tweak in the legend() call. Use rep() for the pch characters. HTH, Marc Schwartz __ 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] Dates are read as factors!
On Wed, 2005-07-27 at 23:07 -0400, John Sorkin wrote: I am using read.csv to read a CSV file (produced by saving an Excel file as a CSV file). The columns containing dates are being read as factors. Because of this, I can not compute follow-up time, i.e. Followup-postDate-preDate. I would appreciate any suggestion that would help me read the dates as dates and thus allow me to calculate follow-up time. Thanks John John, Depending upon how may columns you are reading, you could: 1. Use the 'colClasses' argument in read.csv() to specify the data types for each incoming column, one of which is 'Date' Or 2. Post process the data after importing by using the as.Date() function. See ?as.Date for more information and pay particular attention to the 'format' argument. My own preference is number 2. Once the requisite columns are converted to the Date class, you can engage in date based arithmetic, etc. HTH, Marc Schwartz __ 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] Displaying p-values in latex
On Thu, 2005-07-28 at 14:00 -0700, Juned Siddique wrote: Hi. I want to create a table in latex with regression coefficients and their corresponding p-values. My code is below. How do I format the p-values so that values less than 0.0001 are formated as .0001 rather than just rounded to 0.? Thank you. model-lm(y~x1+x2) output-summary(model) output-as.matrix(coefficients(output)) output-format.df(ouput,cdec=c(2,2,2,4)) latex(output,longtable=TRUE, file=C:/model.tex) I have not used Frank's latex() function, so there may be a setting that helps with this, but something along the lines of: # Using one example from ?lm: ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group - gl(2,10,20, labels=c(Ctl,Trt)) weight - c(ctl, trt) lm.D9 - lm(weight ~ group) output - (summary(lm.D9)) output - as.matrix(coefficients(output)) output - format.df(output, rdec = c(2, 2, 2, 4)) # Here is the line to re-format the p values # Note that column alignment on the decimal may be problematic here # depending upon the specifications for column justifications. # If the column is right justified, it should be easier, since we # are forcing four decimal places. output[, 4] - ifelse(as.numeric(output[, 4]) 0.0001, $$0.0001, sprintf(%6.4f, output[, 4])) output Estimate Std. Error t value Pr(|t|) (Intercept) 5.03 0.22 22.85 $$0.0001 groupTrt-0.37 0.3114 -1.19 0.2490 attr(,col.just) [1] r r r r Note the use of $ to indicate math mode for the symbols. Presumably Frank has a similar approach when the object passed to latex() is a model, since the heading for the p value column should end up being something like: Pr($$$|$t$|$) and the minus signs in the second line should similarly be surrounded: $-$0.37 I have cc:d Frank here for his clarifications. HTH, Marc Schwartz __ 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] question on graphs and finding area under a curve
On Tue, 2005-08-02 at 18:20 +0530, Renuka Sane wrote: Question on graphs: The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) -- there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R? See ?par and take note of the 'xaxs' and 'yaxs' parameters. By default, these are set to 'r', where the axes are extended by 4% in each direction. Thus, set one or both parameters to 'i' to set the axes to exactly the ranges of xlim and/or ylim as you require. Area under the curve: I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two? See Frank Harrell's somers2() function in the Hmisc package on CRAN. Among other things, it outputs a value C, which is the AUC. HTH, Marc Schwartz __ 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] hash code for arbitrary object
On Wed, 2005-08-03 at 12:05 +0800, Adrian Baddeley wrote: Can anyone suggest a simple way to calculate a 'hash code' from an arbitrary R object? hash(x) should return an integer or string with the property that if hash(x) != hash(y) then x and y are not identical and the time to compute hash(x) should be quite short. Any suggestions welcome thanks Adrian Baddeley Take a look at Dirk Eddelbuettel's digest() function in the package of the same name on CRAN. Be sure to read the details section for caveats regarding collisions. HTH, Marc Schwartz __ 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] problem with for()
On Wed, 2005-08-03 at 23:24 +0200, Simone Gabbriellini wrote: Dear list, can someone tell me why this two pieces of code give me the same results? for(i in 0:5){ sum[i] = i } sum [1] 1 2 3 4 5 for(i in 1:5){ sum[i] = i } sum [1] 1 2 3 4 5 shouldn't the first one be 0 1 2 3 4 5 thank you, simone Nothe indexing of R objects is 1 based. Thus your first loop tried to set i[0], which is a non-existent entry. i - 0:5 i [1] 0 1 2 3 4 5 i[0] numeric(0) i[1] [1] 0 HTH, Marc Schwartz __ 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] problem with for()
It would help to have an example of what it is you are trying to do. Importantly, keep separate the need to have zero be a value in a vector as opposed to using zero to index a vector. As I note below in my reply, you can have: x - 0:5 x [1] 0 1 2 3 4 5 x ^ 2 [1] 0 1 4 9 16 25 Marc On Thu, 2005-08-04 at 00:25 +0200, Simone Gabbriellini wrote: how can I have a 0 evaluated in my loop then? it is important for my algorithm do you have any hints? simone Il giorno 03/ago/05, alle ore 23:37, Marc Schwartz ha scritto: On Wed, 2005-08-03 at 23:24 +0200, Simone Gabbriellini wrote: Dear list, can someone tell me why this two pieces of code give me the same results? for(i in 0:5){ sum[i] = i } sum [1] 1 2 3 4 5 for(i in 1:5){ sum[i] = i } sum [1] 1 2 3 4 5 shouldn't the first one be 0 1 2 3 4 5 thank you, simone Nothe indexing of R objects is 1 based. Thus your first loop tried to set i[0], which is a non-existent entry. i - 0:5 i [1] 0 1 2 3 4 5 i[0] numeric(0) i[1] [1] 0 HTH, Marc Schwartz __ 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] Determining physical display dimensions
On Fri, 2005-08-19 at 13:17 -0500, Earl F. Glynn wrote: Berton Gunter [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Failing that, (how) can this be done for Windows (XP or 2000, say) ? Take a look at the Windows GetDeviceCaps API call http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_88s3.asp Parameters that can be queried include: HORZRES Width, in pixels, of the screen. VERTRES Height, in raster lines, of the screen. HORZSIZE Width, in millimeters, of the physical screen VERTSIZE Height, in millimeters, of the physical screen The specifics of how to use this API call will vary by language. Google will be your friend. FWIW, in case anyone should see this thread and wonder how to do this somewhat easily in R for systems running X, there is a CLI utility called 'xdpyinfo' that returns a great deal of data on the connected display(s). display.size - system(xdpyinfo | grep dimensions, intern = TRUE) display.dpi - system(xdpyinfo | grep resolution, intern = TRUE) display.size [1] dimensions:1600x1200 pixels (301x231 millimeters) display.dpi [1] resolution:135x132 dots per inch One can then parse the above using R functions as required. Such as: d.size - unlist(strsplit(display.size, split = [[:space:]|(|)|x])) d.size [1] dimensions: [5] 16001200 [9] pi els 301 [13] 231 millimeters h.pix - as.numeric(d.size[7]) v.pix - as.numeric(d.size[8]) h.mm - as.numeric(d.size[12]) v.mm - as.numeric(d.size[13]) line1 - sprintf(The current display is %d x %d pixels, h.pix, v.pix) line2 - sprintf(with a physical size of %d x %d mm, h.mm, v.mm) cat(line1, line2, sep = \n) The current display is 1600 x 1200 pixels with a physical size of 301 x 231 mm This can get more complicated with multi-monitor systems, depending upon whether you are running in xinerama (multi-monitor spanning mode) or non-xinerama mode and consideration for symmetric or asymmetric resolutions. 'man xdpyinfo' and 'man X' (noting the 'DISPLAY' environment variable) will be helpful here to determine which display/screen R is running on. For example, on my system which has two displays, each with 1600x1200, I get: Sys.getenv(DISPLAY) DISPLAY :0.0 with R running on the main laptop LCD (15 diag), versus: Sys.getenv(DISPLAY) DISPLAY :0.1 with R running on the external LCD (20.1 diag), with the DISPLAY variable indicating: :DisplayNumber.ScreenNumber Thus, on my system, the output of the system() calls are actually: display.size - system(xdpyinfo | grep dimensions, intern = TRUE) display.dpi - system(xdpyinfo | grep resolution, intern = TRUE) display.size [1] dimensions:1600x1200 pixels (301x231 millimeters) [2] dimensions:1600x1200 pixels (411x311 millimeters) display.dpi [1] resolution:135x132 dots per inch [2] resolution:99x98 dots per inch HTH, Marc Schwartz __ 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 retrieving output from by( ) for regression
Also, looking at the last example in ?by would be helpful: attach(warpbreaks) tmp - by(warpbreaks, tension, function(x) lm(breaks ~ wool, data = x)) # To get coefficients: sapply(tmp, coef) # To get residuals: sapply(tmp, resid) # To get the model matrix: sapply(tmp, model.matrix) To get the summary() output, I suspect that using: lapply(tmp, summary) would yield more familiar output as compared to using: sapply(tmp, summary) The output from the latter might require a bit more navigation through the resultant matrix, depending upon how the output is to be ultimately used. HTH, Marc Schwartz On Thu, 2005-08-25 at 14:57 +0200, TEMPL Matthias wrote: Look more carefully at ?lm at the See Also section ... X - rnorm(30) Y - rnorm(30) lm(Y~X) summary(lm(Y~X)) Best, Matthias Hi all I used a function qtrregr - by(AB, AB$qtr, function(AB) lm(AB$X~AB$Y)) objective is to run a regression on quartery subsets in the data set AB, having variables X and Y, grouped by variable qtr. Now i retrieved the output using qtrregr, however it only showed the coefficients (intercept and B) with out significant levels and residuals for each qtr. Can some on help me on how can retrieve the detailed regression output. rgds snvk __ 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] Matrix oriented computing
On Fri, 2005-08-26 at 14:44 +0200, Sigbert Klinke wrote: Hi, I want to compute the quantiles of Chi^2 distributions with different degrees of freedom like x-cbind(0.005, 0.010, 0.025, 0.05, 0.1, 0.5, 0.9, 0.95, 0.975, 0.99, 0.995) df-rbind(1:100) m-qchisq(x,df) and hoped to get back a length(df) times length(x) matrix with the quantiles. Since this does not work, I use x-c(0.005, 0.010, 0.025, 0.05, 0.1, 0.5, 0.9, 0.95, 0.975, 0.99, 0.995) df-c(1:100) m-qchisq(x,df[1]) for (i in 2:length(df)) { m-rbind(m,qchisq(x,df[i])) } dim(m)-c(length(df),length(x)) Is there a way to avoid the for loop ? Thanks Sigbert See ?sapply x - c(0.005, 0.010, 0.025, 0.05, 0.1, 0.5, 0.9, 0.95, 0.975, 0.99, 0.995) df - c(1:100) mat - sapply(x, qchisq, df) dim(mat) [1] 100 11 str(mat) num [1:100, 1:11] 3.93e-05 1.00e-02 7.17e-02 2.07e-01 4.12e-01 ... HTH, Marc Schwartz __ 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] standard deviation in barplots
On Thu, 2005-09-01 at 15:00 +0200, Knut Krueger wrote: Sean Davis schrieb: I think barplot2 in the gregmisc (gplots) bundle will do that. Sean Ok thank´s but I've got an error and do not found the solution: ci.l [1] 304.09677 202.49907 0.0 63.14547 0.0 0.0 0.0 [8] 0.0 0.0 0.0 ci.h [1] 633.50323 426.10093 45.12493 344.85453 196.19980 198.17632 208.96365 [8] 76.49691 0.0 0.0 xrow [1] 468.8 314.3 20.1 204.0 96.0 96.0 115.0 36.0 0.0 0.0 barplot2(xrow,plot.ci=TRUE,ci.l=ci.l,ci.h=ci.h) Knut Presumably, you are getting: barplot2(xrow, plot.ci = TRUE, ci.l = ci.l, ci.h = ci.h) Error in barplot2.default(xrow, plot.ci = TRUE, ci.l = ci.l, ci.h = ci.h) : confidence interval values are missing There is an error in your function call. The argument 'ci.h' is incorrect, as it should be 'ci.u'. Thus, use: ci.l - c(304.09677, 202.49907, 0.0, 63.14547, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ci.u - c(633.50323, 426.10093, 45.12493, 344.85453, 196.19980, 198.17632, 208.96365, 76.49691, 0.0, 0.0) xrow - c(468.8, 314.3, 20.1, 204.0, 96.0, 96.0, 115.0, 36.0, 0.0, 0.0) barplot2(xrow, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u) HTH, Marc Schwartz __ 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] png scaling problem
Knut, Gabor has provided a possible approach here. Your comments on using postscript make me wonder how your code looked. The following, for example, will create a 4 inch by 4 inch square plot to an encapsulated postscript file (EPS). It will also specify/include required resources for the Helvetica font, which is one of the requirements on the page you reference. Since Helvetica is one of the standard Adobe PS fonts, I don't believe that it is necessary to actually embed the font here, which would be the case if you used a non-standard font. If you open the EPS file in a text editor, you will see many lines referring to 'Resources' and fonts. postscript(RPlot.eps, onefile = FALSE, horizontal = FALSE, paper = special, height = 4, width = 4, family = Helvetica, font = Helvetica) barplot(1:10) dev.off() They keys above are the 'onefile', 'horizontal' and 'paper' arguments, which must be set as above to generate an EPS file with the specified size and bounding box. The page referenced mentions creating the image as close as possible to the actual size required, so be sure to set the 'height' and 'width' arguments per that specification. Using postscript here will also better enable the 50% reduction that is mentioned, given the vector based format here. The key here also is to be sure that the plot looks good in the target format, not on the screen, which includes text size, readability and positioning, etc. HTH, Marc Schwartz On Fri, 2005-09-02 at 02:03 -0400, Gabor Grothendieck wrote: If you have not already tried it try creating a fig file: xfig(myfile.fig) plot(1:10) dev.off() and then using the fig2dev utility (find it via google) to convert it to a tiff: fig2dev -L tiff myfile.fig myfile.tiff On 9/2/05, Knut Krueger [EMAIL PROTECTED] wrote: Probably a better first question is, why are you using a bitmapped graphics format if you need the image to be re-scaled? I need a 1000 dpi tif file in a size of appr. 10 to 10 cm for applied animal behaviour science: http://authors.elsevier.com/GuideForAuthors.html?PubID=503301dc=GFA images to one of the following formats (Note the resolution requirements for line drawings, halftones, and line/halftone combinations given below.): EPS: Vector drawings. Embed the font or save the text as graphics. TIFF: Colour or greyscale photographs (halftones): always use a minimum of 300 dpi. TIFF: Bitmapped line drawings: use a minimum of 1000 dpi. TIFF: Combinations bitmapped line/half-tone (colour or greyscale): a minimum of 500 dpi is required. DOC, XLS or PPT: If your electronic artwork is created in any of these Microsoft Office applications please supply as is. I tired the Postscript file but the file is double heigh as width i do not know why. The problem was already discussed in the tread: [R] High resolution plots I have to send the images possibly yesterday and I am looking fo a suitable solution since two months now. I tired gsview with converting to all possible Tiff formats but the images appear not in color and in a strange black and white way Some readers are able to read it (Windows Image view) other not and I do not know which reader the journal will use :-( And the ylab is too small ... http://biostatistic.de/temp/1.tif http://biostatistic.de/temp/2.tif http://biostatistic.de/temp/3.tif http://biostatistic.de/temp/4.tif In general, bitmapped graphics do not resize well, though if you have a specific need and know a target image size, you can adjust various parameters to look decent. Are you going to view these images in a web browser, where you are concerned with display size and resolution? From your e-mail headers it appears you are on Windows. If you need a re-sizable graphic, use a vector based format such as wmf/emf, especially if you need the graphics embedded in a Windows application such as Word or Powerpoint. This is the default format under Windows when copying and pasting a graphic between applications. You can then, fairly freely, resize the image in the target application as you may require. If you are going to print the graphic directly or include it in a document for printing (as opposed to just viewing it), then use PDF or Postscript. Ok there is a second description for the file format :-( http://authors.elsevier.com/ArtworkInstructions.html?dc=AI2 there are pdf formats welcome but with defined conditions: Maybe anybody could give me a hint to get the files in the recommendet format. I will ask them immediately which whether the pdf is allowed or not, becaus they have two different instruction sites :-( Regards Knut __ 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
[R] The Perils of PowerPoint
Hi all, Below is a URL for an editorial published today in our local newspaper, the Minneapolis StarTribune. It was originally published in the Washington Post a couple of days ago: http://www.washingtonpost.com/wp-dyn/content/article/2005/08/29/AR2005082901444.html but that site requires registration. The 'Strib site seems to be open for the moment: http://www.startribune.com/stories/1519/5591930.html I thought folks might find it interesting. Best regards, Marc Schwartz __ 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] png scaling problem
On Fri, 2005-09-02 at 15:08 +0200, Knut Krueger wrote: but back to the last problem, what could be wrong that the ylab is not displayed as expected? with regards Knut The TIF files seem to be OK. However, the PNG files, as a result of your attempt to scale the plot, do not have enough margin space for side = 2 (left). You would need to adjust the settings for par(mar) and perhaps adjust the overall plot size in the png() call. This is one of the reasons why trying to scale a bitmapped image is problematic. If you want to have finer control over the text annotation, use something like the following: # Create just the 'bare' barplot and save the bar # midpoints in 'mp' mp - barplot(1:10, xaxt = n, yaxt = n, ann = FALSE) # Now create the x axis labels, using 'mp' for placement # 'cex' controls text size. # See ?axis for more details axis(1, at = mp, labels = LETTERS[1:10], cex = 1.25) # Do the same for the y axis axis(2, at = seq(0, 10, 2), cex = 1) # Do the x axis label, using mtext() # See ?mtext mtext(1, line = 3, text = X Axis Label, cex = 1.5) # Same for y axis mtext(2, line = 2.5, text = y Axis Label, cex = 1.5) # Now the title mtext(3, line = 2, text = Main Barplot Title, cex = 4) Again, with the above, be sure to check the output in the target format, not on the screen. They will not always be the same. HTH, Marc Schwartz __ 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] The Perils of PowerPoint
LOL Ted! That's a great quote for fortune()! On Sat, 2005-09-03 at 01:06 +0100, Ted Harding wrote: On 02-Sep-05 Sean O'Riordain wrote: I can't lay my hands n it at the moment - its around here somewhere, but in Numerical Methods That Work by Forman Acton, the author points out that the result of computation should be insight, not numbers ps. an excellent book if you haven't seen it. https://enterprise.maa.org/ecomtpro/Timssnet/products/TNT_products.cfm cheers, Sean No doubt you're correct -- but I associate it with Richard Hamming (title page of Numerical Methods for Scientists and Engineers as I recall -- yes, for me too it's around here somewhere -- another really excellent book) where he words it: The purpose of computing is insight, not numbers. to which he adds: The purpose of computing numbers is not yet in sight. By the way, the Washington Post/Minneapolis Star Tribune article is somewhat reminiscent of a short (15 min) broadcast on BBC Radio 4 back on October 18 2004 15:45-16:00 called Microsoft Powerpoint and the Decline of Civilisation which explores similar themes and also frequently quotes Tufte. Unfortunately it lapsed for ever from Listen Again after the statutory week, so I can't point you to a replay. (However, I have carefully preserved the cassette recording I made). We are not, of course, going Off Topic here. If, in R, you can not indefinitely extend a tangent, then it's time to extend R. (Oh dear, I feel a fortune coming on ... ) Best wishes to all, Ted. On 02/09/05, Achim Zeileis [EMAIL PROTECTED] wrote: On Fri, 2 Sep 2005 12:27:45 -0500 [EMAIL PROTECTED] wrote: -Original Message- From: ... Robert Baer Sent: Friday, September 02, 2005 11:30 AM It is wrong to blame ANY tool for our own shortcomings! Surely a fortune! thx, added to the devel-version of fortunes. But allow me one remark: Although the above is certainly true, there are computational tools that help us better to realize or avoid our own shortcomings whereas others will make it harder to arrive at the right conclusions. I agree that PowerPoint cannot be blamed for the crash of the space shuttle, but I also see the point that the way presentations are generated in PowerPoint (or graphics in Excel) can easily tempt people into producing presentations/graphics that conceal what is important. This is certainly not an excuse, but I think some criticism (even if phrased a bit provocatively) should be allowed. just my EUR 0.02. Z David L. Reiner __ 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-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 E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 03-Sep-05 Time: 01:00:24 -- XFMail -- __ 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] why this postscript didn't work?
On Tue, 2005-09-20 at 18:30 -0500, [EMAIL PROTECTED] wrote: Hi, List, I used the following codes to generate ps plots but foo.ps contains nothing. Would someone please point out what is wrong with my codes? Thanks a million! postscript('foo.ps') par(mfrow=c(2,1)) par(mfg=c(1,1)) hist(rnorm(100),col='blue') par(mfrow=c(2,2)) par(mfg=c(2,1)) hist(rnorm(50),col='blue') par(mfg=c(2,2)) hist(rnorm(60),col='blue') dev.off() Best, Auston It sort of works here using: Version 2.1.1 Patched (2005-09-14) on FC4 in that the graphic is drawn, but the output device dimensions are not appropriate for the plot and the plot is rotated relative to the page. The page is landscape orientation and the plot is cuttoff on the bottom (actually right axis) as a result of the rotation. Your e-mail headers suggest that you are on Windows and you do not specify which version of R you are running, so there may be some differences in what you see on your system resulting in problematic output. Try this. I am using layout() here and note that your code above can be replaced by: postscript(foo.ps, width = 6, height = 6) layout(matrix(c(1, 1, 2, 3), 2, 2, byrow = TRUE)) hist(rnorm(100),col='blue') hist(rnorm(50),col='blue') hist(rnorm(60),col='blue') dev.off() Note that I am specifying height and width dimensions for the postscript output. See if that changes anything on your system. You can of course modify the dimension arguments as you may require. Also note that if you want to create an EPS output file, you would need something like: postscript(foo.ps, width = 6, height = 6, horizontal = FALSE, onefile = FALSE, paper = special) See the Details section of ?postscript and also ?layout. HTH, Marc Schwartz __ 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] List Email Statistic
On Thu, 2005-09-29 at 23:47 -0500, José Raul Capablanca wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. If you have access to Usenet either via an NNTP server or via Google Groups, there are three principal groups for general statistics discussion: sci.stat.consult (http://groups.google.com/group/sci.stat.consult) sci.stat.math(http://groups.google.com/group/sci.stat.math) sci.stat.edu (http://groups.google.com/group/sci.stat.edu) There is a greater level of volume on the first two for general discussion. sci.stat.edu (which is targeted more to statistics education discussion) has been split off as a gateway to the edstat-L list, which has substantively reduced its daily volume. HTH, Marc Schwartz __ 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] Multiple expressions, when using substitute()
On Sat, 2005-10-01 at 20:32 +1000, John Maindonald wrote: expression() accepts multiple expressions as arguments, thus: plot(1:2, 1:2) legend(topleft, expression(y == a * x^b, where * paste(y==wood; , x==dbh))) Is there a way to do this when values are to be substituted for a and b? i.e., the first element of the legend argument to legend() becomes, effectively: substitute(y == a * x^b, list(a = B[1], b=B[2])) John, Try this: a - 5 b - 3 L - list(bquote(y == .(a) * x^.(b)), where y = wood; x = dbh) plot(1:2, 1:2) legend(legend = do.call(expression, L), topleft) Note the creation of the list 'L', which uses bquote() and then the .(Var) construct, where 'Var' are your variables to be replaced. Then in the legend() call, the use of do.call() to apply expression() to the elements of list 'L'. HTH, Marc Schwartz __ 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] X-Axis Label Overwritten By TickMark Values
On Sat, 2005-10-01 at 06:07 -0500, Paul Roebuck wrote: Can someone tell me how to fix the left margin of plot region such that the tick values don't overwrite the x-axis label? I haven't been able to set the correct par option to fix this... TIA grdev - function(...) { get(getOption(device))(...) } plotFixMe - function(spectrum, ...) { saved.par - par(las = 1, tcl = 0.3) on.exit(par(saved.par)) plot(spectrum, type = l, col = blue, xlab = , ylab = , ...) title(main = x-axis label overwritten by tick values, xlab = Index, ylab = Intensity) } grdev() plotFixMe(rnorm(50)*2, ylim = c(0, 5)) Paul, This is the Y axis label, not the X axis. Set par(mar) prior to creating the plot to increase the left hand margin space and then use mtext() rather than title() to move the Y axis label further left by using the 'line' argument. grdev - function(...) { get(getOption(device))(...) } plotFixMe - function(spectrum, ...) { saved.par - par(las = 1, tcl = 0.3) on.exit(par(saved.par)) par(mar = c(5, 6, 4, 2)) plot(spectrum, type = l, col = blue, xlab = , ylab = , ...) title(main = x-axis label overwritten by tick values) mtext(1, text = Index, line = 3) mtext(2, text = Intensity, line = 5, las = 3) } grdev() plotFixMe(rnorm(50)*2, ylim = c(0, 5)) See ?par and ?mtext for more information. BTW, I would not use 'tcl = 0.3' which, as a positive value, places the tick marks themselves within the plot region. That's contrary to typical guidance, since the tick marks get lost in this plot and more importantly, can overwrite data points in certain plot types. HTH, Marc Schwartz __ 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] questions about R
On Sat, 2005-10-01 at 08:59 -0700, James Anderson wrote: Hi, I am new to R. I have one question about outputing files in a loop; Suppose I have the following loop: for (i in 1:10) { temp = 100*2 matrix; } I want to output the value of temp into 10 files with each file containing the number of looping index (i.e, file1.csv, file2.csv, ...) without headers. How can I realize this? Thanks. James See ?write.table for the file creation and ?paste for creating the filenames themselves: for (i in 1:10) { temp = matrix(rnorm(200), ncol = 2) write.table(temp, file = paste(file, i, .csv, sep = ), row.names = FALSE, col.names = FALSE, sep = ,) } HTH, Marc Schwartz __ 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] List Email Statistic
Indeed. I was not aware of the additional non-usenet statistics Google Groups. Some familiar names on the MEDSTATS list... :-) Thanks Adai. Marc On Sat, 2005-10-01 at 18:17 +0100, Adaikalavan Ramasamy wrote: This also depends on which field you are interested in, for example MEDSTATS (http://tinyurl.com/bwha8) ED-STATS (http://lists.psu.edu/archives/edstat-l.html) and a few more http://tinyurl.com/a8wo4 Regards, Adai On Fri, 2005-09-30 at 07:32 -0500, Marc Schwartz wrote: On Thu, 2005-09-29 at 23:47 -0500, José Raul Capablanca wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. If you have access to Usenet either via an NNTP server or via Google Groups, there are three principal groups for general statistics discussion: sci.stat.consult (http://groups.google.com/group/sci.stat.consult) sci.stat.math(http://groups.google.com/group/sci.stat.math) sci.stat.edu (http://groups.google.com/group/sci.stat.edu) There is a greater level of volume on the first two for general discussion. sci.stat.edu (which is targeted more to statistics education discussion) has been split off as a gateway to the edstat-L list, which has substantively reduced its daily volume. HTH, Marc Schwartz __ 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] Y-Axis Label Overwritten By TickMark Values
On Sat, 2005-10-01 at 16:00 -0500, Paul Roebuck wrote: On Sat, 1 Oct 2005, Marc Schwartz wrote: On Sat, 2005-10-01 at 06:07 -0500, Paul Roebuck wrote: Can someone tell me how to fix the left margin of plot region such that the tick values don't overwrite the x-axis label? I haven't been able to set the correct par option to fix this... This is the Y axis label, not the X axis. Oops. I'd been up all night... Been there, done that... ;-) Set par(mar) prior to creating the plot to increase the left hand margin space and then use mtext() rather than title() to move the Y axis label further left by using the 'line' argument. [SNIP code] See ?par and ?mtext for more information. What a black art. Pray tell where you learned this that I may study there as well. In at least one of my prior attempts, I had used par(mar) but hadn't realized that title(ylab) would have to be changed; it just didn't seem (to me anyway) like wanting to display slightly larger numbers as tickmark values would have required using other low-level plot commands. Look under the Documentation/Manuals link on the R Home page and read through An Introduction to R. That's the place to start. Searching the e-mail list archives is yet another resource: http://finzi.psych.upenn.edu/search.html There is also a relatively new R Graphics Gallery (with code) here: http://addictedtor.free.fr/graphiques/index.php shameless plug Paul Murrell's new book R Graphics More info here: http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html /shameless plug After about a hour of trying different options, I found myself really wanting to use the R Plot Wizard(TM) that lets you interactively set the LAF of the plot, then generates the appropriate R code to make it so. No MS-like Wizards here...Only the intelligent human ones ;-) BTW, I would not use 'tcl = 0.3' which, as a positive value, places the tick marks themselves within the plot region. That's contrary to typical guidance, since the tick marks get lost in this plot and more importantly, can overwrite data points in certain plot types. Was emulating Matlab's plot output and that's how it places tickmarks (for better or worse). I actually needed to place tickmarks on all sides but hadn't found that option yet. I'd say for worse...See Cleveland and/or Tufte for references. There is a foundational reason for the way R does things: Sensible Defaults. See ?axis (using 'side = 3' and 'side = 4') for more information here. HTH, Marc Schwartz __ 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] multiple line plots
On Wed, 2005-10-05 at 22:19 +1000, sosman wrote: I have some data in a CSV file: time,pos,t,tl 15:23:44:350,M1_01,4511,1127 15:23:44:350,M1_02,4514,1128 15:23:44:350,M1_03,4503,1125 ... 15:23:44:491,M2_01,4500,1125 15:23:44:491,M2_02,4496,1124 15:23:44:491,M2_03,4516,1129 ... 15:23:44:710,M3_01,4504,1126 15:23:44:710,M3_02,4516,1129 15:23:44:710,M3_03,4498,1124 ... Each pos (eg M1_01) is an independent time series. I would like to plot each time series as lines on a single plot and I wondered if there was something more straight forward than I was attempting. I got as far as: fname = 't100.csv' t = read.csv(fname) tpos = split(t, t$pos) plot(tpos[[M1_01]]$t, type='l') for (p in names(tpos)) { lines(tpos[[p]]$t) } which seems to work but then I got stuck on how to make each line a different colour and figured that there might a be a one liner R command to do what I want. Any tips would be appreciated. See the examples in ?plot.ts for some approaches. You will need to review ?ts to create time series objects from your data to be used in plot.ts(). Another approach, which is not specific to time series, is ?matplot. HTH, Marc Schwartz __ 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 control ticks in plots with yasp or xasp
On Sat, 2005-10-08 at 09:28 -0400, Denis Chabot wrote: Hi, A few times I tried to control the number and position of tick marks in plots with the yasp or xasp parameters. For example, a y axis was drawn by default with tick marks at 0, 20, 40, 80 and 100. I tried to get tick marks every 10 by adding yasp=(0, 100, 10) but this had no effect at all. I know I can draw the axis and tick marks manually, but often this simple option would suffice if I could understand how to make it work. Thanks in advance, Denis Chabot I suspect that one problem you are having is that there is no par(xasp) or par(yasp)unless these are typos and you are trying to use par(xaxp) and par(yaxp)? There is an 'asp' argument to some of the plot functions (ie. plot.default), but this has a different intention. par(xaxp) and par(yaxp) are not listed as read only pars in ?par, however, I cannot recall an instance where R does not overwrite the user settings during the calculation of the axes, whether passed as arguments to a plot function or set a priori via a par() call. If you want explicit control over the tick marks, you will need to use axis(), perhaps in combination with axTicks(), after using 'xaxt = n' and/or 'yaxt = n' in the plot call, depending upon the circumstances. HTH, Marc Schwartz __ 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 control ticks in plots with yasp or xasp
On Sat, 2005-10-08 at 16:37 +0100, Prof Brian Ripley wrote: On Sat, 8 Oct 2005, Marc Schwartz wrote: On Sat, 2005-10-08 at 09:28 -0400, Denis Chabot wrote: Hi, A few times I tried to control the number and position of tick marks in plots with the yasp or xasp parameters. For example, a y axis was drawn by default with tick marks at 0, 20, 40, 80 and 100. I tried to get tick marks every 10 by adding yasp=(0, 100, 10) but this had no effect at all. I know I can draw the axis and tick marks manually, but often this simple option would suffice if I could understand how to make it work. Thanks in advance, Denis Chabot I suspect that one problem you are having is that there is no par(xasp) or par(yasp)unless these are typos and you are trying to use par(xaxp) and par(yaxp)? In any case, (0, 100, 10) is invalid syntax, and c(0, 100, 10) is needed. Indeed. There is an 'asp' argument to some of the plot functions (ie. plot.default), but this has a different intention. par(xaxp) and par(yaxp) are not listed as read only pars in ?par, however, I cannot recall an instance where R does not overwrite the user settings during the calculation of the axes, whether passed as arguments to a plot function or set a priori via a par() call. Really? Try plot(1:100, xaxt=n) par(xaxp=c(0, 50, 5)) # the value is reset at each plot axis(1) for how it works (but not inline, which is probably a bug). AhI had not thought about that 'par'ticular combination... ;-) Hence, not R.O. So it must be used _after_ a plot call, which makes sense. I had reached for my copy of Paul's book and on page 96 (last paragraph in section 3.4.5 on Axes), he suggests using the approach I elucidate below with axTicks(). I thought he might have some other ideas and that I was missing something. This is also referenced on page 70, third paragraph in section 3.2.5 on Axes. If you want explicit control over the tick marks, you will need to use axis(), perhaps in combination with axTicks(), after using 'xaxt = n' and/or 'yaxt = n' in the plot call, depending upon the circumstances. That is usually as easy. Agreed. Thanks, Marc __ 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] greek symbols using pch
On Mon, 2005-10-10 at 12:02 +1000, FISCHER, Matthew wrote: Hi R-users, In a plot, can I specify pch to be a greek symbol? (I looked at show.pch() in the Hmisc package but couldn't see the right symbols in there). If not, I guess I can get around this using text(x,y,expression()). cheers!, Matt. You will need to use text() in order to plot greek characters as plotting symbols. The 'pch' argument (or par(pch)) must be a single character or an integer specifying one of the symbols as seen in ?points or as you noted in Frank's show.pch(). See ?plotmath for more information on plotting mathematical expressions. HTH, Marc Schwartz __ 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] text(x,y,greek character)
On Mon, 2005-10-10 at 07:59 -0400, Roy Little wrote: Dear list, I would like to plot points with two types of labels, one at the data point (the name of the point) and another offset a bit with another factor which is either of the two greek characters alpha or beta. I have tried to get the routine to plot a greek character with expression() or with substitute() and have not yet had any success. The following only plots the word in english in plain text. Here is my subroutine and data: --- vmat-as.matrix(read.table(vmat)) Xm-vmat[1:22,1:20] hemd-read.table(threehem,header=T) Ym-as.matrix(hemd[,2]) gvdw.pls-plsr(Ym ~ Xm,6,method=kernelpls) rsltv-predict(gvdw.pls,comps=6) plot(Ym,rsltv,type=n,xlab=Actividad + Biológica,xlim=c(4.6,6),ylim=c(4.8,6),ylab= Act. + Biol.(Pred.),main=QSAR Ligación de Derivados de la Artemisina con + Hemina,sub=Descriptores de Coeficientes VdW) text(Ym,rsltv,labels=threehem$cpd) text(Ym,rsltv,labels=hemd$type,adj=c(0,-1)) - snip of data I believe I have a solution for you, but you may want to consider the presentation, as it gets a bit busy. Perhaps consider using two colors for the numeric text, where each color represents either alpha or beta and then indicate this in a legend. This could be done using: cols - ifelse(hemd$type == alpha, red, blue) text(Ym,rsltv,labels=hemd$cpd, col = cols) legend(topleft, legend = c(expression(alpha), expression(beta)), fill = c(red, blue)) Also, two notes: 1. If you are going to use a function that is not in the base R distribution, please indicate this so that folks can help without having to search. In this case, the plsr() function is in the pls package, which required a library(pls) before using your code. 2. The line: text(Ym,rsltv,labels=threehem$cpd) should be: text(Ym,rsltv,labels=hemd$cpd) Here is a solution: greek - parse(text = as.character(hemd$type)) text(Ym, rsltv, labels = greek, adj=c(0, -1)) hemd$type is a factor, so it needs to be converted to a character vector before being able to be used as an expression. Using parse() then converts the character vector to an expression. The result of the first line is: greek expression(alpha, beta, alpha, beta, beta, beta, beta, beta, beta, beta, alpha, alpha, alpha, alpha, alpha, alpha, alpha, alpha, beta, beta, alpha, alpha) Thus, 'greek' can be used in text() as an expression. HTH, Marc Schwartz __ 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] Writing to a file with fixed precision
On Mon, 2005-10-10 at 19:50 -0400, Richard Hedger wrote: Hi, I'm trying to ouput to a filled with a fixed precision: eg. if I have data x=c(1.0,1.4,2.0), I want to be able to ouput the following to a file: 1.00 1.40 2.00 I was wondering if there was a function to do this in R? Thanks, Richard It is possible that someone has written such a function somewhere. However, this is relatively easy using write.table(). You just need to pre-format the numeric values prior to writing to the file: write.table(sprintf(%.14f, x), data.txt, col.names = FALSE, row.names = FALSE, quote = FALSE) Using sprintf(), we force the floats to have 14 decimal places. sprintf() outputs character vectors, so we remove the quoting of the resultant character vectors and don't write column/row names. Note that if 'x' is a matrix, using sprintf() will return a vector. So you might want to use the following instead to retain the dims: x [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 x.fmt - apply(x, 1, function(x) sprintf(%.14f, x)) x.fmt [,1][,2][,3] [1,] 1.00 2.00 3.00 [2,] 4.00 5.00 6.00 [3,] 7.00 8.00 9.00 [4,] 10.00 11.00 12.00 write.table(x.fmt, data.txt, col.names = FALSE, row.names = FALSE, quote = FALSE) If needed, you can of course change the default delimiter from a to another character in write.table(). See ?write.table and ?sprintf. HTH, Marc Schwartz __ 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] iterative output to file by row
On Mon, 2005-10-10 at 17:04 -0700, Christina Yau wrote: Hi, I'm sort of a newbie to using R to deal with array data. I'm trying to create a simple filtering function, which outputs only the rows of a data frame that satisfies a specific criterion. I've set up an iterative loop to apply the condition to each row. I can create a new matrix and use rbind to fill it in row by row in the loop, before writing the whole matrix to file. But it seems really inefficient, especially considering my very large dataset. In fact, I'm worried it will cause memory problems if I run the function on the full data set. Each row is from a data frame and is associated with a row name and a column name. I'm wondering if there's a way to write each row that satisfy the condition to file within the iterative loop directly, while keeping the data structure. I've read the help on the 'cat' function; but I'm still not entirely sure how to use it in my situation, or if it is the correctly function to use. Any advice will be greatly appreciated. If you can do it with the full dataset, you are probably better off using subset() to select the rows that meet your criteria and then use write.table() to write the resultant smaller data frame to a file. Alternatively, if you do need to do this within the loop, you can use write.table() with the 'append' argument set to TRUE, so that each new row from the data frame that meets your criteria gets added to the existing file, rather than overwriting it. This will be a little slower, since each time write.table() is called, it opens the file, writes the line and closes the file, so there is some file I/O overhead. You don't need to create a new matrix in the loop, just pass the resultant single row of your subsetting operation to write.table(). See ?subset and ?write.table for more information. HTH, Marc Schwartz __ 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] Writing to a file with fixed precision
On Tue, 2005-10-11 at 08:42 +0100, Prof Brian Ripley wrote: On Mon, 10 Oct 2005, Marc Schwartz wrote: On Mon, 2005-10-10 at 19:50 -0400, Richard Hedger wrote: Hi, I'm trying to ouput to a filled with a fixed precision: eg. if I have data x=c(1.0,1.4,2.0), I want to be able to ouput the following to a file: 1.00 1.40 2.00 I was wondering if there was a function to do this in R? Thanks, Richard It is possible that someone has written such a function somewhere. It's called format(). x - c(1.0,1.4,2.0) write(format(x, nsmall=14)) does this. Indeed. Sorry, I was not clear in my use of words. I was thinking along the lines of a single function call such as: write.fmt(x, file = data.txt, ndigits = 14) It would of course be easy enough to create such a wrapper using existing functions. I was aware of format(), but for some reason had in the back of my mind that the use of 'nsmall' was not consistent in the decimal place output based upon prior experience. The result of which led me to use the vectorized formatC() to control such output. I then shifted to using sprintf(), when in 2.1.0, it was vectorized. Using format() also adds the benefit of having methods for matrices, etc., as opposed to sprintf(). Thanks, Marc __ 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] R and SAS pointer/informat functionality
On Tue, 2005-10-11 at 18:55 -0500, Ratnendra Sharma wrote: Hello, I hope all is well. I've gone through and searched just about all the manuals, faqs, contribs available on the data import/export process and have not found any answer to a specific question. Hopefully, I will be able to fall back upon the valuable expertise in mailing list. Here goes: How can I import SPECIFIC columns of data in a fixed width file? E.g. I have a fwf with 40 variables ranging from 1 to 10 characters and at any given time, need only a few to analyze, like so: age: 2 char sex: 1 charmorning: 1 charlocation: 3 char..family: 9 chartagged: date...weight at capture: 4 charlength at capture: 7 charetc. which looks something like: 02M1LOS...xxcanidae011289.10001291412 In essence I am looking for functionality similar to the SAS pointer/informat method. I would appreciate any help anyone would be able to give! Thanks so much for your help. best, Ratnendra Sharma U Minn You just about answered the question yourself in your second paragraph ('fwf') See ?read.fwf and note the Details section regarding the use of negative numbers for the 'widths' argument to skip columns. HTH, Marc Schwartz Greetings from Eden Prairie __ 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] adding 1 month to a date
On Tue, 2005-10-11 at 16:26 -0700, t c wrote: Within an R dataset, I have a date field called date_. (The dates are in the format -MM-DD, e.g. 1995-12-01.) How can I add or subtract 1 month from this date, to get 1996-01-01 or 1995-11-01. There might be an easier way to do this, but using seq.Date(), you can increment or decrement from a Time 0 by months: Add 1 month: This takes your Time 0, generates a 2 element sequence (which begins with Time 0) and then takes the second element: seq(as.Date(1995-12-01), by = month, length = 2)[2] [1] 1996-01-01 Subtract 1 month: Same as above, but we use 'by = -1 month' and take the second element: seq(as.Date(1995-12-01), by = -1 month, length = 2)[2] [1] 1995-11-01 See ?as.Date and ?seq.Date for more information. The former function is used to convert from a character vector to a Date class object. Note that in your case, the date format is consistent with the default. Pay attention to the 'format' argument in as.Date() if your dates should be in other formats. HTH, Marc Schwartz __ 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] bug checking
On Tue, 2005-10-11 at 16:07 -1000, Parlamis Franklin wrote: I have observed the following behavior, wondering if it is a bug before I submit a report. I am using the plot function with call: plot(X, Y, col=red, . . . ) where X is an object that inherits from classes 'dates' and 'times' (created with the 'dates' function from package 'chron') and y is a numeric vector. The color red is applied to the area from the first to the last tick mark on the x axis (even if I don't set col=red and only set, say col.main=red). If instead of feeding the function X, I feed it unclass(X) or as.vector(X) the red color is not applied to the area between the first and last ticks on the x axis. Is this a bug, or just a consequence of there not being a plot method for the class I am trying to feed the function? Franklin Parlamis As per the Posting Guide, it would be immensely helpful in the attempt to help you, if you would provide the exact code you are using and some sample data here, so that we can exactly replicate what you are experiencing. Lacking that, it would be difficult to assist as we can only guess. It does sound like there is an _appropriate_ change in the plot method behavior as a direct consequence of your modifying the class of the argument(s), which is of course how methods are dispatched. Thus, if I were to guess, this is not a bug. I would however, certainly recommend that you submit an example here to confirm the behavior, before you post a bug report, as that would avoid a more energetic response. Marc Schwartz __ 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] bug checking
Thanks for the code and the clarifications, including the PDF file. Yes, I can replicate the behavior here (R 2.2.0 on FC4) and I am cc:ing Kurt Hornik, who ported chron to R and is the chron package maintainer. It appears that the culprit is the argument 'col = red', which towards the end of plot.times() is used as follows: ... else if (x.times) axis.times(1, x, simplify = simplify, labels = TRUE, adj = adj, col = col, cex = cex, font = font, las = las, lab = lab, mgp = mgp, tcl = tcl) ... Thus, if the 'x' data is of class 'times', the above code is used and the color of the axis line and tick marks are set to red as per the 'col' argument to axis(), which axis.times() ultimately calls. This results in the behavior that you are seeing, where both the plot symbols/lines and the axis are colored the same. This does sound like a bug and Kurt can comment better on this. HTH, Marc Schwartz On Tue, 2005-10-11 at 18:02 -1000, Parlamis Franklin wrote: ## Code was long, so I simplified it by creating vectors from scratch so it would run as is. Putative bug is still evidenced on the x axis discount.factors.dates - seq.dates(from=09/30/2005, to=09/30/2035) rates-seq(4.4, 5.2, by=0.0025); plot(discount.factors.dates[1:length(rates)], rates, pch=18, las=1, bty=n, col=red, col.main=red, xlab=Date, ylab=Rate, ylim=c(min(rates)-(max(rates)-min(rates))/10,max(rates)+(max (rates)-min(rates))/10)) ## This is the output: ## Hopefully you all see the red x axis. ## I am running R Cocoa GUI 1.1.2 with R 2.1.1 framework on a dual proc 2.7 Ghz Power Mac. A Quartz device is opened when 'plot' is called. X11User and X11SDK are installed on t he computer, as well as xCode 2.1 (in case that's relevant). On Oct 11, 2005, at 4:47 PM, Marc Schwartz wrote: On Tue, 2005-10-11 at 16:07 -1000, Parlamis Franklin wrote: I have observed the following behavior, wondering if it is a bug before I submit a report. I am using the plot function with call: plot(X, Y, col=red, . . . ) where X is an object that inherits from classes 'dates' and 'times' (created with the 'dates' function from package 'chron') and y is a numeric vector. The color red is applied to the area from the first to the last tick mark on the x axis (even if I don't set col=red and only set, say col.main=red). If instead of feeding the function X, I feed it unclass(X) or as.vector(X) the red color is not applied to the area between the first and last ticks on the x axis. Is this a bug, or just a consequence of there not being a plot method for the class I am trying to feed the function? Franklin Parlamis As per the Posting Guide, it would be immensely helpful in the attempt to help you, if you would provide the exact code you are using and some sample data here, so that we can exactly replicate what you are experiencing. Lacking that, it would be difficult to assist as we can only guess. It does sound like there is an _appropriate_ change in the plot method behavior as a direct consequence of your modifying the class of the argument(s), which is of course how methods are dispatched. Thus, if I were to guess, this is not a bug. I would however, certainly recommend that you submit an example here to confirm the behavior, before you post a bug report, as that would avoid a more energetic response. Marc Schwartz __ 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] bug checking
Three additional comments: 1. The same phenomena occurs on the y axis if the x and y values are reversed. 2. I neglected to mention this last night (my time), but given that chron is not part of the base R distribution, the proper procedure for actually filing a bug against the package would be to contact the author/maintainer (Kurt) and not to file a bug in the main R bug tracking system. 3. The problem with 'col.main' is I believe a result of this argument being passed as part of the ... arguments to plot.times(). Hence you end up with partial matching of the argument here, so col.main is operated upon in the same fashion as col. HTH, Marc Schwartz On Tue, 2005-10-11 at 21:06 -1000, Parlamis Franklin wrote: Thanks all for following up. I'll consider the bug filed. I should note for the record that if 'col=red' is replaced in my code by 'col.main=red' the x axis is still made red. I'll use the workaround for now (for which thanks). Even with little things like this, plotting from the command line in R is orders better than dragging a bunch of frames around an Excel window. On Oct 11, 2005, at 6:34 PM, Marc Schwartz wrote: Thanks for the code and the clarifications, including the PDF file. Yes, I can replicate the behavior here (R 2.2.0 on FC4) and I am cc:ing Kurt Hornik, who ported chron to R and is the chron package maintainer. It appears that the culprit is the argument 'col = red', which towards the end of plot.times() is used as follows: ... else if (x.times) axis.times(1, x, simplify = simplify, labels = TRUE, adj = adj, col = col, cex = cex, font = font, las = las, lab = lab, mgp = mgp, tcl = tcl) ... Thus, if the 'x' data is of class 'times', the above code is used and the color of the axis line and tick marks are set to red as per the 'col' argument to axis(), which axis.times() ultimately calls. This results in the behavior that you are seeing, where both the plot symbols/lines and the axis are colored the same. This does sound like a bug and Kurt can comment better on this. HTH, Marc Schwartz On Tue, 2005-10-11 at 18:02 -1000, Parlamis Franklin wrote: ## Code was long, so I simplified it by creating vectors from scratch so it would run as is. Putative bug is still evidenced on the x axis discount.factors.dates - seq.dates(from=09/30/2005, to=09/30/2035) rates-seq(4.4, 5.2, by=0.0025); plot(discount.factors.dates[1:length(rates)], rates, pch=18, las=1, bty=n, col=red, col.main=red, xlab=Date, ylab=Rate, ylim=c(min(rates)-(max(rates)-min(rates))/10,max(rates)+(max (rates)-min(rates))/10)) ## This is the output: ## Hopefully you all see the red x axis. ## I am running R Cocoa GUI 1.1.2 with R 2.1.1 framework on a dual proc 2.7 Ghz Power Mac. A Quartz device is opened when 'plot' is called. X11User and X11SDK are installed on t he computer, as well as xCode 2.1 (in case that's relevant). On Oct 11, 2005, at 4:47 PM, Marc Schwartz wrote: On Tue, 2005-10-11 at 16:07 -1000, Parlamis Franklin wrote: I have observed the following behavior, wondering if it is a bug before I submit a report. I am using the plot function with call: plot(X, Y, col=red, . . . ) where X is an object that inherits from classes 'dates' and 'times' (created with the 'dates' function from package 'chron') and y is a numeric vector. The color red is applied to the area from the first to the last tick mark on the x axis (even if I don't set col=red and only set, say col.main=red). If instead of feeding the function X, I feed it unclass(X) or as.vector(X) the red color is not applied to the area between the first and last ticks on the x axis. Is this a bug, or just a consequence of there not being a plot method for the class I am trying to feed the function? Franklin Parlamis As per the Posting Guide, it would be immensely helpful in the attempt to help you, if you would provide the exact code you are using and some sample data here, so that we can exactly replicate what you are experiencing. Lacking that, it would be difficult to assist as we can only guess. It does sound like there is an _appropriate_ change in the plot method behavior as a direct consequence of your modifying the class of the argument(s), which is of course how methods are dispatched. Thus, if I were to guess, this is not a bug. I would however, certainly recommend that you submit an example here to confirm the behavior, before you post a bug report, as that would avoid a more energetic response. Marc Schwartz __ 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] adding 1 month to a date
Thanks to Prof. Ripley for pointing this out. One of the approaches that I had considered here was to set up a vector of the number of days in each month (adjusting of course for leap years), and use day arithmetic to add/subtract the appropriate number of days. However, it was easier to use seq.Date() and to further consider putting a wrapper around it to make it yet even easier to use. Marc On Wed, 2005-10-12 at 13:23 +0100, Prof Brian Ripley wrote: On Wed, 12 Oct 2005, bogdan romocea wrote: Simple addition and subtraction works as well: as.Date(1995/12/01,format=%Y/%m/%d) + 30 If you have datetime values you can use strptime(1995-12-01 08:00:00,format=%Y-%m-%d %H:%M:%S) + 30*24*3600 where 30*24*3600 = 30 days expressed in seconds. Sorry, not in general, as a month is not generally of 30 days (including in your example). seq.Date is a good way to do this. -Original Message- From: Marc Schwartz [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 11, 2005 10:16 PM To: t c Cc: r-help@stat.math.ethz.ch Subject: Re: [R] adding 1 month to a date On Tue, 2005-10-11 at 16:26 -0700, t c wrote: Within an R dataset, I have a date field called date_. (The dates are in the format -MM-DD, e.g. 1995-12-01.) How can I add or subtract 1 month from this date, to get 1996-01-01 or 1995-11-01. There might be an easier way to do this, but using seq.Date(), you can increment or decrement from a Time 0 by months: Add 1 month: This takes your Time 0, generates a 2 element sequence (which begins with Time 0) and then takes the second element: seq(as.Date(1995-12-01), by = month, length = 2)[2] [1] 1996-01-01 Subtract 1 month: Same as above, but we use 'by = -1 month' and take the second element: seq(as.Date(1995-12-01), by = -1 month, length = 2)[2] [1] 1995-11-01 See ?as.Date and ?seq.Date for more information. The former function is used to convert from a character vector to a Date class object. Note that in your case, the date format is consistent with the default. Pay attention to the 'format' argument in as.Date() if your dates should be in other formats. HTH, Marc Schwartz __ 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] Newbie problem with read.table
On Wed, 2005-10-12 at 14:31 +0200, Jan Conrad wrote: Hi R, I have a seemingly simple problem. I have a table in following format (tab seperated) Njets NBjets NElec NMuon Meff HTHT3j HEAplan Plan 1 4 32 0 366.278 253.642 87.7473 1385 0.0124566 0.376712 2 3 11 0 235.19 157.688 18.2852 574.253 0.00064187 0.00528814 I read in with: ttbar-read.table(test2.dat,header=TRUE) ttbar Njets NBjets NElec NMuonMeff HTHT3j HE Aplan 1 4 3 2 0 366.278 253.642 87.7473 1385.000 0.01245660 2 3 1 1 0 235.190 157.688 18.2852 574.253 0.00064187 Plan 1 0.37671200 2 0.00528814, i.e.. the table is split after 9 variables. How come ? Thanks, Jan As per ?read.table, the default delimiter is 'sep = ', which is any whitespace. Hence, if your file is tab delimited, you need to modify your call to: ttbar - read.table(test2.dat, header = TRUE, sep = \t) HTH, Marc Schwartz __ 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] Newbie problem with read.table
On Wed, 2005-10-12 at 14:56 +0200, Roger Bivand wrote: On Wed, 12 Oct 2005, Jan Conrad wrote: Hi R, I have a seemingly simple problem. I have a table in following format (tab seperated) Njets NBjets NElec NMuon Meff HTHT3j HEAplan Plan 1 4 3 2 0 366.278 253.642 87.7473 1385 0.0124566 0.376712 2 3 1 1 0 235.19 157.688 18.2852 574.253 0.00064187 0.00528814 I read in with: ttbar-read.table(test2.dat,header=TRUE) ttbar Njets NBjets NElec NMuonMeff HTHT3j HE Aplan 1 4 3 2 0 366.278 253.642 87.7473 1385.000 0.01245660 2 3 1 1 0 235.190 157.688 18.2852 574.253 0.00064187 Plan 1 0.37671200 2 0.00528814, i.e.. the table is split after 9 variables. How come ? options(width) $width [1] 80 says what the width of your console is. Columns beyond this get wrapped gently (not each row by itself) - it can be set different values if you choose - try: ow - options(width) options(width=40) options(width) ttbar options(ow) options(width) So this is just the print function for data.frame objects doing its unsung job. A very useful function for looking at things when they don't seem to be what you think is str(), which concisely says what the structure of an object is, so str(ttbar) should tell you that it is a data frame of 10 variables and 2 observations. Thanks to Roger for this clarification. I took the splitting of the variables to be a consequence of the delimiter and not just a benign consequence of the printed output (at least I presume this is the proper interpretation of Jan's problem.) The tab character is of course included in whitespaceusing \t explicitly would be helpful if there is embedded whitespace (other than a tab) within a field. Marc Off to get another cup of coffee __ 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] shell scripts in R
On Fri, 2005-10-14 at 00:39 +0200, Benedict P. Barszcz wrote: Dnia piątek, 14 października 2005 00:13, Sundar Dorai-Raj napisał: Don't you mean system(ls)? See ?system. Arguments: command: the system command to be invoked, as a string. This is the kind of obstacles a newbie has to overcome. Whoeve is writing the documentation for R, please do not attempt to save on bytes. Life would be so much more pleasureable if only it would say as a quoted string. Jee. The phrase quoted string in my mind is redundant. If you had taken the time to review the 3 examples provided on the same page, you would have seen that all three show the use of quotes around the command and indeed two of the three use the 'ls' command specifically. Marc Schwartz __ 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] unexpected results
On Fri, 2006-07-21 at 04:36 -0700, nathan wrote: Hi, I'm just learning R and am encountering some unexpected results following a guide on the internet. If anyone can help that would be great - I think it is something about the way the data has been read in! I've read a coma delimited text data file that was saved from excel: jacs.data - read.table(/Users/natha/Desktop/JACSdata2.txt, header=TRUE, sep=,) This seemed to work fine, but then I start to get unusual results that don't seem right: The guide says that names(file.data) will give output like ID JURIS RESCODE , but I get ID.JURIS.RESCODE. The guide says that file.data[5,1] will give me the data for the 5th subject but i get: [1] 7\tACT\t\t\tSUMMONS\tACTCC321.001\tA.C.T. - MINOR THEFT (REPLACEMENT VALUE $2000 OR LESS)\ etc - which seems scrambled The guide says that file.data[var50] will give me the data for all subject who meet that condition (ie greater than 0 on var5), but I get: Error in [.data.frame(jacs.data, offend 0) : object offend not found can anyone help? Thanks nathan It would appear that your data file is NOT comma delimited, but TAB delimited. The \t characters in the output above support this, since you asked for just the first column for the 5th subject and it appears that you got the entire row. Re-run the import using: jacs.data - read.table(/Users/natha/Desktop/JACSdata2.txt, header=TRUE, sep = \t) so that you are indicating that the delimiter is a TAB character, not a comma. HTH, Marc Schwartz __ 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] Main title of plot
Gabor, I think that this is actually different, since it does not involve plotmath. The issue here is the use of c() in: main=c(maximum gain=,p) rather than: main = paste(maximum gain =, p) Marco, try this: plot(a, b, type=l, ylim=c(0, 1), xlab = freq, ylab = power, main = paste(maximum gain =,p)) See ?paste for concatenating multiple vectors into a single character vector (string). HTH, Marc Schwartz On Wed, 2006-07-26 at 07:29 -0400, Gabor Grothendieck wrote: This was just discussed yesterday. See the thread: https://www.stat.math.ethz.ch/pipermail/r-help/2006-July/109931.html On 7/26/06, Marco Boks [EMAIL PROTECTED] wrote: I am a newbie, and I am afraid this may be a rather trivial question. However I could not find the answer anywhere. I am plotting a series of plots with different values for p. In the main title of a plot I have used the following code: plot(a,b,type=l,ylim=c(0,1), xlab=freq,ylab=power, main=c(maximum gain=,p) ) That works fine. However the value of p is plotted on a new line, instead of just after the = Is there anyway to print the value of p on the same line? Thanks Marco __ 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] seq unexpected behavior
On Wed, 2006-07-26 at 18:35 -0700, Vries, Han de wrote: seq(0.1, 0.9 - 0.8, by = 0.1) gives the following error message: Error in seq.default(0.1, 0.9 - 0.8, by = 0.1) : wrong sign in 'by' argument but seq(0.1, 0.8 - 0.7, by = 0.1) gives [1] 0.1 (no error message) Why do I get an error message in the first case? Han See R FAQ 7.31 Why doesn't R think these numbers are equal? print(0.9 - 0.8, 20) [1] 0.09997780 print(0.8 - 0.7, 20) [1] 0.10008882 In the first case, the result of the subtraction is slightly less than 0.1, resulting in a negative interval. In the second case, it is slightly greater than 0.1, which is OK. HTH, Marc Schwartz __ 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] RODBC on linux
On Wed, 2006-07-26 at 17:52 -0400, Armstrong, Whit wrote: Anyone out there using Linux RODBC and unixODBC to connect to a Microsoft SQL server? If possible can someone post a sample .odbc.ini file? I saw a few discussions on the archives a few years ago, but no config file details were available. Thanks, Whit Whit, Do you have a Linux ODBC driver for SQL Server? unixODBC is simply the driver manager, not the driver itself. MS does not offer (not surprisingly) an ODBC driver for Unix/Linux. There are resources available however and these might be helpful: http://www.sommarskog.se/mssql/unix.html Note that Easysoft provides (at a cost) an ODBC-ODBC bridge for Unix/Linux platforms which supports ODBC connections to SQL Server: http://www.easysoft.com/products/data_access/odbc_odbc_bridge/index.html I am using RODBC to connect from a FC5 system to an Oracle 10g server running on RHEL, however Oracle provides the ODBC driver for Linux that can work with the unixODBC facilities. Also, note that there is a R-sig-DB e-mail list: https://stat.ethz.ch/mailman/listinfo/r-sig-db HTH, Marc Schwartz __ 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] RODBC on linux
On Wed, 2006-07-26 at 21:38 -0500, Dirk Eddelbuettel wrote: On 26 July 2006 at 20:56, Marc Schwartz wrote: | On Wed, 2006-07-26 at 17:52 -0400, Armstrong, Whit wrote: | Anyone out there using Linux RODBC and unixODBC to connect to a | Microsoft SQL server? [...] | Do you have a Linux ODBC driver for SQL Server? unixODBC is simply the | driver manager, not the driver itself. | | MS does not offer (not surprisingly) an ODBC driver for Unix/Linux. But there is the FreeTDS project (package freetds-dev in Debian) with its associated ODBC drive (package tdsodbc, from the FreeTDS sources). At some point a few years ago, a colleague and I were trying to coax that and unixOBDC to let R (on Solaris) talk to Sybase (on Solaris) and got it to work. MS-SQL is (AFAIK) a descendant of Sybase code originally licensed by MS, hence the common FreeTDS code lineage). So it should be doable. Luckily I haven't needed to talk to MS SQL myself so the usual grain of salt alert... And sorry, hence no working .odbc.ini to share. FreeTDS was one of the options listed on the first URL that I had included. :-) Here is the direct link: http://www.freetds.org/ Regards, Marc __ 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] Problems with RODBC
On Thu, 2006-07-27 at 11:16 +0200, Tomasz Puzyn wrote: Dear Michael, I have a problem with RODBC installation. When I try to install it, I get the output following output. Give me some ideas, why I can not to do it properly? Regards, Tomasz * Installing *source* package 'RODBC' ... checking for gcc... gcc 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 accepts -g... yes checking for gcc option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -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 sql.h usability... no checking sql.h presence... no checking for sql.h... no checking sqlext.h usability... no checking sqlext.h presence... no checking for sqlext.h... no configure: error: ODBC headers sql.h and sqlext.h not found ERROR: configuration failed for package 'RODBC' ** Removing '/usr/local/lib64/R/library/RODBC' The downloaded packages are in /tmp/RtmphYJYHP/downloaded_packages Warning message: installation of package 'RODBC' had non-zero exit status in: install.packages(c(RODBC)) Tomasz, You are missing the unixODBC header files, which are required to compile the package from source. You did not indicate which Linux distribution you are using, but if you are on an RPM based distribution, you need to install 'unixODBC-devel'. It looks like Debian based distributions use 'unixodbc-devel' (Note lack of capitalization). HTH, Marc Schwartz __ 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] deparse(substitute(foo))
On Thu, 2006-07-27 at 08:18 -0400, Armstrong, Whit wrote: I see that plot.default uses deparse(substitute(x)) to extract the character name of an argument and put it on the vertical axis. Hence: foo - 1:10 plot( foo ) will put the label foo on the vertical axis. However, for a function that takes a ... list as an input, I can only extract the first argument name: x - 1:10 y - 10:20 foo - function(...) { print(deparse(substitute(...))) } foo(x,y) returns: foo(x,y) [1] x and when I try to convert the list to a local variable and then extract names, that doesn't work either: x - 1:10 y - 10:20 foo - function(...) { x - list(...) print(deparse(substitute(names(x } foo(x,y) returns: foo(x,y) [1] names(list(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), c(10, 11, 12, 13, [2] 14, 15, 16, 17, 18, 19, 20))) Can someone suggest a way to extract the variable names when they are passed as a list via ... ? Thanks, Whit Try this: x - 1:10 y - 10:20 foo - function(...) { sapply(match.call()[-1], deparse) } foo(x, y) [1] x y HTH, Marc Schwartz __ 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] string-to-number
On Sat, 2006-08-19 at 13:30 +0100, Prof Brian Ripley wrote: On Sat, 19 Aug 2006, Marc Schwartz wrote: On Sat, 2006-08-19 at 07:58 -0400, Charles Annis, P.E. wrote: Greetings, Amigos: I have been trying without success to convert a character string, repeated.measures.columns [1] 3,6,10 into c(3,6,10) for subsequent use. as.numeric(repeated.measures.columns) doesn't work (likely because of the commas) [1] NA Warning message: NAs introduced by coercion I've tried many things including strsplit(repeated.measures.columns, split = ,) which produces a list with only one element, viz: [[1]] [1] 3 6 10 as.numeric() doesn't like that either. Clearly: 1) I cannot be the first person to attempt this, and 2) I've made this WAY harder than it is. Would some kind soul please instruct me (and perhaps subsequent searchers) how to convert the elements of a string into numbers? Thank you. One more step: as.numeric(unlist(strsplit(repeated.measures.columns, ,))) [1] 3 6 10 Use unlist() to take the output of strsplit() and convert it to a vector, before coercing to numeric. Or, more simply, use [[1]] as in as.numeric(strsplit(repeated.measures.columns, ,)[[1]]) Also, eval(parse(text=paste(c(, repeated.measures.columns, looks competitive, and is quite a bit more general (e.g. allows spaces, works with complex numbers), or you can use scan() from an anonymous file or a textConnection. I would say more than competitive: repeated.measures.columns - paste(1:10, collapse = ,) str(repeated.measures.columns) chr 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,4| __truncated__ system.time(res1 - as.numeric(unlist(strsplit(repeated.measures.columns, , [1] 24.238 0.192 26.200 0.000 0.000 system.time(res2 - as.numeric(strsplit(repeated.measures.columns, ,)[[1]])) [1] 24.313 0.196 26.471 0.000 0.000 system.time(res3 - eval(parse(text=paste(c(, repeated.measures.columns, ) [1] 0.328 0.004 0.395 0.000 0.000 str(res1) num [1:10] 1 2 3 4 5 6 7 8 9 10 ... str(res2) num [1:10] 1 2 3 4 5 6 7 8 9 10 ... str(res3) num [1:10] 1 2 3 4 5 6 7 8 9 10 ... all(res1 == res2) [1] TRUE all(res1 == res3) [1] TRUE Best regards, Marc __ 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] string-to-number
, there continues to be an advantage to Prof. Ripley's approach over using strsplit(). Again, one needs to develop an understanding of where the time is spent in the processing by profiling and then consider how to introduce efficiencies, which in some cases may very well require the use of compiled C/FORTRAN as may be appropriate if times become too long. HTH, Marc Schwartz __ 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] boxplot order of the levels
On Tue, 2006-08-22 at 14:27 +0200, Thomas Kuster wrote: hello i drew a boxplot with: boxplot(voxit$AGE ~ voxit$A02X) and the boxes are from left to right: Ja Leer Nein wn k.A. levels(voxit$A02X) [1] Ja Leer Nein wn k.A. 98 there are no entries with 98 but i want: Ja Nein Leer wn k.A. how can i change the order of the boxes bye thomas See the following post from last week: https://stat.ethz.ch/pipermail/r-help/2006-August/111289.html HTH, Marc Schwartz __ 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 question
On Fri, 2006-08-25 at 09:08 -0400, Catherine Carter wrote: Hi everyone, I have what may appear to be a newbie question, but I have looked everywhere I can think to look and I cannot find an answer. On page 35 of An Introduction to R the following command appears: plot(ecdf(eruptions), do.points=FALSE, verticals=TRUE). What is the do.points argument? I know what it does (suppresses printing of the points) but where can I find help on it? I want to be able to explain it fully to my students. Thanks for your help, Cathy A couple of options: 1. If you are aware of how R uses method dispatch, then you might know that the plot() function is a generic method and that plot.ecdf() is the specific method that is called when the initial argument is of class ecdf, as is the case above. Thus, using ?plot.ecdf will get you to the help page, where there is a notation in the Arguments section that the '...' arguments are then passed to plot.stepfun(). 'do.points' is passed in this fashion, so using ?plot.stepfun will then get you to the help page where 'do.points' is defined as: logical; if true, also draw points at the (xlim restricted) knot locations. 2. Using: RSiteSearch(do.points, restrict = functions) will search the online function documentation, bringing up a browser window, where the first link gets you to ?plot.stepfun. HTH, Marc Schwartz __ 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] for() loop question
On Sat, 2006-08-26 at 13:06 -0400, Wensui Liu wrote: Dear Lister, If I have a list of number, say x-c(0.1, 0.5, 0.6...), how to use a for() to loop through each number in x one by one? Thank you so much! wensui Two options: x - c(0.1, 0.5, 0.6) for (i in x) {print (i)} [1] 0.1 [1] 0.5 [1] 0.6 for (i in seq(along = x)) {print (x[i])} [1] 0.1 [1] 0.5 [1] 0.6 Which approach you take tends to depends upon what else you are doing within the loop. I would also take a look at ?sapply, depending up what is it you are doing. HTH, Marc Schwartz __ 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] Legend box line thickness
On Mon, 2006-08-28 at 17:55 -0700, Phil Turk wrote: I am merely trying to increase the line thickness, or line width, of the box drawn around the legend in a plot I am constructing. The help page on 'legend' was of no use. Does anyone have an idea on how to do this? Please respond to [EMAIL PROTECTED] Thanks! There are two options. The easier one is not immediately evident from the help page and requires reviewing the R code for the legend function, which reveals that there is an internal function called rect2(), which is built on top of rect(). It is this function that draws the outer box. The help page for rect() shows that the line width argument 'lwd' in the function defaults to par(lwd). See ?par for more information. Thus using: par(lwd = SomethingGreaterThan1) before the call to legend will set the box to a wider line thickness. Be sure to set par(lwd = 1) before any other plot calls to return to the default setting. Second, the Value section of ?legend clearly indicates: Value A list with list components rect a list with components w, h positive numbers giving width and height of the legend's box. left, top x and y coordinates of upper left corner of the box. text a list with components x, y numeric vectors of length length(legend), giving the x and y coordinates of the legend's text(s). returned invisibly. Thus, expanding on the third example in ?legend: ## right-justifying a set of labels: thanks to Uwe Ligges x - 1:5; y1 - 1/x; y2 - 2/x plot(rep(x, 2), c(y1, y2), type=n, xlab=x, ylab=y) lines(x, y1); lines(x, y2, lty=2) # Key call here temp - legend(topright, legend = c( , ), text.width = strwidth(1,000,000), lty = 1:2, xjust = 1, yjust = 1, title = Line Types) text(temp$rect$left + temp$rect$w, temp$text$y, c(1,000, 1,000,000), pos=2) # Now do the legend box using a wide line: rect(temp$rect$left, temp$rect$top - temp$rect$h, temp$rect$left + temp$rect$w, temp$rect$top + temp$rect$h, lwd = 2) It would not seem unreasonable to add new arguments to legend(), perhaps calling them box.lwd and box.lty, which can then be passed to the rect2() internal function call for the box by modifying the existing call to: rect2(left, top, dx = w, dy = h, col = bg, density = NULL, lwd = box.lwd, lty = box.lty) HTH, Marc Schwartz __ 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] Axes of a histogram
On Thu, 2006-09-07 at 14:35 +0200, Rotkiv, Rehceb wrote: Hello everyone, I would be glad if you could help out an R-beginner here... I have a vector of categorial data like this v - c(1, 1, 2, 2, 2, 3, 3, 4, 4, 4) When I do hist(v) I get the x-axis of the histogram with floating point labels: 1.0, 1.5, 2.0, etc. Is it possible to tell R that the data consists of categories, i.e. that I only want the category names (1, 2, 3, 4) on my x-axis? Thanks in advance, Rehceb Rotkiv You don't want a histogram, but a barplot: barplot(table(v)) See ?barplot and ?table HTH, Marc Schwartz __ 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] barplot: different colors for the bar and the strips
On Thu, 2006-09-07 at 06:18 -0500, Hao Chen wrote: Hi, I am using barplot and would like to know if it is possible to have bars filled with one color while use a different color for the shading lines. The following code colors the shading lines, leaving the bars in white: barplot(1:5, col=c(1:5), density=c(1:5)*5) while the colors are applied to the bars when density is removed. barplot(1:5, col=c(1:5)) I did check ?barplot and found the following: col: a vector of colors for the bars or bar components. Thanks, Hao Note the key word 'or' in the description of the 'col' argument. You need to make two separate calls to barplot(). The first using the fill colors, then the second using the shading lines AND setting 'add = TRUE', so that the second plot overwrites the first without clearing the plot device. barplot(1:5, col=c(1:5)) barplot(1:5, col = black, density=c(1:5), add = TRUE) Just be sure that any other arguments, such as axis limits, are identical between the two calls. HTH, Marc Schwartz __ 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] Kendall's tau-c
On Tue, 2006-09-12 at 15:02 +0200, Knut Wenzig wrote: Hello, I can't find a package which calculates Kendall's tau-c. There is the package Kendall, but it only calcuates Kendall's tau-b. Here is the example from ttp://www2.chass.ncsu.edu/garson/pa765/assocordinal.htm. cityriots - data.frame(citysize=c(1,1,2,2,3,3), riotsize=c(1,2,1,2,1,2), weight=c(4,2,2,3,0,4)) cityriots - data.frame(lapply(cityriots,function(x) rep(x,cityriots$weight))) xtabs(~ riotsize+citysize,cityriots) tau-c should be .57. Do you have a hint? Best regards Knut Wenzig Here is some code: # Calculate CONcordant Pairs in a table # cycle through x[r, c] and multiply by # sum(x elements below and to the right of x[r, c]) # x = table concordant - function(x) { x - matrix(as.numeric(x), dim(x)) # get sum(matrix values r AND c) # for each matrix[r, c] mat.lr - function(r, c) { lr - x[(r.x r) (c.x c)] sum(lr) } # get row and column index for each # matrix element r.x - row(x) c.x - col(x) # return the sum of each matrix[r, c] * sums # using mapply to sequence thru each matrix[r, c] sum(x * mapply(mat.lr, r = r.x, c = c.x)) } # Calculate DIScordant Pairs in a table # cycle through x[r, c] and multiply by # sum(x elements below and to the left of x[r, c]) # x = table discordant - function(x) { x - matrix(as.numeric(x), dim(x)) # get sum(matrix values r AND c) # for each matrix[r, c] mat.ll - function(r, c) { ll - x[(r.x r) (c.x c)] sum(ll) } # get row and column index for each # matrix element r.x - row(x) c.x - col(x) # return the sum of each matrix[r, c] * sums # using mapply to sequence thru each matrix[r, c] sum(x * mapply(mat.ll, r = r.x, c = c.x)) } # Calculate Kendall-Stuart Tau-c # x = table calc.KSTc - function(x) { x - matrix(as.numeric(x), dim(x)) c - concordant(x) d - discordant(x) m - min(dim(x)) n - sum(x) KSTc - (m * 2 * (c - d)) / ((n ^ 2) * (m - 1)) KSTc } calc.KSTc(with(cityriots, table(riotsize, citysize))) [1] 0.569 The above code, along with other such measures, will eventually find its way into the CrossTable() function in the gmodels CRAN package when time permits (which seems to be in short supply of late...) HTH, Marc Schwartz __ 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] hist for two sets
On Thu, 2006-09-14 at 19:37 -0400, Ethan Johnsons wrote: A quick question, please. x = c(0.0001, 0.0059, 0.0855, 0.9082) y = c(0.54, 0.813, 0.379, 0.35) where A = 1st set, B = 2nd set, C = 3rd set, D = 4th set respectivley. How do you make hist plot side by side for x y? i.e. 0.0001 and then to the right 0.54, 0.0059 and then to the right 0.813, etc. thx much You don't want a histogram, but a barplot: x - c(0.0001, 0.0059, 0.0855, 0.9082) y - c(0.54, 0.813, 0.379, 0.35) # create a two row matrix with x and y height - rbind(x, y) # Use height and set 'beside = TRUE' to get pairs # save the bar midpoints in 'mp' # Set the bar pair labels to A:D mp - barplot(height, beside = TRUE, ylim = c(0, 1), names.arg = LETTERS[1:4]) # Draw the bar values above the bars text(mp, height, labels = format(height, 4), pos = 3, cex = .75) See ?barplot, ?text and ?format (or ?formatC or ?sprintf). HTH, Marc Schwartz __ 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] group bunch of lines in a data.frame, an additional requirement
Emmanuel, I wouldn't be surprised if Gabor comes up with something, but since aggregate() can only return scalars, you can't do it in one step here. There are possibilities using other functions such as split(), tapply() or by(), but each has it own respective limitations requiring more than one step or post consolidation reformatting. You could certainly write a unified wrapper function that would do this in a single call, but unless you plan on doing this sort of operation a lot, it is probably easier with multiple calls. I suspect using Gabor's approach as he had below, combined with my own on using aggregate() (now twice) then using merge() may be the easiest. HTH, Marc On Thu, 2006-09-14 at 21:35 +0100, Emmanuel Levy wrote: Thanks Gabor, that is much faster than using a loop! I've got a last question: Can you think of a fast way of keeping track of the number of observations collapsed for each entry? i.e. I'd like to end up with: A 2.0 400 ID1 3 (3obs in the first matrix) B 0.7 35 ID2 2 (2obs in the first matrix) C 5.0 70 ID1 1 (1obs in the first matrix) Or is it required to use an temporary matrix that is merged later? (As examplified by Mark in a previous email?) Thanks a lot for your help, Emmanuel On 9/13/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: See below. On 9/13/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Thanks for pointing me out aggregate, that works fine! There is one complication though: I have mixed types (numerical and character), So the matrix is of the form: A 1.0 200 ID1 A 3.0 800 ID1 A 2.0 200 ID1 B 0.5 20 ID2 B 0.9 50 ID2 C 5.0 70 ID1 One letter always has the same ID but one ID can be shared by many letters (like ID1) I just want to keep track of the ID, and get a matrix like: A 2.0 400 ID1 B 0.7 35 ID2 C 5.0 70 ID1 Any idea on how to do that without a loop? If V4 is a function of V1 then you can aggregate by it too and it will appear but have no effect on the classification: aggregate(DF[2:3], DF[c(1,4)], mean) V1 V4 V2 V3 1 A ID1 2.0 400 2 C ID1 5.0 70 3 B ID2 0.7 35 Many thanks, Emmanuel On 9/12/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort of apply shortcut but I can't figure it out. Please note that it is not exactly a matrix I'm using, the function typeof tells me it's a list, however I access to it like it was a matrix. Could someone help me with the right function to use, a help topic or a piece of code? Thanks, Emmanuel __ 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-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] LARS for generalized linear models
On Fri, 2006-09-15 at 18:49 -0400, Ravi Varadhan wrote: Hi, Is there an R implementation of least angle regression for binary response modeling? I know that this question has been asked before, and I am also aware of the lasso2 package, but that only implements an L1 penalty, i.e. the Lasso approach. Madigan and Ridgeway in their discussion of Efron et al (2004) describe a LARS-type algorithm for generalized linear models. Has anyone implemented this in R? Thanks for any help. Best, Ravi This just came up last month. See this post: https://stat.ethz.ch/pipermail/r-help/2006-August/111352.html HTH, Marc Schwartz __ 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] Insert R code in LaTeX document
On Sun, 2006-09-17 at 16:45 +0200, Alexandre Depire wrote: Hello, i would like to insert R code in LaTeX document. I see something about the 'listings' package, but i would like if it is the best way and if it is possible to use the command \include{programme.R}. I have the following solution but it doesn't work with \include and \input == LaTex == main.tex -- \documentclass{report} \usepackage{listings} \lstloadlanguages{R} \begin{document} \include{annexe} \end{document} annexe.tex --- The code is: \lstset{language=R} #\include{} or \input or direct code ??? R code # test rm(list=ls()) x-1:10 mean(x) Depending upon how much functionality you actually need, using the 'verbatim' environment may be easier: \begin{verbatim} R Code Here \end{verbatim} Then you don't need the rest of the LaTeX packages and associated code. The verbatim environment will use a monospace font by default. It is available by default in LaTeX, but you can also load the verbatim package (\usepackage{verbatim}) for a better implementation. The verbatim environment also provides a \verbatiminput{FileName} command that will enable you to insert a text file that will automatically be put in a verbatim environment: \verbatiminput{FileName.R} The listings package provides a lot of other functionality such as syntax highlighting, line numbers and so forth. I presume, given what you have above, that you have already looked at the manual for the package. If not and you are mimicking some online examples, then you might want to review it: ftp://indian.cse.msu.edu/pub/mirrors/CTAN/macros/latex/contrib/listings/listings-1.3.pdf In either case, if you have an external file, you don't want to use \include, as that is for .tex files specifically. The file argument is the base name of the file only, without the extension and .tex is presumed. Thus, you want to use \input, where you can specify the full FileName.R as the argument: \input{FileName.R} If you just have a small amount of R code to include, then just put it in the body of your main .tex file and you don't have to worry about multiple files or using \input, etc. HTH, Marc Schwartz __ 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] Thousand separator in format of axis
On Sun, 2006-09-17 at 17:47 -0400, Ruben Roa Ureta wrote: Hi: How can i make that the numbers in the tick annotations of an axis be written as, say 20 000 and not 2 (i.e. with the little gap seprating thousands)? Thanks Ruben There are several ways to format numbers: ?format ?sprintf ?formatC A quick example: y - seq(0, 10, 1) # Set the y axis so that it does not get drawn # See ?par plot(1:11, y, yaxt = n, ylab = ) # Use formatC() and set 'big.mark' to # See ?axis also axis(2, at = y, labels = formatC(y, big.mark = , format = d), las = 2) HTH, Marc Schwartz __ 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] Cochrans Q Test
On Mon, 2006-09-18 at 14:01 +1000, [EMAIL PROTECTED] wrote: Hi! I would like to conduct a Cochran`s Q Test in R, but have not found any suitable function. My first idea was: J - as.table(matrix(c(6,16,2,4),ncol=2, dimnames = list(C = c(Favorable,Unfavorable),Drug A Favorable=c(B Favorable,B Unfavorable L - as.table(matrix(c(2,4,6,6),ncol=2, dimnames = list(C = c(Favorable,Unfavorable),Drug A Unfavorable=c(B Favorable,B Unfavorable mantelhaen.test(J,L, alternative=t) But this is obviously the wrong function. The CMH test does not consider the dependent nature of the measurements, so it is indeed the wrong test, if you have dependent measures as your data 'K' below would suggest. Cochran's Q is a generalization of the McNemar paired chi square. Then I googled and found (different data): K - as.table(matrix(c(1,1,0,0, 1,1,0,1, 1,1,1,1, 1,1,1,1, 1,0,0,0, 1,1,1,1, 1,1,1,1, 0,0,0,0, 0,1,0,1, 1,1,1,1, 0,1,0,1, 0,1,0,1),ncol=12, dimnames = list(Seating type = c(I,II,III,IV),Test subject=c(A,B,C,D,E,F,G,H,I,J,K,L K pcochran(K,4,12) But R said that this function does not exist. Can anyone help? Here is a version of the Cochran's Q that I wrote and posted to sci.stat.consult back in June in response to a thread there. This is based upon Sheskin's Handbook of Parametric and Nonparametric Statistical Procedures (2004) page 867. You might want to secure a copy of the book and review the comments regarding the assumptions underlying this test and the considerations for it use. cochranq.test - function(mat) { k - ncol(mat) C - sum(colSums(mat) ^ 2) R - sum(rowSums(mat) ^ 2) T - sum(rowSums(mat)) num - (k - 1) * ((k * C) - (T ^ 2)) den - (k * T) - R Q - num / den df - k - 1 names(df) - df names(Q) - Cochran's Q p.val - pchisq(Q, df, lower = FALSE) QVAL - list(statistic = Q, parameter = df, p.value = p.val, method = Cochran's Q Test for Dependent Samples, data.name = deparse(substitute(mat))) class(QVAL) - htest return(QVAL) } Using your matrix 'K': K Test subject Seating type A B C D E F G H I J K L I 1 1 1 1 1 1 1 0 0 1 0 0 II 1 1 1 1 0 1 1 0 1 1 1 1 III 0 0 1 1 0 1 1 0 0 1 0 0 IV 0 1 1 1 0 1 1 0 1 1 1 1 cochranq.test(K) Cochran's Q Test for Dependent Samples data: K Cochran's Q = 23.9298, df = 11, p-value = 0.01303 BTW, a quick Google search shows that the pcochran() function is in the 'outliers' package on CRAN, which also has a cochran.test() function HTH, Marc Schwartz __ 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] R data query
On Thu, 2006-09-21 at 13:07 +0100, Al-Kharusi, L. wrote: Dear Sir/Madam, I am encountering one of those alien computer momements one finds every so often in life. See the sequence below: fish3.fis -read.csv(emperor2.csv, check.names = TRUE, strip.white = TRUE) colnames(fish3.fis) [1] Month YearFishingArea SumOfTotalCatch CPUE [6] rCPUE PA LatitudeLongitude Depth [11] SST hist(CPUE) Error in hist(CPUE) : Object CPUE not found So, the system knows CPUE exists, but will not do a hist or a gam model using the term - but for some strange reason it will do a plot. I have created a completely different data file and that same problem is happening. The imported files are exactly the same as I was using quite happily last month. As you will see from the above I've tried adding check.names and strip.white in the reading in process to avoid the unseen effect of blank spaces. Any ideas what I might do next? Have you come across this issue at all? Thanks CPUE is not found, as it is a column within the R data frame object fish3.fis. There are (at least) 5 ways to do a histogram on CPUE: 1. attach() the data frame, which puts it in the search path and you can then use the column name alone: attach(fish3.fis) hist(CPUE) detach(fish3.fis) 2. Identify the column using the '$' function: hist(fish3.fis$CPUE) 3. Use with() to evaluate the hist() call within the environment of the data frame: with(fish3.fis, hist(CPUE)) 4. Use the [ function: hist(fish3.fis[, CPUE]) 5. Use the [[ function: hist(fish3.fis[[CPUE]]) This is covered in An Introduction to R. HTH, Marc Schwartz __ 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] Print and supressing printing in function
On Sun, 2006-09-24 at 11:31 -0700, Jonathan Greenberg wrote: Another newbie question for you all: In a function, say I have: countme - function() { for(i in 1:10) { i } } How do I get R to print i as it runs (e.g. By calling countme) -- right now it seems to supress most output. On a related note, my program uses remove.vars, which always prints its output -- how to I *supress* that output? Thanks! You need to explicitly print() the value. Thus: countme - function() { for(i in 1:10) { print(i) } } countme() [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 HTH, Marc Schwartz __ 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] Print and supressing printing in function
On Sun, 2006-09-24 at 14:14 -0500, Sundar Dorai-Raj wrote: Marc Schwartz said the following on 9/24/2006 1:56 PM: On Sun, 2006-09-24 at 11:31 -0700, Jonathan Greenberg wrote: Another newbie question for you all: In a function, say I have: countme - function() { for(i in 1:10) { i } } How do I get R to print i as it runs (e.g. By calling countme) -- right now it seems to supress most output. On a related note, my program uses remove.vars, which always prints its output -- how to I *supress* that output? Thanks! You need to explicitly print() the value. Thus: countme - function() { for(i in 1:10) { print(i) } } countme() [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 HTH, Marc Schwartz (Answering remove.vars question) Please read ?remove.vars. (You neglected to mention this function is part of the gdata package.) There is an info argument you want to set to FALSE. Thanks for noticing my oversight Sundar. Marc __ 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
On Wed, 2006-09-27 at 18:29 -0400, Mohsen Jafarikia wrote: Dear all, I want to design a histogram and I need to have the frequency at certain points. For example I have the following 2 columns: *X Y* 0.125 0.422 0.45 11 0.55 21 I want the chart to have 4 columns. First column is from 0.0-0.1 (on X) and frequency is 25. Next colum is wider and form 0.1-0.4 with 22 frequency. Next column is narrow with 11 frequency and the last column is the same as the first one with 21 frequency. Can anybody tell me how I can have this chart. Thanks, Mohsen How about this: X - c(0, 0.1, 0.4, 0.45, 0.55) Y - c(25, 22, 11, 21) barplot(Y, space = 0, width = diff(X)) axis(1) See ?barplot and ?diff HTH, Marc Schwartz __ 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] Writing Text into Plots
On Thu, 2006-10-05 at 22:10 +0200, Lothar Botelho-Machado wrote: Hello, I have a simple question on the text() method in plots, e.g.: text(3,4,adj=1,cex=1.0, expression(alpha == beta)) I know there exists a lot more like frac(), etc which could be used for expression. But a help(frac) doesn't return any results - where do I have to look for a documentation of possible text commands? More in detail I'm searching for how to set an index like mu_{1} and mu_{2} ? And how to get something like a bar over a character like \bar x ? See ?plotmath, which BTW, is listed in the See Also section of ?text HTH, Marc Schwartz __ 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] Aggregate Values for All Levels of a Factor
On Thu, 2006-10-05 at 15:44 -0700, Kaom Te wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello, I'm a novice user trying to figure out how to retain NA aggregate values. For example, given a data frame with data for 3 of the 4 possible factor colors(orange is omitted from the data frame), I want to calculate the average height by color, but I'd like to retain the knowledge that orange is a possible factor, its just missing. Here is the example code: data - data.frame(color = factor(c(blue,red,red,green,blue), levels = c(blue,red,green,orange)), height = c(2,8,4,4,5)) aggregate(data$height, list(color = data$color), mean) color x 1 blue 3.5 2 red 6.0 3 green 4.0 Instead I would like to get color x 1 blue 3.5 2red 6.0 3 green 4.0 4 orange NA Is this possible. I've read as much documentation as I can find, but am unable to find the solution. It seems like something people would need to do. So I would assume it must be built in somewhere or do I need to write my own version of aggregate? Thanks in advance, Kaom If you review the Details section of ?aggregate, you will note: Empty subsets are removed, ... Thus, one approach is: tmp - tapply(data$height, data$color, mean, na.rm = TRUE) tmp bluered green orange 3.56.04.0 NA DF - data.frame(color = names(tmp), mean.height = tmp, row.names = seq(along = tmp)) DF color mean.height 1 blue 3.5 2red 6.0 3 green 4.0 4 orange NA HTH, Marc Schwartz __ 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 about error of non-numeric argument to binary operator
On Tue, 2006-10-10 at 22:35 -0400, Yulei Gong wrote: Hi, I have the following data and there is no binary operator contained, however, I still receive the error message when running unitrootTest function, could someone give me a guidance on it?? readClipboard() [1] 245246261.5 275.5 307284.5 289313.5 323.75 334 312.5 325305.5 322.5 317310.5 [17] 302301305287277.5 271 271.5 278.5 279271263262262271262257 [33] 251.5 258 252.5 254.5 253251.5 255 253253243238.5 234229.5 230.5 237.5 235.5 [49] 238225227.5 233236.5 236.5 231.5 225221.5 221.5 221.5 221.5 221.5 221.25 221 206 [65] 207.5 196192.5 193.5 186 197.5 193.5 201195183185.5 181.5 179177173 169.5 [81] 173178169173167 158.5 169.5 164145127.5 132131131120120.5 120.25 [97] 120 112.5 114.5 106113111113118.5 131131146.5 133.5 128132 130.5 122 [113] 122.5 123.5 126140132140143 148168162.5 152.5 148144144150.5 151 [129] 156156156152156 153.5 137 135140135138.5 139130131125 125 [145] 121.5 125.5 128128129.5 133129.5 140154.5 167.5 156179 178.5 174188 214 [161] 197.5 181.5 181.5 197.5 191.5 179189.5 184.5 183182 182.5 177191198191180.5 [177] 182183.5 183182 189.5 195208 203194176.5 173173174165.5 163 162.5 [193] 159162.5 171168.5 164158147 149149.5 144141 138.5 138136138 140 [209] 135132.5 130.75 129129.5 126127 128.5 127.5 124117119120.5 122129133 [225] 136137133133127123122 117122126126133 127.5 129130 125 [241] 122126.5 136148147150.5 143.5 138.5 134135 135.75 136.5 132129127.5 118.5 x-readClipboard() unitrootTest(x) Error in r[i1] - r[-length(r):-(length(r) - lag + 1)] : non-numeric argument to binary operator I also try to do simple code with it, and getting error message as well, such as for(j in 1:length(x)){w-x/1} Error in x/1 : non-numeric argument to binary operator Thanks for your help! Yulei Your 'x' is a character vector, not numeric. The tip is that the values are surrounded by double quotes. Thus, you are trying to use operators intended for numerics on characters. For example: x - c(122, 126.5, 136, 148, 147, 150.5, 143.5) x [1] 122 126.5 136 148 147 150.5 143.5 x / 1 Error in x/1 : non-numeric argument to binary operator is.numeric(x) [1] FALSE is.character(x) [1] TRUE It's not clear from your post how you read in the data originally. You should review that process or alternatively, coerce 'x' to numeric: x.num - as.numeric(x) x.num [1] 122.0 126.5 136.0 148.0 147.0 150.5 143.5 x.num / 1 [1] 122.0 126.5 136.0 148.0 147.0 150.5 143.5 HTH, Marc Schwartz __ 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] impossible escape?
On Wed, 2006-10-11 at 13:30 -0400, Charles Annis, P.E. wrote: Greetings: I've searched the R archives with no luck. I want to print this to the screen as part of on-screen instructions as an example: default.FACTOR.labels - c(Probe1, Probe2, Probe3) I can't seem to trick gsub() gsub(', \, default.FACTOR.labels - c('Probe1', 'Probe2', 'Probe3'))) [1] default.FACTOR.labels - c(\Probe1\, \Probe2\, \Probe3\)) ^ ^ ^ ^ ^ ^ which gives me \ rather than Is it possible to escape the character? Thanks. Charles Annis, P.E. You don't need the gsub() and you want to use cat() to output the text: cat(default.FACTOR.labels - c(\Probe1\, \Probe2\, \Probe3 \)\n) default.FACTOR.labels - c(Probe1, Probe2, Probe3) cat() will properly interpret and output the escaped characters. The newline character \n will return the cursor to the next line, so that the R prompt is not at the end of the last line output. HTH, Marc Schwartz __ 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 about error of non-numeric argument to binary operator
Yulei, It would appear that the default mechanism for the function (which appears to be Windows specific) is to read in the data from the current system clipboard as a _character vector_. Thus, perhaps something like: x.num - as.numeric(readClipboard()) would be helpful. With respect to reading in Excel files, you cannot directly import Excel files using read.table() and friends. You can export from Excel to an ASCII delimited file and then use these functions. Alternatively, there is the read.xls() function in the 'gdata' CRAN package, which can directly read such files. I would strongly advise reviewing the R Import/Export Manual, which is available from the menus in the Windows GUI, as it will provide guidance in this area. HTH, Marc On Wed, 2006-10-11 at 14:25 -0400, Yulei Gong wrote: Thanks, Marc, I tried it and it didn't really work. x.num-as.numeric(x) is.numeric(x.num) [1] TRUE x.num-readClipboard() is.numeric(x.num) [1] FALSE is.character(x.num) [1] TRUE I use readClipboard to take in data, and it seems after the data is taken in, x.num changed to character. I just start using R, not familiar with the data import/export functions...besides of that, I have a question about read.table, can this function read in spreadsheet data? if so, is the excel file supposed to put in the same directory with the R-2.4.0 folder?? Which is what I did, but I got the following error read.table(bra5y.xls,header = TRUE, row.names = 2) Error in read.table(bra5y.xls, header = TRUE, row.names = 2) : object bra5y.xls not found Pls help. Thanks! __ 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] sending help output to a file
On Thu, 2006-10-12 at 10:22 -0400, Leeds, Mark (IED) wrote: when i do ?whatever at the R prompt ( i use linux ), the help comes up but it comes up like a man page. i would prefer to send it to a file. i did a ?help and it says something about sending the output to a file but nothing specific enough that i can figure out what to do. the help page talks about a parameter called type but as far as i can tell, there is no type parameter in the call to the help function ? if someone could tell me how to send output to a file instead of the screen, i would really appreciate it. thanks. also , i am using linux but i haven't figured out what kind or what version #. Typically, R's help files are already available as text files. They are usually in: $R_HOME/library/PACKAGENAME/help where $R_HOME on Linux is usually: R.home() [1] /usr/local/lib/R Note that if you might prefer that help files come up in a browser window (ie. Firefox), you can set: options(htmlhelp=TRUE) in your ~/.Rprofile. In this way, they won't come up in the pager within the terminal console. See ?options and section 10.8 in the Intro to R Manual. WRT to the Linux version, most recent versions support the LSB command of: $ lsb_release -a LSB Version::core-3.0-ia32:core-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch Distributor ID: FedoraCore Description:Fedora Core release 5 (Bordeaux) Release:5 Codename: Bordeaux You can also get kernel version information with: $ uname -a Linux horizons 2.6.17-1.2187_FC5 #1 Mon Sep 11 01:17:06 EDT 2006 i686 i686 i386 GNU/Linux HTH, Marc Schwartz __ 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] avoiding a loop?
On Thu, 2006-10-12 at 12:43 -0400, Charles Annis, P.E. wrote: I have a vector, (not a list) repeated.measures.FACTOR.names [1] Insp1 Insp2 Insp3 Insp4 Insp5 Insp6 Insp7 Insp8 Insp9 and would like to convert this into a single string Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9 I can do that with a loop, but isn't there a more elegant way? result - repeated.measures.FACTOR.names[[1]] for(i in 2:length(repeated.measures.FACTOR.names)) { result - paste(result, repeated.measures.FACTOR.names[[i]], sep=,) } result [1] Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9 paste() is vectorized and note the use of 'collapse' in lieu of 'sep': paste(repeated.measures.FACTOR.names, collapse = ,) [1] Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9 HTH, Marc Schwartz __ 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] avoiding a loop?
On Thu, 2006-10-12 at 12:07 -0500, Marc Schwartz wrote: On Thu, 2006-10-12 at 12:43 -0400, Charles Annis, P.E. wrote: I have a vector, (not a list) repeated.measures.FACTOR.names [1] Insp1 Insp2 Insp3 Insp4 Insp5 Insp6 Insp7 Insp8 Insp9 and would like to convert this into a single string Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9 I can do that with a loop, but isn't there a more elegant way? result - repeated.measures.FACTOR.names[[1]] for(i in 2:length(repeated.measures.FACTOR.names)) { result - paste(result, repeated.measures.FACTOR.names[[i]], sep=,) } result [1] Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9 paste() is vectorized and note the use of 'collapse' in lieu of 'sep': paste(repeated.measures.FACTOR.names, collapse = ,) [1] Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9 Before I forget, you can also do the following to reconstruct the initial sequence and the final result in a single step: paste(Insp, 1:9, sep = , collapse = ,) [1] Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9 In this case, we use 'sep' to indicate that there should be no space between each occurrence of 'Insp' and the integers and then use 'collapse' to indicate (as above) that each alphanum construct is to be joined by a comma into a single element. HTH, Marc __ 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] Multiple barplots on the same axis
On Thu, 2006-10-12 at 23:08 -0300, Andre Nathan wrote: Hi R newbie here :) I need to plot 3 barplots in the same axis, something like | | ___ | | | _| | _| | _ | _ | || | _ | || | _ | || | | | || || || || || || || || | -+- | v1 v2 v3 Is there any documentation describing how to achieve that, and what data file layout would make the job easier? Thanks in advance, Andre There are examples in ?barplot, where the VADeaths data is used. The key is the use of 'beside = TRUE', to enable grouped bars: barplot(VADeaths, beside = TRUE, col = c(lightblue, mistyrose, lightcyan, lavender, cornsilk), legend = rownames(VADeaths), ylim = c(0, 100)) To see what the VADeaths data set looks like: VADeaths See ?barplot for more information. There is also an R Graphics Gallery with code at: http://addictedtor.free.fr/graphiques/index.php and From Data to Graphics at: http://zoonek2.free.fr/UNIX/48_R/03.html Both of which are helpful. HTH, Marc Schwartz __ 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] Log-scale in histogramm
On Fri, 2006-10-13 at 13:33 +0200, David Graf wrote: Hello My data looks ugly in a normal histogramm. How can I create a histogramm with a Y-axis in log-scale? Thanks for your help! David Graf I'm not sure that you want to use a log scale here, but may be better served by log transforming your data. For example: # Generate 100 random values from a log normal dist: x - rlnorm(100) # Now do a histogram on x hist(x, freq = FALSE) # Now use log(x) hist(log(x), freq = FALSE) Does that help? Marc Schwartz __ 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] nontabular logistic regression
On Fri, 2006-10-13 at 09:28 -0500, Jeffrey Stratford wrote: Hi. I'm attempting to fit a logistic/binomial model so I can determine the influence of landscape on the probability that a box gets used by a bird. I've looked at a few sources (MASS text, Dalgaard, Fox and google) and the examples are almost always based on tabular predictor variables. My data, however are not. I'm not sure if that is the source of the problems or not because the one example that includes a continuous predictor looks to be coded exactly the same way. Looking at the output, I get estimates for each case when I should get a single estimate for purbank. Any suggestions? Many thanks, Jeff THE DATA: (200 boxes total, used [0 if unoccupied, 1 occupied], the rest are landscape variables). box use purbank purban2 purban1 pgrassk pgrass2 pgrass1 grassdist grasspatchk 1 1 0.003813435 0.02684564 0.06896552 0.3282487 0.6845638 0.7586207 0 3.73 2 1 0.04429451 0.1610738 0.1724138 0.1534174 0.3825503 0.6551724 0 1.023261 3 1 0.04458785 0.06040268 0 0.1628043 0.5570470.7586207 0 0.9605769 4 1 0.06072162 0.2080537 0.06896552 0.01936052 0 0 323.10990.2284615 5 0 0.6080962 0.6979866 0.6896552 0.03168084 0.1275168 0.2413793 30 0.2627027 6 1 0.6060428 0.6107383 0.3448276 0.04077442 0.2885906 0.4482759 30 0.2978571 7 1 0.3807568 0.4362416 0.6896552 0.06864183 0.03355705 0 94.868330.468 8 0 0.3649164 0.3154362 0.4137931 0.06277501 0.1275168 0 120 0.4585714 THE CODE: box.use- read.csv(c:\\eabl\\2004\\use_logistic2.csv, header=TRUE) attach(box.use) box.use - na.omit(box.use) use - factor(use, levels=0:1) levels(use) - c(unused, used) glm1 - glm(use ~ purbank, binomial) THE OUTPUT: Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept)-4.544e-16 1.414e+00 -3.21e-161.000 purbank02.157e+01 2.923e+04 0.0010.999 purbank0.001173365 2.157e+01 2.067e+04 0.0010.999 purbank0.001466706 2.157e+01 2.923e+04 0.0010.999 purbank0.001760047 6.429e-16 2.000e+00 3.21e-161.000 purbank0.002346729 2.157e+01 2.923e+04 0.0010.999 purbank0.003813435 2.157e+01 2.923e+04 0.0010.999 purbank0.004106776 2.157e+01 2.067e+04 0.0010.999 purbank0.004693458 2.157e+01 2.067e+04 0.0010.999 It appears that the 'purbank' variable is being imported as a factor, hence the multiple levels indicated in the left hand column. Check: str(box.use) right after the read.csv() step and see what it shows. From the sample data above, it _should_ be along the lines of: str(box.use) 'data.frame': 8 obs. of 10 variables: $ box: int 1 2 3 4 5 6 7 8 $ use: int 1 1 1 1 0 1 1 0 $ purbank: num 0.00381 0.04429 0.04459 0.06072 0.60810 ... $ purban2: num 0.0268 0.1611 0.0604 0.2081 0.6980 ... $ purban1: num 0.069 0.172 0.000 0.069 0.690 ... $ pgrassk: num 0.3282 0.1534 0.1628 0.0194 0.0317 ... $ pgrass2: num 0.685 0.383 0.557 0.000 0.128 ... $ pgrass1: num 0.759 0.655 0.759 0.000 0.241 ... $ grassdist : num0 0 0 323 30 ... $ grasspatchk: num 3.730 1.023 0.961 0.228 0.263 ... Hence, you should be able to use: model - glm(use ~ purbank, data = box.use, family = binomial) summary(model) Call: glm(formula = use ~ purbank, family = binomial, data = box.use) Deviance Residuals: Min1QMedian3Q Max -1.61450 -0.03098 0.31935 0.45888 1.39194 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept)3.223 2.225 1.4480.147 purbank -6.129 4.773 -1.2840.199 (Dispersion parameter for binomial family taken to be 1) Null deviance: 8.9974 on 7 degrees of freedom Residual deviance: 6.5741 on 6 degrees of freedom AIC: 10.574 Number of Fisher Scoring iterations: 5 Note that na.omit() is the default operation for most R models, so is redundant. Also, I would not attach the data frame, as you can use the 'data' argument in model related functions. This avoids the confusion of having multiple copies of the source data set and wondering why changes made can become confusing and problematic. HTH, Marc Schwartz __ 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] Hide line ends behind unfilled circles?
On Sun, 2006-10-15 at 11:21 -0400, Michael Kubovy wrote: Dear r-helpers, xx - c(0.000, 0.210, 0.714, 0.514, 1.000, 0.190, 0.590, 0.152) yy - c(0.000, 0.265, 0.256, 0.521, 0.538, 0.761, 0.821, 1.000) aa - c(19, 19, 19, 21, 19, 21, 21, 21) x0 - xx[c(1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 6, 6, 7)] y0 - yy[c(1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 6, 6, 7)] x1 - xx[c(2, 3, 3, 4, 6, 4, 5, 5, 6, 7, 7, 7, 8, 8)] y1 - yy[c(2, 3, 3, 4, 6, 4, 5, 5, 6, 7, 7, 7, 8, 8)] plot(yy ~ xx, pch = aa, cex = 3) segments(x0, y0, x1, y1) Can anyone suggest a way of insuring that the lines are hidden behind the unfilled circles? Try this: # Set up the plot region plot(yy ~ xx, type = n) # Draw the segments first segments(x0, y0, x1, y1) # Set the circle (pch) background colors col - c(rep(black, 3), white, black, rep(white, 3)) # Now draw the circles over the line intersections points(xx, yy, pch = 21, bg = col, cex = 3) The unfilled circles in this case are actually solid white or black. So instead of altering the point character (pch), we alter the colors. HTH, Marc Schwartz __ 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] BarPlot
On Sat, 2006-10-14 at 23:52 -0400, Mohsen Jafarikia wrote: Hello everyone, I have the following program to draw a barplot. MP-read.table(file='AR.out') names(MP)-c('BN','BL','LR','Q') Graph- barplot(MP$LR, main='LR Value', col='orange', border='black', space= 0.05, width=(MP$BL), xlab='Length', ylab='LR each') axis(1, at=Graph, sprintf('%0.2f',MP$BL)) mtext(1, at=Graph, text=sprintf('%0.2f',MP$Q), line=2) mtext(1, at=par('usr')[1], text='BL', line=1) mtext(1, at=par('usr')[1], text='Var', line=2) abline(h=3.841,col='blue') abline(h=6.635,col='red') I have two more questions about the graph that I have: 1) I want to write the 'Q' only when it is not equal to zero. 2) I would like to change the bars when 'Q' is not zero. For example, from orange to green. I would appreciate your input to this question. Thanks, Mohsen It would be helpful to have the data that you are working with so that we can provide each other a working example. However, here are some hints: 1. mtext(1, at = Graph, text = ifelse(MP$Q != 0, sprintf('%0.2f',MP$Q), ), line=2) 2. cols - ifelse(MP$Q != 0, orange, green) barplot(..., col = cols, ...) See ?ifelse HTH, Marc Schwartz __ 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] help with plot()
Tom, If your text file, 'sp.txt' contains the headers used on that web page, then your read.table() function call is incorrect. Your call below presently has 'header = 0'. Use TRUE/FALSE for easier reading of code. The tutorial seems to be inconsistent with that. If your text file contains the 'Date' and 'SP500' column headers, then your SP500 data column is going to be read in as a character variable, as R will see the first entry of 'SP500' as a character value, not as a column header. This column in turn, will be coerced to a factor, resulting in the errors you are seeing, as plot.factor() will be used. You should be using: d - read.table(c:/test/sp.txt, header = TRUE) Use: str(d) to review the current structure of your data frame. That should give you some hints. HTH, Marc Schwartz On Mon, 2006-10-16 at 10:54 -0500, tom soyer wrote: Hi David and Duncan, Thanks for the reply. I am using R-2.4.0 for windows. All I am trying to do is follow an online tutorial ( http://www.onlamp.com/pub/a/onlamp/2005/11/17/r_for_statistics.html) step by step. spval is just an array of numbers. I also tried using type=1 instead of l, but got same warning message and the same bar graph. Are there any packages that I should have installed? I haven't installed any contributed package, only the base distribution. Thanks, Tom On 10/16/06, David Barron [EMAIL PROTECTED] wrote: It's possible the problem is with your data; could you provide some sample data with which we can reproduce the error? On 16/10/06, tom soyer [EMAIL PROTECTED] wrote: Hi, I am new to R and I have been trying it out. I ran into a problem with the plot() function. Below is my code: d - read.table(c:/test/sp.txt,header=0) spval - d[,2] plot(spval,type=l) Warning messages: 1: graphical parameter type is obsolete in: plot.window(xlim, ylim, log, asp, ...) 2: graphical parameter type is obsolete in: axis(side, at, labels, tick, line, pos, outer, font, lty, lwd, 3: graphical parameter type is obsolete in: title(main, sub, xlab, ylab, line, outer, ...) 4: graphical parameter type is obsolete in: axis(side, at, labels, tick, line, pos, outer, font, lty, lwd, I tried to plot a line graph from a text file with two columns. Some how R won't plot the data as lines, and it kept giving me the same warning: type is obsolete. What does this mean? Am I doing something wrong, or is the parameter really obsolete, or do I need install some package? Thanks, Tom __ 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] using text on the x axis ticks rather than numbers
On Tue, 2004-09-07 at 12:52, Rajarshi Guha wrote: Hello, is there a way in which I can use text labels rather than numbers on the x axis ticks? I basically have a vector of (say) 8 points and I want to plot these sequentially. Thus the x axis would have ticks at 1 .. 8. Rather than having the labels 1 .. 8 I would like to have some arbitrary text labels. Ideally I would like the labels to be rotated (say at 45 degrees) so that they don't overlap with each other. Is this possible? Thanks, Here is an example. For the axis labels, you need to use text() and not mtext() as the latter does not allow for text rotation: # Set margins to make room for x axis labels par(mar = c(7, 4, 4, 2) + 0.1) # Create plot with no x axis and no x axis label plot(1:8, xaxt = n, xlab = ) # Set up x axis with tick marks alone axis(1, labels = FALSE) # Create arbitrary text labels - paste(arbitrary text, 1:8, sep = ) # plot x axis labels using: # par(usr)[3] - 0.25 as the vertical placement # srt = 45 as text rotation angle # adj = 1 to place right end of text at tick mark # xpd = TRUE to allow for text outside the plot region text(1:8, par(usr)[1] - 0.25, srt = 45, adj = 1, labels = labels, xpd = TRUE) # plot x axis label at line 6 (of 7) mtext(1, text = X Axis Label, line = 6) You can adjust the value of the '0.25' offset as required to move the x axis labels up or down relative to the x axis. HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] boxplot() from list
On Sun, 2004-09-12 at 10:10, Laura Quinn wrote: I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list - I have also tried to create 4 new lists (one for each column of each object) by using variations on the following, but none seems to work: newlist-oldlist[,1] newlist-oldlist[[]][,1] newlist-oldlist[[]][,$colone] can anyone please offer some insight?? Thanks in advance, For each individual boxplot, you could do something like: boxplot(data.frame(sapply(mylist, function(x) x[, 1]))) adjusting the index (1) for each of the four columns in your list matrices. You can then adjust the additional arguments to boxplot() as you require. See ?sapply for more information on accessing list member elements and returning a vector or matrix. HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] boxplot() from list
On Sun, 2004-09-12 at 11:42, Prof Brian Ripley wrote: On Sun, 12 Sep 2004, Marc Schwartz wrote: On Sun, 2004-09-12 at 10:10, Laura Quinn wrote: I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list - I have also tried to create 4 new lists (one for each column of each object) by using variations on the following, but none seems to work: newlist-oldlist[,1] newlist-oldlist[[]][,1] newlist-oldlist[[]][,$colone] can anyone please offer some insight?? Thanks in advance, For each individual boxplot, you could do something like: boxplot(data.frame(sapply(mylist, function(x) x[, 1]))) adjusting the index (1) for each of the four columns in your list matrices. You can then adjust the additional arguments to boxplot() as you require. See ?sapply for more information on accessing list member elements and returning a vector or matrix. I think that is overly complex, as boxplot accepts a list. I had tested (but decided not to send) mylist - vector(list, 48) for(i in 1:48) mylist[[i]] - matrix(rnorm(30*4), 30) for (J in 1:4) boxplot(lapply(mylist, function(x, j) x[, j], j = J)) Fair enough. I did not want to presume that the remaining arguments to boxplot might be the same for each plot. Though one could also put those into an appropriate structure and still do the loop. Also, if using the display, one would probably want to set par(ask = TRUE), lest the four plots flash by in rapid sequence. Marc __ [EMAIL PROTECTED] 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] Spare some CPU cycles for testing lme?
On Mon, 2004-09-13 at 07:40, Frank Samuelson wrote: If anyone has a few extra CPU cycles to spare, I'd appreciate it if you could verify a problem that I have encountered. Run the code below and tell me if it crashes your R before completion. library(lme4) data(bdf) dump-sapply( 1:5, function(i) { fm - lme(langPOST ~ IQ.ver.cen + avg.IQ.ver.cen, data = bdf, random = ~ IQ.ver.cen | schoolNR); cat( ,i,\r) 0 }) The above code simply reruns the example from the lme help page a large number of times and returns a bunch of 0's, so you'll need to have the lme4 and Matrix packages installed. It might take a while to complete, but you can always nice it and let it run. I'm attempting to bootstrap lme() from the lme4 package, but it causes a segfault after a couple hundred iterations. This happens on my Linux x86 RedHat 7.3, 8.0, 9.0, FC1 systems w/ 1.9.1 and devel 2.0.0 (not all possible combinations actually tested.) I've communicated w/ Douglas Bates about this and he doesn't appear to have the problem. Thanks for any help. -Frank Replicated here on FC 2 running: Version 1.9.1 Patched (2004-09-07) The backtrace from gdb follows. It would probably make sense to move this thread to r-devel. As you can see, it got through 10,546 runs before segfaulting. cc: to Doug. HTH, Marc Schwartz dump-sapply( 1:5, function(i) { + fm - lme(langPOST ~ IQ.ver.cen + avg.IQ.ver.cen, data = bdf, +random = ~ IQ.ver.cen | schoolNR); + cat( ,i,\r) + 0 + }) 10546 Program received signal SIGSEGV, Segmentation fault. 0x00982242 in _int_free () from /lib/tls/libc.so.6 (gdb) bt #0 0x00982242 in _int_free () from /lib/tls/libc.so.6 #1 0x0098373b in free () from /lib/tls/libc.so.6 #2 0x080c4003 in ReleaseLargeFreeVectors () at memory.c:695 #3 0x080c5999 in RunGenCollect (size_needed=1144) at memory.c:1282 #4 0x080c7084 in R_gc_internal (size_needed=1144) at memory.c:1933 #5 0x080c6b67 in Rf_allocVector (type=16, length=2287) at memory.c:1788 #6 0x0809b6b1 in Rf_duplicate (s=0xbed5d40) at duplicate.c:150 #7 0x0809b335 in Rf_duplicate (s=0xb64a3bc) at duplicate.c:100 #8 0x0809b517 in Rf_duplicate (s=0xbed15a8) at duplicate.c:142 #9 0x0809b777 in Rf_duplicate (s=0xb3f6048) at duplicate.c:137 #10 0x080a796d in EnsureLocal (symbol=0x9719f38, rho=0xb64c2b8) at eval.c:765 #11 0x080a8691 in evalseq (expr=0x9719f38, rho=0xb64c2b8, forcelocal=1, tmploc=0xb64a340) at eval.c:1135 #12 0x080a8847 in applydefine (call=0x97f9818, op=0x9705264, args=0x97f9834, rho=0xb64c2b8) at eval.c:1199 #13 0x080a7055 in Rf_eval (e=0x97f9818, rho=0xb64c2b8) at eval.c:375 #14 0x080a8436 in do_begin (call=0x97f97fc, op=0x9705168, args=0x97f97e0, rho=0xb64c2b8) at eval.c:1046 #15 0x080a7055 in Rf_eval (e=0x97f97fc, rho=0xb64c2b8) at eval.c:375 #16 0x080a7055 in Rf_eval (e=0x97f9bdc, rho=0xb64c2b8) at eval.c:375 #17 0x080a8436 in do_begin (call=0x97f4ac8, op=0x9705168, args=0x97f9bc0, rho=0xb64c2b8) at eval.c:1046 #18 0x080a7055 in Rf_eval (e=0x97f4ac8, rho=0xb64c2b8) at eval.c:375 #19 0x080a7301 in Rf_applyClosure (call=0xb64c130, op=0x97f9a8c, arglist=0xb64c050, rho=0xb65989c, suppliedenv=0xb64c0f8) at eval.c:566 #20 0x080cd2fb in applyMethod (call=0xb64c130, op=0x97f9a8c, args=0xb64c050, rho=0xb65989c, newrho=0xb64c0f8) at objects.c:119 #21 0x080cd985 in Rf_usemethod (generic=0x81a1f2b [, obj=0xb3ebbc0, call=0x9a668f0, args=0xb64c050, rho=0xb65989c, callrho=0xb65989c, defrho=0x96f6338, ans=0xfef58728) at objects.c:326 #22 0x080a994d in Rf_DispatchOrEval (call=0x9a668f0, op=0x9705050, generic=0x81a1f2b [, args=0xb64bffc, rho=0xb65989c, ans=0xfef58728, dropmissing=0, argsevald=1) at eval.c:1719 #23 0x0811d5aa in do_subset (call=0x9a668f0, op=0x9705050, args=0x9a66944, rho=0xb65989c) at subset.c:504 #24 0x080a7055 in Rf_eval (e=0x9a668f0, rho=0xb65989c) at eval.c:375 #25 0x080a8bc3 in do_set (call=0x9a66880, op=0x9705264, args=0x9a668b8, rho=0xb65989c) at eval.c:1271 #26 0x080a7055 in Rf_eval (e=0x9a66880, rho=0xb65989c) at eval.c:375 ---Type return to continue, or q return to quit--- #27 0x080a8436 in do_begin (call=0x9a67184, op=0x9705168, args=0x9a66864, rho=0xb65989c) at eval.c:1046 #28 0x080a7055 in Rf_eval (e=0x9a67184, rho=0xb65989c) at eval.c:375 #29 0x080a7055 in Rf_eval (e=0x9a66c44, rho=0xb65989c) at eval.c:375 #30 0x080a8436 in do_begin (call=0x9a66b10, op=0x9705168, args=0x9a66c28, rho=0xb65989c) at eval.c:1046 #31 0x080a7055 in Rf_eval (e=0x9a66b10, rho=0xb65989c) at eval.c:375 #32 0x080a7301 in Rf_applyClosure (call=0xb659730, op=0x9a67900, arglist=0xb65a558, rho=0xb65966c, suppliedenv=0xb6596f8) at eval.c:566 #33 0x080cd2fb in applyMethod (call=0xb659730, op=0x9a67900, args=0xb65a558, rho=0xb65966c, newrho=0xb6596f8) at objects.c:119 #34 0x080cd985 in Rf_usemethod (generic=0x9b1f300 model.matrix, obj=0xb415a64, call=0x9a6783c, args=0x96f6338, rho=0xb65966c, callrho=0xb415bb4, defrho=0xa038100, ans
Re: followup: Re: [R] Issue with predict() for glm models
On Thu, 2004-09-23 at 12:02, Paul Johnson wrote: I have a follow up question that fits with this thread. Can you force an overlaid plot showing predicted values to follow the scaling of the axes of the plot over which it is laid? Here is an example based on linear regression, just for clarity. I have followed the procedure described below to create predictions and now want to plot the predicted values on top of a small section of the x-y scatterplot. x - rnorm(100, 10, 10) e - rnorm(100, 0, 5) y - 5 + 10 *x + e myReg1 - lm (y~x) plot(x,y) newX - seq(1,10,1) myPred - predict(myReg1,data.frame(x=newX)) Now, if I do this, I get 2 graphs overlaid but their axes do not line up. par(new=T) plot(newX,myPred$fit) The problem is that the second one uses the whole width of the graph space, when I'd rather just have it go from the small subset where its x is defined, from 1 to 10. Its stretching the range (1,10) for newX to use the same scale that goes from (-15, 35) where it plots x I know abline() can do this for lm, but for some other kinds of models, no lines() method is provided, and so I am doing this the old fashioned way. Paul, Instead of using plot() for the second set of points, use points(): x - rnorm(100, 10, 10) e - rnorm(100, 0, 5) y - 5 + 10 * x + e myReg1 - lm (y ~ x) plot(x, y) newX - seq(1, 10, 1) myPred - predict(myReg1, data.frame(x = newX)) points(newX, myPred$fit, pch = 19) This will preserve the axis scaling. If you use plot() without explicitly indicating xlim and ylim, it will automatically scale the axes based upon your new data, even if you indicated that the underlying plot should not be cleared. Alternatively, you could also use the lines() function, which will draw point to point lines: lines(newX, myPred$fit, col = red) If you want fitted lines and prediction/confidence intervals, you could use a function like matlines(), presuming that a predict method exists for the model type you want to use. There is an example of using this in R Help Desk in R News Vol 3 Number 2 (October 2003), in the first example, with a standard linear regression model. HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] using tcltk in R under ESS/XEmacs on Windows
On Fri, 2004-09-24 at 15:02, Liaw, Andy wrote: Sorry for the cross-post. Not sure where the problem is... A while back I posted an R function to R-help: cd - function (dir = tclvalue(tkchooseDirectory()), saveOld = FALSE, loadNew = TRUE) { stopifnot(require(tcltk)) if (saveOld) save.image(compress = TRUE) setwd(dir) rm(list = ls(all = TRUE, envir = .GlobalEnv), envir = .GlobalEnv) if (loadNew file.exists(.RData)) { loaded - load(.RData, envir = .GlobalEnv) return(invisible(loaded)) } where the default value for the `dir' argument is to run the tcltk directory chooser and get the directory name chosen. (Thanks to Prof. John Fox for the tcltk part!!) While this function works fine under Rgui on Windows, it doesn't work when running R within ESS (5.2.3) and XEmacs (21.4.13). The directory chooser never shows up, and dir just gets the empty string. Does anyone have any idea what could be the problem? I'd very much appreciate any pointers. Best, Andy Andy, This works under FC2 using ESS 5.2.3 with XEmacs version 21.4.15, so presumably there is something specific to the Windows implementation? Also, two things: 1. You are missing a closing brace above, which I presume may be a simple copy and paste issue. 2. If you successfully change the directory, the cd() function itself is deleted from the global environment via your rm(...), as you currently have it implemented. I am not sure if this is intentional or not. HTH, Marc __ [EMAIL PROTECTED] 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] R plot problems
On Fri, 2004-10-15 at 07:18, Henric Nilsson wrote: At 10:51 2004-10-15 +0100, you wrote: If you are using base grafics, you use the argument srt (see help(par)), How do you get a, say, 45 degree rotation of the axis labels using `srt'? The help page for par's `las' argument says Note that other string/character rotation (via argument srt to par) does not affect the axis labels Henric See the new R FAQ: 7.27 How can I create rotated axis labels? HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] pdf device --- axes labels text disappeared?
On Fri, 2004-10-15 at 09:13, [EMAIL PROTECTED] wrote: Dear R Wizards: Running R 1.9.1. on amd64. Promise- c(0,20,40); Expect- c(0, 20, 0.2*20+.8*40 ); # this omits printing numbers on the axes labels. pdf(file = bug.pdf ); plot(Promise, Expect, type=b, ylim=c(0,60)); dev.off(); # this works postscript(file = bug.eps ); plot(Promise, Expect, type=b, ylim=c(0,60)); dev.off(); apologies if this has already been noted elsewhere---I looked but did not find it. (probably googled for the wrong terms, if so.) is this my bug, or R's bug or my R installation bug? help appreciated. /iaw Hey Ivo! No problems here using R 2.0.0 on 32 bit Intel FC2. Both plots are fine. I don't have a 1.9.1 install at the moment, but I would guess that we would have heard about the problem prior to this. That suggests a possible issue with your install or a change of some sort with 64 bit R. Though again, I suspect other 64 bit users would have commented on this already... HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] displaying sample size in boxplots
On Wed, 2004-09-29 at 07:46, Patrick Drechsler wrote: Hi, I was wondering if there is a ready made function or parameter for indicating the sample size in boxplots? Here's what I came up with so far: library(ISwR) data(energy) attach(energy) boxplot(expend~stature) sample.size - tapply(expend, stature, length) sample.size - paste(N=, sample.size, sep=) mtext(sample.size, at=1:length(unique(stature)), line=2, side=1) Note that boxplot() returns values, which includes a variety of summary information on each group within your data. See the Value section of ?boxplot and ?boxplot.stats for more information. Thus, you can do something like (using the first example in ?boxplot): data(InsectSprays) # Save the returned values from boxplot() in S S - boxplot(count ~ spray, data = InsectSprays, col = lightgray) # S$n is the sample size for each group # S$names contains the group names mtext(side = 1, text = S$n, at = 1:length(S$names), line = 2) HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] Boxplot, space to axis
On Thu, 2004-09-30 at 10:22, [EMAIL PROTECTED] wrote: Hello Deepayan, thanks for your suggestion, xaxs='i' works, but it leaves no space at all. I though this may be configurable by a real value. kind regards, Arne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Deepayan Sarkar Sent: 30 September 2004 17:12 To: [EMAIL PROTECTED] Cc: Muller, Arne PH/FR Subject: Re: [R] Boxplot, space to axis On Thursday 30 September 2004 09:41, [EMAIL PROTECTED] wrote: Hello, I've crearted a boxplot with 84 boxes. So fat everything is as I expect, but there is quite some space between the 1st box and axis 2 and the last box and axis 4. Since 84 boxes get very slim anyway I'd like to discribute as much of the horizontal space over the x-axis. Maybe I've forgotten about a graphics parameter? Perhaps par(xaxs = i) ? Deepayan Here is a possible solution, albeit a little kludgy. The problem is that there is no way to define the x axis range in the call to boxplot(), which would allow you to make some adjustments that way. If you trace through the code for boxplot() and then bxp() [the latter actually does the plotting], you could figure out how the range of the x axis is computed and the factors that influence that calculation. With that knowledge, you could feasibly adjust the 'at' argument for the placement of the boxes. However, that may be more complicated than my approach below. Create some test data: set.seed(2) MyData - matrix(rnorm(84 * 100), ncol = 84) and then plot it normally: boxplot(as.data.frame(MyData)) You can then see the par(usr) values: par(usr) [1] -2.86 87.86 -4.379829 3.844485 Note the extra space on the x axis range. Now, let's control that part of the process: # Open a new plotting device plot.new() # Now specify the plotting coordinate system # There are 84 boxes, so let's add one unit before # and after to the 'xlim'. Also, specify 'i' for # xaxs, so there is no expansion of the x axis # range as per the default. plot.window(xlim = c(0, 85), ylim = range(MyData), xaxs = i) # Now do the boxplot, setting 'add = TRUE' so that # the plot is added to the current window, also # specifying the 'at' argument boxplot(as.data.frame(MyData), add = TRUE, at = 1:84) Now note the par(usr) values: par(usr) [1] 0.00 85.00 -4.379829 3.844485 You can do further adjustments to the x axis range as you require in the call to plot.window(). HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] Can grid lines color in a plot be specified?
On Fri, 2004-10-01 at 07:44, Luis Rideau Cruz wrote: R-help Is there any way to specify the color of grid lines in a simple plot? par(color.tick.marks=c(grey)) plot(rnorm(10),tck=1) Thank you This is one approach: plot(rnorm(10)) # Now draw both axes axis(1, tck = 1, col = grey, lty = dotted) axis(2, tck = 1, col = grey, lty = dotted) # Replace the grey plot region border lines with black box() In this case, the grid lines are being drawn after the data is plotted, so it is possible that the lines may overwrite your symbols or other important visual information. An alternative would be to create the plot background first, including the grid lines, then add the data with lines() or points() or other functions. For example: x - rnorm(10) plot(x, type = n) axis(1, tck = 1, col = grey, lty = dotted) axis(2, tck = 1, col = grey, lty = dotted) box() points(x, pch = 19) HTH, Marc Schwartz __ [EMAIL PROTECTED] 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] Can grid lines color in a plot be specified?
On Fri, 2004-10-01 at 08:15, Marc Schwartz wrote: On Fri, 2004-10-01 at 07:44, Luis Rideau Cruz wrote: R-help Is there any way to specify the color of grid lines in a simple plot? par(color.tick.marks=c(grey)) plot(rnorm(10),tck=1) Thank you Oknow that I have finished my second cup of coffee... For some reason, I keep forgetting about the grid() function: plot(rnorm(10)) grid() The same comment applies here with respect to the grid being drawn after your data, so you might want to do something like: x - rnorm(10) plot(x, type = n) grid() points(x, pch = 19) See ?grid for more information. Marc __ [EMAIL PROTECTED] 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] Can grid lines color in a plot be specified?
On Fri, 2004-10-01 at 09:31, [EMAIL PROTECTED] wrote: I usually use something like abline(h=seq(...),col=green) abline(v=seq(...),col=green) This allows you to have irregularly spaced grid lines if you want. (Say for futures expiration dates in my case.) Also, as Marc pointed out, you may want to draw the lines or points after the grid lines. snip Also, again with the aid of further caffeine, as noted in the help for grid(), one can use the 'panel.first' argument in plot() to enable the creation of the grid prior to the plotting of the data. For example: plot(rnorm(10), panel.first = grid(), pch = 19) yields the same results and plotting sequence as: x - rnorm(10) plot(x, type = n) grid() points(x, pch = 19) As an example of using this approach with irregularly space grid lines and axis tick marks, as per David's point: plot(rnorm(10), panel.first = abline(v = c(1, 2, 3, 7), col = grey, lty = dotted), pch = 19, xaxt = n) axis(1, at = c(1, 2, 3, 7)) There is also a 'panel.last' argument available which, of course, is executed after all other plotting is done. More information is available from ?plot.default. I have not done an exhaustive review of all plotting functions/methods, but I suspect not all of them support the panel.first and panel.last arguments. HTH, Marc __ [EMAIL PROTECTED] 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] Lattice .ps graphic is rotated in LaTeX slides
On Fri, 2004-10-01 at 10:58, Peter Dalgaard wrote: Michael Friendly [EMAIL PROTECTED] writes: ! Package graphics Error: Division by 0. What am I doing wrong, or how could I do it differently so it would work? You might try \usepackage{graphicx} instead. I seem to recall (vaguely) getting better results with that sometimes. That should be part of the preamble for using 'seminar', if it is setup properly. There is a decent tutorial for using seminar at: http://astronomy.sussex.ac.uk/~eddie/soft/tutorial.html There is also a great reference for including graphics in LaTeX: www.ctan.org/tex-archive/info/epslatex.pdf FWIW, though I have been using seminar for such presentations, I have been recently looking at the Beamer package: http://latex-beamer.sourceforge.net/ and of course, there is also the Prosper package: http://prosper.sourceforge.net/ The one advantage of the Beamer package, for those that require it, is that it supports pdflatex, which the others do not. Though, it can be used with dvips/latex + ps2pdf, where needed. HTH, Marc __ [EMAIL PROTECTED] 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] Lattice .ps graphic is rotated in LaTeX slides - PDF weirdness
On Fri, 2004-10-01 at 12:54, Peter Dalgaard wrote: Barry Rowlingson [EMAIL PROTECTED] writes: Marc Schwartz wrote: The one advantage of the Beamer package, for those that require it, is that it supports pdflatex, which the others do not. Though, it can be used with dvips/latex + ps2pdf, where needed. Has anyone else hit the problem that sometimes occurs with embedded PostScript graphics generated by R when viewed in full-screen mode using Adobe Acrobat Reader in Linux? Yes, its _that_ specific. You get black areas all round your graphic. It looks a mess. Does it in acroread4 and 5. But only Linux, and only full-screen mode. Doesn't seem to want to happen to me, with acrobat 5, in full-screen mode, on Linux, so it must be more specific than that... Can't say that I have ever seen that and I do use acroread 5 under FC2 for full screen slide presentations. Barry, do you have a specific R example that I could try to replicate here? Marc __ [EMAIL PROTECTED] 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] Off-Topic: LaTeX package listings
On Sun, 2004-10-03 at 21:26, Kjetil Brinchmann Halvorsen wrote: Hola! I ask here since I learnt from this list that the LaTeX package listings should be good for typesetting R code. I encountered one problem: \begin{lstlisting} X %*% V \end{lstlisting} in the output the * in %*% disappears! same with %/%, etc, the / disappears. Any ideas? Kjetil That's because the % is a comment character in LaTeX. Thus, anything after it will be ignored. For program code, you generally want to use the 'verbatim' or 'smallverbatim' environment: \begin{verbatim} X %*% V \end{verbatim} In the verbatim environment, all characters are treated literally, rather than interpreted by any special meaning. Outside of that, say in a regular LaTeX document, you can escape the %: \% HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html