similar to: Alternating numbers in rep()

Displaying 20 results from an estimated 7000 matches similar to: "Alternating numbers in rep()"

2009 Jul 24
1
Aggregate, max and time of max
All, For data consisting of serial measurements on subjects, one may use the aggregate function to say compute the peak response for each subject for each design condition. Is there a way to alter this or another one-liner to also retain the time at which the peak occurred and thus avoid writing a doing this via a loop? I suppose one could attempt to employ the split function but that's
2007 Jun 28
3
applying max elementwise to two vectors
All, Is there one liner way to obtain the max per observation for two vectors? I looked at apply and lapply but it seems that groundwork would have to be done before applying either of those. The code below does it but seems like overkill. Thanks! Dave x = rnorm(10) y = rnorm(10) ind = which(x < y) z = x z[ind] <- y[ind] ## z now contains the max's
2005 Oct 03
2
"symbol print-name too long"
All, I've coded a function and it works manually if I copy it line by line into R. However, when I try to "load" (copy and paste) the entire function into R, I get the following error after the listed line of code: + N.j.list = lapply(rej.hyp, length) Error: symbol print-name too long Does anyone you know what this error means? Strangely, when I copy the same line verbatim
2007 Nov 20
2
Adding points on top of lines in xyplot
All, I'm trying to make a basic plot: data points superimposed upon the a line connecting the points w/ a different color. Example below doesn't work as the first xyplot call doesn't remain. Suggestions? David Hour = c(NA,1,2,3,4) y = c(2,2,3,2,1.5) xyplot(y ~ Hour, xlab = list("Hour", font=2, cex=2), ylab= list("U_x * V", font=2, cex=2), type = 'l',
2008 Jun 26
3
Connecting lines across missing data points, xyplot
All, I have data across 5 time points that I am graphing via xyplot, along with error bars. For one of the variables I have missing data for two of the time points. The code below is okay but I can't seem to get the lines to connect across the missing time points. Does anyone now how to rectify this? Cheers, David Afshartous library(lattice) ## the data junk = data.frame( Visit =
2008 Feb 28
2
Replacing plot symbols w/ subject IDs in xyplot()
All, How does one replace plot symbols with say subject IDs when using xyplot? Or superimpose them next to plot symbols? I searched the archives under various key words but haven't had much. Any suggestions or links much appreciated. Sample code below. David junk.frm = data.frame(ID = rep(1:16, each = 2), x, y, z = rep(c("D", "P"), 16)) y = c( 0.4, 0.6, -0.1,
2007 Oct 12
2
Basic plot question: Figure 1.1 Pinheiro & Bates
All, Sorry for overly simplistic question, but I can't seem to remember how to create the basic plot shown in Figure 1.1 of Pinheiro & Bates (2004; p.4). The y-axis delineates a factor (Rail) while the x-axis displays the distribution of a continuous variable (time) according to each level of the factor. Didn't see it in archives but perhaps I'm not searching on correct key words,
2006 Sep 07
5
augPred plot in nlme library
All, I'm trying to create an augPred plot in the nlme library, similar to the plot on p.43 of Pinheiro & Bates (Mixed Effects Models in S and S-Plus) for their Pixel data. My data structure is the same as the example but I still get the error msg below. > comp.adj.UKV <- groupedData(adj.UKV ~ Time | Patient_no/Lisinopril, data = comp.adj.UKV.frm, order.groups = F) >
2008 Feb 26
2
Subsetting within xyplot()
All, I'm having problems w/ a simple attempt to subset an xyplot. The first plot below is a plot of y versus x for certain values of a third categorical variable z. Now I'd like to further restrict this to certain values of variable y. Neither of the two attempts below work. Any suggestions much appreciated. (note: I don't want to merely use ylim since I have a loess plot and I
2006 Jun 28
5
sapply question
sent this to the list yesterday but didn't see it listed in the daily summary ... apologies if you receive it twice ... ________________________________ From: Afshartous, David Sent: Tuesday, June 27, 2006 10:02 AM To: 'r-help@stat.math.ethz.ch' Subject: sapply question All: I'm trying to use sapply to break up data within another function. (tapply doens't seem to work
2006 Sep 12
11
levels of factor when subsetting the factor
All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still "remembers" the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep("A", 3),rep("B", 3), rep("C",
2006 Sep 23
4
plotting grouped data object
All, I'd like to plot the main relationship of a grouped data object for all levels of a factor in a single panel. The sample code below creates a separate panel for each level of the factor. I realize that this could be done in other ways, but I'd like to do it via plotting the grouped data object. thanks! dave z = rnorm(18, mean=0, sd=1) x = rep(1:6, 3) y =
2007 Nov 29
1
Wireframe graph: black and white shading instead of color
All, The code below produces a color 3D graph. I'd like to make it black and white shading. I tried setting col.regions to FALSE but this just made it completely white. I want the graph to look exactly as is, except black (or grey) and white shading. Is this possible? Cheers, David p.list = c(.01, .1, .25, .5, .75, .9) cov.list = c(.2, .1, .05) ### leave out .01 X = rep(p.list, 3)
2009 May 16
1
Lattice scales question: using "at" when log = TRUE
All, I have a simple lattice plot where I have set log = TRUE for the y scale. When I attempt to change the tick locations via the "at" argument within scales, the supplied numeric vector is not followed. Any suggestions much appreciated for the example below: y = c(10^1.5, 10^2, 10^3, 10^2) t = c(1,2,3,4) xyplot(y ~ t, type = "b", scales = list(y = list(log = TRUE))) ##
2009 Sep 09
1
Xyplot, multi line title via main, all lines left justified
All, Below is an xyplot plot with multiple panels and a title produced via main: library("lattic") data.ex = data.frame(y = rnorm(10), t = rep(1:5, 2), group = rep(c(0,1), each = 5)) xyplot(y ~ t | as.factor(group), data = data.ex, main = list("Put figure caption here xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx want this line left justified" )) I must be mis-interpreting the
2008 Aug 27
1
Significant digits for checking values of variable?
All, I'm witnessing some strange behavior when checking the values of one of my variables. My guess is that it has something to do with the number of significant digits being represented, but perhaps not as my variable was created from other variables that only had one decimal place. See below. I'm sure this is something basic, any suggestions much appreciated. Cheers, David >
2009 Sep 26
1
Lattice, stripplot (xyplot), plotting data with median line, numeric x-axis
All, On p.52 of Deepayan Sarkar's Lattice book there is a nice plot of showing residuals with median lines superimposed or various groups: library("lattice") stripplot(sqrt(abs(residuals(lm(yield~variety+year+site)))) ~ site, data = barley, groups = year, jitter.data = TRUE, type = c("p", "a"), fun = median) Suppose we wanted to make a similar plot for a
2008 Oct 20
3
? extended rep()
Hi Folks, I'm wondering if there's a compact way to achieve the following. The "dream" is that, by analogy with rep(c(0,1),times=c(3,4)) # [1] 0 0 0 1 1 1 1 one could write rep(c(0,1),times=c(3,4,5,6)) which would produce # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 in effect "recycling" x through 'times'. The objective is to produce a vector of
2008 May 20
5
Alignment of axes intersection
All, Very basic question I can't seem to find the answer to: plot(0:10, 0:10) The axes intersection is not aligned at (0,0) in the lower left. How does one force this? I searched for graphical parameters under par(graphics) but can't seem to find it. Thanks! David
2008 Jul 08
1
aggregate() function and na.rm = TRUE
All, I've been using aggregate() to compute means and standard deviations at time/treatment combinations for a longitudinal dataset, using na.rm = TRUE for missing data. This was working fine before, but now when I re-run some old code it isn't. I've backtracked my steps and can't seem to find out why it was working before but not now. In any event, below is a reproducible