[R] melt error that I don't understand.

2013-09-06 Thread Nutter, Benjamin
I'm stumped.  I have a dataset I want to melt to create a temporal sequence of 
events for each subject, but in each row, I would like to retain the baseline 
characteristics.

D - structure(list(ID = c(A, B, C, D, E, F, G, H, I, J), 
AGE = structure(c(68L, 63L, 55L, 64L, 60L, 78L, 60L, 62L, 
60L, 75L), 
label = Age, class = labelled), 
BMI = structure(c(25L, 27L, 27L, 28L, 32L, NA, 36L, 27L, 
31L, 25L), 
label = BMI (kg/m2), class = labelled), 
EventDays = structure(c(722L, 738L, 707L, 751L, 735L, 728L, 
731L, 717L, 728L, 735L), 
  label = Time to first ACM/censor 
(days), class = labelled), 
ImplantDays = c(NA, NA, 575, NA, NA, NA, 490, 643, NA, 
NA)), 
   .Names = c(ID, AGE, BMI, EventDays, InterventionDays), 
   row.names = c(NA, 10L), 
   class = data.frame)

melt(D, c(ID, AGE, BMI)) # produces the following error

Error in data.frame(ids, variable, value, stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 10, 20


Now, I know AGE and BMI aren't exactly identifying variables, but my hope would 
be that, since ID uniquely identifies the subjects, I could use this as a short 
cut to getting the data set I want.  I can get the data I want if I go about it 
a little differently.

#* What I would like it to look like.
Timeline - melt(D[, c(ID, EventDays, InterventionDays)], ID, 
na.rm=TRUE)
Timeline - arrange(Timeline, ID, value)
Timeline - merge(D[, c(ID, AGE, BMI)],
  Timeline,  
  by=ID, all.x=TRUE)


At first I thought it might be the mixture of character and numeric variables 
as IDs, but the following example works

A - data.frame(id = LETTERS[1:10],
age = c(50, NA, 51, 52, 53, 54, 55, 56, 57, 58),
meas1 = rnorm(10),
meas2 = rnorm(10, 5),
stringsAsFactors=FALSE)
melt(A, c(id, age))


I'm sure I'm missing something really obvious (kind of like how I can stare at 
the dry goods aisle for 10 minutes and still not find the chocolate chips).  If 
anyone could help me understand why this error is occurring, I'd greatly 
appreciate it.  

 sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
[1] C

attached base packages:
[1] splines   stats graphics  grDevices utils datasets  methods   base  
   

other attached packages:
[1] lazyWeave_2.2.3  Hmisc_3.10-1 survival_2.36-14 plyr_1.7.1   
reshape2_1.2.2  

loaded via a namespace (and not attached):
[1] cluster_1.14.3  grid_2.15.2 lattice_0.20-10 stringr_0.6.1   tools_2.15.2


  Benjamin Nutter |  Biostatistician |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365



===


 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked as one of the top hospitals in America by U.S.News  
World Report (2013).  
Visit us online at http://www.clevelandclinic.org for a complete listing of our 
services, staff and locations.


Confidentiality Note:  This message is intended for use ...{{dropped:18}}

__
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] lmer, p-values and all that

2013-04-03 Thread Nutter, Benjamin
My apologies for coming late into this conversation, but I'm curious about 
something in your response

You use the following code to peform a likelihood ratio test between an lm 
object and a mer object

fm0 - lm(distance~age,data=Orthodont)
fm2 - lmer(distance~age+(1|Subject),data=Orthodont,REML=FALSE)

ddiff - -2*c(logLik(fm0)-logLik(fm2))
pchisq(ddiff,1,lower.tail=FALSE)

It seems like this would be simple to roll up into a function, such as

lrtestGeneric - function(fit1, fit2){
  chisq - -2 * c(logLik(fit1) - logLik(fit2))
  df - abs(attributes(logLik(fit1))$df - attributes(logLik(fit2))$df)
   p - pchisq(chisq, df, lower.tail=FALSE)
   lrtest - data.frame(L.R.Chisq=chisq, d.f.=df, P=p)
   return(lrtest)
}

lrtestGeneric(fm0, fm2)


My question is about whether it is appropriate to use the degrees of freedom 
returned by logLik or if I should just use 1 degree of freedom when comparing a 
model without the random effect to one with the random effect.  For instance, 
logLik returns a difference of 3 between degrees of freedom in the models.  
Should I be using the 3 degrees of freedom in the likelihood ratio test, or is 
it better to go with 1? 


fit0 - lm(Reaction ~ Days, sleepstudy)
fit1 - lmer(Reaction ~ Days + (Days|Subject), sleepstudy)

lrtestGeneric(fit0, fit2)


Any education you can provide would be great appreciated.

Thanks

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Ben Bolker
Sent: Wednesday, March 27, 2013 10:34 PM
To: David Winsemius
Cc: r-h...@stat.math.ethz.ch
Subject: Re: [R] lmer, p-values and all that

On 13-03-27 10:10 PM, David Winsemius wrote:
 
 On Mar 27, 2013, at 7:00 PM, Ben Bolker wrote:
 
 Michael Grant michael.grant at colorado.edu writes:
 Dear Help:

 I am trying to follow Professor Bates' recommendation, quoted by 
 Professor Crawley in The R Book, p629, to determine whether I should 
 model data using the 'plain old' lm function or the mixed model 
 function lmer by using the syntax anova(lmModel,lmerModel).
 Apparently I've not understood the recommendation or the proper 
 likelihood ratio test in question (or both) for I get this error
 message: Error: $ operator not defined for this S4 class.

  I don't have the R Book handy (some more context would be extremely 
 useful!  I would think it would count as fair use to quote the 
 passage you're referring to ...)
 
 This is the quoted Rhelp entry:
 
 http://tolstoy.newcastle.edu.au/R/help/05/01/10006.html
 
 (I'm unable to determine whether it applies to the question at hand.)

  OK, I misspoke -- sorry.  I think the lmer()/lme() likelihoods are actually 
comparable; it's GLMMs (glmer(), with no analogue in lme()-land except for 
MASS::glmmPQL, which doesn't give you log-likelihoods at all) where the problem 
arises.

  You can (1) use lme(), (2)  look at http://glmm.wikidot.com/faq for 
suggestions about testing random-effects terms (including perhaps don't do it 
at all), or (3) construct the likelihood ratio test yourself as follows:

library(nlme)
data(Orthodont)
fm1 - lme(distance~age,random=~1|Subject,data=Orthodont)
fm0 - lm(distance~age,data=Orthodont)
anova(fm1,fm0)[[p-value]]
detach(package:nlme,unload=TRUE)
library(lme4.0) ## stable version of lme4
fm2 - lmer(distance~age+(1|Subject),data=Orthodont,REML=FALSE)
anova(fm2,fm0) ## fails
ddiff - -2*c(logLik(fm0)-logLik(fm2))
pchisq(ddiff,1,lower.tail=FALSE)
## not identical to above but close enough

 

 Would someone be kind enough to point out my blunder?

  You should probably repost this to the 
 r-sig-mixed-mod...@r-project.org mailing list.

  My short answer would be: (1) I don't think you can actually use 
 anova() to compare likelihoods between lm() and lme()/lmer() fits in 
 the way that you want: *maybe* for lme() [don't recall], but almost 
 certainly not for lmer().  See http://glmm.wikidot.com/faq for 
 methods for testing significance/inclusion of random factors (short 
 answer: you should *generally* try to make the decision whether to 
 include random factors or not on _a priori_ grounds, not on the basis 
 of statistical tests ...)

  Ben Bolker



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

===


 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals in America by U.S.News  
World Report (2012).  
Visit us online at http://www.clevelandclinic.org for a complete listing of our 
services, staff and locations.


Confidentiality Note:  This message is intended for use ...{{dropped:18}}


[R] Comparing dcast and reshape

2012-10-17 Thread Nutter, Benjamin
I'm in the middle of my own little intellectual exercise comparing
dcast() and reshape() and have successfully stumped myself.  I want to
melt() a data frame, then dcast() it into a new form.  After doing so, I
want to duplicate the process using reshape().  

So far, I can do the melt and cast

require(reshape2)

Raw - data.frame(site = c(1, 1, 1, 1, 2, 2, 2, 2),
  id   = c(1, 1, 2, 2, 1, 1, 2, 2),
  instrument = rep(c(beck, phq), 4),
  base.score = c(27, 13, 31, 11, 22, 10, 41, 17),
  score.90d = c(20, 11, 27, 12, 24, 8, 34, 15))

Full.Melt - melt(Raw, id.vars=c(site, id, instrument), 
  measure.vars=c(base.score, score.90d))

FullCast - dcast(Full.Melt, site + id ~ instrument + variable, 
   value.var=value)

 FullCast
  site id beck_base.score beck_score.90d phq_base.score phq_score.90d
11  1  27 20 1311
21  2  31 27 1112
32  1  22 24 10 8
42  2  41 34 1715


I can also replicate the melt using reshape, but I can't reshape it into
the same wide format.

FullLong - reshape(Raw,
varying=list(score=c(base.score, score.90d)),
idvar=c(site, id, instrument),
direction=long)


Any pointers on how to get FullLong into the same wide format as
FullCast?

Thanks for taking the time to educate me.
  Benjamin Nutter |  Biostatistician |  Quantitative Health Sciences
  Cleveland Clinic|  9500 Euclid Ave.  |  Cleveland, OH 44195  |
(216) 445-1365


===


 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals in America by U.S.News  
World Report (2012).  
Visit us online at http://www.clevelandclinic.org for a complete listing of our 
services, staff and locations.


Confidentiality Note:  This message is intended for use ...{{dropped:15}}

__
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] Comparing dcast and reshape

2012-10-17 Thread Nutter, Benjamin
Thanks for the prompt reply, Dr. Winsemius.

reshape(FullLong)  

Will return the original data frame, but that wasn't quite what I wanted.  I 
wanted to take it to a wider form than the original.

But I just answered my own question (typically, _after_ asking the world at 
large).

FullWide - reshape(Raw,
v.names=c(base.score, score.90d),
timevar=instrument,
idvar=c(site, id),
direction=wide)

gives me what I was looking for.  I suspect there isn't a way to go directly 
from FullLong to FullWide, but if someone can prove me wrong, I'd love to see 
how.

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365



-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Wednesday, October 17, 2012 5:18 PM
To: Nutter, Benjamin
Cc: r-help@r-project.org
Subject: Re: [R] Comparing dcast and reshape


On Oct 17, 2012, at 2:09 PM, Nutter, Benjamin wrote:

 I'm in the middle of my own little intellectual exercise comparing
 dcast() and reshape() and have successfully stumped myself.  I want to
 melt() a data frame, then dcast() it into a new form.  After doing so, 
 I want to duplicate the process using reshape().

 So far, I can do the melt and cast

 require(reshape2)

 Raw - data.frame(site = c(1, 1, 1, 1, 2, 2, 2, 2),
  id   = c(1, 1, 2, 2, 1, 1, 2, 2),
  instrument = rep(c(beck, phq), 4),
  base.score = c(27, 13, 31, 11, 22, 10, 41, 17),
  score.90d = c(20, 11, 27, 12, 24, 8, 34, 15))

 Full.Melt - melt(Raw, id.vars=c(site, id, instrument),
  measure.vars=c(base.score, score.90d))

 FullCast - dcast(Full.Melt, site + id ~ instrument + variable,
   value.var=value)

 FullCast
  site id beck_base.score beck_score.90d phq_base.score phq_score.90d
 11  1  27 20 1311
 21  2  31 27 1112
 32  1  22 24 10 8
 42  2  41 34 1715


 I can also replicate the melt using reshape, but I can't reshape it 
 into the same wide format.

 FullLong - reshape(Raw,
varying=list(score=c(base.score, score.90d)),
idvar=c(site, id, instrument),
direction=long)


 Any pointers on how to get FullLong into the same wide format as 
 FullCast?

The reshape function will recognize that the object was created as a  
wide-long reshaping and if you just use this code, you will get back
the original:

reshape(FullLong)

-- 

David Winsemius, MD
Alameda, CA, USA


===


 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals in America by U.S.News  
World Report (2012).  
Visit us online at http://www.clevelandclinic.org for a complete listing of our 
services, staff and locations.


Confidentiality Note:  This message is intended for use ...{{dropped:18}}

__
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] Opinion: Why I find factors convenient to use

2012-08-20 Thread Nutter, Benjamin
Whether I use stringsAsFactors=FALSE or stringsAsFactors=TRUE tends to rely on 
where my data are coming from.  If the data are coming from our Oracle 
databases (well controlled data), I import the with stringsAsFactors=TRUE and 
everything is great.  If the data are given to me by a fellow in the form of an 
Excel spreadsheet, I have a good cry and then set stringsAsFactors=FALSE.  
Regardless, before I get to analyzing the data, I convert them all to factors.  
I imagine people's preferences for the default setting are strongly tied to the 
quality of the data with which they tend to work.

I would prefer the default argument be left as it is, however.  Mostly because
1) I feel like it assumes you are importing data for analysis and not for data 
management; and more importantly
2) Changing the default would mean I have to change the way I approach data 
import--and I don't like to change.

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Rui Barradas
Sent: Monday, August 20, 2012 8:03 AM
To: S Ellison
Cc: r-help
Subject: Re: [R] Opinion: Why I find factors convenient to use

Hello,

Em 20-08-2012 12:30, S Ellison escreveu:
   

 -Original Message-
 Over the years, many people -- including some who I would consider 
 real expeRts -- have criticized factors and advocated the use 
 (sometimes exclusively) of character vectors instead.
 Exclusive use of character vectors is not going to do the job.

 The concept of a factor is fundamental to a lot of statistics; a programming 
 environment that does not implement factors and their associated special 
 behaviour is probably not a statistical programming language.

 Special behaviours I have in mind include:
 - Level order can be arbitrarily specified for display purposes
 - A control level can be intentionally chosen for contrasts
 - the option of ordered factors (for example, for polr and the like)

 So I think the language does and will require a 'factor' type in one form or 
 another.

   _When_ you decide to convert a character input to a factor is, of course, 
 up to the user,and for cleanup it's very often better to stick with character 
 early and convert to factor a bit later. But personally, I think that there 
 is sufficient control over the coding of data to allow user discretion. and 
 on the whole, it seems to me that character input gets used as factor data so 
 much of the time when it is used at all that the default 
 stringsAsFactors=TRUE setting seems the more sensible default.

I disagree with this last point. Just think of the number of questions to this 
list about, say, dates. When read from file using one of the forms of 
read.table, they usually cause problems. Unless the user is an experienced one, 
in which case he/she might not have a question to ask.
Besides, the default TRUE is contradictory with stick with character early and 
convert to factor a bit later. With both early and later.
A different thing is to have a very used function's default behavior change 
from one version of R to the next one. What about all the code in use? Maybe 
it's better to leave it be.

Rui Barradas

 S Ellison

 ***
 This email and any attachments are confidential. Any 
 use...{{dropped:8}}

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

