Take single element of a list, and compare to average of whole list
If I have a list
lst = {1,2,3,4,5};
Is there someway of taking the first element and then comparing it to the average of the other 4? Then to take element 2 and compare it to the average of element 1,3,4,5? I can see how to do this with a For loop and a procedural style, but I am wondering if an easy functional style solution is possible.
Similar to This:
1 == Mean[{2,3,4,5}]
2 == Mean[{1,3,4,5}]
3 == Mean[{1,2,4,5}]
PS. I plan on using a more elaborate comparison, but ==
seemed like an easy one for this example.
list-manipulation functional-style averages
add a comment |
If I have a list
lst = {1,2,3,4,5};
Is there someway of taking the first element and then comparing it to the average of the other 4? Then to take element 2 and compare it to the average of element 1,3,4,5? I can see how to do this with a For loop and a procedural style, but I am wondering if an easy functional style solution is possible.
Similar to This:
1 == Mean[{2,3,4,5}]
2 == Mean[{1,3,4,5}]
3 == Mean[{1,2,4,5}]
PS. I plan on using a more elaborate comparison, but ==
seemed like an easy one for this example.
list-manipulation functional-style averages
add a comment |
If I have a list
lst = {1,2,3,4,5};
Is there someway of taking the first element and then comparing it to the average of the other 4? Then to take element 2 and compare it to the average of element 1,3,4,5? I can see how to do this with a For loop and a procedural style, but I am wondering if an easy functional style solution is possible.
Similar to This:
1 == Mean[{2,3,4,5}]
2 == Mean[{1,3,4,5}]
3 == Mean[{1,2,4,5}]
PS. I plan on using a more elaborate comparison, but ==
seemed like an easy one for this example.
list-manipulation functional-style averages
If I have a list
lst = {1,2,3,4,5};
Is there someway of taking the first element and then comparing it to the average of the other 4? Then to take element 2 and compare it to the average of element 1,3,4,5? I can see how to do this with a For loop and a procedural style, but I am wondering if an easy functional style solution is possible.
Similar to This:
1 == Mean[{2,3,4,5}]
2 == Mean[{1,3,4,5}]
3 == Mean[{1,2,4,5}]
PS. I plan on using a more elaborate comparison, but ==
seemed like an easy one for this example.
list-manipulation functional-style averages
list-manipulation functional-style averages
asked 3 hours ago
olliepower
1,21511127
1,21511127
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
if you want to choose a specific element use
F[x_] := Mean@Complement[lst, {x}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
Note
if you want to choose the first,second,nth element use
F[x_] := Mean@Complement[lst, {lst[[x]]}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
add a comment |
ClearAll[subMeans]
subMeans = (Total[#] - #)/(Length[#] - 1) &;
Examples:
lst = {a, b, c, d};
subMeans[lst]
{1/3 (b + c + d), 1/3 (a + c + d), 1/3 (a + b + d), 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ lst
{a == 1/3 (b + c + d), b == 1/3 (a + c + d), c == 1/3 (a + b + d),
d == 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ Range[5]
{False, False, True, False, False}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f188740%2ftake-single-element-of-a-list-and-compare-to-average-of-whole-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
if you want to choose a specific element use
F[x_] := Mean@Complement[lst, {x}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
Note
if you want to choose the first,second,nth element use
F[x_] := Mean@Complement[lst, {lst[[x]]}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
add a comment |
if you want to choose a specific element use
F[x_] := Mean@Complement[lst, {x}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
Note
if you want to choose the first,second,nth element use
F[x_] := Mean@Complement[lst, {lst[[x]]}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
add a comment |
if you want to choose a specific element use
F[x_] := Mean@Complement[lst, {x}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
Note
if you want to choose the first,second,nth element use
F[x_] := Mean@Complement[lst, {lst[[x]]}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
if you want to choose a specific element use
F[x_] := Mean@Complement[lst, {x}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
Note
if you want to choose the first,second,nth element use
F[x_] := Mean@Complement[lst, {lst[[x]]}]
1 == F[1]
2 == F[2]
3 == F[3]
False
False
True
edited 2 hours ago
answered 2 hours ago
J42161217
3,732220
3,732220
add a comment |
add a comment |
ClearAll[subMeans]
subMeans = (Total[#] - #)/(Length[#] - 1) &;
Examples:
lst = {a, b, c, d};
subMeans[lst]
{1/3 (b + c + d), 1/3 (a + c + d), 1/3 (a + b + d), 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ lst
{a == 1/3 (b + c + d), b == 1/3 (a + c + d), c == 1/3 (a + b + d),
d == 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ Range[5]
{False, False, True, False, False}
add a comment |
ClearAll[subMeans]
subMeans = (Total[#] - #)/(Length[#] - 1) &;
Examples:
lst = {a, b, c, d};
subMeans[lst]
{1/3 (b + c + d), 1/3 (a + c + d), 1/3 (a + b + d), 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ lst
{a == 1/3 (b + c + d), b == 1/3 (a + c + d), c == 1/3 (a + b + d),
d == 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ Range[5]
{False, False, True, False, False}
add a comment |
ClearAll[subMeans]
subMeans = (Total[#] - #)/(Length[#] - 1) &;
Examples:
lst = {a, b, c, d};
subMeans[lst]
{1/3 (b + c + d), 1/3 (a + c + d), 1/3 (a + b + d), 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ lst
{a == 1/3 (b + c + d), b == 1/3 (a + c + d), c == 1/3 (a + b + d),
d == 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ Range[5]
{False, False, True, False, False}
ClearAll[subMeans]
subMeans = (Total[#] - #)/(Length[#] - 1) &;
Examples:
lst = {a, b, c, d};
subMeans[lst]
{1/3 (b + c + d), 1/3 (a + c + d), 1/3 (a + b + d), 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ lst
{a == 1/3 (b + c + d), b == 1/3 (a + c + d), c == 1/3 (a + b + d),
d == 1/3 (a + b + c)}
MapThread[Equal, {#, subMeans @ #}]& @ Range[5]
{False, False, True, False, False}
edited 1 hour ago
answered 1 hour ago
kglr
177k9198405
177k9198405
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f188740%2ftake-single-element-of-a-list-and-compare-to-average-of-whole-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown