[R] set dataframe field value from lookup table
dwinsemius at comcast.net
Thu Dec 9 17:00:34 CET 2010
On Dec 9, 2010, at 10:33 AM, David Winsemius wrote:
> On Dec 9, 2010, at 9:34 AM, Jon Erik Ween wrote:
>> This is (hopefully) a bit more cogent phrasing of a previous post.
>> trying to compute a z-score to rows in a large dataframe based on
>> values in
>> another dataframe. Here's the script (that does not work). 2
>> 1) Anyone know of a more elegant way to calculate the "rounded" age
>> than the nested ifelse's I've used?
>> 2) how to reference the lookup table based on computed indices?
>> # Define tables
>> DSTzlook <-
>> header=TRUE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE)
>> # Compute rounded age.
> Ew, painful. If you want categorized ages (since what the above
> coding is producing is not "rounded" in any sense of that word as I
> understand it, then why not findInterval() as an index into the ages
> you wnat to label these case with?
> ### Cut out incorrect code from prior posting:
c(17, 17, 19, 24, 29, 34, 44, 54, 64, 69, 74, 79, 84, 89)[
findInterval( 19, c(0, 17, 19, 24, 29, 34, 44, 54, 64, 69, 74,
79, 84, 89) ) ]
I see my pasting of a test vector didn't get properly replaced. Also
added the missing "89" and fixed the mis-registration of "label
vector" with interval vector. (This reply was better tested than the
first, but you clearly need to check my work here.)
> The other option, of course, and a more "honest" one in this
> instance would be
> cut(vec, breaks=c(...), labels=c(...) )
> (It's not clear why you are not picking midpoint ages within those
> brackets to me.)
>> # Reference the lookup table based on computed indices
> I have not been able to figure out what you are trying to do here.
> Trying to use a 2d lookup looks promising a a way to emulate what an
> Excel user might attempt, but an example (as requested in the
> message at the bottom of every posting) would really be of great
> help in making this more concrete for those of us with insufficient
> abstractive abilities.
>> # Cleanup
>> View this message in context: http://r.789695.n4.nabble.com/set-dataframe-field-value-from-lookup-table-tp3080245p3080245.html
>> Sent from the R help mailing list archive at Nabble.com.
> David Winsemius, MD
> West Hartford, CT
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help