[R] aggregation-type question

2013-02-08 Thread carslaw
I seem to have a Friday afternoon block and can't see the easiest way of doing this. Given a data frame like: dat <- data.frame(x = runif(100), y = runif(100), group = rep(letters[1:10], each = 10)) > head(dat) x y group 1 0.876751503 0.6518345 a 2 0.627067150 0.8801790

[R] question about split

2011-06-17 Thread carslaw
thing like: splits <- c("fac1", "fac2") split(dat, list(splits)) But that is clearly wrongand I can't see the solution Many thanks David Carslaw Science Policy Group Environmental Research Group MRC-HPA Centre for Environment and Health King's College London

[R] Examples of web-based Sweave use?

2011-04-04 Thread carslaw
tions where pdf reports have been produced rather than, say, a plot/table etc shown on a web page. I've had limited success finding examples on this. Many thanks. David Carslaw Environmental Research Group MRC-HPA Centre for Environment and Health King's College London Franklin W

Re: [R] beamer overlays with Sweave?

2011-03-08 Thread carslaw
I don't have an example to hand, but check out the animation package. I have been able to include animations in pdf documents using this and it worked really well - and I think it works with sweave too. I think you could set it up to allow the user to press a button to go through each graphic in

[R] remote data access from Sweave - does not evaluate?

2011-02-16 Thread carslaw
y references to similar problems in R-help, hence my enquiry to you. Any tips would be welcome! David Dr David Carslaw Science Policy Group Environmental Research Group MRC-HPA Centre for Environment and Health King's College London Room 4.129 Franklin Wilkins Building Stamford Street London

Re: [R] reshape to wide format takes extremely long

2010-09-02 Thread carslaw
picking up on Thierry's example, I don't think you need any function because you are just reshaping (not aggregating). Therefore: bigtab2 <- cast(data = big, study + subject + cycle + day ~type, value = "obs") > head(bigtab2) study subject cycle day ALB ALP ALT AST 1 1 1 1 1

[R] aggregate with non-scalar functions

2010-08-04 Thread carslaw
Hi R-users, Since R.2.11 aggregate can now deal with non-scalar functions, which is very useful to me. However, I have a question about how best to process the output. test <- data.frame(a = rep(c("g1", "g2"), each = 50), b = runif(100)) res <- aggregate(test$b, list(group = test$a), function(

[R] aggregate with non-scalar functions

2010-08-04 Thread David Carslaw
Hi R-users, Since R.2.11 aggregate can now deal with non-scalar functions, which is very useful to me. However, I have a question about how best to process the output. test <- data.frame(a = rep(c("g1", "g2"), each = 50), b = runif(100)) res <- aggregate(test$b, list(group = test$a), function(

Re: [R] Sweave: infelicities with lattice graphics

2010-07-15 Thread carslaw
I have wondered about this too. The approach I use isn't pretty but does have a couple of advantages - there is only one set of code to run and I have control over the figure size. The first part of the code below is what is shown in the document (but not run), and the second part actually run

Re: [R] difference in sort order linux/Windows (R.2.11.0)

2010-05-28 Thread carslaw
Thanks Ted, Indeed, there is a difference between the systems on your much-simplified example (thanks). So, linux: sort(c("AB CD","ABCD")) [1] "ABCD" "AB CD" Windows: sort(c("AB CD","ABCD")) [1] "AB CD" "ABCD" Regards, David -- View this message in context: http://r.789695.n4.nabble.com/

[R] difference in sort order linux/Windows (R.2.11.0)

2010-05-28 Thread carslaw
[1] LC_CTYPE=en_GB.utf8 LC_NUMERIC=C [3] LC_TIME=en_GB.utf8 LC_COLLATE=en_GB.utf8 [5] LC_MONETARY=en_GB.utf8 LC_MESSAGES=en_GB.utf8 [7] LC_PAPER=en_GB.utf8 LC_NAME=en_GB.utf8 [9] LC_ADDRESS=en_GB.utf8LC_TELEP

[R] xyplot axis scaling with dates/times

2009-07-23 Thread David Carslaw
Dear R users, I'm trying to get a good x-scale and labels on a plot like the one below. library(lattice) ## make almost a year of hourly data: mydat <- data.frame(dates = Sys.time() + 3600 * (1:7000), y = runif(7000)) ## plot it xyplot(y ~ dates, data = mydat, type = "l") Only one x-label is

Re: [R] Creating smooth color regions with panel.contourplot()

2008-09-17 Thread David Carslaw
I think this is a very useful function that I imagine has wide appeal - thanks. Using the code below produces the plot OK but when I try and copy/save it (as a metafile) I receive the following error and an hourglass: Error: invalid graphics state [using XP, 2.72, lattice 0.17.13] Regards, Dav

[R] how to split a data framed with sequences

2008-09-09 Thread David Carslaw
Hi all, Given a data frame: my.df <- data.frame(a = c(1:5, 1:10, 1:20), b = runif(35)) I want to split it by "a" such that I end up with a list containing 3 components i.e. the first containing a = 1 to 5, the second a = 1 to 10 etc. In other words, sets of sequences of a. I can't seem to find

[R] text processing for plots

2008-09-05 Thread David Carslaw
27;m not sure of the best strategy for this having read through previous posts etc., and would appreciate your help! Many thanks. David Carslaw - Institute for Transport Studies University of Leeds -- View this message in context: http://www.nabble.com/text-processing-for-plots-tp19331219p193

[R] subset grouped data with quantile and NA's

2008-08-22 Thread David Carslaw
= 0.95, na.rm = TRUE)]) My difficulty is putting them into a data frame along with the other columns "fac" and "other". Note that quantile will return different length vectors due to different numbers of NAs for a and b. There's something I'm just not seeing - can yo

Re: [R] Frequency vector

2008-08-12 Thread David Carslaw
how about: a <- c(1,1,1,1,2,3,4,5,5) b <- as.data.frame(table(a)) b a Freq 1 14 2 21 3 31 4 41 5 52 which you can then select the bits you want from. David dennis11 wrote: > > I want to create a vecor with frequencies. > > I have tried this: > > a <- c(1,1,1,1,2,3,