===


 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals in America by U.S.News  
World Report (2010).  
Visit us online at http://www.clevelandclinic.org for a complete listing of our 
services, staff and locations.


Confidentiality Note:  This message is intended for use only by the individual 
or entity to which it is addressed and may contain information that is 
privileged, confidential, and exempt from disclosure under applicable law.  If 
the reader of this message is not the intended recipient or the employee or 
agent responsible for delivering the message to the intended recipient, you are 
hereby notified that any dissemination, distribution or copying of this 
communication is strictly prohibited.  If you have received this communication 
in error,  please contact the sender immediately and destroy the material in 
its 

Re: [R] Variable labels

2012-07-18 Thread Nutter, Benjamin
I have my own function for doing this that is similar to the one presented 
below.  Others may have other ideas that work better.  As a general rule, I 
would caution against writing out just the label without the variable name.  
The only reason I see to separate the labels and names is if you are generating 
a report (and using write.table wouldn't be my first choice for doing that).  
However, the function below at least allows you to decide when you call it.  If 
you want to exclude the names, just set names=FALSE.


#*** possibly buggy.  I didn't do much testing on this function.
write.table.with.labels - function(data, file, names=TRUE, labels=TRUE, 
append=FALSE, ...){
  if (names) write.table(t(names(data)), file, col.names=FALSE, ...)
  if (labels) write.table(t(label(data)), file, col.names=FALSE, 
append=any(c(names, append)), ...)
  write.table(data, file, col.names=FALSE, append=TRUE, any(c(names, labels, 
append)), ...)
}

label(mtcars$mpg) - Miles per gallon

write.table.with.labels(mtcars, test.csv, sep=,)



  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Francois Maurice
Sent: Tuesday, July 17, 2012 4:36 PM
To: r-help@r-project.org
Subject: [R] Variable labels



Hi,
 
I'm using write.table() to export dataframe to Excel. All works fine except 
that I want to export the variable labels instead of variable names.

 I can see the labels in the R consol using attr(), but I just don't know how 
to use the labels instead of the names.

Thanks,

François Maurice
[[alternative HTML version deleted]]


===


 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals in America by U.S.News  
World Report (2010).  
Visit us online at http://www.clevelandclinic.org for a complete listing of our 
services, staff and locations.


Confidentiality Note:  This message is intended for use ...{{dropped:18}}

__
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 a bunch of csv files into R

2012-05-25 Thread Nutter, Benjamin
For example:

myDir - some file path 
filenames - list.files(myDir)
filenames - filenames[grep([.]csv, filenames)]

data_names - gsub([.]csv, , filenames)

for(i in 1:length(filenames)) assign(data_names[i], read.csv(file.path(myDir, 
filenames[i])))

 

 Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Kevin Wright
Sent: Friday, May 25, 2012 2:55 PM
To: HJ YAN
Cc: r-help@r-project.org
Subject: Re: [R] Reading a bunch of csv files into R

See ?dir

Assign the value to a vector and loop over the elements of the vector.

Kevin


On Fri, May 25, 2012 at 12:16 PM, HJ YAN yhj...@googlemail.com wrote:
 Dear R users


 I am struggling from a data importing issue:

 I have some hundreds of csv files needed to be read into R for futher 
 analysis. All those csv files are named in one of the three formats:

 (1) strings: e.g. London_Oxford street
 (2) Integer: e.g. 1234_5678
 (3) combined: e.g. London_1234

 I intend to use read.csv(_xxx.csv) but I only dealt with sigle 
 documents before and if there are only no more than 20 files, I do not 
 bother to search a more efficient way.


 Is there any claver way that I do not have to type in all these 
 hundreds names by hand, maybe using a R package or write some code in 
 some other languages if it is not too difficult to learn.

 Any thoughts/hints please??

 Many thanks in advance!

 HJ

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



--
Kevin Wright

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


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] R help!

2012-05-03 Thread Nutter, Benjamin
So long as x is a character vector, I tend to use the following for this 
problem.

 x - c(12/31/11 23:45, 1/1/12 2:15)
 
 x.split - strsplit(x,  )
 
 x.date - sapply(x.split, function(y) return(y[1]))
 x.time - sapply(x.split, function(y) if (length(y)  1) return(y[2]) else NA)
 
 x.date
[1] 12/31/11 1/1/12  
 x.time
[1] 23:45 2:15 


  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Alex Roth
Sent: Wednesday, May 02, 2012 4:01 PM
To: r-help@r-project.org
Subject: [R] R help!

Hello there, I was wondering if you could help me with a quick R issue.

I have a data set where one of the columns has both date and time in it, e.g. 
12/31/11 23:45 in one cell. I want to use R to split this column into two new 
columns: date and time.

One of the problems with splitting here is that when the dates go into single 
digits there are no 0's in front of months January-September (e.g., January is 
represented by 1 as opposed to 01), so every entry is a different length. 
Therefore, splitting by the space is the only option, I think.

Here's the coding I've developed thus far:

z$dt - z$Date#time and date is all under z$Date
foo - strsplit( , z$dt) #attempted split based on the space

And then if that were to work, I would proceed use the coding:

foo2 - matrix(unlist(foo), ncol = 2, byrow=TRUE) z$Date - foo[ ,1] z$Time - 
foo[ ,2]

However, foo - strsplit( , z$dt) isn't working. Do you know what the problem 
is? If you could respond soon, that would be greatly appreciated!

Thanks so much!
Alex

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


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] VarCorr procedure from lme4

2012-05-02 Thread Nutter, Benjamin
I've run into this situation and have been able to prevent problems by using

 lme4::VarCor(...)

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Stevens
Sent: Tuesday, May 01, 2012 9:58 PM
To: r-help@r-project.org
Subject: Re: [R] VarCorr procedure from lme4

That was it - detaching 'nlme' was the trick. Thanks Walmes and the rest.

David

On 5/1/2012 7:47 PM, David Stevens wrote:
 Yes - I also have nlme.  Bad juju?

 David

 On 5/1/2012 1:32 PM, Walmes Zeviani wrote:
 It could be a bad coexistence between packages in the same R session. 
 Are you using nlme and/or doBy packages too?

 Bests.
 Walmes.

 =
 =
 Walmes Marques Zeviani
 LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 
 49.231759 W) Departamento de Estatística - Universidade Federal do 
 Paraná
 fone: (+55) 41 3361 3573
 VoIP: (3361 3600) 1053 1173
 e-mail: wal...@ufpr.br
 twitter: @walmeszeviani
 homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 
 =
 =

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

--
David K Stevens, P.E., Ph.D., Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stev...@usu.edu




[[alternative HTML version deleted]]


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] multiple values in one column

2012-04-06 Thread Nutter, Benjamin
This is a function I use for these kinds of situations.  Assuming the delimiter 
within the column is consistent and the spelling is consistent, it is pretty 
useful.

The function returns a vector of 0/1 values, 1 if the text in level is found, 0 
otherwise.
var=the variable
level=The value of interest in var

'split_levels' - function(var, level, sep=,){

#*** identify level in var.
  f - function(v){
v - unlist(strsplit(v,sep))
ifelse(level %in% v, return(1), return(0))
  }

#*** split the variable
  new.var - unlist(sapply(var,f))
  names(new.var) - NULL

#*** assign NA's where they were in original variable
  new.var[is.na(var)] - NA
  return(new.var)
}


  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Mark Grimes
Sent: Friday, April 06, 2012 11:16 AM
To: John D. Muccigrosso
Cc: r-help@r-project.org
Subject: Re: [R] multiple values in one column

John

I have to deal with this kind of thing too for my class.

#   Some functions
# for ad$Full.name = Mark Grimes
get.first.name - function(cell){
x-unlist(strsplit(as.character(cell),  ))
return(x[1]) 
}
get.last.name - function(cell){
x-unlist(strsplit(as.character(cell),  ))
return(x[2]) 
}
# For roster$Name = Grimes, Mark L
get.first.namec - function(cell){
x-unlist(strsplit(as.character(cell), , ))
y - get.first.name(x[2])
return(y) 
}
get.last.namec - function(cell){
x-unlist(strsplit(as.character(cell), , ))
return(x[1]) 
}
Use these functions with the apply family for processing class files. 

Hope this helps,

Mark

On Apr 6, 2012, at 9:09 AM, John D. Muccigrosso wrote:

 I have some data files in which some fields have multiple values. For example
 
 first  last   sex   major
 John   Smith  M ANTH
 Jane   DoeF HIST,BIOL
 
 What's the best R-like way to handle these data (Jane's major in my example), 
 so that I can do things like summarize the other fields by them (e.g., sex by 
 major)?
 
 Right now I'm processing the files (in excel since they're spreadsheets) by 
 duplicating lines with two values in the major field, eliminating one value 
 per row. I suspect there's a nifty R way to do this.
 
 Thanks in advance!
 
 John Muccigrosso
 
 __
 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.


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


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Reading Text Files with RODBC

2012-02-16 Thread Nutter, Benjamin
I'm thoroughly stumped.  I've been playing with RODBC and wanted to see if I 
could retrieve data from text files using this package as well (for the most 
part, this is an intellectual exercise, but occasionally I do get data files 
large enough in CSV format RODBC could be helpful) .

I set up a DNS called Text Files and then ran the following code in R 

 library(RODBC)
 mtg - odbcConnect(Text Files)
 sqlTables(mtg)
 TABLE_CAT TABLE_SCHEMTABLE_NAME  TABLE_TYPE
REMARKS
1 C:\\USERS\\NUTTERB   NACore2012.txt  TABLE  
   NA
2 C:\\USERS\\NUTTERB   NA MTGCards.csv  TABLE 
NA
 sqlFetch(mtg, MTGCards.csv)
Error in odbcTableExists(channel, sqtable) : 
  'MTGCards.csv': table not found on channel


MTGCards.csv is an export from an MS Access database, and I'm able to get it 
out of Access, and I'm also able to connect to our Oracle databases.  So I'm 
not sure what it is I'm not getting about reading the text files.  If anyone 
has done this successfully and has any pointers, I'd appreciate it.  So far 
I've not been able to solve it with documentation from RODBC, RStudio (I get 
the same error messages when I use the RGui), or Microsoft ODBC drivers.

Windows 7, 32 bit
R 2.14.1
RODBC 1.3-4
RStudio Version 3



  Benjamin Nutter |  Biostatistician |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365



===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.
__
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 Text Files with RODBC

2012-02-16 Thread Nutter, Benjamin
Ah, yes.  If you can't find the answer to your question, ask a different 
question!

sqldf does, indeed, do what I want.  Thank you

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] 
Sent: Thursday, February 16, 2012 1:15 PM
To: Nutter, Benjamin
Cc: r-help@r-project.org
Subject: Re: [R] Reading Text Files with RODBC

On Thu, Feb 16, 2012 at 10:12 AM, Nutter, Benjamin nutt...@ccf.org wrote:
 I'm thoroughly stumped.  I've been playing with RODBC and wanted to see if I 
 could retrieve data from text files using this package as well (for the most 
 part, this is an intellectual exercise, but occasionally I do get data files 
 large enough in CSV format RODBC could be helpful) .

 I set up a DNS called Text Files and then ran the following code in 
 R

 library(RODBC)
 mtg - odbcConnect(Text Files)
 sqlTables(mtg)
                         TABLE_CAT TABLE_SCHEM    TABLE_NAME  
 TABLE_TYPE        REMARKS
 1 C:\\USERS\\NUTTERB                   NA    Core2012.txt              
 TABLE                 NA
 2 C:\\USERS\\NUTTERB                   NA MTGCards.csv              
 TABLE                 NA
 sqlFetch(mtg, MTGCards.csv)
 Error in odbcTableExists(channel, sqtable) :
  'MTGCards.csv': table not found on channel


 MTGCards.csv is an export from an MS Access database, and I'm able to get it 
 out of Access, and I'm also able to connect to our Oracle databases.  So I'm 
 not sure what it is I'm not getting about reading the text files.  If anyone 
 has done this successfully and has any pointers, I'd appreciate it.  So far 
 I've not been able to solve it with documentation from RODBC, RStudio (I get 
 the same error messages when I use the RGui), or Microsoft ODBC drivers.


This isn't precisely what you are asking for but if the idea is to apply an sql 
statement to a csv file then read.csv.sql in the sqldf package can apply an sql 
statement to a csv file reading the result into R.  If you omit the sql 
statement then it reads it all in.

--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] R not recognizing words

2012-01-06 Thread Nutter, Benjamin
I've developed a preference for 

x$y %in% Low

when subsetting.  

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of arabarkev
Sent: Friday, January 06, 2012 12:20 AM
To: r-help@r-project.org
Subject: [R] R not recognizing words

Hello all

I'm new to R and am experiencing a problem with a categorical variable.  All 
the data of this variable are Low, High, or NA.  When I put summary(x$y), 
it gives me the number of High, Low, and NA entries.  However,
when I try to subset by writing x$y==Low  or x$y==High, R does not
recognize the word and it writes FALSE for all the entries (but not the NA 
entries). 

Can anybody help me out?

Thanks
 



--
View this message in context: 
http://r.789695.n4.nabble.com/R-not-recognizing-words-tp4268283p4268283.html
Sent from the R help mailing list archive at Nabble.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.


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] nice report generator?

2011-12-07 Thread Nutter, Benjamin
With any sort of reproducible report, you'll have to 'manually place' all of 
the tables and figures at least once.  If done well, however, you'll only have 
to ever do it once.  

I'm not an Sweave expert (yet, regrettably), but using lazyWeave, you could 
generate a customized ANOVA table using the code below.  If you're familiar 
with Sweave, I'd recommend using it.



library(lazyWeave)
#*** Function to produce the latex code for an ANOVA table
anova.table - function(aov.object, caption=, ...){
  out - data.frame(Source = rownames(anova(aov.object)),
SS = anova(aov.object)[, 2],
D.F. = anova(aov.object)[, 1],
stringsAsFactors=FALSE)
  out$MS - out$SS / out$D.F.
  out$F - NA
  out$F[-nrow(out)] - out$MS[-nrow(out)] / out$MS[nrow(out)]
  out$p - 1 - pf(out$F, out$D.F., out$D.F.[nrow(out)])
  
  out - rbind(out, data.frame(Source = Total, SS=sum(out$SS), 
D.F.=sum(out$D.F.), MS=NA, F=NA, p=NA))
  
  out$SS - round(out$SS, 3)
  out$MS - round(out$MS, 3)
  out$F - round(out$F, 3)
  
  rownames(out) - NULL
  out[is.na(out)] - 
  paste(lazy.table(colnames(out), rborder=c(0, 0, 1), open=TRUE, close=FALSE, 
caption=caption),
lazy.table(out, rborder=2, open=FALSE, close=TRUE), sep=\n)
}

#***
#*** Analysis of Variance
m1 - aov(mpg ~ cyl, data=mtcars)


#***
#*** Write the result to a file
lazy.write(
  lazy.file.start(),
  anova.table(m1, caption=An example ANOVA table from the dataset \\tt 
mtcars\\rm.),
  lazy.file.end(),
  OutFile=TestFile.tex)

