[R] lattice - change background strip color in one panel

2011-05-27 Thread Coen van Hasselt
Hello,

I would like to change the background color in only -one- of the strips in a
multipanel lattice xyplot, from the default yellow-brown color.
Until now, I only managed to change the background strip color in all of the
strips using the par.settings, but I do not get it to work for only 1 strip.

Below is the current code I am using.
The resulting plot is here:
http://dl.dropbox.com/u/9788680/01_DoseIntensity_MonitoringInterval_BW.pdf
(i.e. I'd like to color the 3 months strip in red)

xyplot(value~ant|paste(intv, Months), groups=perc, data=di,
   type=b, layout=c(4,1),xlab=Prior anthracyclines,
lty=c(1,2),lwd=2,col=black,main=Dose intensity ~ Monitorings Interval,
   ylab=Dose intensity,
scales=list(x=list(at=c(0,0.5,1)),y=list(at=seq(0,1,.1))),
   par.settings = list(superpose.line=list(lwd=2,lty=1:2, col=black)),

   auto.key = list(space = right, points = FALSE, ncol=3,nrow=1, lines
= TRUE, title=Percentiles, cex=.7, cex.title=.7, siz=6))

I would greatly appreciate it if someone could guide me in the right
direction!

Thanks

Coen

[[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 improve this inefficient R code for imputing missing values

2010-11-19 Thread Coen van Hasselt
Hello all,

I have a big data.frame multiple studies, subjects and timepoints per
subject, i.e.

STUDY[,1] SUBJECT[,2] .. WT[,16] HT[,17] TEMP[,18] BSA[,19]
1   150  170   37
 1.90
1   1NA   NA  NA
NA
1   152  170   38
 1.94


In this dataset, three types of missing (demographic) values exist:

1) first value for a subject is missing:
ie. study 1, subject 1: mis X1 X2 X3.
Here I want to carry the first non-missing value backwards to the missing value.

2) last values for a subject is missing:
ie. study 1, subject 1: X1 X2 X3 mis.
Here I want to carry the last non-missing value forwards to the missing value

3) some intermediate value for a subject is missing (like example
data.frame above)
i.e. study 1, subject 1: X1 mis X2 X3.
Here I want to impute the missing value with the mean value between X1 and X2

The missing value is actually a subset of columns in the data frame,
ie. always the columns WT HT TEMP BSA (m[,16:19]) are missing
altogether.

I have written some R code that tries to do this, but it is incredibly
slow due to the many for-loops and the big dataset I have (and might
not even be completely correct yet).

QUESTION:
I would greatly appreciate it if somebody can be give me some
guidance/hints on what direction I should roughly think for coding the
above a little more efficient then the horribly inefficient code
pasted below.

Thank you in advance and best regards,

Coen


for(s in unique(m$Study)){ # for each study
 for(i in unique(m$Subject[m$Study==s  is.na(m$Wt)])){  # for each
subject with a missing value (if $Wt is missing, all 4 columns 16:19
are missing)
   vals-which(m$Study==s  m$Subject==i  !is.na(m$Wt))  # values
with NO missing values
   for(w in which(m$Study==s  m$Subject==i  is.na(m$Wt))){  # for
each value that is missing for subject i and study s
 if(w  min(vals) ){  # FIRST VALUES MISSING ?   #
carry the backwards
   m[w,][16:19]-m[min(vals),][16:19]
 } else if(w  max(vals) ) {  # LAST VALUES MISSING#
carry forwards
   m[w,][16:19]-m[max(vals),][16:19]
 } else { # INTERMEDIATE VALUES MISSING  #
impute missing with mean
   maxV-min(vals[valsw])
   minV-max(vals[valsw])
   m[w,][16:19]- mean(m[c(maxV,minV),][16:19],na.rm=T)
 }
   }
 }
}

__
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] lattice xyplot - formatting of multiple Y variables when using subgroups

2010-10-17 Thread Coen van Hasselt
Hi all,

Using xyplot I want to print to Y variables (y1, y2) versus X, conditional
on the group.
How can I obtain a line (type=l) for one relationship (ie. y1 ~ x) and
points (type=p) for the other (y2 ~ x) ?

library(lattice)

# create some sample data
df-data.frame(group=as.factor(c(rep(a,4), rep(b,4))), # grouping
variable for conditional plots
x=c(1:4,1:4), # x variable
y1=rnorm(4,0,1), # y1
y2=rnorm(4,0,1)) # y2


# Basically I want this plot, but then for y1~x points and for y2~x lines.
xyplot(y1+y2 ~ x|group, data=df)

# This works, but then I get the same plot in the two grouping windows
because conditioning is lost in the panel function.
xyplot(y1+y2 ~ x|group, data=df, type=l,
panel=function(...){panel.xyplot(df$x,df$y1);
panel.xyplot(df$x,df$y1, type=l)})

Thanks for your help.

Coen

