Filter out rows/columns which hold less 10% of the results in a matrix
I have a matrix build from data in a similar structure:
airport.departure <- c("CDG", "QNY", "QXO", "CDG", "QNY")
airport.arrival <- c("SYD", "CDG", "QNY", "SYD", "QXO")
amount <- c(1, 3, 1, 10, 5)
df <- data.frame(airport.departure, airport.arrival, amount)
xtabs(amount ~ airport.arrival + airport.departure
That results in like here:
airport.departure
airport.arrival CDG QNY QXO
CDG 0 3 0
QNY 0 0 1
QXO 0 5 0
SYD 11 0 0
Now I need to filter out rows/columns which contain a very low amount of the values. Only rows/columns which contain more than 10% of the total data should be shown.
r dataframe matrix
add a comment |
I have a matrix build from data in a similar structure:
airport.departure <- c("CDG", "QNY", "QXO", "CDG", "QNY")
airport.arrival <- c("SYD", "CDG", "QNY", "SYD", "QXO")
amount <- c(1, 3, 1, 10, 5)
df <- data.frame(airport.departure, airport.arrival, amount)
xtabs(amount ~ airport.arrival + airport.departure
That results in like here:
airport.departure
airport.arrival CDG QNY QXO
CDG 0 3 0
QNY 0 0 1
QXO 0 5 0
SYD 11 0 0
Now I need to filter out rows/columns which contain a very low amount of the values. Only rows/columns which contain more than 10% of the total data should be shown.
r dataframe matrix
2
That code looks familiar :) Can you please post what you have tried as well?
– Sotos
Nov 21 '18 at 15:03
2
your question should always contain the desired result. Also read my comment on the very familiar question. Then you will google:"remove columns rows based on condition r"
.
– Andre Elrico
Nov 21 '18 at 15:09
1
Please, Confusulum, please do some research about R. There are several really good tutorials on R (google/bing/rseek are your friends) that demonstrate selecting rows or columns based on some condition. Even if you choose to not use google or bing, SO has a lot of questions that likely contain what you are looking for (one such search on SO:[r] matrix filter column
). Regardless, please search before you ask, you'll often get what you need much faster. idownvotedbecau.se/noresearch
– r2evans
Nov 21 '18 at 15:17
Hello again @Sotos! The advices of you other two guys have not helped me sadly. I have researched and am trying to figure the prerequisits out that need to be fullfilled before I can do the conversion that I want, but R is a language that I don't understand. I would not have asked if time wasn't an issue. I understand that this kind of posts annoy you, though. Sorry for wasting your time and have nice evening.
– Confusulum
Nov 21 '18 at 18:10
add a comment |
I have a matrix build from data in a similar structure:
airport.departure <- c("CDG", "QNY", "QXO", "CDG", "QNY")
airport.arrival <- c("SYD", "CDG", "QNY", "SYD", "QXO")
amount <- c(1, 3, 1, 10, 5)
df <- data.frame(airport.departure, airport.arrival, amount)
xtabs(amount ~ airport.arrival + airport.departure
That results in like here:
airport.departure
airport.arrival CDG QNY QXO
CDG 0 3 0
QNY 0 0 1
QXO 0 5 0
SYD 11 0 0
Now I need to filter out rows/columns which contain a very low amount of the values. Only rows/columns which contain more than 10% of the total data should be shown.
r dataframe matrix
I have a matrix build from data in a similar structure:
airport.departure <- c("CDG", "QNY", "QXO", "CDG", "QNY")
airport.arrival <- c("SYD", "CDG", "QNY", "SYD", "QXO")
amount <- c(1, 3, 1, 10, 5)
df <- data.frame(airport.departure, airport.arrival, amount)
xtabs(amount ~ airport.arrival + airport.departure
That results in like here:
airport.departure
airport.arrival CDG QNY QXO
CDG 0 3 0
QNY 0 0 1
QXO 0 5 0
SYD 11 0 0
Now I need to filter out rows/columns which contain a very low amount of the values. Only rows/columns which contain more than 10% of the total data should be shown.
r dataframe matrix
r dataframe matrix
edited Nov 21 '18 at 15:03
Confusulum
asked Nov 21 '18 at 15:01
ConfusulumConfusulum
225
225
2
That code looks familiar :) Can you please post what you have tried as well?
– Sotos
Nov 21 '18 at 15:03
2
your question should always contain the desired result. Also read my comment on the very familiar question. Then you will google:"remove columns rows based on condition r"
.
– Andre Elrico
Nov 21 '18 at 15:09
1
Please, Confusulum, please do some research about R. There are several really good tutorials on R (google/bing/rseek are your friends) that demonstrate selecting rows or columns based on some condition. Even if you choose to not use google or bing, SO has a lot of questions that likely contain what you are looking for (one such search on SO:[r] matrix filter column
). Regardless, please search before you ask, you'll often get what you need much faster. idownvotedbecau.se/noresearch
– r2evans
Nov 21 '18 at 15:17
Hello again @Sotos! The advices of you other two guys have not helped me sadly. I have researched and am trying to figure the prerequisits out that need to be fullfilled before I can do the conversion that I want, but R is a language that I don't understand. I would not have asked if time wasn't an issue. I understand that this kind of posts annoy you, though. Sorry for wasting your time and have nice evening.
– Confusulum
Nov 21 '18 at 18:10
add a comment |
2
That code looks familiar :) Can you please post what you have tried as well?
– Sotos
Nov 21 '18 at 15:03
2
your question should always contain the desired result. Also read my comment on the very familiar question. Then you will google:"remove columns rows based on condition r"
.
– Andre Elrico
Nov 21 '18 at 15:09
1
Please, Confusulum, please do some research about R. There are several really good tutorials on R (google/bing/rseek are your friends) that demonstrate selecting rows or columns based on some condition. Even if you choose to not use google or bing, SO has a lot of questions that likely contain what you are looking for (one such search on SO:[r] matrix filter column
). Regardless, please search before you ask, you'll often get what you need much faster. idownvotedbecau.se/noresearch
– r2evans
Nov 21 '18 at 15:17
Hello again @Sotos! The advices of you other two guys have not helped me sadly. I have researched and am trying to figure the prerequisits out that need to be fullfilled before I can do the conversion that I want, but R is a language that I don't understand. I would not have asked if time wasn't an issue. I understand that this kind of posts annoy you, though. Sorry for wasting your time and have nice evening.
– Confusulum
Nov 21 '18 at 18:10
2
2
That code looks familiar :) Can you please post what you have tried as well?
– Sotos
Nov 21 '18 at 15:03
That code looks familiar :) Can you please post what you have tried as well?
– Sotos
Nov 21 '18 at 15:03
2
2
your question should always contain the desired result. Also read my comment on the very familiar question. Then you will google:
"remove columns rows based on condition r"
.– Andre Elrico
Nov 21 '18 at 15:09
your question should always contain the desired result. Also read my comment on the very familiar question. Then you will google:
"remove columns rows based on condition r"
.– Andre Elrico
Nov 21 '18 at 15:09
1
1
Please, Confusulum, please do some research about R. There are several really good tutorials on R (google/bing/rseek are your friends) that demonstrate selecting rows or columns based on some condition. Even if you choose to not use google or bing, SO has a lot of questions that likely contain what you are looking for (one such search on SO:
[r] matrix filter column
). Regardless, please search before you ask, you'll often get what you need much faster. idownvotedbecau.se/noresearch– r2evans
Nov 21 '18 at 15:17
Please, Confusulum, please do some research about R. There are several really good tutorials on R (google/bing/rseek are your friends) that demonstrate selecting rows or columns based on some condition. Even if you choose to not use google or bing, SO has a lot of questions that likely contain what you are looking for (one such search on SO:
[r] matrix filter column
). Regardless, please search before you ask, you'll often get what you need much faster. idownvotedbecau.se/noresearch– r2evans
Nov 21 '18 at 15:17
Hello again @Sotos! The advices of you other two guys have not helped me sadly. I have researched and am trying to figure the prerequisits out that need to be fullfilled before I can do the conversion that I want, but R is a language that I don't understand. I would not have asked if time wasn't an issue. I understand that this kind of posts annoy you, though. Sorry for wasting your time and have nice evening.
– Confusulum
Nov 21 '18 at 18:10
Hello again @Sotos! The advices of you other two guys have not helped me sadly. I have researched and am trying to figure the prerequisits out that need to be fullfilled before I can do the conversion that I want, but R is a language that I don't understand. I would not have asked if time wasn't an issue. I understand that this kind of posts annoy you, though. Sorry for wasting your time and have nice evening.
– Confusulum
Nov 21 '18 at 18:10
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53414858%2ffilter-out-rows-columns-which-hold-less-10-of-the-results-in-a-matrix%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- 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.
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%2fstackoverflow.com%2fquestions%2f53414858%2ffilter-out-rows-columns-which-hold-less-10-of-the-results-in-a-matrix%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
2
That code looks familiar :) Can you please post what you have tried as well?
– Sotos
Nov 21 '18 at 15:03
2
your question should always contain the desired result. Also read my comment on the very familiar question. Then you will google:
"remove columns rows based on condition r"
.– Andre Elrico
Nov 21 '18 at 15:09
1
Please, Confusulum, please do some research about R. There are several really good tutorials on R (google/bing/rseek are your friends) that demonstrate selecting rows or columns based on some condition. Even if you choose to not use google or bing, SO has a lot of questions that likely contain what you are looking for (one such search on SO:
[r] matrix filter column
). Regardless, please search before you ask, you'll often get what you need much faster. idownvotedbecau.se/noresearch– r2evans
Nov 21 '18 at 15:17
Hello again @Sotos! The advices of you other two guys have not helped me sadly. I have researched and am trying to figure the prerequisits out that need to be fullfilled before I can do the conversion that I want, but R is a language that I don't understand. I would not have asked if time wasn't an issue. I understand that this kind of posts annoy you, though. Sorry for wasting your time and have nice evening.
– Confusulum
Nov 21 '18 at 18:10