[R] Is there a neat R trick for this?

2013-02-12 Thread Robert Latest
Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding element in Y (or NA if that element isn't in Y). Example: x <- c(4,5,6) y <- c(10,1,5,12,4,13,14) z <- findIndexIn(x, y) z [1] 5 3 NA 1st element of z is 5,

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Robert Latest
Hi guys, like so often, the answert came to me minutes after posting. pmatch() does exactly what I need. match() gives the values of the elements, but not their positions. Thanks, robert __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman

[R] Simple permutation question

2014-06-25 Thread Robert Latest
So my company has hired a few young McKinsey guys from overseas for a couple of weeks to help us with a production line optimization. They probably charge what I make in a year, but that's OK because I just never have the time to really dive into one particular time, and I have to hand it to the co

Re: [R] Simple permutation question

2014-06-26 Thread Robert Latest
On Wed, 25 Jun 2014 14:16:08 -0700 (PDT) Jeff Newmiller wrote: > The brokenness of your perm.broken function arises from the attempted > use of sapply to bind matrices together, which is not something > sapply does. > > perm.fixed <- function( x ) { >if ( length( x ) == 1 ) return( matrix( x

[R] How to get function arguments as list?

2014-02-09 Thread Robert Latest
Hello all, To set options in a package I'm putting together I'd like to write a function like options, that is: my.options <- function(...) { # ... } Now I'd like to access the named arguments that were passed to my funtion within that function. How does that work? formals() doesn't do it, neith

Re: [R] How to get function arguments as list?

2014-02-09 Thread Robert Latest
On Sun, 09 Feb 2014 12:28:11 + Rui Barradas wrote: > Hello, > > Inside the function try > > dots <- list(...) Hi guys, thanks a lot. I knew it HAD to be something ultra-simple, like most things in R. Regards, robert __ R-help@r-project.org mai

Re: [R] Adding lines to complex xyplot

2014-02-25 Thread Robert Latest
Hello Lib, I think what you're trying to do is very easy using ggplot2 -- easy, that is, once you got your hear around ggplot2 in the first place. The layering you mention is the core feature of ggplot2. Fortunately it is well-documented including a thin, overpriced book from Springer (which I hav

[R] Finding the last value before a certain date

2012-07-19 Thread Robert Latest
Hello all, I have a dataframe that looks like this: head(df) datey 1 2010-09-27 1356 2 2010-10-04 1968 3 2010-10-11 2602 4 2010-10-17 3116 5 2010-10-24 3496 6 2010-10-31 3958 I need a function that, given any date, returns the y value corresponding to the given date or the last day b

[R] Applying a function to categorized data?

2012-04-12 Thread Robert Latest
Hi all, I'm just getting started in R. My problem is the following: I have a data frame (v1) with lots of production data measurements. Each row contains a single measurement ('ARI_MIT') with a timestamp. I want to "lump" the data by months with their mean and standard deviation. I have already

Re: [R] Applying a function to categorized data?

2012-04-13 Thread Robert Latest
h > > ?aggregate > >  you will need to specify   "by"  to aggregate by month > > Steve > > On Thu, Apr 12, 2012 at 7:10 AM, Robert Latest wrote: >> >> Hi all, >> >> I'm just getting started in R. My problem is the following: >>

[R] How to create a data.frame from several time series?

2012-04-16 Thread Robert Latest
Hello all, please look at my code below. The problems start where it says # PROBLEMS START HERE. Some sample data is at the very bottom. This is the disgnostic output from the script: > source('load.R') ts.null 1 NA 2 NA 3 NA 4 NA 5 NA 6 NA [1] "Adding data" "VS1A

Re: [R] How to create a data.frame from several time series?

2012-04-17 Thread Robert Latest
Hello all, followup to yesterday's question: Part of my confusion was caused by my embarrassing mistake of overwriting the "ppk" function with another object, which of course broke the next iteration of the loop. Secondly, I got exactly what I wanted like this: aggregate.zoo <- function(series)

[R] Replacing tick labels in a plot

2012-05-04 Thread Robert Latest
Hello, is it possible to replace the text of tick marks in a plot? Specifically, I'd like to have a ppnorm plot in which the theoretical quantiles are not expressed in terms of standard deviations, but in actual percentages. Anybody who's seen a probability plot in MINITAB knows what I'm talking a

Re: [R] Replacing tick labels in a plot

2012-05-04 Thread Robert Latest
sed when you signed up? > That's a frequent cause of moderation. > > Sarah > > On Fri, May 4, 2012 at 1:09 PM, Robert Latest wrote: >> Hello, >> >> is it possible to replace the text of tick marks in a plot? >> Specifically, I'd like to have a ppnor

[R] How to deal with a dataframe within a dataframe?

2012-05-08 Thread Robert Latest
Hello all, I am doing an aggregation where the aggregating function returns not a single numeric value but a vector of two elements using return(c(val1, val2)). I don't know how to access the individual columns of that vector in the resulting dataframe though. How is this done correctly? Thanks, r

Re: [R] How to deal with a dataframe within a dataframe?

2012-05-08 Thread Robert Latest
On Tue, May 8, 2012 at 3:38 PM, R. Michael Weylandt wrote: > So this actually looks like something of a tricky one: if you wouldn't > mind sending the result of dput(head(agg)) I can confirm, but here's > my hunch: Hi Michael, while I'm trying to get my head around the rest of your post, here's

[R] How to apply functions across columns?

2012-05-09 Thread Robert Latest
Hello, me again. I have a data frame that looks like this (actual dput output at bottom): > head(tencor) datelot wf.id s1 s2 s3 s4 s5 1 08.05.2012 W0X3H0 9 1238 1263 1244 1200 1183 2 08.05.2012 W0X3H010 1367 1396 1371 1325 1311 3 08.05.2012 W0X3H011 1383 1417 13

Re: [R] How to apply functions across columns?

2012-05-09 Thread Robert Latest
On Wed, May 9, 2012 at 4:19 PM, R. Michael Weylandt wrote: > Good reproducible example ;-) > > Easiest is probably just: > > cbind(tencor, ThisRowMean =  rowMeans(tencor[, 4:8])) Actually, after frying my brain on tapply() and sapply() I found that just plain apply() does what I need: tencor$mea

[R] ANOVA question

2012-05-11 Thread Robert Latest
Hello all, I'm very satisfied to say that my grip on both R and statistics is showing the first hints of firmness, on a very greenhorn level. I'm faced with a problem that I intend to analyze using ANOVA, and to test my understanding of a primitive, one-way ANOVA I've written the self-contained p

Re: [R] ANOVA question

2012-05-11 Thread Robert Latest
Hello Thierry, thanks for your answer! There is one thing, however, that I don't understand. The values labeled "B" in my data are generated with 1/20th the variance of the others, yet the standard error and confidence intervals are the same for all levels of the factor. How come? > summary(mod_

[R] How to interpret an ANOVA result?

2012-05-14 Thread Robert Latest
Hello all, here's a real-world example: I'm measuring a quantity (d) at five sites (site1 thru site5) on a silicon wafer. There is a clear site-dependence of the measured value. To find out if this is a measurement artifact I measured the wafer four times: twice in the normal position (posN), and

Re: [R] How to interpret an ANOVA result?

2012-05-15 Thread Robert Latest
On Tue, May 15, 2012 at 1:59 PM, Bryan Hanson wrote: > I see that no one has replied on this, so I'll take a stab. Hi, Ryan! > This is probably a matter of personal taste, but I would suggest a somewhat > different and simpler approach.  What you have done is not strictly an ANOVA, > it's a li

[R] How to include known errors in a regression?

2012-05-15 Thread Robert Latest
Hello all, I have a bunch of aggregated measurement data. The data describe two different physical properties that correlate, and I want to estimate the coefficients (slope and intercept) from the dataset. This is of course easy, I've done it, and I got the expected result. But here's the thing:

Re: [R] Regression Analysis or Anova?

2012-05-15 Thread Robert Latest
Hello Andrea, I don't know if I can help you (probably not, I'm a beginner myself), but you that you should make it a lot easier for those that can if you post a self-contained script in this forum that shows what you're trying to do. Use dput() to dump your dataset in text form. Good luck, rober