[[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] reshape to wide format takes extremely long

2010-09-02 Thread Coen van Hasselt
Hello,

I have a data.frame with the following format:

 head(clin2)
Study Subject  Type  Obs Cycle Day   Date  Time
1 A001101   10108   ALB 44.098   1 2004-03-11 14:26
2 A001101   10108   ALP 95.098   1 2004-03-11 14:26
3 A001101   10108   ALT 61.098   1 2004-03-11 14:26
5 A001101   10108   AST 33.098   1 2004-03-11 14:26

I want to transform this data.frame so that I have Obs columns for
each Type. The full dataset is 45000 rows long. For a short subset
of 100 rows, reshaping takes 0.2 seconds, and produces what I want.
All columns are either numeric or character format (incl. date/time).

 reshape(clin2, v.names=Obs, timevar=Type, 
 direction=wide,idvar=c(Study,Subject,Cycle,Day,Date,Time),)
  Study Subject Cycle Day   Date  Time Obs.ALB Obs.ALP Obs.ALT Obs.AST
1   A001101   1010898   1 2004-03-11 14:26  44  95  61  33
11  A001101   10108 1   1 2004-03-12 14:01  41  85  39  33
21  A001101   10108 1   8 2004-03-22 10:34  40  90  70  34
30  A001101   10108 1  15 2004-03-29 09:56  45  97  66
 48 []

However, when using the same reshape command for the full data.frame
of 45000 rows, it still wasn't finished when run overnight (8 GB RAM +
8 GB swap in use).

The time to process this data.frame from a 100-row subset to a
1000-row subset increases from 0.2 sec to 60 sec.

I would greatly appreciate a advice why the time for reshaping is
increasing exponentially with the nr. of rows, and how I can do this
in an elegant way.

Thanks!

Coen.

__
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] xyplot: filtering out empty plots

2010-07-06 Thread Coen van Hasselt
Hello,

I would like to know how I can filter out empty plots in xyplot, when
stratifying on some variables.

Example:

I have a dataset in which I plot CONC ~ TIME, stratified for patient
ID(1,2,..,100), FORM(1,2) and BOOST (1,2).
Some patients (ID's) do not have values for all stratification
conditions. I.e. one patient may have values for FORM=1 and BOOST=1,2,
while others may have data on alle combinations.

xyplot(CONC ~ TIME | ID + FORM + BOOST, dat=data)

If I do this I also get empty plots for all the combinations for which
I do not have data for. Is it possible for xyplot NOT to make plots
for combinations of ID, FORM and BOOST that do not contain data ?

Thanks in advance!

Coen

__
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] Reading comments in text file from R

2009-12-02 Thread Coen van Hasselt
Try readLines, for instance:

# test.txt contents
comments
a,b,c
1,1,1
2,2,2

 readLines(c:/test.txt,1)
[1] comments
 read.csv(c:/test.txt,skip=1)
  a b c
1 1 1 1
2 2 2 2


Coen

On Wed, Dec 2, 2009 at 19:26, Graham Smith myotis...@gmail.com wrote:
 When a text file starts with a few lines commented out with # can you
 read those line from within R.

 read.table ignores the comments to load the file, but it would
 sometimes  be useful to be able to read what these comments say.

 Thanks,

 Graham

 __
 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.


Re: [R] string to integer

2009-04-16 Thread Coen van Hasselt
?as.integer

xChar-as.character(c(1,2,3))
xInt-as.integer(xChar)

On Fri, Apr 17, 2009 at 09:38, Romildo Martins
romildo.mart...@gmail.com wrote:
 Hi,

 exists a function to converts string to integer?

 Thanks

 Romildo Martins

 __
 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.


Re: [R] excluding a column from a data frame

2009-04-14 Thread Coen van Hasselt
Alternatively you could also drop the column like this:

xx$x2-NULL


On Wed, Apr 15, 2009 at 15:51, Peter Alspach
palsp...@hortresearch.co.nz wrote:
 Tena koe Erin

 xx[, names(xx)!='x2']

 HTH 

 Peter Alspach

 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess
 Sent: Wednesday, 15 April 2009 5:39 p.m.
 To: R help
 Subject: [R] excluding a column from a data frame

 Dear R People:

 Suppose I have the following data frame:

           x1         x2       x3
 1 -0.1582116 0.06635783 1.765448
 2 -1.1407422 0.47235664 0.615931
 3  0.8702362 2.32301341 2.653805
  str(xx)
 'data.frame':   3 obs. of  3 variables:
  $ x1: num  -0.158 -1.141 0.87
  $ x2: num  0.0664 0.4724 2.323
  $ x3: num  1.765 0.616 2.654

 I can exclude the second column nicely via:
  xx[,-2]
           x1       x3
 1 -0.1582116 1.765448
 2 -1.1407422 0.615931
 3  0.8702362 2.653805

 Now suppose I wanted to exclude the column called x2.  If I try:
  xx[,-x2]
 Error in -x2 : invalid argument to unary operator
 

 things don't work.  Is there a simple way to do this by name
 rather than number, please?

 Thanks,
 Erin



 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences University
 of Houston - Downtown
 mailto: erinm.hodg...@gmail.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.


 The contents of this e-mail are confidential and may be subject to legal 
 privilege.
  If you are not the intended recipient you must not use, disseminate, 
 distribute or
  reproduce all or any part of this e-mail or attachments.  If you have 
 received this
  e-mail in error, please notify the sender and delete all material pertaining 
 to this
  e-mail.  Any opinion or views expressed in this e-mail are those of the 
 individual
  sender and may not represent those of The New Zealand Institute for Plant and
  Food Research Limited.

 __
 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.