lazy.build(TestFile.tex)

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Sarah Goslee
Sent: Wednesday, December 07, 2011 2:34 PM
Cc: r-help; Janko Thyson
Subject: Re: [R] nice report generator?

On Wed, Dec 7, 2011 at 1:50 PM, Michael comtech@gmail.com wrote:
 Thanks a lot!

 Typically the console output will be something like this:

 Analysis of Variance Table

 Response: as.double(my.delta)
             Df Sum Sq Mean Sq F value Pr(F) my.factor    1      0   
 0.005   2e-04  0.988 Residuals  1484  32630  21.988

 I am looking for a report-generator to make this look nicer and tabularize 
 it...

 It doesn't matter if the outputs are in HTML, PDF, etc.

 As long as it looks fantastic, that's what we are looking for ... and 
 also the convenience is important... we dont' want to create Latex 
 document with manual insertaion of tables and plots... These need 
 automation... thx a lot!

That's what sweave is *for* - automation and reproducible research. It takes 
care of the heavy lifting of generating and inserting tables and figures.

You will almost certainly need some tweaking to match your own definition of 
looks fantastic though.

Sarah

 On 07.12.2011 19:19, Sarah Goslee wrote:
 Sweave.

 Or ODFWeave, if Sweave/LaTeX are too much overhead.

 But really, it depends on what kind of report output you need to 
 deliver. Printed? HTML? PDF?

 Sarah

 On Wed, Dec 7, 2011 at 1:14 PM, Michaelcomtech@gmail.com  wrote:
 Hi all,

 I am looking for recommendations/pointers about best report 
 generator you think that are currently available?

 i.e. the package that can help turn console output into 
 nice-looking neat report to send to bosses?

 thanks a lot!
 .




--
Sarah Goslee
http://www.functionaldiversity.org

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


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Loading an S object into R

2011-05-24 Thread Nutter, Benjamin
I hope you'll all forgive me for displaying my severe lack of knowledge on this 
topic, and I can't really provide much in the way of reproducible code.

A colleague of mine has asked if I know how to import an S object into R.  The 
object is stored in a file named 'pre3.f'   When I open the file as a text 
document I get what's printed below.  Being one of those young bucks with no 
experience with S, and not having access to a license of S in which to play 
with this, does anyone have any suggestions on how to get this (what I assume 
is) data from the .f file into R?

Benjamin



S data      
   .Data class             8   €- ß   coefficients var loglik score iter 
