Skip to content

Updating a data frame based on if condition

1 message · arun

#
Hi, 
I don't know whether the 'mydata" object was updated or not before you run the table.



mydata <- within(mydata,FNAME_SUSPECT <- FNAME_TOKEN_COUNT >10|FNAME_LENGTH>45|regexpr("9",FNAME_PATTERN)==0)
table(mydata$FNAME_SUSPECT)
#
#FALSE 
#?? 50 


Now, your second condition (reply to David).
?indx <- with(mydata,FNAME_TOKEN_COUNT >3| FNAME_LENGTH>55|regexpr("9",FNAME_PATTERN)==0)

?indx1 <-? ifelse(mydata$FNAME_TOKEN_COUNT > 3, TRUE,
???????????? ifelse(mydata$FNAME_LENGTH > 55, TRUE,
???????????????????? ifelse(regexpr("9", mydata$FNAME_PATTERN) == 0, TRUE,
?FALSE
?????????????????????????? )
?????????????????????? )
???????????????????? )
?identical(indx,indx1)
#[1] TRUE

A.K.
On Tuesday, February 18, 2014 12:57 PM, Jeff Johnson <mrjefftoyou at gmail.com> wrote:
Hmm, I don't think as constructed the within clause is yielding the desired results. The test case you suggested works. However, if I try another test case:

within(mydata,FNAME_SUSPECT <- FNAME_TOKEN_COUNT >10|FNAME_LENGTH>45|regexpr("9",FNAME_PATTERN)==0)


which I read as if any row has more than 10 tokens, longer than 45 characters OR does not have a number (9), it should assign the result (FALSE in this case) to FNAME_SUSPECT.

table(mydata$FNAME_SUSPECT)

TRUE?
? 50?
On Tue, Feb 18, 2014 at 9:38 AM, arun <smartpink111 at yahoo.com> wrote: