Re: Replace specific element with specific value.
- To: mathgroup at smc.vnet.net
- Subject: [mg99679] Re: Replace specific element with specific value.
- From: nick.maj at mssm.edu
- Date: Mon, 11 May 2009 06:22:54 -0400 (EDT)
- References: <gu661d$9kf$1@smc.vnet.net>
Thank you all for the replies.
Bill, you are right. To manually input the replacement rules is fine
for only a view variables. For simplicity I kept my example short.
However, I am dealing with quite large lists (100+), so a functional/
programatical approach is necessary. Also, I used characters for
clarity.
Rule @@@ (ToExpression[{#, # <> "+" <> # <> #}] & /@ {"1", "2", "3"})
gives: {1 -> 12, 2 -> 24, 3 -> 36}
Let me elaborate on this problem again with numbers only.
data = {{0, 2}, {2, 3}, {3, 4}, {4, 6}, {6, 8}, {8, 9}, {9, 10}}
positionList = {3, 6, 7}
replacementList = {8, 17, 25}
needed output:
{{0, 2}, {2, 3}, {3, 8}, {4, 6}, {6, 8}, {8, 17}, {9, 25}}
Based on the positionList - replacementList information, the function
must replace the 2nd element in the 3rd, 6th and 7th list of data with
the value 8, 17 and 25 respectively.
I experimented with MapThread[ReplacePart ... but without success.
Thanks in advance, Nick.