Skip to content
Prev 343564 / 398506 Next

Unexpected behavior when giving a value to a new variable basedon the value of another variable

On Fri, 29 Aug 2014 06:33:01 -0700 Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
wrote
<...snip...>
<...sip...>
<...snip...>

Having seen all the responses about partial matching I almost understand. I've
also replicated the behaviour on R 2.11.1 so it's been around awhile. This
tells me it ain't a bug - so if any of the cognoscenti have the time and
inclination can someone give me a brief (and hopefully simple) explanation of
what is going on under the hood?

It looks (to me) like N$sample[N$age >= 65] <- 1 copies N$samplem to N$sample
and then does the assignment. If partial matching is the problem (which it
clearly is) my expectation is that  the  output should look like

   age samplem
1   67       1
2   62       1
3   74       1
4   61       1
5   60       1
6   55       1
7   60       1
8   59       1
9   58      NA
That is - no new column.
(and I just hate it when the world doesn't live up to my expectations!)

Bewildered and confused,
DMcP

____________________________________________________________
South Africas premier free email service - www.webmail.co.za 

Cotlands - Shaping tomorrows Heroes http://www.cotlands.org.za/