linear.predictors residuals means terms n call Design assign na.action fail 
non.slopes stats method maxtime time.inc units fitFunction center scale.pred x 
y time surv std.err surv.summary                               ,    
                                                            
                
         
                                       
      À      À      ƒ  €  K  [   c   g   d`  a·  Á·  
À  (Á  -Å  ÄÍ  ’Î  ;à  ?à  Gà  âà  ìà  ôà  üà  á  á  á  ?á  %’    ¾) 
¾, 
   .Data .Names       
   
   ¬  
  ŧÀ1Æ?1o`kŠÉ¿E…­:ñ¯¿•¤28q|á?9V
9`™Ì?7ÏCÌ%¼æ?KI¸Éèó?œ?±Bt0ê?K#4¢öª?\½ÿ_ï“°¿d}˜e±¿‡çÏ=6ìá¿p   PREOP.PSA 
PREOP.PSA' T.STG=T2A T.STG=T2B T.STG=T2C T.STG=T3 G1= 3 G2= 3 BX.POS BX.NEG 
RP.YEAR G1= 3 * G2= 3    .Data .Dim .Dimnames                   ½  = 
 E  6¨¢wåÈa?®_¨JMg¿˜ªjŒðÊE?¡rVÍ?ò›T­ÑWDôOw:?–
 ...
SA?;_ws6Ê@?(óèLp@¿öšQEF?ŠVU9Xf?…—ï’[¿Ÿ¹ê'¬ÏT? Ó×-’91¿×ÈF¡Ú¯¿K ?Ø' ¿øP¼ÕJf?ӁP
(¿;_ws6Ê@?%–ô£k1¾?
   
          
   
   c  ×  p   PREOP.PSA PREOP.PSA' T.STG=T2A T.STG=T2B T.STG=T2C T.STG=T3 G1= 
3 G2= 3 BX.POS BX.NEG RP.YEAR G1= 3 * G2= 3 p   PREOP.PSA PREOP.PSA' 
T.STG=T2A T.STG=T2B T.STG=T2C T.STG=T3 G1= 3 G2= 3 BX.POS BX.NEG RP.YEAR G1= 
3 * G2= 3 ÔwÎ
8”Àñp|ù°»’ÀI=ÍΊ=l@   
   .Data .Names       Ð  Ð   @   õ‹•obð?@+
tYÜ@@Ð×Æa
@À‚j
ç@€ã
øqý
@@.ŸŸB
@@?œ(°ˆ
@€'w¹æý?€z¾
...
â? ¡’ø¿ ˆÄ]¤eð¿ ¦mÉëå¿ Ð‚v×ç¿€
ˆWc󿀐ù¬Oô¿ €[iŸìÅ¿€2#_? À X×
äIÊ? 
KZªó¿ (ù'~ä¿ uÊäá¿ àø¤:üÙ¿ ’ ëu Ô¿ »­Ý›²ð¿ déÂg«Ï? üÄ NÊ¿ J³–ñ¿  
´¶}Òh¿€ž8rNù¿ uí{[ð¿ €‰¡íu©¿ èíÑ¿ NðÚ׿ z0QÂ_ï? ͤ³×¿ æGM’Iå¿ ½ÜGçâ¿ 
È*ùö»ò¿ ‚ս࿠8îvç÷¿ °¦­nMß¿ «‹9Ýô¿ PŒãC¸¿€°jø£ù¿ ›»›  ×? ²ñð¿ V   
 òÝmï¿€=CÀ‡ó¿€NíÈ‘ñ? £Yﲁ÷¿€ÇŒHuKÿ¿ ävw™ö¿ ùÄSdgö¿ /ϸá À ${Fƒü¿ 
N—$ÕSá¿€U~A©ù¿€Ÿš»âû¿€h±š–àú¿ 2ŒÜ?ú¿ 
ύ`ä¿ \#‘‰î¿ rc¯^é¿€Z«¿/ü¿ K Õ”õ¿ ·râ¯ô¿€¤lJüíô¿ -
\
›ã¿€M‚
ªôñ¿@˺º×Ä À Ä¥.vú¿ ·Ûô ›õ¿ ¿¦3p×è¿€'ÆûSÕú¿ S7ôîÓð¿ X9=   î¿€
žQÎö¿ ¶.Ì2ú¿€·Â9['ú¿€œ—Çÿ¿ LÌFœ_æ? FÿŒ7Ÿú¿P   2 3 4 5 6 8 13 15 18 21 22 24 
25 26 28 31 32 34 37 39 40 42 45 46 49 53 54 60 61 62 65 74 75 78 79 81 82 83 
84 85 90 91 93 94 95 100 102 103 104 105 106 110 112 114 116 117 119 123 127 
128 130 132 137 138 141 143 145 146 152 153 154 155 164 167 168 171 175 177 179 
180 181 182 187 188 189 193 195 198 199 200 201 204 206 216 220 221 230 233 236 
237 239 241 242 248 253 257 258 259 261 263 267 268 275 276 277 279 283 284 286 
293 294 297 299 300 301 304 306 307 308 310 313 317 320 327 328 330 331 336 337 
338 339 342 346 347 349 351 358 359 360 361 362 363 366 368 369 370 373 377 384 
388 390 391 395 397 401 402 403 407 ...
 3522 3523 3524 3525 3526 3527 3528 3529 3530 3537 3541 3545 3548 3554 3555 
3558 3560 3561 3562 3563 3565 3570 3572 3576 3577 3581 3582 3583 3584 3585 3586 
3587 3588 3589 3597 3600 3601 3603 3604 3606 3607 3610 3612 3613 3615 3616 3617 
3618 3619 3620 3626 3627 3628 3632 3633 3635 3636 3642 3643 3646 3647 3648 3649 
3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3669 3671 3672 3673 3674 3686 
3687 3688 3689 3690 3691 3693 3694 3695 3696 3697 3698 3709 3710 3711 3713 3719 
3722 3726 3728 3729 3730 3732 3733 3734 3735 3736 3737 3740 3741 3742 3743 3744 
3746 3756 3758 3759 3760 3761 3762 3766 3767 3768 3769 3770 3771 3772 3777 3783 
3784 3787 3788 3789 3790 3791 3792 3795 3798 3801 3802 3803 3805 3814 3817 3818 
3819 3821 3822 3824 3826 3836 3837 3838 3840 3841 3842 3848 3850 3854 3855 3856 
3857 3858 3864 3868 3870 3871 3878 3884 3888 3898 3900 3901 3902 3903 3904 3905 
3912 3914 3915 3916 3917 3918 3921 3924 3927 3928 3930 3931 3932 3935 3946 3947 
3948 3949 3951 3952 3954 3957 3958 3961 3963 3964 3971 3981 3985 3988 4007 4014 
4015 
   .Data .Names       Ð  Ð  `  
...

===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under 

Re: [R] Loading an S object into R

2011-05-24 Thread Nutter, Benjamin
Shoot!  I was really hoping this would be something not in an obvious 
documentation.  Feel free to stamp my forehead with One of Them

And you were right, it turned out to be a cph model.

Thanks, Josh.

-Original Message-
From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] 
Sent: Tuesday, May 24, 2011 12:20 PM
To: Nutter, Benjamin
Cc: r-help@r-project.org
Subject: Re: [R] Loading an S object into R

Hi Benjamin,

I also have no experience with S plus, but the suggestions on the R 
Import/Export manual seem worth trying:

http://cran.r-project.org/doc/manuals/R-data.html#EpiInfo-Minitab-SAS-S_002dPLUS-SPSS-Stata-Systat

I also question whether this is just data, words like loglik, iter, etc. 
seem more like a model object of some kind (which I suppose is a type of data, 
but...)

Good luck,

Josh

On Tue, May 24, 2011 at 8:24 AM, Nutter, Benjamin nutt...@ccf.org wrote:

 I hope you'll all forgive me for displaying my severe lack of knowledge on 
 this topic, and I can't really provide much in the way of reproducible code.

 A colleague of mine has asked if I know how to import an S object into R.  
 The object is stored in a file named 'pre3.f'   When I open the file as a 
 text document I get what's printed below.  Being one of those young bucks 
 with no experience with S, and not having access to a license of S in which 
 to play with this, does anyone have any suggestions on how to get this (what 
 I assume is) data from the .f file into R?

 Benjamin



 S data
   .Data class                 8   €-  ß   coefficients var loglik 
 score iter linear.predictors residuals means terms n call Design 
 assign na.action fail non.slopes stats method maxtime time.inc units 
 fitFunction center scale.pred x y time surv std.err surv.summary              
                            
 ,


       À       À       ƒ   €   K          [       c       g       d`  
 a·  Á·   À  (Á  -Å  ÄÍ  ’Î  ;à  ?à  Gà  âà  ìà  ôà  üà   á   á   á  ?á  
 %’         ¾)  ¾,
   .Data .Names

   ¬
   ŧ À 1Æ?1o`kŠ É¿E…­: ñ¯¿•¤28q|á?9V
 9`™Ì?7ÏCÌ%¼æ?K I¸Éèó?œ?±Bt0ê?K#4¢öª?\½ÿ_ï“°¿d  }˜e±¿‡çÏ=6ìá¿p   
 PREOP.PSA PREOP.PSA' T.STG=T2A T.STG=T2B T.STG=T2C T.STG=T3 G1= 3 
 G2= 3 BX.POS BX.NEG RP.YEAR G1= 3 * G2= 3     .Data .Dim .Dimnames         
                 
 ½   =   E   6¨¢wåÈa?®_¨JM g¿˜ªjŒðÊE?  ¡rVÍ? ò› T­ÑW DôOw:?–
  ...
 SA?;_ws6Ê@?(ó èLp@¿  öšQEF?ŠVU9X f?… —ï’[¿Ÿ¹ê'¬ÏT? Ó×-’91¿×ÈF ¡Ú¯¿K 
 ?Ø'  ¿øP¼ÕJf? Ó  P (¿;_ws6Ê@?%–ô£k1¾?



   c   ×   p   PREOP.PSA PREOP.PSA' T.STG=T2A T.STG=T2B T.STG=T2C 
 T.STG=T3 G1= 3 G2= 3 BX.POS BX.NEG RP.YEAR G1= 3 * G2= 3 p   
 PREOP.PSA PREOP.PSA' T.STG=T2A T.STG=T2B T.STG=T2C T.STG=T3 G1= 3 
 G2= 3 BX.POS BX.NEG RP.YEAR G1= 3 * G2= 3 ÔwÎ 8”Àñp|ù°»’ÀI=ÍΊ=l@
   .Data .Names         Ð   Ð              @   õ‹•obð?@+ tYÜ @@Ð ×Æa 
 @À‚ j ç @€ã øqý @@.ŸŸ B @@?œ(°ˆ @€ 'w¹æý?€z¾ ...
 â?      ¡’ø¿ ˆÄ]¤eð¿ ¦ mÉëå¿ Ð‚v ×ç¿€ ˆWcó¿€  ù¬Oô¿ €[iŸìÅ¿€ 2#_? À 
 X× äIÊ?
 K Zªó¿ (ù' ~ä¿ uÊ ä á¿ àø¤:üÙ¿ ’ ëu Ô¿ »­Ý›²ð¿ déÂg«Ï? üÄ NÊ¿ J³ – ñ¿  
 ´¶}Òh¿€ž8r Nù¿ uí {[ð¿ €‰¡íu©¿ è  í Ñ¿ N  ðÚ׿ z0QÂ_ï?  Í¤³×¿ æGM’Iå¿ 
 ½ÜG çâ¿ È*ùö»ò¿ ‚Õ ½à¿ 8î vç÷¿ °¦­nMß¿ «‹ 9Ýô¿ PŒãC ¸¿€° jø£ù¿  ›»›      
 ×? ²ñ ð¿ V    òÝmï¿€ =CÀ‡ó¿€NíÈ‘ ñ? £Yï² ÷¿€ÇŒHuKÿ¿ ävw™ ö¿ ùÄSdgö¿ 
 /Ï¸á  À ${ Fƒü¿ N—$ÕSá¿€U~A© ù¿€Ÿ š»âû¿€h±š–àú¿ 2ŒÜ ?ú¿ Ï `ä¿ \ #‘‰î¿ 
 r c¯^é¿€Z«¿/ü¿  K Õ”õ¿ ·râ ¯ô¿€¤lJüíô¿ - \ ›ã¿€M‚ ªôñ¿@˺º×Ä À Ä ¥.vú¿ 
 ·Ûô ›õ¿ ¿¦3p×è¿€'ÆûSÕú¿ S7ôîÓð¿ X 9=       î¿€ ž QÎö¿ ¶ .Ì2ú¿€·Â9['ú¿€ œ—Ç ÿ¿ 
 LÌFœ_æ? FÿŒ7Ÿú¿P   2 3 4 5 6 8 13 15 18 21 22 24 25 26 28 31 32 34 37 39 40 
 42 45 46 49 53 54 60 61 62 65 74 75 78 79 81 82 83 84 85 90 91 93 94 95 100 
 102 103 104 105 106 110 112 114 116 117 119 123 127 128 130 132 137 138 141 
 143 145 146 152 153 154 155 164 167 168 171 175 177 179 180 181 182 187 188 
 189 193 195 198 199 200 201 204 206 216 220 221 230 233 236 237 239 241 242 
 248 253 257 258 259 261 263 267 268 275 276 277 279 283 284 286 293 294 297 
 299 300 301 304 306 307 308 310 313 317 320 327 328 330 331 336 337 338 339 
 342 346 347 349 351 358 359 360 361 362 363 366 368 369 370 373 377 384 388 
 390 391 395 397 401 402 403 407 ...
  3522 3523 3524 3525 3526 3527 3528 3529 3530 3537 3541 3545 3548 3554 
 3555 3558 3560 3561 3562 3563 3565 3570 3572 3576 3577 3581 3582 3583 
 3584 3585 3586 3587 3588 3589 3597 3600 3601 3603 3604 3606 3607 3610 
 3612 3613 3615 3616 3617 3618 3619 3620 3626 3627 3628 3632 3633 3635 
 3636 3642 3643 3646 3647 3648 3649 3651 3652 3653 3654 3655 3656 3657 
 3658 3659 3660 3669 3671 3672 3673 3674 3686 3687 3688 3689 3690 3691 
 3693 3694 3695 3696 3697 3698 3709 3710 3711 3713 3719 3722 3726 3728 
 3729 3730 3732 3733 3734 3735 3736 3737 3740 3741 3742 3743 3744 3746 
 3756 3758 3759 3760 3761 3762 3766 3767 3768 3769 3770 3771 3772 3777 
 3783 3784 3787 3788 3789 3790 3791 3792 3795 3798 3801 3802 3803 3805 
 3814 3817 3818 3819 3821 3822 3824 3826 3836 3837 3838 3840 3841 3842 
 3848 3850 3854 3855 3856 3857 3858 3864 3868 3870 3871 3878 3884 3888 
 3898 3900 3901 3902 3903 3904 3905 3912

Re: [R] help with \ in strings

2011-04-25 Thread Nutter, Benjamin
Depending on what else you're writing around the %, you might consider
using the latexTranslate() function in Hmisc.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of viostorm
Sent: Sunday, April 24, 2011 8:48 AM
To: r-help@r-project.org
Subject: Re: [R] help with \ in strings

Josh,

Thank you so much!!! Works perfectly!

-Rob


Robert Schutt III, MD, MCS
Resident - Department of Internal Medicine University of Virginia,
Charlottesville, Virginia 

--
View this message in context:
http://r.789695.n4.nabble.com/help-with-in-strings-tp3470964p3471386.htm
l
Sent from the R help mailing list archive at Nabble.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.


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Fibonacci

2011-04-20 Thread Nutter, Benjamin
Fibonacci - c(1, 1)
while (max (Fibonacci)  500){
  Fibonacci - c(Fibonacci, sum(tail(Fibonacci, 2))) } 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Georgina Imberger
Sent: Wednesday, April 20, 2011 5:43 AM
To: r-help@r-project.org
Subject: [R] Fibonacci

Hi!

I am trying to work out the code to get a Fibonacci sequence, using the
while() loop and only one variable. And I can't figure it out.

Fibonacci-c(1,1)
while (max(Fibonacci)500){
Fibonacci-c(Fibonacci, (max(Fibonacci) + ?(Fibanacci))) }


How can I tell R to take the value one before the max value? (Without
defining another variable)

(Probably super easy... I am a beginner...)

Thanks,
Georgie

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


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] the first. from SAS in R

2010-11-29 Thread Nutter, Benjamin
My apologies for coming to the party so late.

I'm sure this question has been answered a couple of times.  The
attached function is one I pulled from the help archives, but I can't
seem to duplicate the search that led me to it.

In any case, I've attached the function I found, and an .Rd file I use
as part of a local package.  I've also attached a pair of accompanying
records to retrieve the last record and the nth record.  These have the
advantage of not requiring data frames to be sorted prior to
extraction--the function will sort them for you.

Benjamin  

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of David Katz
Sent: Wednesday, November 24, 2010 10:17 AM
To: r-help@r-project.org
Subject: Re: [R] the first. from SAS in R


Often the purpose of first/last in sas is to facilitate grouping of
observations in a sequential algorithm. This purpose is better served in
R by using vectorized methods like those in package plyr.

Also, note that first/last has different meanings in the context of by
x;
versus by x notsorted;. R duplicated does not address the latter,
which splits noncontiguous records with equal x.

Regards,
David
--
View this message in context:
http://r.789695.n4.nabble.com/the-first-from-SAS-in-R-tp3055417p3057476.
html
Sent from the R help mailing list archive at Nabble.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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.
__
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] Tinn-R looses connection to R (Windows Vista)

2010-11-17 Thread Nutter, Benjamin
I've noticed it, but I haven't looked into it much since I rarely work
on Vista.  I have found that opening R before I open Tinn-R tends to
work better than using Tinn-R to open the preferred GUI.

Benjamin 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Agi Richard
Sent: Wednesday, November 17, 2010 4:43 AM
To: R-help@r-project.org
Subject: [R] Tinn-R looses connection to R (Windows Vista)

Hi everyone,
I wonder, if anyone can help me with this annoying issue, although it is
related to Tinn-R and Windows Vista...
I am running R 2.11.1 and Tinn-R 2.3.5.2 together. I saved 2 R-hotkeys:
ALT+A for sending the whole content of one file and ALT+S for a 
ALT+selection
from one file from Tinn-R to R. Everything works fine with other windows
versions, also with Vista at the beginning of every session, but after a
certain time (not always the same, neither the number of times, that I
used the hotkeys is the same, so it occurs randomly, but quite fast,
lets say on average within half an hour - 2hs) ALT+S does not work
anymore, but instead this hotkey opens the start menue of Vista!! (The
same function the windows key has!) I would be very happy, if anyone has
an idea why this could be!! Is it related to R, to Tinn-R or to Vista?
Thank you very very much in advance!
Carol

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Opening a .R file with R (Windows)

2010-09-30 Thread Nutter, Benjamin
Here's a thread that has some good discussion on the topic

http://r.789695.n4.nabble.com/Running-script-with-double-click-td1579014.html

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Bert Gunter
Sent: Tuesday, September 28, 2010 1:48 PM
To: Joshua Wiley
Cc: r-help@r-project.org
Subject: Re: [R] Opening a .R file with R (Windows)

Well, try following the correct conventions ...

1. Double click on an .Rdata file, which is produced by saving from R, and it 
will open.

2. Drag and drop a .R or any text file into an open R window and it will source 
the contents.

This is probably documented somewhere .. maybe in the RW FAQ.

-- Bert

On Tue, Sep 28, 2010 at 10:22 AM, Joshua Wiley jwiley.ps...@gmail.com wrote:
 Hi Kye,

 I have never gotten .R files to work quite like other types (e.g., 
 double-clicking a .PDF) in Windows.  AFAIK there is no simple way to 
 do it, because you do not edit scripts directly in R (I am happy to be 
 corrected if someone knows better).  For general use, I would just 
 open R first and then open the file, or if you just want to run the 
 file, you can use R's batch mode from the Windows command prompt.

 Best regards,

 Josh

 On Tue, Sep 28, 2010 at 10:11 AM, Kye Gilder kye.gil...@gmail.com wrote:

 I am new to using R.  I installed R on my computer (Windows) and 
 everything things appears to be just fine.  However, I have a simple 
 script RTest.R that does a few simple calculations.  When I 
 double-click the RTest.R icon, I get an Information dialong box which 
 says, ARGUMENT 'C:\Documents and Settings\kgilder\Desktop\RTest.R' 
 __ignored__ .  When I choose OK, R then opens, but it does not open or 
 display the script.  Any help or suggestions?

 When I open R and use File  Open New Script and path to the file, 
 it opens just fine.
 Regards,

 Kye

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



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.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.




--
Bert Gunter
Genentech Nonclinical Biostatistics

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Converting date format

2010-03-23 Thread Nutter, Benjamin
If x is your vector of character date variables:

orig.date - as.Date(x, format=c(%m/%d/%Y))
new.date - format(x, format=c(%m/%d/%y))

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Hosack, Michael
Sent: Tuesday, March 23, 2010 10:11 AM
To: R-help@r-project.org
Subject: [R] Converting date format

R community:

Hello, I would to like to convert a character date variable from
%m/%d/%Y to %m/%d/%y. Any advice would be greatly appreciated. I have
tried functions for changing the formatting and removing the unnecessary
digits without success.

Mike

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Retrieving latitude and longitude via Google Maps API

2010-03-16 Thread Nutter, Benjamin
Does anyone have any experience retrieving latitutde and longitude for
an address from the Google Maps API?  

I'd like to have an R script that submits a street address, city, state,
and zip code and returns the coordinates.  So far, I've been submitting
the coordinates from another program, then loading the coordinates in R
and merging them back into the data frame I want to use.  It'd be nice
to be able to do it all in one script, but I'm not comprehending the API
thing very well.

I'm using R 2.9.1 on Windows XP.  Any suggestions or pointers?

Benjamin

 
 
  Benjamin Nutter |  Biostatistician  |  Quantitative Health Sciences
  Cleveland Clinic  |  9500 Euclid Ave.   |  Cleveland, OH 44195  |
(216) 445-1365


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Help on getting help from manuals

2010-03-12 Thread Nutter, Benjamin
As has been pointed out, there are tools in R to help find the commands
you are looking for.

As a practical note, I recommend starting with '?' if you think you know
what command you need.

If you're unsure of what command you need, my next step would be
help.search().  Often, the results from here will point you to a command
that you are looking for.

If a handful of tries with help.search() doesn't get you what you need,
then try RSiteSearch().  This will search the mailing list for entries
relevant to your search criteria.  Often times, you'll find that someone
has already asked your question.  In fact, I can only recall a couple of
times where a search of the mailing list has failed to provide a
solution for me.

Aside from reading lots of documentation, the one thing that has helped
me the most in picking up R has been reading Peter Dalgaard's
Introductory Statistics with R.  It's a very small, basic introduction
to R, but laid a solid enough foundation that I soon found myself able
to produce and refine my own solutions.

In short, the best way to improve our knowledge of R is lots of reading
and a bit of trial and error.

Benjamin 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of ManInMoon
Sent: Friday, March 12, 2010 4:41 AM
To: r-help@r-project.org
Subject: [R] Help on getting help from manuals


Hi,

A number of people have suggested I read the manuals...

Could someone help me by telling me where the primary start point is
please?

For example, I am interested in writing functions with variable number
of arguments - where should I start to look?

An introduction to R only show a brief example - with no pointer to
where to find further data.

I can't do ?xxx from R console in most cases - as I don't know what the
function name is that I am looking for!!!

People have helped me find substitute to get some metadata out - BUT
how could I have found that without guidance from nice people in Nabble?

Any help on this very much appreciated.


--
View this message in context:
http://n4.nabble.com/Help-on-getting-help-from-manuals-tp1590323p1590323
.html
Sent from the R help mailing list archive at Nabble.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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Row-wisely converting a data frame into a list

2010-03-02 Thread Nutter, Benjamin
 as.data.frame(t(df)) 

For example

 x - as.data.frame(t(mtcars))
 typeof(x)
[1] list

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Sebastian Bauer
Sent: Tuesday, March 02, 2010 8:12 AM
To: r-help@r-project.org
Subject: [R] Row-wisely converting a data frame into a list

Hello,

is there an elegant way, how I can convert each row of a data frame into
distinct elements of a list?

In essence, what I'm looking for is something like

rows.to.lists - function( df ) {
ll - NULL
for( i in 1:nrow(df) )
ll - append( ll, list(df[i,]) )
return (ll)
}

but more done more efficiently (the data frame may contain ten-thousands
of rows). I thought about using apply() but this function always returns
a matrix.

Thanks in advance!

Bye,
Sebastian

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] counting the number of ones in a vector

2010-02-26 Thread Nutter, Benjamin
What you did works well.  You could also try the following.

table(x)[1]



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Randall Wrong
Sent: Friday, February 26, 2010 9:41 AM
To: r-help@r-project.org
Subject: [R] counting the number of ones in a vector

Dear R users,

I want to count the number of ones in a vector x.

That's what I did : length( x[x==1] )

Is that a good solution ?
Thank you very much,
Randall

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] counting the number of ones in a vector

2010-02-26 Thread Nutter, Benjamin
But if x has any missing values:

 x - c(1, 1, 1, NA, NA, 2, 1, NA)
 
 sum( x == 1)
[1] NA
 
 sum(x==1, na.rm=TRUE)
[1] 4




-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Henrique Dallazuanna
Sent: Friday, February 26, 2010 9:47 AM
To: Randall Wrong
Cc: r-help@r-project.org
Subject: Re: [R] counting the number of ones in a vector

Try:

sum(x == 1)

On Fri, Feb 26, 2010 at 11:40 AM, Randall Wrong randall.wr...@gmail.com wrote:
 Dear R users,

 I want to count the number of ones in a vector x.

 That's what I did : length( x[x==1] )

 Is that a good solution ?
 Thank you very much,
 Randall

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




--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] First. Last. Data row selection

2010-02-23 Thread Nutter, Benjamin
I've attached some functions I've written based on previous questions
that have been posted here.  Unfortunately, I was too lazy to give
credit to previous commenters in my Rd file, and for that I hope they'll
forgive me.  

In any case, please be assured that the functions I've attached are in
no way my original work.

Benjamin

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of wookie1976
Sent: Tuesday, February 23, 2010 12:40 PM
To: r-help@r-project.org
Subject: [R] First. Last. Data row selection


I am in the process of switching from SAS over to R.  I am working on
very large CSV datasets that contain vehicle information.  As I am
processing the data, I need to select the first (or sometimes the
second) record (by date) for any records that have the same license
plate number.  In SAS, there is a function called 'first.' that can be
used on sorted datasets to pull out those first entries for each
occurrence of a particular variable  (in this case the variable is
'license plate') found in the data.  I have spent some time looking
around and cannot seem to find an equivalent function in R. 
Can anyone recommend an efficient technique that would pull this off?  I
assume the database must first be sorted by vehicle plate and date, and
then apply the filter or function.  Any help would be greatly
appreciated.  

Thanks, Joe
--
View this message in context:
http://n4.nabble.com/First-Last-Data-row-selection-tp1566260p1566260.htm
l
Sent from the R help mailing list archive at Nabble.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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.
__
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] Circles around letters or numbers in plot title

2010-02-23 Thread Nutter, Benjamin
Has anyone ever tried putting a circle around a letter or a number in a
plot title?

For instance, if I have a plot title Scatterplot for Subject 24, I
want to put a circle around 24 to distinguish that plot from the other
30 I've generated.  Any tips or ideas beyond plotting a circle in the
margin?

Benjamin 
 


  Benjamin Nutter |  Biostatistician  |  Quantitative Health Sciences
  Cleveland Clinic  |  9500 Euclid Ave.   |  Cleveland, OH 44195  |
(216) 445-1365


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] all possible subsets, with AIC

2010-02-15 Thread Nutter, Benjamin
I've dabbled in this a little bit, and the result of my dabbling is
attached.  I'll give you fair warning, however.  The attached function
can take a long time to run, and if your model has 10 or more
predictors, you may be retired before it finishes running.

In any case, it will models for all possible subsets of predictors in
lm, glm, or coxph.  If requested, it will also plot the R-squared,
Adjusted R-squared, AIC, or BIC of those models (when the values are
applicable to the model).  It might give you a good starting point.

Benjamin

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of kcleary2
Sent: Friday, February 12, 2010 3:19 PM
To: r-help@r-project.org
Subject: [R] all possible subsets, with AIC



Hello, 

I have a question about doing ALL possible subsets regression with a
general linear model. My goal is to produce cumulative Akaike weights
for each of 7 predictor variables-to obtain this I need R to: 

1.
Show me ALL possible subsets, not just the best possible subsets 

2. Give
me an AIC value for each model (instead of a BIC value). 

I have tried to
do this in library(RcmdrPlugin.HH), and using the leaps code below.
With the leaps code my problem is that my response is not a vector, it's
a single value (density of a species) 

ANy help would be greatly
appreciated. Thanks a lot,
Kate 

ALL-SUBSETS
REGRESSIOM

DESCRIPTION

leaps() performs an exhaustive search for the best subsets of the
variables in x for predicting y in linear regression, using an efficient
branch-and-bound algorithm. It is a compatibility wrapper for regsubsets
[1] does the same thing better. 

Since the algorithm returns a
best model of each size, the results do not depend on a penalty model
for model size: it doesn't make any difference whether you want to use
AIC, BIC, CIC, DIC, ... 

USAGE

leaps(x=, y=, wt=rep(1, NROW(x)), int=TRUE, method=c(Cp, adjr2,
r2), nbest=10, names=NULL, df=NROW(x),
strictly.compatible=TRUE)

ARGUMENTS

x
A matrix of predictors

y

A response vector

wt
Optional weight vector

int
Add an
intercept to the model

method
Calculate Cp, adjusted R-squared or
R-squared

nbest
Number of subsets of each size to report

names

vector of names for columns of x

df
Total degrees of freedom to
use instead of nrow(x) in calculating Cp and adjusted R-squared


strictly.compatible
Implement misfeatures of leaps() in S

--
Kate
Cleary
MS Candidate
Department of Fish, Wildlife, and Conservation Biology Colorado State
University Fort Collins, CO
970-491-3535



Links:
--
[1]
https://webmail.warnercnr.colostate.edu/leaps/help/regsubsets

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.
__
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] Drop last numeral

2010-01-12 Thread Nutter, Benjamin
Data-c(1131, 1132, 1731 ,1732 ,1821 ,1822, 2221 ,,
2241 ,2242,414342 ,414371 ,414372)
Bldgid-substring(as.character(Data),1,nchar(Data)-1)

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of LCOG1
Sent: Tuesday, January 12, 2010 1:37 PM
To: r-help@r-project.org
Subject: [R] Drop last numeral


Hello all,
  Frustrated and i know you can help 

I need to drop the last numeral of each of my values in my data set.  So
for the following i have tried the ?substring but since i have to
specify the length, but because my data are of varying lengths it doenst
work so well

Data-c(1131, 1132, 1731 ,1732 ,1821 ,1822, 2221 ,,
2241 ,2242,414342 ,414371 ,414372)
Bldgid-substring(as.character(Data),1,3)

returns:
113 113 173 173 182 182 222 222 224 224 414 414
414

but i want

113, 113, 173 ,173 ,182 ,182, 222 ,222, 224
,224,41434
,41437 ,41437)

The values thats have more than 4 numerals are whats messing things up. 
Tried ?formatC as well but couldn't get it to coerce things correctly. 
Thanks for the help

JR
--
View this message in context:
http://n4.nabble.com/Drop-last-numeral-tp1012347p1012347.html
Sent from the R help mailing list archive at Nabble.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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] %d/%m/%Y can not be displayed in a .rd file

2010-01-07 Thread Nutter, Benjamin
Try \%d/\%m/\%Y

Escaping the % should do the trick.  If I remember correctly, Latex uses
the % as the comment delimiter.  I don't know if that's the cause of the
error, but escaping it has always solve the problem for me. 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of rusers.sh
Sent: Thursday, January 07, 2010 2:09 PM
To: r-help@r-project.org
Subject: [R] %d/%m/%Y can not be displayed in a .rd file

Hi all,
  I found the date format (e.g.%d/%m/%Y) in the .rd file cannot be
displayed after building the package. See below, ###.rd file
\examples{ a-10/20/1999
DateConversion(a,DateIn=%m/%d/%Y,DateOut=%d/%m/%Y)
}
The result is 
Examples:
 a-10-20-1999
 DateConversion(a,DateIn=

  ??%m/%d/%Y seems cannot be recognized.
Is there some method to solve this and make it visible?
  Thanks a lot.
--
-
Jane Chang
Queen's

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Newbie needs to count elements in a row

2009-12-29 Thread Nutter, Benjamin
For a single row where mat is your matrix and r is the row

 sum(!is.na(mat[r,])) 

For every row in the matrix

 rowSums(!is.na(mat))

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Verena Weber
Sent: Tuesday, December 29, 2009 8:50 AM
To: r-help@r-project.org
Subject: [R] Newbie needs to count elements in a row

Hi,

I have a n*m matrix and would like to count the number of elements not
equal to NA in a ROW.

e.g.

x 1 2 3 NA 10
y 2 NA 8 9 NA

Which function can I use to obtain
4 for row x and
3 for row y?

Could you help me? I found some functions for columns but not for
rows...

Thank you very much!

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Remove double quotation marks

2009-12-29 Thread Nutter, Benjamin
It seems from your example that you're assuming all of the vectors have
the same length.  If this is the case, then a data.frame might be your
friend.

 df - data.frame(
v1 = c(0, 1, 0),
v2 = c(1, 1, 0),
v3 = c(2, 1, 2),
v4 = c(2, 2, 1),
v5 = c(0, 1, 1) )

 x - 5

 get.var - c(v1, v2, paste(v, x, sep=))

 df[, get.var]

Or, if you know your variables in the data.frame will be named
sequentially

 df[, c(1, 2, x)]


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Lisa
Sent: Tuesday, December 29, 2009 3:55 PM
To: r-help@r-project.org
Subject: Re: [R] Remove double quotation marks


Thank you for your help. But here I just want to combine some vectors by
column based on the numbers determined by other R script. 

For example, I have five vectors:

v1 - c(0, 1, 0)
v2 - c(1, 1, 0)
v3 - c(2, 1, 2)
v4 - c(2, 2, 1)
v5 - c(0, 1, 1)

If I am going to combine the first two vectors, and one more other
vector determined by my other R script, say, vector 5.  Then my R script
is

x - 5
cbind(v1, v2, paste(v, x, sep = ))

The output is

 v1  v2  
[1,] 0 1 v5
[2,] 1 1 v5
[3,] 0 0 v5

This is not what I want. I want to get this:

 v1  v2  v5 
[1,]  0   1   0
[2,]  1   1   1
[3,]  0   0   1

Can you give me further suggestions or comments? Thanks a lot.

Lisa



Barry Rowlingson wrote:
 
 On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote:

 Thank you for your reply. But in the following case, cat() or
print()
 doesn't work.

 data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), 
 \n))), where x is a random number generated by other R script.

 Lisa
 
  Yes, because you are Doing It Wrong. If you have data that is indexed

 by an integer, don't store it in variables called variable1, variable2

 etc, because very soon you will be posting a message to R-help that is

 covered in the R FAQ...
 
  Store it in a list:
 
  v = list()
  v[[1]] = c(1,2,3,4,5)
  v[[2]] = c(4,5,6,7,8,9,9,9)
 
 then you can do v[[i]] for integer values of i.
 
 If you really really must get values of variable by name, perhaps 
 because someone has given you a data file with variables called
 variable1 to variable99, then use the paste() construction together 
 with the 'get' function:
 
 [ not tested, but should work ]
 
   v1=99
   v2=102
   i=2
   get(paste(v,i,sep=))
  [1] 102
 
 Barry
 
 __
 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.
 
 

--
View this message in context:
http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.html
Sent from the R help mailing list archive at Nabble.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.

===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] extracting the last row of each group in a data frame

2009-11-17 Thread Nutter, Benjamin
I usually use the following function:

last.record - function(data, id, ..., na.last=TRUE, decreasing=FALSE){

  #*** Make vector of variables to sort by
  v - c(id, unlist(list(...)))

  #*** Sort Data Frame
  data - data[do.call(order,
c(data[,v, drop=FALSE], na.last=na.last,
decreasing=decreasing)),]

  #*** Extract last record for each id
  data[!duplicated(data[,id], fromLast=TRUE),]
}


DataData Frame from which the record is to be extracted
Id  ID variable from which the record is to be extracted.  The
data frame is automatically
  sorted by this variable.  May be either a character string
or an integer.
... Names of variables (or indices) in additon to id by which
data should be sorted.
na.last Argument passed to order().  Determines if missing values
are placed at the end
  of the sorting.
Decreasing  Argument passed to order().  Determines if data frame is
sorted in descending
  order.



So, in your example

 df - data.frame(Name = c(A, A, A, B, B, C, D),
   Value = c(1, 2, 3, 4, 8, 2, 3))


 last.record(df, Name, Value)

 last.record(df, 1, 2)

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Hao Cen
Sent: Monday, November 16, 2009 2:43 PM
To: r-help@r-project.org
Subject: [R] extracting the last row of each group in a data frame

Hi,

I would like to extract the last row of each group in a data frame.

The data frame is as follows

Name Value
A 1
A 2
A 3
B 4
B 8
C 2
D 3

I would like to get a data frame as
Name Value
A 3
B 8
C 2
D 3

Thank you for your suggestions in advance

Jeff

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2009).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] row selection

2009-10-09 Thread Nutter, Benjamin
sub3 - x[-seq(1, nrow(x), by=5), ]
 
Notice the '-' in front of the seq() command.  This will select
everything but what is in the sequence.

 



From: Ashta [mailto:sewa...@gmail.com] 
Sent: Friday, October 09, 2009 12:42 PM
To: Nutter, Benjamin
Cc: r-help@r-project.org
Subject: Re: [R] row selection


Hi all,

Thank you for your help. Now I am able to select every 5th row of the
data from the main data set (x) 
using

sub1- x[seq(1, nrow(x), by=5), ]


So sub1 contains one fith of the data set  X.  I want also create
another data set that will contain the remaining  data set from X (ie.,
four fifth of the data set).

Any help is highly appreciated.








I have a matrix  named x with N by  C
I want to select every 5 th rrow from matrix x I used the following
code
 n- nrow(x)
 for(i in 1: n){
 + b - a[i+5,]
 b
 }



sc  x[seq(1, nrow(x), by=5), ]



-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org]
On Behalf Of David Winsemius
Sent: Thursday, October 08, 2009 4:19 PM
To: Ashta
Cc: R help
Subject: Re: [R] row selection


On Oct 8, 2009, at 4:14 PM, Ashta wrote:

 Hi all,
 I have a matrix  named x with N by  C
 I want to select every 5 th rrow from matrix x I used the
following
 code
 n- nrow(x)
 for(i in 1: n){
 + b - a[i+5,]
 b
 }
 Error: subscript out of bounds

What did you expect when i in your loop counter became one
greater
than the number of rows?




David Winsemius, MD
Heritage Laboratories
West Hartford, CT


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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for
use\...{{dropped:13}}

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




===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:16}}

__
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] Drawing lines in margins

2009-07-29 Thread Nutter, Benjamin
Look at the xpd option in ?par.  If you set par(xpd=TRUE) you should be
able to add a segment for what you want.  But please let me know if
someone gives you a better way to do this.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Alan Cohen
Sent: Wednesday, July 29, 2009 10:22 AM
To: r-help@r-project.org
Subject: [R] Drawing lines in margins

Hi all,

Quick question: What function can I use to draw a line in the margin of
a plot?  segments() and lines() both stop at the margin.

In case the answer depends on exactly what I'm trying to do, see below.
I'm using R v. 2.8.1 on Windows XP.

Cheers,
Alan

I'm trying to make a horizontal barplot with a column of numbers on the
right side.  I'd like to put a line between the column header and the
numbers.  The following reconstructs the idea - just copy and paste it
in:
aa - 1:10
plot.mtx2-cbind(aa,aa+1)
colnames(plot.mtx2)-c(Male,Female)
lci2- cbind(aa-1,aa)
uci2- cbind(aa+1,aa+2)
par(mar=c(5,6,4,5))
cols - c(grey79,grey41)
bplot2-barplot(t(plot.mtx2),beside=TRUE,xlab=Malaria death rates per
100,000,
names.arg=paste(state,aa,sep=),legend.text=F,las=1,xlim=c(0,13),
horiz=T, col=cols,
main=Malaria death rates by state and sex)
legend(8,6,legend=c(Female,Male),fill=cols[order(2:1)])
segments(y0=bplot2, y1=bplot2, x0=t(lci2), x1=t(uci2))
mtext(10*(aa+1),side=4,line=4,at=seq(3,3*length(aa),by=3)-0.35,padj=0.5,
adj=1,las=1,cex=0.85)
mtext(10*aa,side=4,line=4,at=seq(2,3*length(aa)-1,by=3)-0.65,padj=0.5,ad
j=1,las=1,cex=0.85)
mtext(Estimated,side=4,line=3,at=3*length(aa)+2.75,padj=0.5,adj=0.5,la
s=1,cex=0.85)
mtext(Deaths,side=4,line=3,at=3*length(aa)+1.25,padj=0.5,adj=0.5,las=1
,cex=0.85)

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] numbers on barplot

2009-07-27 Thread Nutter, Benjamin
The only thing you're missing is the midpoints of the bars.  Since you
specified

 Graph - barplot(dat$Average)

You can get the midpoints from the Graph object.  So to put the number
on top of each bar you might use something like:

 text(Graph, dat$Average, dat$Average)


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Mohsen Jafarikia
Sent: Monday, July 27, 2009 10:02 AM
To: r-h...@stat.math.ethz.ch
Subject: [R] numbers on barplot

Hello all,
I have this simple barplot code:

ifn - id.dat
dat - read.table(ifn)
ofn - id.png

bitmap(ofn, type = png256, width = 30, height = 30, pointsize = 30, bg
=
white,res=50)
par(mar=c(5, 5, 3, 2),lwd=5)
par(cex.main=1.6,cex.lab=1.6,cex.axis=1.6)

names(dat)-c(NumberOfPeople,Average)
Graph-barplot(dat$Average)
dev.off()

and here is the data (id.dat):

150.08
 60.09
 70.37

I want to write down the NumberOfPeople on top of each of the bars.
Can
anybody help me on this?

Thanks,
Mohsen

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] help with as.numeric

2009-05-15 Thread Nutter, Benjamin
as.numeric() doesn't convert factors to the explicit value, nor should
it.  Under what you're expecting, ff you have a factor where the levels
are Female and Male, using as.numeric() wouldn't produce anything
meaningful.

However, as.numeric() does something much smarter.  It converts Female
to 1, and Male to 2.  More generally, if you have n levels, it will
produce a vector of values between 1 and n.  This is referred to as the
'internal coding.'

If you want to convert your height and bmi variables to their numeric
values, you need to do

 as.numeric(as.character(height))

This will get you around the internal coding.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of deanj2k
Sent: Friday, May 15, 2009 7:58 AM
To: r-help@r-project.org
Subject: [R] help with as.numeric


hi everyone, wondering if you could help me with a novice problem.  I
have a
data frame called subjects with a height and weight variable and want to
calculate a bmi variable from the two.  i have tried:

attach(subjects)
bmi - (weight)/((height/100)^2)

but it comes up with the error:
Warning messages:
1: In Ops.factor(height, 100) : / not meaningful for factors
2: In Ops.factor((weight), ((height/100)^2)) :
  / not meaningful for factors

I presume that this means the vectors height and weight are not in
numeric
form (confirmed by is.numeric) so i changed the code to:

bmi - (as.numeric(weight))/((as.numeric(height)/100)^2)

but this just comes up with a result which doesnt make sense i.e.
numbers
such as 4 within bmi vector.  Ive looked at
as.numeric(height)/as.numeric(weight) and these numbers just arnt the
same
as height/weight which is the reason for the incorrect bmi.  Cant anyone
tell me where I am going wrong?  Its quiet frustrating because I cant
understand why a function claiming to convert to numeric would come up
with
such a bizarre result.
-- 
View this message in context:
http://www.nabble.com/help-with-as.numeric-tp23558326p23558326.html
Sent from the R help mailing list archive at Nabble.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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Help with a cumullative Hazrd Ratio plot

2009-05-13 Thread Nutter, Benjamin
?mtext

You may need to adjust the margins.  For this I recommend adjusting that
mar option in par (see ?par).



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Bernardo Rangel Tura
Sent: Wednesday, May 13, 2009 6:31 AM
To: r-help
Subject: Re: [R] Help with a cumullative Hazrd Ratio plot

On Wed, 2009-05-13 at 07:19 -0300, Bernardo Rangel Tura wrote:
 Hi R-masters
 
 I need help to make modified cumulative hazard ratio plot.
 
 I need create a common plot but with the number of subjects in risk
each
 ticks times for two different groups in bottom of plot (I put one
 example in attach).
 
 Do you know a routine for this?
 Is possible create a routine for this? 
 In this case with how commands?
 
 Thanks in advance!

Sorry I put attach in jpeg format 
In this mail a attach in PDF format
-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Selecting all rows of factors which have at least one positive value?

2009-04-02 Thread Nutter, Benjamin
x -
data.frame(matrix(c(rep(11,4),rep(12,3),rep(13,3),rep(0,3),1,rep(0,4),re
p(1,2)),ncol=2))

id.keep - unique(subset(x,X20)$X1)

x2 - subset(x,X1 %in% id.keep)

x2

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Stephan Lindner
Sent: Thursday, April 02, 2009 11:26 AM
To: r-h...@stat.math.ethz.ch
Subject: [R] Selecting all rows of factors which have at least one
positive value?

Dear all,

I'm trying to select from a dataframe all rows which correspond to a
factor (the id variable) for which there exists at least one positive
value of a certain variable. As an example:

x -
data.frame(matrix(c(rep(11,4),rep(12,3),rep(13,3),rep(0,3),1,rep(0,4),re
p(1,2)),ncol=2))

 x


   X1 X2
1  11  0
2  11  0
3  11  0
4  11  1
5  12  0
6  12  0
7  12  0
8  13  0
9  13  1
10 13  1 


and I want to select all rows pertaining to factor levels of X1 for
which exists at least one 1 for X2. To be clear, I want rows 1:4
(since there exists at least one observation for X1==11 for which
X2==1) and rows 8:10 (likewise). 

It is easy to obtain the corresponding factor levels (i.e.,
unique(x$X1[x$X2==1])), but I got stalled selecting the corresponding
rows. I tried grep, but then I have to loop and concatenate the
resulting vector. Any ideas?


Thanks a lot!


Stephan





-- 
---
Stephan Lindner
University of Michigan

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] adding matrices with common column names

2009-03-27 Thread Nutter, Benjamin
Shucks, Dimitris beat me to it.  And his code is a bit more elegant than
mine.  But since I did the work I may as well post it, right?

This version incorporates a couple of error checks to make sure all your
arguments are matrices with the same number of rows.

add.by.name - function(...){
  args - list(...)
  
  mat.test - sapply(args,is.matrix)
  if(FALSE %in% mat.test) stop(All arguments must be matrices)

  mat.row - unique(sapply(args,nrow))
  if(length(mat.row)1) stop(All matrices must have the same number of
rows)
  
  all.names - unique(as.vector(sapply(args,colnames)))
  
  sum.mat - matrix(0,nrow=mat.row,ncol=length(all.names))
  colnames(sum.mat) - all.names

  for(i in 1:length(args)){
tmp - args[[i]]
sum.mat[,colnames(tmp)] - sum.mat[,colnames(tmp)] + tmp
  }

  return(sum.mat)
}

m1 - matrix(1:20,ncol=4); colnames(m1) - c(a,b,c,d)
m2 - matrix(1:20,ncol=4); colnames(m2) - c(b,c,d,e)
m3 - matrix(1:20,ncol=4); colnames(m3) - c(a,b,d,e)

add.by.name(m1,m2,m3)



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of murali.me...@fortisinvestments.com
Sent: Friday, March 27, 2009 9:25 AM
To: r-help@r-project.org
Subject: [R] adding matrices with common column names

folks,
 
if i have three matrices, a, b, cc with some colnames in common, and i
want to create a matrix which consists of the common columns added up,
and the other columns tacked on, what's a good way to do it? i've got
the following roundabout code for two matrices, but if the number of
matrices increases, then i'm a bit stymied.
 
 a - matrix(1:20,ncol=4); colnames(a) - c(a,b,c,d) b - 
 matrix(1:20,ncol=4); colnames(b) - c(b,c,d, e)
 cbind(a[,!(colnames(a) %in% colnames(b)), drop = FALSE],
a[,intersect(colnames(a),colnames(b))] +
b[,intersect(colnames(a),colnames(b)), drop = FALSE],
b[,!(colnames(b) %in% colnames(a)), drop = FALSE])
 
 a  b  c  d  e
[1,] 1  7 17 27 16
[2,] 2  9 19 29 17
[3,] 3 11 21 31 18
[4,] 4 13 23 33 19
[5,] 5 15 25 35 20
 
now, what if i had a matrix cc? i want to perform the above operation on
all three matrices a, b, cc.
 
 cc - matrix(1:10,ncol=2); colnames(cc) - c(e,f)

i need to end up with:

 a  b  c  d  e  f
[1,] 1  7 17 27 17  6
[2,] 2  9 19 29 19  7
[3,] 3 11 21 31 21  8
[4,] 4 13 23 33 23  9
[5,] 5 15 25 35 25 10

and, in general, with multiple matrices with intersecting colnames?

thanks,

murali

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Plot inside For loop

2009-03-25 Thread Nutter, Benjamin
I understood this to mean you want to open a new plotting window on each
iteration of the loop.  If this is correct, I usually go about it by
using x11()

If you're looking to add additional lines or points, then you may want
to look at the aptly named functions lines() and points().

If neither of these are your goal, then I'm afraid I'll need more
clarification on what you're trying to do.

Benjamin

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Mohan Singh
Sent: Wednesday, March 25, 2009 1:54 PM
To: r-help@r-project.org
Subject: [R] Plot inside For loop

Hi

   I am plotting a set of data inside a for loop.

   Is it possible to use plot in for loop without redrawing the whole  
plot? Am using par(new=TRUE) but that draws on top of the previous plot.

   Couldn't find any threads about the topic.

Thanks
Mohan
--

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Plot inside For loop

2009-03-25 Thread Nutter, Benjamin
This might not be particularly elegant, but if you put your initial
plot() outside of the loop and then use the loop to place your points,
you might get what you want.  If others have better solutions, I'd be
interested as well.  Note that if you take this approach, you might want
to specify xaxt=n and yaxt=n and draw your own axes.

 

plot(NA,NA,xlim=c(-30,100), ylim=c(-30,90), ...);

for(i in 1:query) {

  points(..);

 

  #count increments

}

axis(...)

 

 



From: Mohan Singh [mailto:mohan.si...@ucd.ie] 
Sent: Wednesday, March 25, 2009 3:00 PM
To: Nutter, Benjamin
Cc: r-help@r-project.org
Subject: Re: [R] Plot inside For loop



basically the for loop goes something like this



setCounters(135);



for(i in 1:query) {

 plot(c2data[start1:count,],c3data[start1:count,],xlim=c(-30,100),
ylim=c(-30,90), sub=i);

 points(..);



  #count increments

}



so if i use windows() or x11(), i get different plot windows



if I use par(), i get one plot, but it redraws on top of previous plots,
so if my query goes from 1 to 5, it plots 5 plots on top of each other,
which in some ways, is ok, but doesn't go well for putting it in a
publication.



i want to draw a single plot with additional data from each for loop..
as the loop proceeds, it adds another set of data onto the previous plot
, i suppose, it doesn't redraw the axis and labels and just plot the
data



Mohan





On 25 Mar 2009, at 18:43, Nutter, Benjamin wrote:





I understood this to mean you want to open a new plotting window on each
iteration of the loop.  If this is correct, I usually go about it by
using x11()

If you're looking to add additional lines or points, then you may want
to look at the aptly named functions lines() and points().

If neither of these are your goal, then I'm afraid I'll need more
clarification on what you're trying to do.

Benjamin

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Mohan Singh
Sent: Wednesday, March 25, 2009 1:54 PM
To: r-help@r-project.org
Subject: [R] Plot inside For loop

Hi

  I am plotting a set of data inside a for loop.

  Is it possible to use plot in for loop without redrawing the whole  
plot? Am using par(new=TRUE) but that draws on top of the previous plot.

  Couldn't find any threads about the topic.

Thanks
Mohan
--

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.



--

CASL, MLG

UCD, Dublin 

+353-85-7279622












===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.

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


Re: [R] help with loop

2009-03-12 Thread Nutter, Benjamin
Why use a loop? Try using diff()

x - c(4, 19, 21, 45, 50, 73, 78, 83, 87, 94)
sum(diff(x))

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Rafael Moral
Sent: Thursday, March 12, 2009 9:04 AM
To: r-help@r-project.org
Subject: [R] help with loop

Dear useRs,
I'm trying to write a loop to sum my data in the following way:
(the second - the first) + (the third - the second) + (the fourth - the third) 
+ ...
for each column.

So, I wrote something like this:

  c - list()
  for(i in 1:ncol(mydata)) {
  for(j in 2:nrow(mydata)) {
  c[[i]] - sum(yc[j,i] - yc[(j-1),i])
  }}}

As for the columns it works pretty fine, but it only returns the last 
subtraction, however, I need the sum of all subtractions.

Any ideas?

Regards,
Rafael.


  Veja quais são os assuntos do momento no Yahoo! +Buscados

[[alternative HTML version deleted]]


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] The Origins of R

2009-02-04 Thread Nutter, Benjamin
snip

Those of us on this list (with the possible exception of one or two  
nutters)
would take it that it goes without saying that R was developed on the  
basis
of S --- we all ***know*** that.  

snip


Just want to clarify that the nutters referred to here are not the same
as the Nutters that bear my name :-)

===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] parsing problem

2009-02-02 Thread Nutter, Benjamin


-Original Message-
From: Nutter, Benjamin 
Sent: Monday, February 02, 2009 7:37 AM
To: 'venkata kirankumar'
Subject: RE: [R] parsing problem

This is how I would approach it.  I'd be happy to know if there's a
better way.

#*** Initial Data Frame
x -
c(Kontrolle,Placebo,125mg/kg,250mg/kg,500mg/kg,1000mg/kg))
x

#*** Convert alphabetical and punctuation characters to  (see ?regex)
y - gsub([[:alpha:],[:punct:]],,x)
y

#*** Convert character strings to numeric
z - as.numeric(y)
z

#*** Calculate minimum
min(df$z,na.rm=TRUE)




-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of venkata kirankumar
Sent: Monday, February 02, 2009 7:18 AM
To: r-help@r-project.org
Subject: [R] parsing problem

Hi all,
I am trying to parse a vector for caliculating minimum in that vector
the
vector having values like

1Kontrolle
2  Placebo
3 125mg/kg
4 250mg/kg
5 500mg/kg
61000mg/kg
hear i tries for comverting it into numeric with using  as.numaric()
 function
but i got values like
5
6
2
3
4
1

it gives 1000mg/kg is the least one
but i have toget 125mg/kg as the minimum value
for that i have to remove all the strings and spetial charecters from
that
for that i used  parse()  but i am not able to get the out put

can anyone suggest how I will solve it


thanks in advance



regards;
kiran

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Text data

2009-01-28 Thread Nutter, Benjamin
Jim's solution is more elegant than the following (and probably more
efficient) but you could also try the following (This let's you sort by
AN/HN, and then by the number at the start of the filename):

 text - c( 26M_AN_C.bmp, 22M_AN_C.bmp, 20M_HA_O.bmp,
 20M_AN_C.bmp, 26M_HA_O.bmp, 22M_HA_O.bmp,
 31M_AN_C.bmp, 38M_HA_O.bmp)

 split - do.call(rbind,strsplit(text,_))

 o - order(split[,2],split[,1],split[,3])

 text[o]

[1] 20M_AN_C.bmp 22M_AN_C.bmp 26M_AN_C.bmp 31M_AN_C.bmp
20M_HA_O.bmp
[6] 22M_HA_O.bmp 26M_HA_O.bmp 38M_HA_O.bmp

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Alice Lin
Sent: Wednesday, January 28, 2009 3:38 PM
To: r-help@r-project.org
Subject: [R] Text data


i have a data column of text entries:
26M_AN_C.bmp
22M_AN_C.bmp
20M_HA_O.bmp
20M_AN_C.bmp
26M_HA_O.bmp
22M_HA_O.bmp
31M_AN_C.bmp
38M_HA_O.bmp
.
.
.
.


And I would like to sort by the middle tag: AN, HA, etc.
Is there a way to parse text data in R? 

In excel, I would have used the left and right function to cut out
just
the middle two letters out and put into another column to sort by. 

Thanks!

-- 
View this message in context:
http://www.nabble.com/Text-data-tp21714334p21714334.html
Sent from the R help mailing list archive at Nabble.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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] help

2009-01-14 Thread Nutter, Benjamin
?floor 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of zahid khan
Sent: Wednesday, January 14, 2009 8:34 AM
To: r-h...@stat.math.ethz.ch
Subject: [R] help

Dear ALL
suppose x=7.5,and i need of only integer part of variable x that is
7 only then what command i can use in R.
THANKS

Zahid Khan
Lecturer in Statistics
Department of Mathematics
Hazara University Mansehra.


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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Colors in barplot

2008-12-04 Thread Nutter, Benjamin
I believe the defaults in barplot are found using
grey.colors{GrDevices}.

?grey.colors

(For some reason my machine won't pull up the help files for grey.colors
from the command line, but I can still access it through the html help).

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Antje
Sent: Thursday, December 04, 2008 6:32 AM
To: [EMAIL PROTECTED]
Subject: [R] Colors in barplot

Hello,

Can anybody help me to find out which colors are used automatically when

calling barplot (e.g. 3 series beside each other will get different gray
values).
I want to apply a legend but I don't know the colors used...

Antje

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Changing the position of the origin

2008-11-18 Thread Nutter, Benjamin
If I understand what you're seeking to do, you might also consider the
rplot() function written by Rolf Turner.  It can be found at

http://tolstoy.newcastle.edu.au/R/help/02a/1174.html


Benjamin


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Plantky
Sent: Monday, November 17, 2008 11:46 PM
To: r-help@r-project.org
Subject: [R] Changing the position of the origin

Hi all,

Can anyone tell me how I can make 0,0 start at the top left hand
corner of a graph, instead of the typical lower left hand corner? I've
tried to plot with axes=F and then putting on the axes later, but I
want the points to correspond to the axes.

Thanks,
Kang Min

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



P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Is there a way to vectorize this? [with correction]

2008-10-31 Thread Nutter, Benjamin
** Sorry to repost.  I forgot to include a function necessary to make
the example work **

I apologize up front for this being a little long. I hope it's
understandable.  Please let me know if I need to clarify anything.

Several months ago I wrote a series of functions to help me take my R
analyses and build custom reports in html files.  Each function either
builds or modifies a string of html code that can then be written to a
file to produce the desired output.

To make modifications in the html code, I've placed 'markers' around
certain characteristics that I might want to change.  For instance, the
alignment characteristics have an 'algnmark' on either side of them.
When I wish to change the alignment, I can find where these markers are,
determine their location, and replace the contents between them. 

I've been using the functions for a few months now, and am pleased with
the utility.  Unfortunately, as I was writing these, I wasn't very
strong with my vectorization skills and relied on for loops (lots of for
loops) to get through the work.  So while I'm pleased with the utility,
I've been trying to optimize the functions by vectorizing the for loops.

At this point, I've hit a small snag.  I have a situation where I can't
seem to figure out how to vectorize the loop.  Part of me wonders if it
is even possible. 

The scenario is this:  I run a string of code through the loop, on each
pass, the section of code in need of modification is identified and the
changes are made.  When this is done, however, the length of the string
changes.  The change in length needs to be recognized in the next pass
through the loop.

Okay, some code to illustrate what I mean.  This first function formats
the html file.  I only include it because it will be necessary to create
illustrate what the function is doing.  I am eliminating all comments
and spacing from the code for brevity.

#*** Start of html.file.start
'html.file.start' - function(title, size=11, font=Times New Roman){
  size - format(floor(size),nsmall=1)
  code - paste(
html xmlns:o='urn:schemas-microsoft-com:office:office\'
  xmlns:w=\'urn:schemas-microsoft-com:office:word\'
  xmlns=\'http://www.w3.org/TR/REC-html40\'
  head
meta http-equiv=Content-Type content=\'text/html;
charset=windows-1252\'
meta name=ProgId content=Word.Document
meta name=Generator content=\'Microsoft Word 11\'
meta name=Originator content=\'Microsoft Word 11\'
   style
  !--
/* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
 p.MsoEndnoteText, li.MsoEndnoteText, div.MsoEndnoteText
  {margin-top:2.0pt;
  margin-right:0in;
  margin-bottom:0in;
  margin-left:.15in;
  margin-bottom:.0001pt;
  text-indent:-.15in;
  mso-pagination:none;
  font-size:9.0pt;
  mso-bidi-font-size:10.0pt;
  font-family:'Times New Roman';
  mso-fareast-font-family:'Times New Roman';}
   p.Textbody, li.Textbody, div.Textbody--
   /style
,
title,title,/title
  /head
  body lang=EN-US style=\'tab-interval:.5in;,
   textmark; font-size:,size,pt; textmark;,
   fontmark; font-family:,font,; fontmark;\', sep=)
  return(code)
} # End of html.file.start


# Start of html.text
'html.text' - function(text, size=11, font=Times New Roman,
align=left, title){
  size - format(floor(size),nsmall=1)
  if(missing(title)) title -  else title - paste(br/,title)
  title - paste(b,title,/bbr/\n,sep=)
  code - paste(
p class=MsoNormal ,
 algnmark align=,align, algnmark
  span class=GramE style=\',
 textmark; font-size:,size,pt; textmark;,
 fontmark; font-family:,font,; fontmark;,
 stylemark; font-weight:normal; font-style:normal;,
 text-decoration:none; stylemark;\',
  title,text,  
  /span
/p,sep=)
  return(code)
} #** End of html.text


So here is the function I'm trying to vectorize.

#*** Start of html.align
html.align - function(code,new.align=left){
  #* Create a string to replace the current alignment setting.
  align - paste( align=,new.align, ,sep=)

  #* Function to pass to sapply.  This is handy when 'code'
  #*  is a vector.
  f1 - function(code,align=align){
mark - unlist(gregexpr(algnmark,code)) #* Get positions of
markers
if(mark[1]0){
  odd - seq(1,length(mark),by=2) #* odd elements are starting
marker
  evn - seq(2,length(mark),by=2) #* even elements are ending marker

  mark[odd] - mark[odd]+9  #* These two lines determine the
starting
  mark[evn] - mark[evn]-1  #* and ending elements of the substring
to
#* be replaced

  for(i in 1:length(odd)){

l.old - nchar(code)  #* store the length of the code segment.

old.align - substr(code,mark[odd[i]],mark[evn[i]]) 

Re: [R] Standard deviation for rows

2008-10-15 Thread Nutter, Benjamin
?apply

e.g. apply(matrix,1,sd)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Alex99
Sent: Wednesday, October 15, 2008 1:17 PM
To: r-help@r-project.org
Subject: [R] Standard deviation for rows


Hi everyone,

I have just started using R, and I have a simple question.
How can I get the Standard deviation for rows. basically I am looking
for
something like  rowMeans()  
but for Standard deviation (I tried rowSds() didn't exist)

Thanks,
-- 
View this message in context:
http://www.nabble.com/Standard-deviation-for-rows-tp19998106p19998106.ht
ml
Sent from the R help mailing list archive at Nabble.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.



P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

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

2008-10-07 Thread Nutter, Benjamin
Perhaps it would be easier to try something like this:

 df1 - read.table(filename, ... )  # All columns read as characters
 df1 - t(df1)  # Transpose df1
 write.table - (df1, newfile, ...) # Write the transposed data 
 # to a new file
 df2 - read.table(newfile, header=TRUE, ...)  # Read in transposed
data

I doubt it's the most computation-time-efficient, but conceptually it's
pretty quick.

Benjamin

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Tuesday, October 07, 2008 8:28 AM
To: [EMAIL PROTECTED]; r-help@r-project.org
Subject: [R] FW: Reading Data

 
 

Rahul Agarwal 
Analyst 
Equities Quantitative Research 
UBS_ISC, Hyderabad 
On Net: 19 533 6363 



 

 hi let me explain you the problem
we have a database which is in this format


Stocks   30-Jan-08   28-Feb-08   31-Mar-08   30-Apr-08  
a1.003.007.003.00   
b2.004.004.007.00   
c3.008.00655.00  3.00   
d4.0023.00   4.005.00   
e5.0078.00   6.005.00   

 and we have a query which is in this format
 
Identifier   weight  Start_Date  End_Date   
a6.7631-Jan-06   31-Jan-07  
e2.8628-Feb-06   28-Feb-07  
f22.94   31-Mar-06   30-Mar-07  
y30.05   28-Apr-06   30-Apr-07  
h20.55   31-May-06   31-May-07  
d6.76   
f2.86   
r22.94  
  okay now my task is to calculate returns for all the indentifiers for
a respective start and end date from table 1.
 
now length of start date and end date column is same and that of weight
and identifier is same.
i hope everything is clear now.
 
let me also send you the code that i have written but in my code i have
problem with the date format and also with the stocks name
 
data=read.table(H:/Rahul/london/david/rexcel/price.txt)
query=read.table(H:/Rahul/london/david/rexcel/prac.txt,header=TRUE)
 
data=as.matrix(data)
instrument=data[,1]
date=data[1,]
 
query=as.matrix(query)
q_ins=query[,1]
wt=query[,2]
q_sd=query[,3]
q_ed=query[,4]
 
returns=function(I,SD,ED){
  p=rep(0,2)
  for(i in 2:length(instrument))
  {
if(instrument[i]==I)
{
  for(j in 2:length(date))
  {
if(date[j]==SD)
p[1]=data[i,j]
  }
  for(j in 2:length(date))
  {
if(date[j]==ED)
p[2]=data[i,j]
  }
}
returns=(p[2]/p[1])-1
  }
#print(p)
#print(I)
return(returns)
}
 
##The original Funda##
 
matrix_ret=matrix(0,length(q_ins),length(q_sd))
 
for(i in 1:length(q_sd))
{
 for(j in 1:length(q_ins))
 {
  matrix_ret[j,i]=returns(q_ins[j],q_sd[i],q_ed[i])
 }
}
 
#Removing NA from the matrix
 
matrix_ret1=sapply(X=matrix_ret, FUN=function(x)
ifelse(is.na(x),0.00,x))
matrix_ret=matrix(matrix_ret1,length(q_ins),length(q_sd))
 

wt_ret=matrix(0,length(q_sd),1)
for(i in 1:length(q_sd))
{
 for(j in 1:length(q_ins))
 {
  wt_ret[i]=wt_ret[i]+(wt[j]*matrix_ret[j,i])
 }
}
 
result=cbind(q_ed,wt_ret)

  
Rahul Agarwal
Analyst
Equities Quantitative Research
UBS_ISC, Hyderabad
On Net: 19 533 6363




-Original Message-
From: Gustaf Rydevik [mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] ]
Sent: Tuesday, October 07, 2008 2:19 PM
To: Agarwal, Rahul-A
Cc: [EMAIL PROTECTED]; r-help@r-project.org
Subject: Re: [R] Reading Data

On Tue, Oct 7, 2008 at 10:36 AM,  [EMAIL PROTECTED] wrote:

 Hi,
 I have a data in which the first row is in date format and the first
 column is in text format and rest all the entries are numeric.
 Whenever I am trying to read the data using read.table, the whole of
 my data is converted in to the text format.

 Please suggest what shall I do because using the numeric data which
 are prices I need to calculate the return but if these prices are not
 numeric then calculating return will be a problem

 regards

 Rahul Agarwal
 Analyst
 Equities Quantitative Research
 UBS_ISC, Hyderabad
 On Net: 19 533 6363


Hi,

A single column in a data frame can't contain mixed formats.
In the absence of example data,  would guess one of the following could
work :

1)
read.table(data.txt,skip=1, header=T) ## If you have headers

2)
read.table(data.txt, header=T) ## If the date row is supposed to be
variable names.

3)
 read.table(data.txt,skip=1) ## If there are no headers, and you want
to ignore the date


regards,

Gustaf

--
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do 

Re: [R] lsmeans

2008-09-26 Thread Nutter, Benjamin
I hope you'll forgive me for resurrecting this thread.  My question
refers to John Fox's comments in the discussion of lsmeans from 
https://stat.ethz.ch/pipermail/r-help/2008-June/164106.html

John you said, It wouldn't be hard, however, to do the computations
yourself, using the coefficient vector for the fixed effects and a
suitably constructed model-matrix to compute the effects; you could also
get standard errors by using the covariance matrix for the fixed
effects.

I've been able to make use of all of that except for the 'suitably
constructed model-matrix' part.  I've looked through some other threads
on this topic, but am still a little in the dark as to what I'd need to
do to construct a suitable matrix.

I would like to use the least squares means to develop parameter
estimates for a parametric ROC analysis, as described by Mithat Gonen's
book (Analyzing Receiver Operating Characteristic Curves with SAS,
2007).  

Any suggestions on references that would explain how to go about
constructing the suitable model matrix?  

Many Thanks
Benjamin


P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Coefficients, OR and 95% CL

2008-09-23 Thread Nutter, Benjamin
You might also consider

?confint

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Jorge Ivan Velez
Sent: Monday, September 22, 2008 5:36 PM
To: Luciano La Sala
Cc: R mailing list
Subject: Re: [R] Coefficients, OR and 95% CL

Dear Luciano,
See ?logistic.display in the epicalc package. If glm1 is your model,
something like

logistic.display(glm1)

should do the job.


HTH,


Jorge


On Mon, Sep 22, 2008 at 5:28 PM, Luciano La Sala
[EMAIL PROTECTED]wrote:

 Dear R-users,

 After running a logistic regression, I need to calculate OR by
 exponentiating the coefficient, and then I need the 95% CL for the OR
as
 well. For the following example (taken from P. Dalaagard's book), what
would
 be the most straightforward method of getting what I need? Could
anyone
 enlight me please?

 Thank you!
 Lucho

  summary(glm(menarche~age,binomial))

 Call:
 glm(formula = menarche ~ age, family = binomial)

 Deviance Residuals:
 Min1QMedian3Q   Max
 -4.68654  -0.13049  -0.01067   0.09608   2.35254

 Coefficients:
Estimate Std. Error z value Pr(|z|)
 (Intercept) -17.9175 1.7074  -10.49   2e-16 ***
 age   1.3549 0.1296   10.45   2e-16 ***
 ---
 Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

 (Dispersion parameter for binomial family taken to be 1)

Null deviance: 974.31  on 703  degrees of freedom
 Residual deviance: 223.95  on 702  degrees of freedom
  (635 observations deleted due to missingness)
 AIC: 227.95

 Number of Fisher Scoring iterations: 9






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


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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] HI

2008-09-16 Thread Nutter, Benjamin
Perhaps a simpler way might be to use the na argument in read.table. for
instance:

 read.table( filename, na=0, ...)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Amit Patel
Sent: Tuesday, September 16, 2008 9:32 AM
To: r-help@r-project.org
Subject: [R] HI

Does anyone know an easy way to convert all the zero values in a
imported csv table into NA's



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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Color of box frame in Legend (Was: Matrix barplot)

2008-07-28 Thread Nutter, Benjamin
Try sourcing in the 'new.legend' function below. It's the legend
function with a new argument called 'box.col'.  The argument will change
the color of the box surrounding the legend.  If I understand what it is
you are looking for, this should work.  Also, I didn't see a way to
change the axis bar in your code, so I suppressed the axis in the call
to barplot, and manually replaced the axis using the axis function.  I
hope this works for you.

Benjamin

data - data.frame(Year=c(2000,2001,2002),
  A=c(2,2,1),
  B=c(3,1,2),
  C=c(0,3,5))

data.mat - as.matrix(data)[,2:4]
rownames(data.mat) - data[['Year']]
data.mat - t(data.mat)

textcolor=yellow
par(col.axis=textcolor,col.main=textcolor)

barplot(data.mat,beside=TRUE,col=rainbow(3),main=Test,yaxt=n)
axis(2,at=0:5,col=textcolor)
new.legend(x=topleft, colnames(data[,2:4]),fill=rainbow(3),
inset=0.05,
text.col=textcolor,box.col=textcolor
   )



###

###
new.legend - function (x, y = NULL, legend, fill = NULL, col =
par(col), 
lty, lwd, pch, angle = 45, density = NULL, bty = o, bg =
par(bg), 
box.lwd = par(lwd), box.lty = par(lty), box.col=black,
pt.bg = NA, cex = 1, 
pt.cex = cex, pt.lwd = lwd, xjust = 0, yjust = 1, x.intersp = 1, 
y.intersp = 1, adj = c(0, 0.5), text.width = NULL, text.col =
par(col), 
merge = do.lines  has.pch, trace = FALSE, plot = TRUE, 
ncol = 1, horiz = FALSE, title = NULL, inset = 0) 
{
if (missing(legend)  !missing(y)  (is.character(y) || 
is.expression(y))) {
legend - y
y - NULL
}
mfill - !missing(fill) || !missing(density)
title - as.graphicsAnnot(title)
if (length(title)  1) 
stop(invalid title)
legend - as.graphicsAnnot(legend)
n.leg - if (is.call(legend)) 
1
else length(legend)
if (n.leg == 0) 
stop('legend' is of length 0)
auto - if (is.character(x)) 
match.arg(x, c(bottomright, bottom, bottomleft, 
left, topleft, top, topright, right, center))
else NA
if (is.na(auto)) {
xy - xy.coords(x, y)
x - xy$x
y - xy$y
nx - length(x)
if (nx  1 || nx  2) 
stop(invalid coordinate lengths)
}
else nx - 0
xlog - par(xlog)
ylog - par(ylog)
rect2 - function(left, top, dx, dy, density = NULL, angle, 
...) {
r - left + dx
if (xlog) {
left - 10^left
r - 10^r
}
b - top - dy
if (ylog) {
top - 10^top
b - 10^b
}
rect(left, top, r, b, angle = angle, density = density, 
...)
}
segments2 - function(x1, y1, dx, dy, ...) {
x2 - x1 + dx
if (xlog) {
x1 - 10^x1
x2 - 10^x2
}
y2 - y1 + dy
if (ylog) {
y1 - 10^y1
y2 - 10^y2
}
segments(x1, y1, x2, y2, ...)
}
points2 - function(x, y, ...) {
if (xlog) 
x - 10^x
if (ylog) 
y - 10^y
points(x, y, ...)
}
text2 - function(x, y, ...) {
if (xlog) 
x - 10^x
if (ylog) 
y - 10^y
text(x, y, ...)
}
if (trace) 
catn - function(...) do.call(cat, c(lapply(list(...), 
formatC), list(\n)))
cin - par(cin)
Cex - cex * par(cex)
if (is.null(text.width)) 
text.width - max(abs(strwidth(legend, units = user, 
cex = cex)))
else if (!is.numeric(text.width) || text.width  0) 
stop('text.width' must be numeric, = 0)
xc - Cex * xinch(cin[1], warn.log = FALSE)
yc - Cex * yinch(cin[2], warn.log = FALSE)
if (xc  0) 
text.width - -text.width
xchar - xc
xextra - 0
yextra - yc * (y.intersp - 1)
ymax - yc * max(1, strheight(legend, units = user, cex = cex)/yc)
ychar - yextra + ymax
if (trace) 
catn(  xchar=, xchar, ; (yextra,ychar)=, c(yextra, 
ychar))
if (mfill) {
xbox - xc * 0.8
ybox - yc * 0.5
dx.fill - xbox
}
do.lines - (!missing(lty)  (is.character(lty) || any(lty  
0))) || !missing(lwd)
n.legpercol - if (horiz) {
if (ncol != 1) 
warning(horizontal specification overrides: Number of
columns := , 
n.leg)
ncol - n.leg
1
}
else ceiling(n.leg/ncol)
if (has.pch - !missing(pch)  length(pch)  0) {
if (is.character(pch)  !is.na(pch[1])  nchar(pch[1], 
type = c)  1) {
if (length(pch)  1) 
warning(not using pch[2..] since pch[1] has multiple
chars)
np - nchar(pch[1], type = c)
pch - substr(rep.int(pch[1], np), 1:np, 1:np)
}
if (!merge) 
dx.pch - 

Re: [R] Simple... but...

2008-07-23 Thread Nutter, Benjamin
 x - c(1,3,5)
 y - c(2,4,6)
 xy - sort(c(x,y))

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Shubha Vishwanath Karanth
Sent: Wednesday, July 23, 2008 8:55 AM
To: [EMAIL PROTECTED]
Subject: [R] Simple... but...

Hi R,

 

If 

x=c(1,3,5)

y=c(2,4,6)

 

I need a vector which is c(1,2,3,4,5,6) from x and y.

 

How do I do it? I mean the best way

 

Thanks, Shubha

 

This e-mail may contain confidential and/or privileged
i...{{dropped:13}}

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



P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2007).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] Bland-Altman method to measure agreement with repeated measures

2008-07-07 Thread Nutter, Benjamin
The function given below is one I've written to handle repeated
measures.  I've also included the Help File.  If you happen to see any
potential improvements, I would be open to suggestions.  

###
### Function Code
###

'Bland.Altman' - function(x,y,alpha=.05,rep.meas=FALSE,subject,...){
#**
#* Construct a Bland Altman Plot
#* 1. Set a few constants
#* 2. Calculate mean difference
#* 3. Calculate difference standard deviation
#* 4. Calculate upper and lower confidence limits
#* 5. Make Plot
#**

#*** 1. Set a few constants
  z - qnorm(1-alpha/2)  ## value of z corresponding to alpha
  d - x-y   ## pair-wise differences
  m - (x+y)/2   ## pair-wise means

#*** 2. Calculate mean difference
  d.mn - mean(d,na.rm=TRUE)

#*** 3. Calculate difference standard deviation
  if(rep.meas==FALSE){ d.sd=sqrt(var(d,na.rm=TRUE)) }
  else{

#*** 3a. Ensure subject is a factor variable
if(!is.factor(subject)) subject - as.factor(subject)

#*** 3b. Extract model information
n - length(levels(subject))  # Number of subjects
model - aov(d~subject)   # One way analysis of variance
MSB - anova(model)[[3]][1]   # Degrees of Freedom
MSW - anova(model)[[3]][2]   # Sums of Squares

#*** 3c. Calculate number of complete pairs for each subject
pairs - NULL
for(i in 1:length(levels(as.factor(subject{
  pairs[i] - sum(is.na(d[subject==levels(subject)[i]])==FALSE)
}
Sig.dl - (MSB-MSW)/((sum(pairs)^2-sum(pairs^2))/((n-1)*sum(pairs)))
d.sd - sqrt(Sig.dl+MSW)
  }

#*** 4. Calculate lower and upper confidence limits
  ucl - d.mn+z*d.sd
  lcl - d.mn-z*d.sd

#*** 5. Make Plot
  plot(m, d,abline(h=c(d.mn,ucl,lcl)),  ...)
  values - round(cbind(lcl,d.mn,ucl),4)
  colnames(values) - c(LCL,Mean,UCL)
  if(rep.meas==FALSE) Output - list(limits=values,Var=d.sd^2)
else Output - list(limits=values,Var=Sig.dl)
  return(Output)
}


###
### Help File
###

Bland Altman Plots

Description:

 Constructs a Bland-Altman Plot.

Usage:

  Bland.Altman(x,y,alpha=.05,rep.meas=FALSE,subject,...) 

Arguments:

 x,y: vectors of values to be compared.

   alpha: Significance level for determining confidence limits.
  Defaults to 0.05

rep.meas: Toggles if data provided should be considered as repeated
  measures.  Defaults to 'FALSE'

 subject: Required if 'rep.meas=TRUE'.  A vector of the same length of
  'x' and 'y' that  denotes which subject/group the measurement
  belongs to.

 ...: Other arguments to be passed to the 'plot' method.

Details:

 When 'rep.meas=TRUE', the confidence limits are calculated using a
 method proposed by Bland and Altman. These limits are slightly
 wider, allowing for the correlation within subjects/factors.  The
 standard deviation used to compute these limits is:


sigma^2[d] = sigma^2[dI] + sigma^2[dw]


 where  sigma^2[d]  is the variance of the differences, sigma^2[dI]
  is the variance of the subjects and methods interaction, and 
 sigma^2[dw]  is the within subject variation. Estimates of these
 values can be found with


s^2[dw] = MSw



 s^2[dI] = (MSb - MSw) / ((sum(m[i])^2 - sum(m[i]^2)) /
((n-1)*sum(m[i]))

 )

 Where MSb and MSw are the between and within subject variance of
 the one way analysis of  variance and m[i] is the number of pairs
 for the ith subject.  The sum of these two estimates provides the
 estimate for  s^2[d]  .

Value:

  limits: A vector containing the Mean Bias and confidence limits.

  Var.dl: The Variance of the Bias.  If 'rep.meas=TRUE', this is 

   s^2[dI]

  .

Author(s):

 Benjamin Nutter [EMAIL PROTECTED]

   Created:  December 2007

References:

 J Martin Bland and Douglass G Altman, Measuring Agreement in
 Method Comparison Studies, _Statistical Methods in Medical
 Research_, 1999; 8: 135 - 160.

 J Martin Bland and Doublas G. Altman, Agreement Between Methods
 of Measurement with Multiple Observations per Individual _Journal
 of Biopharmaceutical Statistics_ 17:571-582, 2007. (Corrects the
 formula  given in the 1999 paper).

 Burdick RK, Graybill FA. _Confidence Intervals on Variance
 Components_. New York: Dekker, 1992.

Examples:

 observer1=rnorm(500,5,2)
 observer2=rnorm(500,10,4)
 ID=rep(1:50,10)

 Bland.Altman(observer1,observer2)

 Bland.Altman(observer1,observer2,rep.meas=TRUE,subject=ID)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of kende jan
Sent: Saturday, July 05, 2008 4:18 AM
To: R-help@r-project.org
Subject: [Possible SPAM] [R] Bland-Altman method to measure agreement
with repeated measures


Dear all, 
 
I want to 

Re: [R] [Possible SPAM] Reading selected lines in an .html file

2008-06-05 Thread Nutter, Benjamin
I've tried to tackle a similar question at the request of a coworker.
Unfortunately, it is difficult to read in HTML code because it lacks
character that can consistently be used as a delimiter.  The only
guideline I can offer is that any text you're interested in is going to
be between a  and a .  So the goal is to eliminate anything
between  and .

What's more, if you really want to read in HTML code, you'll need a good
grasp on HTML itself, and some familiarity with how the code you're
reading in is structured.  For instance, I'm attaching code that I wrote
to read in HTML tables that were generated by other functions commonly
used in my work place.  But my code assumes that the tables are written
by row (using the tr tag.

Essentially, after studying the code I was going to read in, I hand
picked the markers that I could use to isolate the text I wanted.  I
then proceeded to play a game of Simon Says to break down the code to
smaller and smaller pieces until I got what I wanted.  

Unless you're going to be doing this a lot, I wouldn't recommend taking
the time to try and write a function like this.  In most cases it's
probably faster just to copy the data by hand.  But if you are
determined to make it work, I hope the ideas help.

Benjamin

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of vittorio
Sent: Wednesday, June 04, 2008 3:50 PM
To: [EMAIL PROTECTED]
Subject: [Possible SPAM] [R] Reading selected lines in an .html file

Dear friend, 

In an R program running permanently on a server I would like to read
hour by 
hour the temperature in *C and the humidity from a  site like this
(actually, 
from many of such sites):

http://www.wunderground.com/global/stations/16239.html

How can I read the content of the site and select the info I need?

Ciao
Vittorio

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


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2007).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.
__
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] How do I import packages with the package I've built?

2007-11-19 Thread Nutter, Benjamin
So if I understand you correctly, if I include in my namespace file the
commandimportFrom(MASS, stepAIC),   whenever stepAIC is called from
my package, it will still run even if I haven't explicitly imported the
MASS package?

Or if I use the command  import(survival)   then the functions in
the survival package will work within my functions even without
explicitly loading the package?

Thanks for the help.

Benjamin

-Original Message-
From: Uwe Ligges [mailto:[EMAIL PROTECTED] 
Sent: Saturday, November 17, 2007 12:04 PM
To: Nutter, Benjamin
Cc: [EMAIL PROTECTED]
Subject: Re: [R] How do I import packages with the package I've built?

There is a difference between importing a namespace and loading a
package:

If you import functions from a namespace into your package, these 
functions are known within that namespace, i.e. functions from your 
package's namespace know the other functions and can use them. The user 
still won't see those imported functions while working on the top level.
If you want the latter, you have to load the other package explicitly, 
e.g. in your .onLoad directives.

Uwe Ligges


Nutter, Benjamin wrote:
 I have successfully completed building a package to contain the
 functions I commonly use.  However, I need to have other packages
 installed in order for some of my functions to work.  I've been
studying
 the instructions on installing packages for about a month now, but
still
 haven't figured this one out.  From what I do understand, to import
 additional packages I need some combination of commands in my
 DESCRIPTION and NAMESPACE files.  Currently, these are what mine look
 like:
 
 DESCRIPTION
 Package: myPackage
 Type: Package
 Title: Commonly used functions.
 Version: 1.0
 Date: 2007-11-08
 Author: My Name
 Maintainer: My Name [EMAIL PROTECTED]
 Description: Blah Blah Blah
 License: R 2.3.0
 Depends: MASS, survival
 
 
 NAMESPACE
 export(func1, func2, ... , funcx)
 
 import(MASS, survival)
 
 
 These pass all the checks, and the package installs just fine, but it
 doesn't load MASS and survival when I load myPackage.  What am I doing
 wrong?
 
 Benjamin
 
 
 P Please consider the environment before printing this e-mail
 
 Cleveland Clinic is ranked one of the top hospitals
 in America by U.S. News  World Report (2007).  
 Visit us online at http://www.clevelandclinic.org for
 a complete listing of our services, staff and
 locations.
 
 
 Confidentiality Note:  This message is intended for
use\...{{dropped:13}}
 
 __
 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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2007).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

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