I have a subset of data that I have identified as suspect (for example,
the first name has excessive spaces, is longer than 35 characters or has a
number).
What I want to do is update the FNAME_SUSPECT field in mydata to TRUE if
any of those conditions are met.
Here's my data:
dput(mydata)
Not always true, but it is in this case:
?ifelse
David C
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Johnson
Sent: Tuesday, February 18, 2014 11:24 AM
To: R help
Subject: [R] Updating a data frame based on if condition
I
Johnson
Sent: Tuesday, February 18, 2014 11:24 AM
To: R help
Subject: [R] Updating a data frame based on if condition
I have a subset of data that I have identified as suspect (for
example,
the first name has excessive spaces, is longer than 35
characters or has a
number).
What I want to do
:
?ifelse
David C
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Johnson
Sent: Tuesday, February 18, 2014 11:24 AM
To: R help
Subject: [R] Updating a data frame based on if condition
I have a subset of data that I have
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_LENGTH45|regexpr(9,FNAME_PATTERN)==0)
table(mydata$FNAME_SUSPECT)
#
#FALSE
# 50
Now, your second condition (reply to David).
[49] TRUE TRUE
And adding or changing a condition is pretty simple
David C
From: Jeff Johnson [mailto:mrjeffto...@gmail.com]
Sent: Tuesday, February 18, 2014 12:54 PM
To: dcarl...@tamu.edu
Cc: R help
Subject: Re: [R] Updating a data frame based on if condition
Ahh, I was specifying
, 2014 12:54 PM
To: dcarl...@tamu.edu
Cc: R help
Subject: Re: [R] Updating a data frame based on if condition
Ahh, I was specifying the second argument FALSE incorrectly.
Works now as:
mydata$FNAME_SUSPECT - ifelse(mydata$FNAME_TOKEN_COUNT 3,
TRUE,
ifelse(mydata$FNAME_LENGTH 55
Hi,
I have a global data-frame in my R script.
At some point in my script, I want to update certain columns of this
data-frame by calling in an update function.
The function looks like this:
# get events data. This populates a global event data frame in the R-script
events - getEvents(con,
Looks like your event id is unique. If that is so, why not just do
##Not checked
events - events[sort(events$event),]
dataF - dataF[sort(data$event),]
if(doUpdate == 1){
if(!is.null(dataF) nrow(dataF) 0){
events[events$eventid %in% dataF$event, c(timestamp,
isSynchronized,timediff)]
To my earlier question about updating a dataframe, and certainty that this
has been solved several times before, Dr. Winsemius suggests (Thanks!):
I am sure this is not the most elegant method, but it will work.
new - merge(nn,uu, by = c(a,b), all.x=T)
new$y - with( new,
Folks,
Updating values in a table is simple in SAS or SQL, but I've wracked my
brain looking for an elegant solution in R to no avail thus far. Certainly
this is a common need that's been solved in dozens of different ways.
Given an initial dataframe nn and a smaller dataframe of updates uu,
I am sure this is not the most elegant method, but it will work.
new - merge(nn,uu, by = c(a,b), all.x=T)
new
a bx.xy.x x.y y.y
1 1 1 0.03648491 0.69644753 100 -100
2 1 2 0.76826365 0.28821953 NA NA
3 1 3 0.62744363 0.08373154 NA NA
4 2 1 0.27503185 0.55738251
12 matches
Mail list logo