Skip to content
Back to formatted view

Raw Message

Message-ID: <5372B778-5C50-4C04-81B1-9FAB9BF542FC@comcast.net>
Date: 2016-04-08T03:03:39Z
From: David Winsemius
Subject: why data frame's logical index isnt working
In-Reply-To: <CA+pG8eMq8SauinbLbrUdxn4pkm2MHWhNiUfSR_XAvN4hyQpb6w@mail.gmail.com>

> On Apr 7, 2016, at 7:44 PM, Michael Artz <michaeleartz at gmail.com> wrote:
> 

> I don't get it, I thought the double index was to indicate and individual element within a column(vector)?

Character values by themselves either quoted or not are not assumed to refer to column names unless you use `with` or `within`.


> I will stop using data.frame, thanks a lot!

You will have a lot of problems using R if you stop using data.frames.

-- 
David.
> 
> On Thu, Apr 7, 2016 at 9:29 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> 
> > On Apr 7, 2016, at 6:46 PM, Michael Artz <michaeleartz at gmail.com> wrote:
> >
> > data.frame.$columnToAdd["CurrentColumnName" == "ConditionMet"] <- 1
> >
> > Can someone please explain to me why the above command gives all NAs to
> > columnToAdd?  I thought this was possible in R to do logical expression in
> > the index of a data frame
> 
> It is possible, but please execute this at a console line and then read ?"[" to see what is happening:
> 
> "CurrentColumnName" == "ConditionMet"  # almost surely FALSE
> 
> Let's assume your dataframe were named 'dat'.
> 
> Perhaps you meant to write:
> 
> dat$colToAdd[ dat[["CurrentColumnName"]] == dat[["ConditionMet"]] ] <- 1
> 
> And do please stop naming your dataframes "data.frame".
> 
> 
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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 Winsemius
> Alameda, CA, USA
> 
> 

David Winsemius
Alameda, CA, USA