Thanks for the explainable, Denes.  Your solution worked a charm.  I should
have seen things more clearly, but sometimes I just get stuck in a rut.

The help of this list is always appreciated -- such a fantastic resource.

Cheers,

Sarah



2011/7/28 "Dénes TÓTH" <tde...@cogpsyphy.hu>

>
> Sorry, I was wrong. Of course you can assign a variable to itself, but it
> does not make much sense...
> What you misunderstood was that in the assignment you assign the data
> frame (e.g. "df1") to itself. You do not modify the frame object which
> remains a character string.
>
>
> >
> > The problem is that you can not assign a variable to itself.
> >
> > rm(list=ls())
> > df1 <- data.frame(ResultValue=as.character(1:5))
> > df2 <- data.frame(ResultValue=as.character(1:10))
> > frames = ls()
> > for (frame in frames){
> >      temp <- get(frame)
> >      temp[,"ResultValue"] = as.numeric(temp[,"ResultValue"])
> >      assign(frame,temp)
> > }
> >
> > HTH,
> >   Denes
> >
> >
> >
> >> Greetings to all --
> >>
> >> I am having a silly problem that I just can't solve.  Someone has given
> >> me
> >> an .RData file will hundreds of data frames.  Each data frame has a
> >> column
> >> named ResultValue, currently character when it should be numeric.  I
> >> want
> >> to
> >> loop through all of the data frames to change the variable to numeric,
> >> but
> >> I
> >> cannot figure out how to do it. My best guess was along the lines of:
> >>
> >> frames = ls()
> >> for (frame in frames){
> >>      assign(frame, get(frame), .GlobalEnv)
> >>      frame[,"ResultValue"] = as.numeric(frame[,"ResultValue"])
> >>      }
> >>
> >> It doesn't work.  After the assign() the frame object remains the
> >> character
> >> name of the dataframe I am trying to change.  If I do the following, the
> >> TEST object comes out just fine.
> >>
> >> frames = ls()
> >> for (frame in frames){
> >>      assign("TEST", get(frame), .GlobalEnv)
> >>      TEST[,"ResultValue"] = as.numeric(TEST[,"ResultValue"])
> >>      }
> >>
> >> Seems like it should be simple, but I am misunderstanding something and
> >> not
> >> following the logic.  Any insight?
> >>
> >> Thanks,
> >>
> >> Sarah
> >>
> >>      [[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.
> >
>
>

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

Reply via email to