Thanks, that has worked like a dream!
--
View this message in context:
http://r.789695.n4.nabble.com/conditional-value-assignment-tp4646945p4646988.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
htt
Hello,
First of all, two notes on the way you create your data.frame
1. Use age <- c("Adult", NA, ...etc...) _without_ quotes around NA. If
you use quotes it will seen as a character, not as the value NA.
2. Do not cbind and then coerce to data.frame, use data.frame only.
So the data and an
Hi,
I am trying to assign values to records based conditionally on other records
within a dataframe. For example, in the following dataframe the "NA" value
in dat$age would be replaced if the age status for that individual and
specific year can be found in another record. Ideally this would then a
ifelse worked like a charm for this newbie. Thanks, Dennis!
-Frank
On Feb 14, 2011, at 3:39 AM, Dennis Murphy wrote:
> Hi:
>
> Wouldn't ifelse() work here?
>
> tco <- with(df, ifelse(TargetColor == 'B', CannonOriB, CannonOriR))
>
> ifelse() is vectorized, so there should be no need for a loop
Hi:
Wouldn't ifelse() work here?
tco <- with(df, ifelse(TargetColor == 'B', CannonOriB, CannonOriR))
ifelse() is vectorized, so there should be no need for a loop.
Test:
> df <- data.table(TargetColor = c('B', 'R'), CannonOriB = c(5, 5),
+ CannonOriR = c(3, 3), stringsAsFactors
Dear R-Help,
I am trying to compute a new variable, let's call it "target cannon orientation
(tco)" based conditionally on old variables, "TargetColor," "CannonOriB," and
"CannonOriR." For every case in the data set, if TargetColor is "B" then I want
tco to equal the value for that case of Cann
6 matches
Mail list logo