Displaying 20 results from an estimated 40000 matches similar to: "levels of factor when subsetting the factor"
2007 Jul 05
3
summarizing dataframe at variable/factor levels
All,
Is there an efficient way to apply say "mean" or "median" to a dataframe
according to say all combinations of two variables in the dataframe?
Below is a simple example and the outline of a "manual" solution that
will work but is not very efficient
(could also generalize this to a function). Searched the archives and
docs but didn't see anything close to
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 =
2006 Jun 27
2
supplying dynamic main argument to plot?
All,
Simple question but I don't seem to be able to find the answer in the
documentation:
When using "plot" within a loop, is there any way to supply the argument
to "main" dynamically,
i.e., so that the title is Patient k below as the loop cycles through
each value of k?
plot(x,y, xlim=c(0,250), ylim=c(0,1000), xlab="gamma", ylab="r1",
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)
>
2006 Sep 06
1
Covariance/Correlation matrix for repeated measures data frame
All,
I have a repeated measures data frame and was wondering if the
covariance matrix can be
calculated via some created indexing or built-in R function.
Specifically, say there are 3 variables, where potassium concentration
is measured 6 times on each patient.
Patient number (discrete)
Time (1 to 6, discrete)
Potassium (continuous variable)
I want the covariance/correlation matrix for the
2007 Jul 03
1
xyplot and autokey, maintaining colors specified via "col" in key
All,
When specifying colors to xyplot w/ a groups argument, using
auto.key no longer maintains the colors properly. I've searched
the docs and help but haven't found exactly what I need ... I saw
a few examples in the archives involving par.settings but that doesn't
seem to do it. I also saw some people using key instead of auto.key, but
that didn't seem consistent. Is there a
2005 Aug 09
2
numeric operations w/ lists
Hello all,
X is a list of 20 lists, and each individual list has 65 elements.
Y is a list of 65 elements.
WANT: subtract Y from each of the 20 lists in X.
Here's what I tried and the error messages:
> X - rep(Y, 20)
Error in X - rep(Y 20) : non-numeric argument to binary operator
I tried several methods w/o success. Any suggestions kindly
appreciated.
Thanks,
Dave
ps - please copy
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
2005 Aug 20
2
diagonal matrices
Hello all,
I have matrices V.i of dimension n.i x n.i, where i = 1, ..., J, and the sum of n.i equals N. (and n.i ! = n.j)
goal: create one large matrix V, where V has matrices V.i on diagonal.
I create each matrix V.i in a for loop (1 to J), so each time I'd like to augment V with the
most recently calculated V.i, such that I'll have V after the final iteration of the for loop.
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
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 14
3
appending
All,
In the function below I have 24 individuals and 6 calculations per
individual.
The 6 calculations are collected each time in a 1:24 loop when
calculating "delta".
I'd like to collect all 144 = 24*6 calculations in one vector
("delta.patient.comb").
The function works as is via indexing, but is there an easier way to
collect the measurements via appendinng the 6
2010 Jun 02
2
pdf function, resize xyplot plot automatically
All,
When saving plots to a pdf file via the pdf function, I would like to be
able to automatically expand the graphics device to achieve the same result
as when one does this manually (e.g., clicking the green expand button on
the upper left of the graph on Mac OS). Consider simple example below:
library("lattice")
foo.frm = data.frame(Subject = rep(c(1:4), each = 9), Y =
2007 Jul 06
1
maintaining specified factor contrasts when subsetting in lmer
All,
I'm using lmer for some repeated measures data and have specified
the contrasts for a time factor such that say time 3 is the base. This
works fine. However, when
I next use the subset argument to remove the last two time values, the
output indicates that
the specified contrast is not maintained (see below). I can solve this
by creating a new dataframe
for the subset of interest
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
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
2005 Oct 10
2
wildcards and removing variables
All,
Is there are a wildcard in R for varible names as in unix? For example,
rm(results*)
to remove all variable or function names that begin w/ "results"?
cheers,
Dave
ps - please respond directly to afshar@miami.edu
[[alternative HTML version deleted]]
2006 Feb 03
2
workspace question
All,
When starting R, how does one prevent the loading the previous
workspace which was saved? I'd like to start a new project
and save the new image in a different directory, but I'd like to
partition this from the old project. Does there exist a better
way than just deleting the files associated w/ the old project
manually? I looked in the Intro to R manual and searched for
2005 Nov 16
2
save to ascii
All,
Usually when I save a variable I have ascii = FALSE since I usually
load the variable via the load(variable) command and do not need to
view the variable outside of R.
When I set ascii = TRUE and view the variable outside of R in a text editor,
I notice additional characters (starting w/ RDA2 ...) before the first actual value
in the vector.
Is there are way to save to ascii such that this
2008 Jul 02
1
auto.key in xyplot in conjunction with panel.text
All,
I can't seem to get auto.key to work properly in an xyplot that is employing
panel.text. Specifically, I often change the default grouping colors then
use auto.key accordingly, but for some reason the same functionality isn't
working for this different type of plot. Any help much appreciated.
Cheers,
David
library("lattice")
dat = data.frame( Y = c(rnorm(18,1),