Re: [R] Writing specific columns to a data file

2009-04-06 Thread Coen van Hasselt
By only selecting the first column, i.e. write.table(data[,1], file=, .) ?


On Tue, Apr 7, 2009 at 12:28, Brendan Morse morse.bren...@gmail.com wrote:
 Hi, I have a function that generates some output with 2 columns, but I
 only want to write the first column to a file. Is there a way to do
 this in the write.table command?

 thetaout=write.table(estimatedtheta, file=/Users/morse07/Desktop/R/
 Trial/score.dat, row.names=F, col.names=F)

 Any advice would be great, 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-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] a loop for boxplot graphs

2009-03-29 Thread Coen van Hasselt
You could use the paste() function to dynamically assign label values.
For instance, like this:

dat-data.frame(id=1:4,x=1:4,y=1:4)
par(mfrow=c(2,2))
for (i in dat$id){
boxplot(dat$x[dat$id==i],
  dat$y[dat$id==i],
  main=paste(Results for Subject,i) )
}

There might be a better answer though- e.g. avoiding a for-loop.


Coen


On Mon, Mar 30, 2009 at 07:08, James Lenihan jamesleni...@sbcglobal.net wrote:

 Dear Colleagues

 I have the following code that generates a boxplot for one specific labtest:

 boxplot.n(LBSTRESN~COHORT, main=Boxplot of laboratory data for XLXXX-XXX 
 test=Creatinine,
 subset = LBTEST==Creatinine,
 xlab = Cohort Number,
 ylab = Units = umol/L,
 varwidth=TRUE

 I would like to know if there is a way to loop through the dataset and 
 produce the boxplot for a number of specific labtest.

 Looking at the documentation for loops I can't see how I would change the 
 ylab,mainand subset

 Can someone refer me to a similar example in the online documentation?

 Thanks,


 Jim L
        [[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-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] a loop for boxplot graphs

2009-03-29 Thread Coen van Hasselt
Oops, the example only accounts for 1 observation, so better do
something like this in that case:
..
for (i in unique(dat$id)){
..

On Mon, Mar 30, 2009 at 07:50, Coen van Hasselt
coenvanhass...@gmail.com wrote:
 You could use the paste() function to dynamically assign label values.
 For instance, like this:

 dat-data.frame(id=1:4,x=1:4,y=1:4)
 par(mfrow=c(2,2))
 for (i in dat$id){
 boxplot(dat$x[dat$id==i],
          dat$y[dat$id==i],
          main=paste(Results for Subject,i) )
 }

 There might be a better answer though- e.g. avoiding a for-loop.


 Coen


 On Mon, Mar 30, 2009 at 07:08, James Lenihan jamesleni...@sbcglobal.net 
 wrote:

 Dear Colleagues

 I have the following code that generates a boxplot for one specific labtest:

 boxplot.n(LBSTRESN~COHORT, main=Boxplot of laboratory data for XLXXX-XXX 
 test=Creatinine,
 subset = LBTEST==Creatinine,
 xlab = Cohort Number,
 ylab = Units = umol/L,
 varwidth=TRUE

 I would like to know if there is a way to loop through the dataset and 
 produce the boxplot for a number of specific labtest.

 Looking at the documentation for loops I can't see how I would change the 
 ylab,mainand subset

 Can someone refer me to a similar example in the online documentation?

 Thanks,


 Jim L
        [[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-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] Output an RWeka model via sink

2009-03-28 Thread Coen van Hasselt
I tried your code and it seems to work fine; the file contains the
expected output.
I used R 2.8.1 on WinXP.

On Sun, Mar 29, 2009 at 07:48, Francisco Javier Perez Caballero
fjpcaball...@gmail.com wrote:
 When I sink the output of an RWeka model to a text file, the output file 
 appears empty:

 library(RWeka)
 model = LogitBoost(Species~.,data=iris)
 print(model)
 sink(output.txt)
 print(model)
 #file output.txt is created, but it is blank
 sink()


 Am I doing anything wrong?
        [[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-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] A beginner's question

2009-03-27 Thread Coen van Hasselt
Here's an example:

mydata-data.frame(skill=c(1,2,3,4),x=c(1,1,1,1))
mydata[mydata$skill==1,]


On Fri, Mar 27, 2009 at 16:40, minben minb...@gmail.com wrote:
 I am a new R-language user. I have set up a data frame mydata,one of
 the colume of which is skill. Now I want to select the observations
 whose skill value is equal to 1,by what command can I get it?

 __
 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.