[R] What is wrong with this code?

John Kane jrkrideau at yahoo.ca
Wed Jun 30 22:07:19 CEST 2010



--- On Wed, 6/30/10, Cable, Samuel B Civ USAF AFMC AFRL/RVBXI <Samuel.Cable at hanscom.af.mil> wrote:

> From: Cable, Samuel B Civ USAF AFMC AFRL/RVBXI <Samuel.Cable at hanscom.af.mil>
> Subject: Re: [R] What is wrong with this code?
> To: r-help at r-project.org
> Received: Wednesday, June 30, 2010, 3:41 PM
> OK, let me wipe the egg off of my
> face .... The problem wasn't with the
> break statement, it was with how I had included my
> functions in the
> "input.list" list.  I promise, I pounded on this for
> hours and saw the
> problem five minutes after I sent off the e-mail. 
> Anybody else ever
> have this happen?

Happens all the time, usually 30 seconds after you press the send button. What took you so long?  :)
> 
> Anyway, I still wouldn't mind some advice on character
> matching.
> Thanks.
> 
If so we need a reproducible example of what you are doing. 

Here is a simple example of what it wanted.

#Quick and dirty example
#=================================================================
# sample data set created using dput()
df1 <- structure(list(site = c(1, 1, 4, 4, 1, 4), id = structure(c(1L,
2L, 2L, 3L, 1L, 2L), .Label = c("a", "b", "c"), class = "factor"),
    cata = c(1, 1, 6, 1, 1, NA), catb = c(1, 2, 3, 4, 5, 6),
    doga = c(3, 5, 3, 6, 4, 0), dogb = c(2, 4, 6, 8, 10, 12),
    rata = c(NA, 9, 9, 8, 9, 8), ratb = c(1, 2, 3, 4, 5, 6),
    bata = c(12, 42, NA, 45, 32, 54), batb = c(13, 15, 17, 19,
    21, 23)), .Names = c("site", "id", "cata", "catb", "doga",
"dogb", "rata", "ratb", "bata", "batb"), row.names = c("aa",
"bb", "cc", "dd", "ee", "ff"), class = "data.frame")

mean(df1[,2])
#=================================================================

Question : Why is R giving me a warning when I ask for the mean?

(Answer, by the way is ?str which shows that df1[,2] is a factor

> > Cable, Samuel B Civ USAF AFMC AFRL/RVBXI wrote:
> > > Here it is:
> > >
> > > read.inputs<-function(infile) {
> > >
> > >    for (counter in
> 1:length(input.list)) {
> > >   
>    seek(infile,where=0,origin='start')
> > >   
>    newline<-readLines(infile,n=1)
> > >   
>    while(length(newline)>0) {
> > >
> > >
> if(!is.na(grep(as.character(input.list[[counter]][1]),newline)[1]))
> {
> > >       
>    break
> > >         }
> > >     
>    newline<-readLines(infile,n=1)
> > >       }
> > >       if
> (length(newline)>0) input.list[[counter]][2](infile)
> > >    }
> > >
> > > }
> 
> ______________________________________________
> R-help at 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.
> 





More information about the R-help mailing list