[R] draw borders of bars inside of the rectangles in a barplot
Dear R-users, I want to draw a barplot with beside=TRUE. One halve of the bars are drawn with a border, while the other halve are drawn without a border (i.e. filled bars vs. non-filled bars next to each other). Because borders are drawn around the bars, doing this leads to one halve of the bars being wider than the other halve, expanding across the 0-point of the y-axis. This problem emerges especially with small figures and rather large border width. Now my question: Is there a way to draw the border inside of the bars instead of surrounding the bars? (similar to border-drawing options in graphics software, like photoshop or inkscape). Here some example code: x <- matrix(c(1:10), 2,5) par(lwd = 5) barplot(x, beside=T, border=rep(c(NA, 'black'),5), space=c(0.08,1), col=rep(c('black', 'white'),5)) Thank you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] copy/paste of large amount of code to terminal leads to scrambled/missing characters
Dear R-users, This question might not be restricted to R, but I hope that some might have experienced similar problems and could help me. When using R, I usually work with a text-editor (textmate2) in which I prepare the script. To execute code, I then copy and paste it to an R-session running in the terminal/shell (on Mac OS). Unfortunately, when pasting too much code into the terminal (e.g. 60 lines), some characters are occasionally and randomly scrambled or missing. For example "col <- ifelse(..." turns into "col < col < cse(…". This happens very randomly, is difficult to predict, and while it only affects a hand full of characters in total, it leads to a lot of errors in the code execution along the way. Apparently, it has to do with the buffer size and paste-speed of the terminal. So far, I could not find any solution to the problem. Therefore, I wanted to ask; Do others here use a similar workflow (i.e. having a text-editor for coding and using copy/paste to the terminal for code execution) and encountered similar problems with big chunks of code in the clipboard? Are there any solutions for this problem, specifically for running R over the shell? Thank you very much! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plot 2D matrix of RGB values
Hi, I have a 2 dimensional matrix with RGB values and would like to plot it as a two dimensional surface. I am aware of functions like image() that plot a matrix of values as a grid of coloured rectangles. But I can not directly feed in the specific color value for each of these rectangles, as far as I understand. Is there an easy way to just take a matrix of color values and plot it in R? Thank You! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] best way to globally set parameters for base graphics
Thanks for the reply. It works fine for a single plot-call. But as soon as I call layout() before plotting I again run into the problem that plots are not drawn into one graphic device but another one is opened for the second plot-call. see here; setHook("plot.new", function() par(bty='n', cex=0.8, las=1, ann=F, lwd=2, mar=c(5, 4, 2, 1), oma=c(0,0,0,0), pch=19, xpd=T, cex.axis=0.85, mgp=c(2.5, 0.72, 0), tcl=-0.4 ) ) layout(matrix(1:2, 1, 2, byrow=T)) plot(c(1,2,3)) plot(c(3,2,1)) On 20 Jul 2015, at 17:48 , Duncan Murdoch wrote: > On 20/07/2015 11:27 AM, Martin Batholdy via R-help wrote: >> Hi, >> >> I am looking for a way to modify the basic setup for any kind of plot. >> (everything that is set with the par function – like margins, cex, las etc.) >> >> I want to do this once – preferably across R sessions and not individually >> before every plot. >> >> >> My first attempt was to add a par() with all my own defaults to the >> .Rprofile file. >> This obviously does not work because par opens a new drawing device, >> applying its effect only to this device. >> >> My next attempt was to write my own version of all basic plot functions >> (like plot, barplot etc.) adding a par() call within these functions. >> This works but only if I draw a single plot. As soon as I want to use mfrow >> or layout to draw multiple plots side by side into one device this version >> also does not work, since each of these functions will open a new drawing >> device by themselves. >> >> >> So, my question is; >> Is there any way to globally define parameters given to par() so that they >> apply to all plots in (at least) an entire R-session? > > I haven't played with it, but setting a "plot.new" hook (or > "before.plot.new") might do it for you. See ?plot.new. > > It might be tricky, because some par() parameters (e.g. "mfrow") > shouldn't be called before every plot. You'd have to look at > par("mfrow") to decide whether to call it or not. > > Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] best way to globally set parameters for base graphics
Hi, I am looking for a way to modify the basic setup for any kind of plot. (everything that is set with the par function – like margins, cex, las etc.) I want to do this once – preferably across R sessions and not individually before every plot. My first attempt was to add a par() with all my own defaults to the .Rprofile file. This obviously does not work because par opens a new drawing device, applying its effect only to this device. My next attempt was to write my own version of all basic plot functions (like plot, barplot etc.) adding a par() call within these functions. This works but only if I draw a single plot. As soon as I want to use mfrow or layout to draw multiple plots side by side into one device this version also does not work, since each of these functions will open a new drawing device by themselves. So, my question is; Is there any way to globally define parameters given to par() so that they apply to all plots in (at least) an entire R-session? Thank You! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] define absolute size in plots ... possible?
Hi, > That's the default, isn't it? I am sorry – one of my plots was actually set up with mfrow. But the documentation actually explains the change in cex when using mfrow; "In a layout with exactly two rows and columns the base value of "cex" is reduced by a factor of 0.83: if there are three or more of either rows or columns, the reduction factor is 0.66.” On 24 Jun 2015, at 13:17 , Duncan Murdoch wrote: > On 24/06/2015 7:08 AM, Martin Batholdy via R-help wrote: >> Hi, >> >> I would like to define the size for tick-marks, axis-titles, legends, >> drawing symbols etc. absolute, >> meaning that regardless of the size of the plot device, the font-size / >> character size is the same. >> >> Thus if I output my plot with pdf(width=5, height=5) or pdf(width=15, >> height=15), the font-size / symbol-size remains the same. >> >> >> Is that possible in R? > > That's the default, isn't it? > > You need to give some reproducible code and explain what you don't like > about the results. > > Duncan Murdoch > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] define absolute size in plots ... possible?
Hi, I would like to define the size for tick-marks, axis-titles, legends, drawing symbols etc. absolute, meaning that regardless of the size of the plot device, the font-size / character size is the same. Thus if I output my plot with pdf(width=5, height=5) or pdf(width=15, height=15), the font-size / symbol-size remains the same. Is that possible in R? Thank you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] set par options once for entire R session
Hi, I would like to set plot-options via par() and keep them for all plots that are created thereafter. Currently after each plot device the parameters I can set with par() are reseted to their default value, at least on a Mac (R 3.2.1). Is there a way to define the parameters for plotting once at the beginning and then keep them for an entire R session? Thank you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] export vector with write() introduces line breaks
Hi, I have a long vector which I want to export as a simple ascii text file via write(1:600, file='test.txt', sep=',') When I open the text file with my text editor I see that the data is structured in columns. So it seems that line breaks are introduced. How can I prevent this? Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] colour code areas of a plot
Hi, I would like to colour different areas of a plot. But I don't know how to do this efficiently. As an example; lets say three stimuli were presented in an experiment, alternating, one at a time. Now I want to plot time on the x-axis and the plot-area should colour code the stimulus that was presented at that time interval (green for stimulus 1, yellow for stimulus 2 etc.) here an example: (t = time) t <- 1:100 bg_colors <- c(rep('green',20), rep('yellow',10), rep('green',20), rep('red',5), rep('yellow',45)) color_scheme <- data.frame(t, bg_colors) plot(c(), c(), xlim = c(1,100), ylim=c(-1,1)) rect(xleft = 1, ybottom = -1, xright = 20, ytop = 1, col = 'green', lwd=0) rect(xleft = 20, ybottom = -1, xright = 30, ytop = 1, col = 'yellow', lwd=0) … now how can I do this efficiently based on the color_scheme data-frame and without having to manually draw all the rectangles as in the example above? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cluster option in stata for random intercept model in the R language?
Dear R-list, I am currently working on a dataset with a colleague who uses stata. We fit a random intercept model to the data (decisions clustered in participants) and get closely the same results in stata (using xtreg re) and R (using the lme4 or multilevel package). Now in stata, there is an additional option for the regression to control for clustering; the vce(cluster clustvar) option, which changes the standard errors quite a bit. (see http://www.stata.com/support/faqs/statistics/standard-errors-and-vce-cluster-option/ or http://www.stata.com/manuals13/xtxtreg.pdf). Unfortunately I don't understand what this 'correction' does and why it yields different results. First I thought it would control for autocorrelations over time (decisions), but if I model this directly with a random-intercept random-slope model, I don't get nearly the same results. Can someone help me understand what stata is doing here? And what would be the equivalent in R to get similar results? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sequentially aggregating elements of a vector
> The last element 11 in y is confusing. sorry for the typo. It is of course y <- c(1,3,6,10) > cumsum(x) thanks! On Oct 14, 2013, at 20:57 , arun wrote: > The last element 11 in y is confusing. > > cumsum(x) > [1] 1 3 6 10 > A.K. > > > On Monday, October 14, 2013 2:51 PM, Martin Batholdy > wrote: > Hi, > > for labelling the stacked bars in a barplot, I need to sequentially sum up > the elements of a vector. > > > Suppose I have; > > x <- c(1,2,3,4) > > (which correspond to the bar-width of stacked bars) > > I need; > > y <- c(1,3,6,11) > > > (which corresponds to the upper y-values for each bar). > > > > > What is the easiest way in R to get from x to y? > (Or more general; to add labels inside the bars in a stacked barplot) > > > > thanks! > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sequentially aggregating elements of a vector
Hi, for labelling the stacked bars in a barplot, I need to sequentially sum up the elements of a vector. Suppose I have; x <- c(1,2,3,4) (which correspond to the bar-width of stacked bars) I need; y <- c(1,3,6,11) (which corresponds to the upper y-values for each bar). What is the easiest way in R to get from x to y? (Or more general; to add labels inside the bars in a stacked barplot) thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] convert string to date format
Hi, I have a vector that looks like this; (imported from another file) dates <- c("Tue Sep 17 2013 16:25:17", "Wed Sep 18 2013 16:35:17", "Thu Sep 19 2013 16:55:17") now I need a data frame with two columns; datetime 2013.09.17 16:25:17 2013.09.18 16:35:17 … I first started with functions like strsplit to do string manipulations. But since I have to do this for multiple files with different native date-formats, probably there is a more general way to deal with dates and time formats in R. How can I make R recognize that the dates vector does not contain strings but a dates in a specific format? And then how can use this to create the mentioned data-frame? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] import function without overwriting function with the same name
> env.lst <- lapply(1:5, new.env) > > seems to work just fine ok, as far as I understand I would create 5 new environments by this. But how do I access and change the environment? What is the name of the environment? Here is a more concrete example and the general problem: source('functions1.R') source('functions2.R') now functions1.R and functions2.R contain function definitions with the same function-names. So as soon as I execute source('functions2.R'), I overwrite the function definitions already imported by source('functions1.R'). How can I avoid this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] import function without overwriting function with the same name
Hi, I have to import multiple R-files. Each file consists of several functions with the same function name across the R-files. When I import all files one by one (with source()) I overwrite the function definition of the previous file until only the very last function definition lasts. However, I need them separately (although they have the name, they solve a certain task differently). Now I thought about creating a separate environment for each file / function-group, but I do not know upfront how many files I have to import and therefore how many different environments I need. But since the creation of an environment works like variable assignments (myEnv <- new.env()) I cannot just loop over the number of files and create x environments. What is the best way to solve this problem of importing functions without overwriting already existing functions with the same name? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] add diagonal to matrix
Hi, I have a 5 columns x 4 rows matrix and would like to add a diagonal of zeros so that I end up with a 5x5 matrix. x <- matrix(1:20, 4,5) what is the easiest way to accomplish this in R? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] update an array of plots in 'real-time' without drawing lags
Hi, I know R is not made for this, but I still wanted to ask if there are possibilities to do this; I repeatedly collect data from a database for a given time interval. Now I would like to monitor the change of this data with some nice plots. I actually have to draw 15 plots to get the whole picture. Now I can write a loop that, for a given time interval, updates the data and plots them using one quartz window that is split into subparts with the layout function. However, since I redraw every plot every time, the drawing takes some time and it is not an "instant update" that I see. The plots are slowly redrawn from the upper left corner of the quartz window to the bottom right. That makes me wonder; Is there a way to buffer the graphical device before updating it? Or are there any other solutions for R that enables to smoothly plot / visualize data in 'real-time'? I am grateful for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] connect to local mySQL database
> Can you clarify: are you trying to connect to a mySQL database, or to a > sqlite database? It is a sqlite database. Thanks for pointing that out! Now it works just like in python ;). con <- dbConnect(SQLite(), dbname="xy.sqlite") res <- dbSendQuery(conn = con, "SELECT * FROM table1 WHERE x = y") data <- fetch(res, n = -1) dbCommit(con) dbDisconnect(con) thanks! On May 16, 2013, at 23:51 , Sarah Goslee wrote: > Hi Martin, > > Can you clarify: are you trying to connect to a mySQL database, or to a > sqlite database? They're not at all the same thing, and I can't tell from > your question which you're after. > > You need either RMySQL, or if you actually want an sqlite database, RSQLite > or sqldf. > > Sarah > > On Thursday, May 16, 2013, Martin Batholdy wrote: > Hi, > > I would like to access a local mysql database. > > In python using the sqlite3 library it is quite straightforward. I just have > to pass the path to the sqlite-file; > sqlite3.connect('.../xy.sqlite') > > Is there something similar in R (or specifically in the RMySQL package)? > > > It seems like I have to use the MySQL function in the RMySQL package in order > to ... > "initializes a MySQL client. It returns an driver object that allows you to > connect to one or several MySQL servers." > > > But is that also possible with a local mySQL database? > Can't I just provide the information where to find the sqlite file and then > open it? > > > sorry if this are stupid questions, > I am not very familiar with databases and just have to access a database on a > shared network drive, which worked fine in python but seems to be not so > straightforward in R. > > > I am grateful for any suggestions! > > > > > -- > Sarah Goslee > http://www.stringpage.com > http://www.sarahgoslee.com > http://www.functionaldiversity.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] connect to local mySQL database
Hi, I would like to access a local mysql database. In python using the sqlite3 library it is quite straightforward. I just have to pass the path to the sqlite-file; sqlite3.connect('.../xy.sqlite') Is there something similar in R (or specifically in the RMySQL package)? It seems like I have to use the MySQL function in the RMySQL package in order to ... "initializes a MySQL client. It returns an driver object that allows you to connect to one or several MySQL servers." But is that also possible with a local mySQL database? Can't I just provide the information where to find the sqlite file and then open it? sorry if this are stupid questions, I am not very familiar with databases and just have to access a database on a shared network drive, which worked fine in python but seems to be not so straightforward in R. I am grateful for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] dispersion indicator for clustered data
Hi, I have a dataset with clustered data (observations within groups) and would like to make some descriptive plots. Now, I am a little bit lost on how to present the dispersion of the data (what kind of residuals to plot). I could compute the standard error of the mean (SEM) ignoring the clustering (very low values and misleading) or I could first aggregate the data by calculating th mean for each group and calculate the SEM for this means. But I am not so sure what implication these two approaches have. In the end, I take the clustering into account by fitting a random-intercept regression model – however for plotting I would like to have a descriptive dispersion indicator of the data. Now, I heard a lot about 'clustered' or 'robust' standard errors. Is there some kind of correction I can apply to the simple SEM formula (sd(x)/sqrt(m)) to take care of correlated observations within clusters? Or are there bootstrapping or jackknife approaches implemented in R (or cran package) which give me unbiased variance estimation for clustered data? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] understanding cex (R plots)
thank you! It seems like the problem was the layout-function automatically changing the cex parameter for the subplots. adding par(cex =1) after the layout() call solved it. Now, character expansion levels seem equal across plots. On Feb 27, 2013, at 00:57 , Greg Snow <538...@gmail.com> wrote: > Have you queried the value of 'cex' and related parameters at the different > time points? > > The help page for par says that when you set mfcol or mfrow that cex is > changed, but I don't know if the layout function also changes those or not. > I would start by peppering your code with calls to par('cex') to see what R > thinks the parameter is at the time of the different plots. That may answer > your question, or if not at least give up more information to work with. > > > On Tue, Feb 26, 2013 at 3:46 PM, Martin Batholdy > wrote: > Hi, > > I try to make multiple plots look as similar as possible. > > > I create each plot with pdf(), using the same height but different width in > inch. > For some plots I use the layout() function to draw multiple subplots side by > side in one pdf. > > For each plot I use the same cex values for the different plotting functions > (cex.axis, cex.lab, cex.points etc.) > > Still, when I compare the pdf's the axis labels, titles etc. have different > size factors! > > Is that expected? > > I thought by fixing the height parameter and using the same character > expansion values I would end up with similar plots > (and especially same font size across pdfs). > > How can I make sure that across multiple plot calls the character expansion > level (font size) is the same? > > > > thanks! > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > > -- > Gregory (Greg) L. Snow Ph.D. > 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] understanding cex (R plots)
Hi, I try to make multiple plots look as similar as possible. I create each plot with pdf(), using the same height but different width in inch. For some plots I use the layout() function to draw multiple subplots side by side in one pdf. For each plot I use the same cex values for the different plotting functions (cex.axis, cex.lab, cex.points etc.) Still, when I compare the pdf's the axis labels, titles etc. have different size factors! Is that expected? I thought by fixing the height parameter and using the same character expansion values I would end up with similar plots (and especially same font size across pdfs). How can I make sure that across multiple plot calls the character expansion level (font size) is the same? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] cut a vector in equal parts
Hi, I would like to cut a vector of values in parts. Each part should have an equal number of elements. for example: x <- (rnorm(500)^2) now I want 5 vectors each with 100 elements. The first vector should include the 100 lowest values of x and so on (so that the fifth vector contains the 100 highest values of x). thanks for any help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] compute p/t value from pearson r and n
Dear Miguel, thanks! But I actually do not have two vectors but just a correlation coefficient and want to get the p value. As far as I can see it, cor.test only works when having raw data pairs or am I missing something? On Feb 24, 2013, at 22:24 , Miguel Manese wrote: > Hi Martin, > > See ?cor.test > > example(cor.test) > > Regards, > - Jon > > On Mon, Feb 25, 2013 at 5:06 AM, Martin Batholdy > wrote: >> Hi, >> >> is there a predefined function that computes the p- or t-value >> based on a correlation coefficient and its sample size? >> >> >> thanks! >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] compute p/t value from pearson r and n
Hi, is there a predefined function that computes the p- or t-value based on a correlation coefficient and its sample size? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] change confidence interval line length in barplot2 (plotrix package)
Ok, I have to apologize, I confused the packages. It's the function barplot2 from the gplots package! > It calls itself an extenstion of barplot2 and has a ci.lwd argument. Might > save you the time of doing what I thought might be needed, hacking te code. Unfortunately ci.lwd controls the thickness of the line but not the horizontal width. On Jan 22, 2013, at 21:24 , David Winsemius wrote: > > On Jan 22, 2013, at 10:28 AM, Martin Batholdy wrote: > >> Hi, >> >> is there any way to change the width of the horizontal line of confidence >> intervals >> in the barplot2 function in the plotrix package (independent of the width of >> the bars)? >> >> >> example code: >> >> library(plotrix) >> # Example with confidence intervals and grid >> hh <- t(VADeaths)[, 1] >> mybarcol <- "gray20" >> ci.l <- hh * 0.85 >> ci.u <- hh * 1.15 >> mp <- barplot2(hh, beside = TRUE, >> col = c("lightblue", "mistyrose", >> "lightcyan", "lavender"), >> legend = colnames(VADeaths), ylim = c(0, 20), >> main = "Death Rates in Virginia", font.main = 4, >> sub = "Faked 95 percent error bars", col.sub = mybarcol, >> cex.names = 1.5, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u) > > When I did an sos::findFn("barplot2") search to locate the "real" `barplot2` > O alos noted in the same package (gplots) a function named `ooplot`. It calls > itself an extenstion of barplot2 and has a ci.lwd argument. Might save you > the time of doing what I thought might be needed, hacking te code. > > -- > David Winsemius > Alameda, CA, USA > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] change confidence interval line length in barplot2 (plotrix package)
Hi, is there any way to change the width of the horizontal line of confidence intervals in the barplot2 function in the plotrix package (independent of the width of the bars)? example code: library(plotrix) # Example with confidence intervals and grid hh <- t(VADeaths)[, 1] mybarcol <- "gray20" ci.l <- hh * 0.85 ci.u <- hh * 1.15 mp <- barplot2(hh, beside = TRUE, col = c("lightblue", "mistyrose", "lightcyan", "lavender"), legend = colnames(VADeaths), ylim = c(0, 20), main = "Death Rates in Virginia", font.main = 4, sub = "Faked 95 percent error bars", col.sub = mybarcol, cex.names = 1.5, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u) thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] aggregate data.frame based on column class
Hi, When using the aggregate function to aggregate a data.frame by one or more grouping variables I often have the problem, that I want the mean for some numeric variables but the unique value for factor variables. So for example in this data-frame: data <- data.frame(x = rnorm(10,1,2), group = c(rep(1,5), rep(2,5)), gender =c(rep('m',5), rep('f',5))) aggregate(data, by=list(data$group), FUN=mean) I would like to have 'm' and 'f' in the third column, not NA. I see the problem, that it could happen that there is no unique factor level in a group – but is there an alternative function who at least tries what I am aiming at? That is; "aggregate the data.frame by a list of grouping variables, for numeric variables compute the mean, for factor variables return the unique factor value" Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R and SSH / exchange R objects between client and server
Hi, I have a laptop (Mac OS) and a remote PC (Ubuntu) and would like to do the heavy work on the remote machine but control it via the laptop. I managed to install ssh server and can now remotely connect to my PC via ssh and can start an R session in the terminal. However, I still don't quite understand how I can now "exchange" R objects. I have the raw data I want to read and analyse on my laptop. So I need to read the files on the laptop and 'send' the r object to the remote PC. The remote PC should then do the heavy calculations and send back the result data frames, so that I can export/save the result tables on my laptop. Is this even possible with ssh (send R objects from client to server and vice versa)? Are there R packages who help to establish ssh connections? Can I also connect to the server via the R gui? thanks for any suggestions and tips! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] aggregate / collapse big data frame efficiently
Hi, I need to aggregate rows of a data.frame by computing the mean for rows with the same factor-level on one factor-variable; here is the sample code: x <- data.frame(rep(letters,2), rnorm(52), rnorm(52), rnorm(52)) aggregate(x, list(x[,1]), mean) Now my problem is, that the actual data-set is much bigger (120 rows and approximately 100.000 columns) – and it takes very very long (actually at some point I just stopped it). Is there anything that can be done to make the aggregate routine more efficient? Or is there a different approach that would work faster? Thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] create stratified splits
Hi, I have a vector like: r <- runif(100) Now I would like to split r into 10 pieces (each with 10 elements) – but the 'pieces' should be roughly similar with regard to mean and sd. what is an efficient way to do this in R? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] winBUGS with R2WinBUGS on a mac – path issue
Hi, I try to execute a winBUGS model within R on a Mac. I use wine and the R2WinBUGS package. Now I have a small problem with the path variables; the path to the bugs directory include paranthesis and because of that it won't run. error message: sh: -c: line 0: syntax error near unexpected token `(' Is there any way to get winBUGS to run even with a path that includes parenthesis? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mean-aggregate – but use unique for factor variables
Hi, I have a data.frame which I want to aggregate. There are some grouping variables and some continuous variables for which I would like to have the mean. However there are also some factor-variables in the data-frame that are not grouping variables and I actually would like to aggregate these variables with the unique() function. Is that possible with the standard aggregate-function? If I use it like this: aggregate(data, by=list(data$grouping1, data$grouping2), FUN=mean) I get vectors of NAs for the other factor-variables in the data.frame. But I actually want the unique value … Is that possible? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] compare different data-formats
Hi, I have two data-frames which I want to match by a date-variable. The problem now is, that the date-variable has a different format in this two data-frames. So simply matching by this variable wouldn't work. In the one data-frame the date-variable contains strings that look like this: 14.Aug.2012-16:32 3.Sep.2012-16:50 etc. in the other data-frame the date-variable looks like this: 2012.08.14 2012.09.3 is there an easy way to compare these two vectors? Or is there an easy way to transform 14.Aug.2012-16:32 into 2012.08.14 ? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] use R remotely (ssh / shell / emacs)
Hi, I have a laptop and a desktop PC. Now I was wondering, if it is possible to create a setup in which you can use the laptop (where ever you are) to remotely access the PC, open an R-instance and let the PC do the heavy computation. I have no idea about remote control, wake-on-lan, ssh and all these things. I just wanted to know if someone here on the list is actually working with such a setup and if, once all is configured, it works reliable. how much work it is to set it up with an editor like emacs? And for which buzzwords should I search the internet? sorry if that is the wrong mailing-list for this kind of questions, I just hope to get some input on the topic. thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] extract weighting values from a relevance vector machine (kernlab package)
Dear R-users, How can I extract the weighting values (w-values) for each feature from a rvm-object of the kernlab package? I can access the relevance vectors but how can I get the weighting values of each feature? example code: # create data x1 <- rnorm(401,sd=1.10) x2 <- rnorm(401,sd=1.10) x3 <- rnorm(401,sd=1.10) x4 <- rnorm(401,sd=1.10) y <- (0.4 * sin(x1)/x1 + rnorm(401,sd=0.10)) + (0.7 * sin(x2)/x2 + rnorm(401,sd=0.05)) + (1.2 * sin(x3)/x3 + rnorm(401,sd=0.15)) + (2.2 * sin(x4)/x4 + rnorm(401,sd=0.25)) # train relevance vector machine foo <- rvm(data.frame(x1, x2, x3, x4), y, kernel='vanilladot') foo alpha(foo) RVindex(foo) thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cross validation in rvm not working? (kernlab package)
Hi, according to ?rvm the relevance vector machine function as implemented in the kernlab-package has an argument 'cross' with which you can perform k-fold cross validation. However, when I try to add a 10-fold cross validation I get the following error message: Error in match.arg(type, c("C-svc", "nu-svc", "kbb-svc", "spoc-svc", "C-bsvc", : 'arg' should be one of “C-svc”, “nu-svc”, “kbb-svc”, “spoc-svc”, “C-bsvc”, “one-svc”, “eps-svr”, “eps-bsvr”, “nu-svr” code-example: # create data x <- seq(-20,20,0.1) y <- sin(x)/x + rnorm(401,sd=0.05) # train relevance vector machine foo <- rvm(x, y, cross=10) So, does that mean that cross-validation is not working for rvm at the moment? (since the type argument only allows support vector regression or classification) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array
Ok, I am sorry, My trainingset consists of a 60 x 204 matrix (independent_training – 204 features). I have 60 continuous labels (dependent_training, ranging from 2.25 to 135). this is all the code I use: library(kernlab) rvm(as.matrix(independent_training), dependent_training, type="regression", kernel = "vanilladot") On 13.02.2012, at 16:40, David Winsemius wrote: > > On Feb 13, 2012, at 10:23 AM, Martin Batholdy wrote: > >> Hi, >> >> For another trainingset I get this error message, which again is rather >> cryptic to me: >> > Just imagine how it seems to us! > >> Setting default kernel parameters >> >> Error in array(0, c(n, p)) : 'dim' specifies too large an array >> RMate stopped at line 0 of selection >> Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag -> array > > You are on you way to the prize for the greatest number of cryptic (your > word) postings in a short interval. (And this one doesn't even have the > context of your posting of 8 minutes ago.) > >> thanks for any suggestions! > > More details about data and code. > > -- > David Winsemius, MD > West Hartford, CT > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array
I am using a linear kernel (vanilladot). By switching the kernel, I actually get rid of the error message, but I would like to stick to the linear one ... On 13.02.2012, at 16:23, Martin Batholdy wrote: > Hi, > > For another trainingset I get this error message, which again is rather > cryptic to me: > > > Setting default kernel parameters > > Error in array(0, c(n, p)) : 'dim' specifies too large an array > RMate stopped at line 0 of selection > Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag -> array > > > > thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array
Hi, For another trainingset I get this error message, which again is rather cryptic to me: Setting default kernel parameters Error in array(0, c(n, p)) : 'dim' specifies too large an array RMate stopped at line 0 of selection Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag -> array thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] kernlab - rvm error message: Error in if (length(data) != vl)
Hi, I am trying to perform relevance vector machines with the rvm-function from kernlab. On one dataset I get this message: Setting default kernel parameters Error in if (length(data) != vl) { : RMate stopped at line 0 of selection missing value where TRUE/FALSE needed Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag -> array can someone explain this error message? It works for other data-sets with the same feature / example-space. But for one particular trainingset I get this error message... thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] check for nearest value in a vector
great, thanks! On 08.02.2012, at 14:00, Dimitris Rizopoulos wrote: > How about this: > > x <- c(1, 6, 12, 28, 33) > > which.min(abs(x - 14)) > > > I hope it helps. > > Best, > Dimitris > > > On 2/8/2012 1:56 PM, Martin Batholdy wrote: >> Hi, >> >> Is there a way to check which value in a vector is nearest to a given value? >> >> so for example I have vector x: >> >> x<- c(1, 6, 12, 28, 33) >> >> and I would like to get the position of the element of x that is nearest to >> 14 >> (in this case the third element). >> >> >> thanks! >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > -- > Dimitris Rizopoulos > Assistant Professor > Department of Biostatistics > Erasmus University Medical Center > > Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands > Tel: +31/(0)10/7043478 > Fax: +31/(0)10/7043014 > Web: http://www.erasmusmc.nl/biostatistiek/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] check for nearest value in a vector
Hi, Is there a way to check which value in a vector is nearest to a given value? so for example I have vector x: x <- c(1, 6, 12, 28, 33) and I would like to get the position of the element of x that is nearest to 14 (in this case the third element). thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] get mean of same elements in a data.frame
Hi, I have the following data.frame: data.frame(x = c(1:10), y = rnorm(10,2,1), label = rep(c('a', 'b', 'c', 'd', 'e'),2)) in this data.frame there is a label-variable containing strings. Each string is represented two times. Now I would like to have the mean of the corresponding x (and y-values) for every unique label-element. For the label 'a' for example there is an x value of 1 and 6. So the resulting value should be 3.5. How can I do this in R? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] apply lm() to each row of a matrix
Hi, I would like to fit lm-models to a matrix with 'samples' of a dependent variable (each row represents one sample of the dependent variable). The independent variable is a vector that stays the same: y <- c(1:10) x <- matrix(rnorm(5*10,0,1), 5, 10) now I would like to avoid looping over the rows, since my original matrix is much larger; for(t in 1:dim(x)[1]) { print(lm(y ~ x[t,])) } Is there a time-efficient way to do this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sequentially summing up a elements of a vector
Hi, I have a somewhat abstract and tricky problem (at least for me). Perhaps someone here can help me: I would like to convert: x <- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0) into x <- c(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4) every 1 in x marks kind of a 'border' which is separated in different 'regions' in the new x. thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] z-transform each column of a data.frame
great, thank you! On 20.01.2012, at 18:10, R. Michael Weylandt wrote: > ? scale > apply(x, 2, scale) > > Michael > > On Fri, Jan 20, 2012 at 12:04 PM, Martin Batholdy > wrote: >> Hi, >> >> >> I am currently trying to z-transform (that is subtracting the mean and >> divide by the standard deviation) multiple columns of a data.frame at the >> same time. >> >> >> My first approach was: >> >> x <- data.frame(c(0:10), c(10:20)) >> (x - colMeans(x)) / apply(x, 2, sd) >> >> >> This is obviously not working. >> >> Is there a convenient way to z-transform each column separately (so in this >> case, each column represents an independent variable that should be >> z-transformed) >> >> >> thanks! >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] z-transform each column of a data.frame
Hi, I am currently trying to z-transform (that is subtracting the mean and divide by the standard deviation) multiple columns of a data.frame at the same time. My first approach was: x <- data.frame(c(0:10), c(10:20)) (x - colMeans(x)) / apply(x, 2, sd) This is obviously not working. Is there a convenient way to z-transform each column separately (so in this case, each column represents an independent variable that should be z-transformed) thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] get the percentage rank of a value based on an empirical data vector
> > findInterval(6.2, sort(x)) > [1] 704 > > xecdf <- ecdf(x) > > xecdf(6.2) > [1] 0.704 thanks, that helped a lot! On 11.01.2012, at 14:58, David Winsemius wrote: > > On Jan 11, 2012, at 8:12 AM, Martin Batholdy wrote: > >> Hi, >> >> I have a vector with values: >> >> x <- rnorm(1000, 5, 2) >> >> >> and one single value: >> y <- 6.2 >> >> now I would like to know the percent rank of y based on the >> 'population'-vector x. >> Is there a convenient function that calculates the percent rank of a y for >> the given vector x? > > Two options : > 1) sort x and use findInterval, divide the index by length(x) and multiply by > 100 > (It can all be done as a one-liner.) > > 2) I generally "reach for" the `ecdf` "function making machine" when I see > sample quantile problems and see if I can cast the problem in terms for which > it applies. > > For my random draw I get: > > findInterval(6.2, sort(x)) > [1] 704 > > xecdf <- ecdf(x) > > xecdf(6.2) > [1] 0.704 > > -- > David Winsemius, MD > West Hartford, CT > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] get the percentage rank of a value based on an empirical data vector
Hi, I have a vector with values: x <- rnorm(1000, 5, 2) and one single value: y <- 6.2 now I would like to know the percent rank of y based on the 'population'-vector x. Is there a convenient function that calculates the percent rank of a y for the given vector x? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] modeling a haemodynamic response function in R
Hi, I have time-series data and I would like to fit a 2-gamma HRF to the data (http://en.wikibooks.org/wiki/SPM/Haemodynamic_Response_Function) in order to get the explained variance and the maximum of the fitted data. Is there a straightforward function for that or a package that provides functions for this kind of procedure? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] algorithm that iteratively drops columns of a data-frame
great, thank you both! On 09.11.2011, at 17:27, Jeff Newmiller wrote: > Try > > data[,!names(data) %in% names(col_means)] > > On Wed, 9 Nov 2011, Martin Batholdy wrote: > >> Dear R-Users, >> >> >> I have a problem with an algorithm that iteratively goes over a data.frame >> and exclude n-columns each step based on a statistical criterion. >> So that the 'column-space' gets smaller and smaller with each iteration >> (like when you do stepwise regression). >> >> The problem is that in every round I use a new subset of my data.frame. >> >> However, as soon as I "generate" this subset by indexing the data.frame I >> get of course different column-numbers (compared to my original data-frame). >> >> How can I solve this? >> >> >> >> I prepared a small example to make my problem easier to understand: >> >> >> Here I generate a data.frame containing 6 vectors with different means. >> >> The loop now should exclude the vector with the smallest mean in each round. >> >> At the end I want to have a vector ('drop') which contains the column >> numbers that I can apply on the original data.frame to get a subset with the >> highest means. >> >> But the problem is that this is not working, since every time I generate a >> subset ('data[,-drop]') I of course get now different column-numbers that >> differ from the column-numbers of the original data-frame. >> >> So, in the end I can't use my drop-vector on my original data-frame ? since >> the dimension of the testing data-frame changes in every loop-round. >> >> >> How can I deal with this kind of problem? >> >> Any suggestions are highly appreciated! >> (of course for the example code, there are much easier method to achieve the >> goal of finding the columns with the smallest means ? It is a pretty generic >> example) >> >> >> here is the sample code: >> >> >> x1 <- rnorm(200, 5, 2) >> x2 <- rnorm(200, 6, 2) >> x3 <- rnorm(200, 1, 2) >> x4 <- rnorm(200, 12, 2) >> x5 <- rnorm(200, 8, 2) >> x6 <- rnorm(200, 9, 2) >> >> >> data <- data.frame(x1, x2, x3, x4, x5,x6) >> >> col_means <- colMeans(data) >> drop <- match(min(col_means), col_means) >> >> >> for(i in 1:4) { >> >> col_means <- colMeans(data[,-drop]) >> drop <- c(drop, match(min(col_means), col_means)) >> >> } >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > --- > Jeff NewmillerThe . . Go Live... > DCN:Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/BatteriesO.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] algorithm that iteratively drops columns of a data-frame
Dear R-Users, I have a problem with an algorithm that iteratively goes over a data.frame and exclude n-columns each step based on a statistical criterion. So that the 'column-space' gets smaller and smaller with each iteration (like when you do stepwise regression). The problem is that in every round I use a new subset of my data.frame. However, as soon as I "generate" this subset by indexing the data.frame I get of course different column-numbers (compared to my original data-frame). How can I solve this? I prepared a small example to make my problem easier to understand: Here I generate a data.frame containing 6 vectors with different means. The loop now should exclude the vector with the smallest mean in each round. At the end I want to have a vector ('drop') which contains the column numbers that I can apply on the original data.frame to get a subset with the highest means. But the problem is that this is not working, since every time I generate a subset ('data[,-drop]') I of course get now different column-numbers that differ from the column-numbers of the original data-frame. So, in the end I can't use my drop-vector on my original data-frame – since the dimension of the testing data-frame changes in every loop-round. How can I deal with this kind of problem? Any suggestions are highly appreciated! (of course for the example code, there are much easier method to achieve the goal of finding the columns with the smallest means – It is a pretty generic example) here is the sample code: x1 <- rnorm(200, 5, 2) x2 <- rnorm(200, 6, 2) x3 <- rnorm(200, 1, 2) x4 <- rnorm(200, 12, 2) x5 <- rnorm(200, 8, 2) x6 <- rnorm(200, 9, 2) data <- data.frame(x1, x2, x3, x4, x5,x6) col_means <- colMeans(data) drop <- match(min(col_means), col_means) for(i in 1:4) { col_means <- colMeans(data[,-drop]) drop <- c(drop, match(min(col_means), col_means)) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] control the conversion of factor to numeric
Ok, I think that would work – thanks! However, in my case I read a data.frame via read.table(). So some of the columns get transformed to factors automatically – I don't generate the factor-variables as in the example, so I can't control how the levels are ordered (or can I?). On 18.10.2011, at 15:35, R. Michael Weylandt wrote: > Add levels= to your factor() call. > > E.g., > > x1 <- factor(rep(1:4, 5), labels=c("slightly disagree", "disagree", > "agree", "slightly agree"), levels = c(2,1,4,3)) > as.numeric(x1) > [1] 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 > > Michael > > On Tue, Oct 18, 2011 at 7:35 AM, Martin Batholdy > wrote: >> Dear R-list, >> >> >> >> I currently have to convert a data.frame with several factor-variables to a >> numeric matrix. >> >> Now the problem is, that the order of the factor-labels don't match the >> order I would like to use. >> >> >> for example, let's assume I have this factor-variable in my data-frame: >> >> x <- factor(rep(1:4, 5), labels=c("slightly disagree", "disagree", "agree", >> "slightly agree")) >> >> >> Now I would like to convert this to a numeric vector so that disagree == 1, >> slightly disagree == 2, slightly agree == 3, and agree gets the value 4. >> but as.numeric(x) just converts the factor levels to numerical values >> according to their label-order. >> >> >> Is there a convenient, flexible function that let's you control how the >> factor-levels get converted to numerical values? >> >> >> >> thanks for any suggestions! >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] control the conversion of factor to numeric
Dear R-list, I currently have to convert a data.frame with several factor-variables to a numeric matrix. Now the problem is, that the order of the factor-labels don't match the order I would like to use. for example, let's assume I have this factor-variable in my data-frame: x <- factor(rep(1:4, 5), labels=c("slightly disagree", "disagree", "agree", "slightly agree")) Now I would like to convert this to a numeric vector so that disagree == 1, slightly disagree == 2, slightly agree == 3, and agree gets the value 4. but as.numeric(x) just converts the factor levels to numerical values according to their label-order. Is there a convenient, flexible function that let's you control how the factor-levels get converted to numerical values? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replicate data.frame n times
Hi, is there a way to replicate a data.frame like you can replicate the entries of a vector (with the repeat-function)? I want to do this: x <- data.frame(x, x) (where x is a data.frame). but n times. And it should be as cpu / memory efficient as possible, since n is pretty big in my case. thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] calculate multiple means of one vector
Dear R-Users, I have the following two vectors: data <- rnorm(40, 0, 2) positions <- c(3, 4, 5, 8, 9, 10, 20, 21, 22, 30, 31, 32) now I would like to calculate the mean of every chunk of data-points (of the data-vector) as defined by the positions-vector. So I would like to get a vector with the mean of element 3 to 5 of the data-vector, 8 to 10, 20 to 22 and so on. The gaps between the chunks are arbitrary. There is no pattern (meaning the gap from 5 to 8, 10 to 20, 22 to 30 etc.) But the chunks are always of length n (in this case 3). Is there a convenient way to do this without using a for-loop? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generate sequences for every element of a vector
great, thank you! On 07.10.2011, at 15:54, Jean-Christophe BOUËTTÉ wrote: > Hi, > this should work: > as.vector(rbind(x,x+1,x+2)) > > 2011/10/7 Martin Batholdy : >> Dear R-List, >> >> >> I have the following problem: >> >> I have a vector that looks like this: >> >> x <- c(3, 8, 14, 24, 34, 40) >> >> >> And I would like to make a sequence out of every element, starting at the >> value of this element. >> >> So that I get a vector just like this: >> >> x <- c(3, 4, 5, 8, 9, 10, 14, 15, 16, 24, 25, 26, 34, >> 35, 36, 40, 41, 42) >> >> >> >> >> How can I do this without looping over the whole vector or something like >> this? >> >> >> thanks for any suggestions! >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] generate sequences for every element of a vector
Dear R-List, I have the following problem: I have a vector that looks like this: x <- c(3, 8, 14, 24, 34, 40) And I would like to make a sequence out of every element, starting at the value of this element. So that I get a vector just like this: x <- c(3, 4, 5, 8, 9, 10, 14, 15, 16, 24, 25, 26, 34, 35, 36, 40, 41, 42) How can I do this without looping over the whole vector or something like this? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] do calculations as defined by a string / expand mathematical statements in R
Thanks for all the suggestions! Perhaps my post was not clear enough. apply(array,1:2,sum)/dim(array)[3] and # reproducible example x <- 1:1000 dim(x)<-rep(10,3) # code apply(x,1:2,sum) would give me the mean over one whole dimension, right? The problem with that is, that I just want to calculate the mean over a subset of t (where t is the 4th dimension of the array). And the range of this subset should be easily changeable. So for example I have 4D array: x <- 1:1 dim(x)<-rep(10,4) Now I would like to average the 3D array(x,y,z) in the 4th dimension (t) from t_start = a to t_end = b. I don't want to average the whole 3D array. On 05.10.2011, at 22:21, William Dunlap wrote: > Avoid parsing strings to make expressions. It is easy > to do, but hard to do safely and readably. > > In your case you could make a short loop out of it > result <- x[,,,1] > for(i in seq_len(dim(x)[4])[-1]) { > result <- result + x[,,,i] > } > result <- result / dim(x)[4] > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com Wouldn't that be much slower than define a string and evaluate it as an expression since I would have to use a for-loop? thanks again! You helped me a lot today ;) On 05.10.2011, at 22:21, William Dunlap wrote: > Avoid parsing strings to make expressions. It is easy > to do, but hard to do safely and readably. > > In your case you could make a short loop out of it > result <- x[,,,1] > for(i in seq_len(dim(x)[4])[-1]) { > result <- result + x[,,,i] > } > result <- result / dim(x)[4] > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On >> Behalf Of Martin Batholdy >> Sent: Wednesday, October 05, 2011 1:14 PM >> To: R Help >> Subject: [R] do calculations as defined by a string / expand mathematical >> statements in R >> >> Dear R-group, >> >> >> is there a way to perform calculations that are defined in a string format? >> >> >> for example I have different variables: >> >> x1 <- 3 >> x2 <- 1 >> x4 <- 1 >> >> and a string-variable: >> >> do <- 'x1 + x2 + x3' >> >> >> Is there any way to perform what the variable 'do'-describes >> (just like the formula-element but more elemental)? >> >> >> >> Perhaps my idea to solve my problem is a little bit strange. >> >> >> My general problem is, that I have to do arithmetics for which there seems >> to be no function available >> that I can apply in order to be more flexible. >> >> >> To be precise, I have to add up three dimensional arrays. >> >> I can do that like this (as someone suggested on this help-list - thanks for >> that!): >> >> (array[,,1] + array[,,2] + array[,,3]) / 3 >> >> >> However in my case it can happen that at some point, I don't have to add 3 >> but 8 'array-slices' >> (or 10 or x). >> >> And I don't want to manually expand the above statement to: >> >> (array[,,1] + array[,,2] + array[,,3] + array[,,4] + array[,,5] + array[,,6] >> + array[,,7] + >> array[,,8]) / 8 >> >> (ok, now I have done it ;) >> >> >> >> So, my thinking was that I can easily expand and change a string (with the >> paste-function / repeat- >> function etc.). >> But how can I expand a mathematical statement? >> >> >> thanks for any suggestions! >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] do calculations as defined by a string / expand mathematical statements in R
Dear R-group, is there a way to perform calculations that are defined in a string format? for example I have different variables: x1 <- 3 x2 <- 1 x4 <- 1 and a string-variable: do <- 'x1 + x2 + x3' Is there any way to perform what the variable 'do'-describes (just like the formula-element but more elemental)? Perhaps my idea to solve my problem is a little bit strange. My general problem is, that I have to do arithmetics for which there seems to be no function available that I can apply in order to be more flexible. To be precise, I have to add up three dimensional arrays. I can do that like this (as someone suggested on this help-list – thanks for that!): (array[,,1] + array[,,2] + array[,,3]) / 3 However in my case it can happen that at some point, I don't have to add 3 but 8 'array-slices' (or 10 or x). And I don't want to manually expand the above statement to: (array[,,1] + array[,,2] + array[,,3] + array[,,4] + array[,,5] + array[,,6] + array[,,7] + array[,,8]) / 8 (ok, now I have done it ;) So, my thinking was that I can easily expand and change a string (with the paste-function / repeat-function etc.). But how can I expand a mathematical statement? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] speed up this algorithm (apply-fuction / 4D array)
Hi, I have this sample-code (see above) and I was wondering wether it is possible to speed things up. What this code does is the following: x is 4D array (you can imagine it as x, y, z-coordinates and a time-coordinate). So x contains 50x50x50 data-arrays for 91 time-points. Now I want to reduce the 91 time-points. I want to merge three consecutive time points to one time-points by calculating the mean of this three time-points for every x,y,z coordinate. The reduce-sequence defines which time-points should get merged. And the apply-function in the for-loop calculates the mean of the three 3D-Arrays and puts them into a new 4D array (data_reduced). The problem is that even in this example it takes really long. I thought apply would already vectorize, rather than loop over every coordinate. But for my actual data-set it takes a really long time … So I would be really grateful for any suggestions how to speed this up. x <- array(rnorm(50 * 50 * 50 * 90, 0, 2), dim=c(50, 50, 50, 91)) data_reduced <- array(0, dim=c(50, 50, 50, 90/3)) reduce <- seq(1,90, 3) for( i in 1:length(reduce) ) { data_reduced[ , , , i]<-apply(x[ , , , reduce[i] : (reduce[i]+3) ], 1:3, mean) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] converting 3D array to a data-frame (with coordinate-columns x, y, z)
Hi, I am still struggling with three dimensional arrays. Now I would like to convert a three dimensional array into a data-frame with the coordinate-columns: x, y, z and a value-column. And I definitely don't want to loop over every element, since this would be very resource intensive for the actual data-set. Are there any specific functions that are helpful for this task? example-array: x <- array(1:27, dim=c(3,3,3,1)) thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mean of 3D arrays
Hi, I have multiple three dimensional arrays. Like this: x1 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x2 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x3 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) Now I would like to compute the mean for each corresponding cell. As a result I want to get one 3D array (10 x 10 x 10) in which at position x, y, z is the mean of the corresponding values of x1, x2 and x3 (at position x, y, z). How can I do this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] intensity map / plot
thanks! On 03.10.2011, at 19:11, Uwe Ligges wrote: > See ?image > > Uwe Ligges > > > On 03.10.2011 19:05, Martin Batholdy wrote: >> Dear R-list, >> >> >> I would like to generate an intensity map based on a x * y matrix. >> >> Each point in the matrix should get plotted at the coordinate: x = column / >> y = row with >> a color-intensity (for example gray-value) based on the actual value of this >> point. >> >> Is there a convenient package / function for this kind of plot? >> >> >> >> example data: >> x<- matrix(rnorm(100*100, 0, 2), 100, 100) >> >> >> thanks! >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] intensity map / plot
Dear R-list, I would like to generate an intensity map based on a x * y matrix. Each point in the matrix should get plotted at the coordinate: x = column / y = row with a color-intensity (for example gray-value) based on the actual value of this point. Is there a convenient package / function for this kind of plot? example data: x <- matrix(rnorm(100*100, 0, 2), 100, 100) thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] different results aov vs. lm
Hi, I currently running regression models on an experimental dataset. The model contains one independent continuous variable and two independent experimental conditions (one with two factors, the other with three factors) and several covariates. Now I get different results for a covariate in this model when I run aov(modell) vs. lm(modell). In the ancova model, one of the covariates seems to explain a significant amount of variance. But in the lm-statistics this variable doesn't exceed the p-threshold of p = 0.05. How can that be? thanks for any advice on this! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] split variable / create categories
Thanks for the suggestions! However all these functions don't produce exactly what I want (at least with my actual data). I need a split-algorithm that converts the values of my vectors into four factors. And the crucial part is, that I need exactly the same number of elements in each factor-level and no overlapping. cut() seems to find equal intervals but that leads to different numbers of elements in each interval. library(lattice) equal.count(x,number=4,overlap=0) seems to do the job, but strangely enough, it seems to ignore the argument 'overlap = 0' in my actual vector I get factor-borders that overlap. And I really have to prevent this. On 09.09.2011, at 17:49, Andrea Spano wrote: > cut ( x , c(0, 1.4 ,6, 8, Inf ), labels = 1:4, include.lowest = T) > > On 9 September 2011 17:34, Martin Batholdy wrote: > Hi, > > is there a function or an easy way to convert a variable with continuous > values into a categorial variable (with x levels)? > > here is what I mean: > > > I want to transform x: > > x <- c(3.2, 1.5, 6.8, 6.9, 8.5, 9.6, 1.1, 0.6) > > into a 'categorial'-variable with four levels so that I get: > > [1] 2 2 3 3 4 4 1 1 > > so each element is converted into its rank- value / categorial-value > (in this example four levels are created). > > > > thanks for any suggestions! > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > > -- > Andrea Spano' > > Quantide s.r.l > +39 347 747 04 92. > andrea.sp...@quantide.com > > > This electronic mail transmission may contain confidential information > addressed only to the person (s) named. Any use, distribution, copyng or > disclosure by any other person and/or entities other than the intended > recipient is prohibited. If you received this transmission in error, > please inform the sender immediately and delete the material. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] split variable / create categories
Hi, is there a function or an easy way to convert a variable with continuous values into a categorial variable (with x levels)? here is what I mean: I want to transform x: x <- c(3.2, 1.5, 6.8, 6.9, 8.5, 9.6, 1.1, 0.6) into a 'categorial'-variable with four levels so that I get: [1] 2 2 3 3 4 4 1 1 so each element is converted into its rank- value / categorial-value (in this example four levels are created). thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] show equal entries in data.frame
Hi, I have the following data-frame: x <- data.frame(first = c('a','c','k','b'), second = c('b','k','a','j'), third = c('f','a','h','b')) first second third 1 a b f 2 c k a 3 k a h 4 b j b Now I would like to see wether there are entries that exists in all three columns. In the example data-frame this would be true for 'a' and 'b' (so the row-number of the element is not important). can someone help me on this? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] algorithm to merge same entries in a matrix
Hi, I have the following, rather unorthodox problem: I have a matrix that looks like this: m1 <- matrix(c('a','b','d',NA,'c','c'), 2,3, byrow=TRUE) [,1] [,2] [,3] [1,] "a" "b" "d" [2,] NA "c" "c" now I would like to transform this matrix into this matrix: [,1] [,2] [,3] [,4] [1,] "a" "b" "c" "d" [2,] NA NA NA NA so the rule is: if I find the same value (above: 'c') in neighbored cells (here: row wise) put this value in row 1 in a new column between column of neighbor a and column of neighbor b. too make it even more complicated: the definition of neighbored cells is not exclusively row wise. So for example I could encounter this kind of matrix: m2 <- matrix(c('a','b','d',NA,NA,'c',NA, 'c', NA), 3,3, byrow=TRUE) [,1] [,2] [,3] [1,] "a" "b" "d" [2,] NA NA "c" [3,] NA "c" NA which should also be transformed into: [,1] [,2] [,3] [,4] [1,] "a" "b" "c" "d" [2,] NA NA NA NA (or m3 <- matrix(c('a','b','d',NA,'c',NA,NA, NA, 'c'), 3,3, byrow=TRUE) ). Can perhaps someone give me some hints how to solve this efficiently? I think I could solve that with some loops … but I also need to make sure that it is efficient / not taking too much time. thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] control line break behavior of R output
Hi, Is it possible to define at which point a line-break is happening in R-output? I for example would rather like to scroll horizontally in a data-frame with a lot of columns instead of having a lot of breakpoints in the data.frame (to fit the screen). Can you control that? Can you tell R to do a line-break after x symbols of output for example? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] test if vector contains elements of another vector (disregarding the position)
Hi, I have the following problem: I have two vectors: i <- c('a','c','g','h','b','d','f','k','l','e','i') j <- c('a', 'b', 'c') now I would like to generate a vector with the length of i that has zeros where i[x] != any element of j and 1 where i[x] == any element of j. So for the example above the vector would look like this: c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0) can someone help me on this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] compute the mean of two (or more) correlations
Hi, is there a function in R that computes the mean of two (or more) correlations? (that is doing the z-transformation of the correlations, computing the mean of the z-values and then retransform it to a correlation). Or is there a fisher-table implemented? I have not found anything via help.search() or google so far. thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] best way to aggregate / rearrange data.frame with different data types
Hi, I have a data.frame that looks like this: Subject <- c(rep(1,4), rep(2,4), rep(3,4)) y <- rnorm(12, 3, 2) gender <- c(rep("w",4), rep("m",4), rep("w",4)) comment <- c(rep("comment A",4), rep("comment B",4), rep("comment C",4)) data <- data.frame(Subject,y,gender,comment) data Subject y gender comment 11 2.86495339 w comment A 21 3.33758993 w comment A 31 7.00301094 w comment A 41 3.81585998 w comment A 52 2.50300460 m comment B 62 4.93830489 m comment B 72 5.08184289 m comment B 82 4.00552691 m comment B 93 3.16131181 w comment C 10 3 4.61620021 w comment C 11 3 3.68288799 w comment C 12 3 -0.05049953 w comment C So I have multiple lines for one subject because of a repeated measurement of variable y (the rest of the variables stay the same, like gender). Now I would like to transform this data.frame in two ways: 1. a aggregated form, where I only have one row left for each subject - for numerical variables within the data.frame (like y) a mean should be calculated. 2. a restructured form, where I only have one row for each subject, but four different y-columns (y1, y2, y3, y4). What is the easiest way to do this? Are there any functions who do this kind of data-frame rearranging in one step? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] predict.lm with NAs
Hi, I wanted to use the predict.lm() function to compare the empirical data with the predicted values. The problem is that I have NAs in my data. I wanted to cbind my data.frame with the empirical values with the vector I get from predict.lm. But they don't have the same length because predict.lm just skip NA-predictions. Is there a way to get a vector with predicted values of the same length as the empirical values (with NAs)? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] open help files in browser
Hi, I am working on Mac OS X 10.6. R-version: 2.9.0. > the Mac GUI will intercept the call and do HTML display in the internal > browser With internal browser you mean a built-in browser of R? Is there also a way to invoke Safari to display the help-file (with the common help-functions)? With internal you mean On 30.03.2010, at 19:59, Duncan Murdoch wrote: > On 30/03/2010 1:46 PM, Martin Batholdy wrote: >> Hi, >> >> >> Is there a way to open help files in the default web browser instead of a >> new R-window >> when I use the help-functions (like ?, help.search() etc.)? > You don't say what platform you're using. Generally the way to do this is to > run options(help_type="html") but that doesn't necessarily work on all > platforms: the Mac GUI will intercept the call and do HTML display in the > internal browser; other platforms may not be able to run the HTML server. > > Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] open help files in browser
Hi, Is there a way to open help files in the default web browser instead of a new R-window when I use the help-functions (like ?, help.search() etc.)? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plots: gap between x- and y-axis
Hi, I was wondering why the gap between the x- and the y-axis gets bigger with a wider plot window. see this example; quartz("1",10,3) par(bty="n") plot(1:9, xaxt="n") axis(1, 1:9) quartz("2",30,3) par(bty="n") plot(1:9, xaxt="n") axis(1, 1:9) quartz("3",80,3) par(bty="n") plot(1:9, xaxt="n") axis(1, 1:9) Each time the distance between the y-axis to the x-axis gets larger. This looks pretty strange in a big plot. I think on windows machines you have to use X11 instead of quartz; X11("1",10,3) par(bty="n") plot(1:9, xaxt="n") axis(1, 1:9) X11("2",30,3) par(bty="n") plot(1:9, xaxt="n") axis(1, 1:9) X11("3",80,3) par(bty="n") plot(1:9, xaxt="n") axis(1, 1:9) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] add information above bars of a barplot()
hi, I have a barplot with six clusters of four bars each. Now I would like to add the exact value of each bar as a number above the bar. I hoped to get some tips here. I could simply add text at the different positions, but I don't understand how the margins on the x-axis are calculated (how can I get / calculate the x-ticks of a barplot?). Also I would like to code this flexible enough so that it still works when I have more bars in each cluster. thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] add euro sign to a plot
hi, Is it possible to add special characters like the euro sign to a plot? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple logical comparisons
thanks! Now I have one more question; How can I do the reverse? when %in% is == (for two vectors of different lengths); what is the equivalent to != ? On 21.03.2010, at 22:33, Erik Iverson wrote: > Martin Batholdy wrote: >> Hi, >> I would like to compare a column of data with a vector. >> I have this data.frame for example; >> x <- data.frame(A = c(1:5), B = c(1,1,2,2,2)) >> Now I have a search vector: >> search <- c(1,3,5) >> when I now try to get all the data-rows which have a 1, a 3, or a 5 in >> column A and a 2 in column B, I tried this: >> x[x$B == 2 & x$A == search,] >> I hoped to get 3 2 >> 5 2 >> as output. > > See ?%in% > > x[x$B == 2 & x$A %in% search, ] > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] multiple logical comparisons
Hi, I would like to compare a column of data with a vector. I have this data.frame for example; x <- data.frame(A = c(1:5), B = c(1,1,2,2,2)) Now I have a search vector: search <- c(1,3,5) when I now try to get all the data-rows which have a 1, a 3, or a 5 in column A and a 2 in column B, I tried this: x[x$B == 2 & x$A == search,] I hoped to get 3 2 5 2 as output. But I get an empty set. Can someone help me on that? _ search <- c(1,3,5) x <- data.frame(A = c(1:5), B = c(1,1,2,2,2)) x[x$B == 2 & x$A == search,] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] trend test for frequencies
Hi, which test do I have to use if I want to test if the following data follow a monotone trend; 0min5min10min 20min 30min 5 20 55 70 90 ... where the dependent variable contains frequencies. And how is that implemented in R? thanks for any help (on this more statistical-question ...). __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] split strings in a vector and convert it to a data.frame
hi, I have a vector full of strings like; xy_100_ab xy_101_ab xy_102_ab xy_103_ab I want to seperate each string in three pieces and the separator should be the "_" at the end I want a data.frame like: column1 column2 column3 xy 100 ab xy 101 ab xy 102 ab xy 103 ab I tried strsplit but I couldn't figure out how to convert the list I get into a data.frame. I just need a function like read.table. But it seems that read.table only can handle files, not vectors... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error message; ylim + log="y"
> You have no data to plot. What were you expecting it to do? Well, I get the same error messages when I use real data. So it has to do with the ylim-values specified. When I get rid of the ylim argument definition it does work. But why? I don't understand why R can't plot a logarithmic y-axis from 1 to 10.000. It doesn't need data for that, does it? Am 18.11.2009 um 23:19 schrieb jim holtman: > like this? > >> plot(c(),c(), xlim=c(1,10), ylim=c(0,1), log="y") > Error in axis(side = side, at = at, labels = labels, ...) : > CreateAtVector [log-axis()]: axp[0] = 0 < 0! > In addition: Warning messages: > 1: In is.na(y) : is.na() applied to non-(list or vector) of type 'NULL' > 2: In plot.window(...) : > nonfinite axis limits [GScale(-inf,4,2, .); log=1] > 3: In axis(side = side, at = at, labels = labels, ...) : > CreateAtVector "log"(from axis()): axp[0] = 0 ! > > > You have no data to plot. What were you expecting it to do? When you > say "lot of error messages", please include them and also follow the > posting guide. > > On Wed, Nov 18, 2009 at 4:52 PM, Martin Batholdy > wrote: >> Hi, >> >> >> I get a lot of error messages with this command, but I don't understand why; >> >> plot(c(),c(), xlim=c(1,10), ylim=c(0,1), log="y") >> >> >> thanks for any help! >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Jim Holtman > Cincinnati, OH > +1 513 646 9390 > > What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error message; ylim + log="y"
Hi, I get a lot of error messages with this command, but I don't understand why; plot(c(),c(), xlim=c(1,10), ylim=c(0,1), log="y") thanks for any help! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to merge two data.frames – only comp lete observations
Hi, I have two data-frames like: A: USA 3.2 Canada 4.7 Austria 1.5 Iran0.3 China 3.8 Japan 3.0 B: Austria 17 Iran22 Angola 29 Japan 32 England 11 Now I want to merge this two data.frames to one - but I only want entries for the countries I have complete observations for; so the final data.frame should look like this: C: Austria 1.5 17 Iran0.3 22 Japan 3.0 32 How can I do this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plot an arrow / add arrow to a line
hi, is it possible to end a line plotted with lines() with an arrow? Or are there any other functions to add an arrow to plot? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] gsub - replace multiple occurences with different strings
Hi, I search a way to replace multiple occurrences of a string with different strings depending on the place where it occurs. I tried the following; x <- c("xx y e d xx e t f xx e f xx") x <- gsub("xx", c("x1", "x2", "x3", "x4"), x) what I want to get is; x = x1 y y e d x2 e t f x3 e f x4 but what I get is; x = x1 y y e d x1 e t f x1 e f x1 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] (windows xp) start script on startup / double clicking on the script
hi, I am still trying to figure out how it is possible to start an R- script via the R-GUI directly by double-clicking on the script file in windows xp. On Mac OS I have the option "start script in the editor" in the preferences. But on windows XP I always get the "ARGUMENT 'c:\...\...' ___ignored___" error when I try to associate the .R extension with the R program file. My problem is that I don't have the possibility to install any other programs. And the people using the script don't know R. So its really important to find a way to start a script just by double clicking on the file. Now I was wondering if it is possible to make a shortcut of the R script and change the start options. I am not familiar with windows - does someone know if that is a possible way to get R code to the R console (in the R gui) on startup? Or any other clues / tips? thanks for any help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rounding error in seq(...)
hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x <- 0.1 + 0.1 +0.1 not equal to y <- 0.3 ? Am 30.09.2009 um 21:04 schrieb Duncan Murdoch: On 9/30/2009 2:50 PM, Michael Knudsen wrote: On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch wrote: Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Well, the problem is that I don't know how seq is implemented. I just assumed that it wouldn't behave like this. It doesn't really matter how it is implemented: if you ask to start at 0.1 and increment by 0.1, you should expect the result to be the same as 0.1 0.1+0.1 0.1+0.1+0.1 etc. and I think it is. The problem is that 0.1+0.1+0.1 is not the same as 0.3, due to rounding. Neither 0.1 nor 0.3 can be represented exactly in the standard IEEE floating point formats that R uses. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] start a script directly under windows
hi, I try to configure my system so when I click on an .R script, the script is executed in the R GUI. I tried to open .R files with different .exe files that I found in the bin-folder of the R folder (R.exe, Rcmd.exe, Rgui.exe ...). But I always get the message; ARGUMENT 'c:\...\...' ___ignored___ (where c:\...\.. is the path to the .R file) how can I change this behavior? Sorry I am not so familiar with windows OS (I use windows xp). thanks for any help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] start scripts directly in the console on windows machines
hi, on the mac you have the opportunity to start a script directly instead of opening it in the script editor. So when I doubleclick on an .R - file the code is executed immediately. I haven't found such an option in the preferences of the R program for windows. Is there also a way to do something like that? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xtable - print - suppress output
Am 21.09.2009 um 23:59 schrieb Rolf Turner: On 22/09/2009, at 9:52 AM, Martin Batholdy wrote: hi, I use xtable to convert data.frames to html tables. But when I use the print-command I always get the whole output printed even if I just want to save the html table into a variable; table <- print(xtable(CERAT), type="html") How can I suppress that output is printed? If you don't want it printed, then why the are you (explicitly!) using print??? Words fail me!!! cheers, Rolf Turner Because I don't get html code when I only use xtable(xy) ## Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ## __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xtable - print - suppress output
hi, I use xtable to convert data.frames to html tables. But when I use the print-command I always get the whole output printed even if I just want to save the html table into a variable; table <- print(xtable(CERAT), type="html") How can I suppress that output is printed? thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xtable + print (html)
hi, I want html code via the xtable package. I have a data.frame and tried to use the print()-function. But I only get the data.frame printed - no html arround it. what do I have to change? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] latex code in R -> convert to pdf
hi, is it possible to convert latex code to pdf in R (like a latex-program would do it)? Is there a package that comes with this capabilities? My problem is that I want to generate tables automatically - and I can't use a latex editor at that computer ... Besides latex ... are there good ways to generate tables in R? thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] call for input
Hi, is there a way to make a call for an input at some point of a process ..? I don't know how to describe it well ... like; please enter your first name: > and then, what is typed in should be saved into a variable. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.