Issue with conditionally ranking p-valuesRank function in MySQLRemove rows with all or some NAs (missing values) in data.frameHow do I replace NA values with zeros in an R dataframe?r rank value in vectorRank function to rank 0 as 0, apply a function to elements of vector with certain values?R - extracting value by rankRank the dataframe values in RRank values column-wiseR: find value/index which is not in rankwhy ties.method of rank for repeated value works unexpectedly?
Return last number in sub-sequences in a list of integers
Is this popular optical illusion made of a grey-scale image with coloured lines?
Is verification of a blockchain computationally cheaper than recreating it?
Is Illustrator accurate for business card sizes?
cannot trash malware NGPlayerSetup.dmg
Partial Fractions: Why does this shortcut method work?
Applied Meditation
Why do we need a voltage divider when we get the same voltage at the output as the input?
Feedback diagram
speaker impedence
Should 2FA be enabled on service accounts?
Does the use of a new concept require a prior definition?
HackerRank Implement Queue using two stacks Solution
How does Rust's 128-bit integer `i128` work on a 64-bit system?
Will medical institutions reject an applicant based on being 28 years of age?
How do I respond appropriately to an overseas company that obtained a visa for me without hiring me?
Who's behind community AMIs on Amazon EC2?
Can I shorten this filter, that finds disk sizes over 100G?
Plotting Chebyshev polynomials using PolarPlot and FilledCurve
How is Sword Coast North governed?
δόλος = deceit in John 1:47
Why are prop blades not shaped like household fan blades?
Password management for kids - what's a good way to start?
Gold Battle KoTH
Issue with conditionally ranking p-values
Rank function in MySQLRemove rows with all or some NAs (missing values) in data.frameHow do I replace NA values with zeros in an R dataframe?r rank value in vectorRank function to rank 0 as 0, apply a function to elements of vector with certain values?R - extracting value by rankRank the dataframe values in RRank values column-wiseR: find value/index which is not in rankwhy ties.method of rank for repeated value works unexpectedly?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am conducting some time series modelling and want to remove terms from my time series based on removing the lowest rank p-values. The criteria I have is to only rank p-values that exclude "ar", "ma", "intercept", "price.diff" and rank only if p>0.2.
Here is an example:
term pval rank
ar1 0.001 NA
ar2 0.292 NA
ar3 0.000 NA
ma1 0.000 NA
intercept 0.000 NA
Price.Diff 0.859 NA
School 0.818 2
Easter 0.149 NA
Christmas 0.049 NA
High.Week 0.000 NA
Low.Week 0.000 NA
This is the function I have written:
rank_p<-function(x)
x["rank"]<-NA
x$rank<-ifelse(test = substr(x$term,1,2) != "ar" &
substr(x$term,1,2) != "ma" &
substr(x$term,1,stop = nchar(x$term)) != "intercept" &
substr(x$term,1, stop = nchar(x$term)) != "Price.Diff" &
x$pval > 0.2,
yes = rank(-x$pval, na.last = NA),
no = NA)
return(x)
My issue is that the rank for this example begins at 2.This would be the second highest p-value however because I am excluding price.diff, this should be ranked 1.
Is the issue in ordering of the conditions?
r conditional rank
|
show 1 more comment
I am conducting some time series modelling and want to remove terms from my time series based on removing the lowest rank p-values. The criteria I have is to only rank p-values that exclude "ar", "ma", "intercept", "price.diff" and rank only if p>0.2.
Here is an example:
term pval rank
ar1 0.001 NA
ar2 0.292 NA
ar3 0.000 NA
ma1 0.000 NA
intercept 0.000 NA
Price.Diff 0.859 NA
School 0.818 2
Easter 0.149 NA
Christmas 0.049 NA
High.Week 0.000 NA
Low.Week 0.000 NA
This is the function I have written:
rank_p<-function(x)
x["rank"]<-NA
x$rank<-ifelse(test = substr(x$term,1,2) != "ar" &
substr(x$term,1,2) != "ma" &
substr(x$term,1,stop = nchar(x$term)) != "intercept" &
substr(x$term,1, stop = nchar(x$term)) != "Price.Diff" &
x$pval > 0.2,
yes = rank(-x$pval, na.last = NA),
no = NA)
return(x)
My issue is that the rank for this example begins at 2.This would be the second highest p-value however because I am excluding price.diff, this should be ranked 1.
Is the issue in ordering of the conditions?
r conditional rank
Your code may benefit from use of the%in%
operator. To read about it, look at the?match
help page.
– lmo
Mar 27 at 0:39
Thanks for the reply. I see that the %in% will retur a vector of TRUE/FALSE, will i still not have the ranking issue though, unless I i base the ranking on TRUE values only?
– e_conomics
Mar 27 at 0:44
You can use logical vectors to subset, removing the p-values that you don't want to consider in your ranking. See?"["
if this sounds interesting.
– lmo
Mar 27 at 0:50
If the 2 was instead a 1, would that be a desired output? Or would Easter and Christmas also have a ranking?
– Croote
Mar 27 at 4:20
Hi Croote, correct, 2 should be a 1. Eastern and Christmas should not have a ranking as their p-value is <0.2
– e_conomics
Mar 27 at 4:28
|
show 1 more comment
I am conducting some time series modelling and want to remove terms from my time series based on removing the lowest rank p-values. The criteria I have is to only rank p-values that exclude "ar", "ma", "intercept", "price.diff" and rank only if p>0.2.
Here is an example:
term pval rank
ar1 0.001 NA
ar2 0.292 NA
ar3 0.000 NA
ma1 0.000 NA
intercept 0.000 NA
Price.Diff 0.859 NA
School 0.818 2
Easter 0.149 NA
Christmas 0.049 NA
High.Week 0.000 NA
Low.Week 0.000 NA
This is the function I have written:
rank_p<-function(x)
x["rank"]<-NA
x$rank<-ifelse(test = substr(x$term,1,2) != "ar" &
substr(x$term,1,2) != "ma" &
substr(x$term,1,stop = nchar(x$term)) != "intercept" &
substr(x$term,1, stop = nchar(x$term)) != "Price.Diff" &
x$pval > 0.2,
yes = rank(-x$pval, na.last = NA),
no = NA)
return(x)
My issue is that the rank for this example begins at 2.This would be the second highest p-value however because I am excluding price.diff, this should be ranked 1.
Is the issue in ordering of the conditions?
r conditional rank
I am conducting some time series modelling and want to remove terms from my time series based on removing the lowest rank p-values. The criteria I have is to only rank p-values that exclude "ar", "ma", "intercept", "price.diff" and rank only if p>0.2.
Here is an example:
term pval rank
ar1 0.001 NA
ar2 0.292 NA
ar3 0.000 NA
ma1 0.000 NA
intercept 0.000 NA
Price.Diff 0.859 NA
School 0.818 2
Easter 0.149 NA
Christmas 0.049 NA
High.Week 0.000 NA
Low.Week 0.000 NA
This is the function I have written:
rank_p<-function(x)
x["rank"]<-NA
x$rank<-ifelse(test = substr(x$term,1,2) != "ar" &
substr(x$term,1,2) != "ma" &
substr(x$term,1,stop = nchar(x$term)) != "intercept" &
substr(x$term,1, stop = nchar(x$term)) != "Price.Diff" &
x$pval > 0.2,
yes = rank(-x$pval, na.last = NA),
no = NA)
return(x)
My issue is that the rank for this example begins at 2.This would be the second highest p-value however because I am excluding price.diff, this should be ranked 1.
Is the issue in ordering of the conditions?
r conditional rank
r conditional rank
asked Mar 27 at 0:34
e_conomicse_conomics
175 bronze badges
175 bronze badges
Your code may benefit from use of the%in%
operator. To read about it, look at the?match
help page.
– lmo
Mar 27 at 0:39
Thanks for the reply. I see that the %in% will retur a vector of TRUE/FALSE, will i still not have the ranking issue though, unless I i base the ranking on TRUE values only?
– e_conomics
Mar 27 at 0:44
You can use logical vectors to subset, removing the p-values that you don't want to consider in your ranking. See?"["
if this sounds interesting.
– lmo
Mar 27 at 0:50
If the 2 was instead a 1, would that be a desired output? Or would Easter and Christmas also have a ranking?
– Croote
Mar 27 at 4:20
Hi Croote, correct, 2 should be a 1. Eastern and Christmas should not have a ranking as their p-value is <0.2
– e_conomics
Mar 27 at 4:28
|
show 1 more comment
Your code may benefit from use of the%in%
operator. To read about it, look at the?match
help page.
– lmo
Mar 27 at 0:39
Thanks for the reply. I see that the %in% will retur a vector of TRUE/FALSE, will i still not have the ranking issue though, unless I i base the ranking on TRUE values only?
– e_conomics
Mar 27 at 0:44
You can use logical vectors to subset, removing the p-values that you don't want to consider in your ranking. See?"["
if this sounds interesting.
– lmo
Mar 27 at 0:50
If the 2 was instead a 1, would that be a desired output? Or would Easter and Christmas also have a ranking?
– Croote
Mar 27 at 4:20
Hi Croote, correct, 2 should be a 1. Eastern and Christmas should not have a ranking as their p-value is <0.2
– e_conomics
Mar 27 at 4:28
Your code may benefit from use of the
%in%
operator. To read about it, look at the ?match
help page.– lmo
Mar 27 at 0:39
Your code may benefit from use of the
%in%
operator. To read about it, look at the ?match
help page.– lmo
Mar 27 at 0:39
Thanks for the reply. I see that the %in% will retur a vector of TRUE/FALSE, will i still not have the ranking issue though, unless I i base the ranking on TRUE values only?
– e_conomics
Mar 27 at 0:44
Thanks for the reply. I see that the %in% will retur a vector of TRUE/FALSE, will i still not have the ranking issue though, unless I i base the ranking on TRUE values only?
– e_conomics
Mar 27 at 0:44
You can use logical vectors to subset, removing the p-values that you don't want to consider in your ranking. See
?"["
if this sounds interesting.– lmo
Mar 27 at 0:50
You can use logical vectors to subset, removing the p-values that you don't want to consider in your ranking. See
?"["
if this sounds interesting.– lmo
Mar 27 at 0:50
If the 2 was instead a 1, would that be a desired output? Or would Easter and Christmas also have a ranking?
– Croote
Mar 27 at 4:20
If the 2 was instead a 1, would that be a desired output? Or would Easter and Christmas also have a ranking?
– Croote
Mar 27 at 4:20
Hi Croote, correct, 2 should be a 1. Eastern and Christmas should not have a ranking as their p-value is <0.2
– e_conomics
Mar 27 at 4:28
Hi Croote, correct, 2 should be a 1. Eastern and Christmas should not have a ranking as their p-value is <0.2
– e_conomics
Mar 27 at 4:28
|
show 1 more comment
1 Answer
1
active
oldest
votes
The reason your ranking is not as desired is because your yes
term includes the whole column. So you need to subset the column based on your condition.
What is happening in your current function is that you are ranking the column without a filter then changing to NA
everything that doesn't fit the condition.
I have just added a slightly changed version of your code to do this.
All I changed was to define your condition then subset the data frame accordingly. EDIT: this will work on the displayed data but not if there are more than one rows which meet the condition.
rank_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x$rank <- ifelse(test = cond,
yes = rank(-x[cond, ]$pval, na.last = NA),
no = NA)
return(x)
What this does is only rank the rows that meet your condition( x[cond, ]
).
This can be further simplified because you have already set them to NA
just change the ones that meet the condition. It doesn't seem like you need an ifelse
at all! This will also assign a vector of ranking to a subset of the same length which should work for larger sets which contain more than 1 row which meets the condition.
rank1_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x[cond, "rank"] <- rank(-x[cond,]$pval, na.last = NA)
return(x)
Thankyou Croote. That works perfectly. I have accepted your answer. Could you just clarify that rank(-x[cond,$pval) is indexing the rows of x in column pval and that whether the meet the cond criteria. Many thanks
– e_conomics
Mar 27 at 5:41
I see. Thinking on that question has shown me that there is another issue with the first solution and yourifelse()
logic. It will not behave as desired because If there are multiple rows which meet the condition it will attempt to place a vector of ranks into a single row and simply take the first. The second solution is better and will fill the rows accordingly.
– Croote
Mar 27 at 6:04
rank
function in your case is not indexing the rows to check if they meet the condition. It is simply trying to assign the output ofrank
to the yes condition in theifelse
– Croote
Mar 27 at 6:05
Excellent. Thankyou for clarifying and explaining
– e_conomics
Mar 28 at 0:19
add a comment |
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%2f55368131%2fissue-with-conditionally-ranking-p-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The reason your ranking is not as desired is because your yes
term includes the whole column. So you need to subset the column based on your condition.
What is happening in your current function is that you are ranking the column without a filter then changing to NA
everything that doesn't fit the condition.
I have just added a slightly changed version of your code to do this.
All I changed was to define your condition then subset the data frame accordingly. EDIT: this will work on the displayed data but not if there are more than one rows which meet the condition.
rank_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x$rank <- ifelse(test = cond,
yes = rank(-x[cond, ]$pval, na.last = NA),
no = NA)
return(x)
What this does is only rank the rows that meet your condition( x[cond, ]
).
This can be further simplified because you have already set them to NA
just change the ones that meet the condition. It doesn't seem like you need an ifelse
at all! This will also assign a vector of ranking to a subset of the same length which should work for larger sets which contain more than 1 row which meets the condition.
rank1_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x[cond, "rank"] <- rank(-x[cond,]$pval, na.last = NA)
return(x)
Thankyou Croote. That works perfectly. I have accepted your answer. Could you just clarify that rank(-x[cond,$pval) is indexing the rows of x in column pval and that whether the meet the cond criteria. Many thanks
– e_conomics
Mar 27 at 5:41
I see. Thinking on that question has shown me that there is another issue with the first solution and yourifelse()
logic. It will not behave as desired because If there are multiple rows which meet the condition it will attempt to place a vector of ranks into a single row and simply take the first. The second solution is better and will fill the rows accordingly.
– Croote
Mar 27 at 6:04
rank
function in your case is not indexing the rows to check if they meet the condition. It is simply trying to assign the output ofrank
to the yes condition in theifelse
– Croote
Mar 27 at 6:05
Excellent. Thankyou for clarifying and explaining
– e_conomics
Mar 28 at 0:19
add a comment |
The reason your ranking is not as desired is because your yes
term includes the whole column. So you need to subset the column based on your condition.
What is happening in your current function is that you are ranking the column without a filter then changing to NA
everything that doesn't fit the condition.
I have just added a slightly changed version of your code to do this.
All I changed was to define your condition then subset the data frame accordingly. EDIT: this will work on the displayed data but not if there are more than one rows which meet the condition.
rank_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x$rank <- ifelse(test = cond,
yes = rank(-x[cond, ]$pval, na.last = NA),
no = NA)
return(x)
What this does is only rank the rows that meet your condition( x[cond, ]
).
This can be further simplified because you have already set them to NA
just change the ones that meet the condition. It doesn't seem like you need an ifelse
at all! This will also assign a vector of ranking to a subset of the same length which should work for larger sets which contain more than 1 row which meets the condition.
rank1_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x[cond, "rank"] <- rank(-x[cond,]$pval, na.last = NA)
return(x)
Thankyou Croote. That works perfectly. I have accepted your answer. Could you just clarify that rank(-x[cond,$pval) is indexing the rows of x in column pval and that whether the meet the cond criteria. Many thanks
– e_conomics
Mar 27 at 5:41
I see. Thinking on that question has shown me that there is another issue with the first solution and yourifelse()
logic. It will not behave as desired because If there are multiple rows which meet the condition it will attempt to place a vector of ranks into a single row and simply take the first. The second solution is better and will fill the rows accordingly.
– Croote
Mar 27 at 6:04
rank
function in your case is not indexing the rows to check if they meet the condition. It is simply trying to assign the output ofrank
to the yes condition in theifelse
– Croote
Mar 27 at 6:05
Excellent. Thankyou for clarifying and explaining
– e_conomics
Mar 28 at 0:19
add a comment |
The reason your ranking is not as desired is because your yes
term includes the whole column. So you need to subset the column based on your condition.
What is happening in your current function is that you are ranking the column without a filter then changing to NA
everything that doesn't fit the condition.
I have just added a slightly changed version of your code to do this.
All I changed was to define your condition then subset the data frame accordingly. EDIT: this will work on the displayed data but not if there are more than one rows which meet the condition.
rank_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x$rank <- ifelse(test = cond,
yes = rank(-x[cond, ]$pval, na.last = NA),
no = NA)
return(x)
What this does is only rank the rows that meet your condition( x[cond, ]
).
This can be further simplified because you have already set them to NA
just change the ones that meet the condition. It doesn't seem like you need an ifelse
at all! This will also assign a vector of ranking to a subset of the same length which should work for larger sets which contain more than 1 row which meets the condition.
rank1_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x[cond, "rank"] <- rank(-x[cond,]$pval, na.last = NA)
return(x)
The reason your ranking is not as desired is because your yes
term includes the whole column. So you need to subset the column based on your condition.
What is happening in your current function is that you are ranking the column without a filter then changing to NA
everything that doesn't fit the condition.
I have just added a slightly changed version of your code to do this.
All I changed was to define your condition then subset the data frame accordingly. EDIT: this will work on the displayed data but not if there are more than one rows which meet the condition.
rank_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x$rank <- ifelse(test = cond,
yes = rank(-x[cond, ]$pval, na.last = NA),
no = NA)
return(x)
What this does is only rank the rows that meet your condition( x[cond, ]
).
This can be further simplified because you have already set them to NA
just change the ones that meet the condition. It doesn't seem like you need an ifelse
at all! This will also assign a vector of ranking to a subset of the same length which should work for larger sets which contain more than 1 row which meets the condition.
rank1_p <- function(x)
x["rank"] <- NA
cond <- substr(df$term,1,2) != "ar" &
substr(df$term,1,2) != "ma" &
substr(df$term,1,stop = nchar(df$term)) != "intercept" &
substr(df$term,1, stop = nchar(df$term)) != "Price.Diff" &
df$pval > 0.2
x[cond, "rank"] <- rank(-x[cond,]$pval, na.last = NA)
return(x)
edited Mar 27 at 6:07
answered Mar 27 at 4:37
CrooteCroote
7523 silver badges14 bronze badges
7523 silver badges14 bronze badges
Thankyou Croote. That works perfectly. I have accepted your answer. Could you just clarify that rank(-x[cond,$pval) is indexing the rows of x in column pval and that whether the meet the cond criteria. Many thanks
– e_conomics
Mar 27 at 5:41
I see. Thinking on that question has shown me that there is another issue with the first solution and yourifelse()
logic. It will not behave as desired because If there are multiple rows which meet the condition it will attempt to place a vector of ranks into a single row and simply take the first. The second solution is better and will fill the rows accordingly.
– Croote
Mar 27 at 6:04
rank
function in your case is not indexing the rows to check if they meet the condition. It is simply trying to assign the output ofrank
to the yes condition in theifelse
– Croote
Mar 27 at 6:05
Excellent. Thankyou for clarifying and explaining
– e_conomics
Mar 28 at 0:19
add a comment |
Thankyou Croote. That works perfectly. I have accepted your answer. Could you just clarify that rank(-x[cond,$pval) is indexing the rows of x in column pval and that whether the meet the cond criteria. Many thanks
– e_conomics
Mar 27 at 5:41
I see. Thinking on that question has shown me that there is another issue with the first solution and yourifelse()
logic. It will not behave as desired because If there are multiple rows which meet the condition it will attempt to place a vector of ranks into a single row and simply take the first. The second solution is better and will fill the rows accordingly.
– Croote
Mar 27 at 6:04
rank
function in your case is not indexing the rows to check if they meet the condition. It is simply trying to assign the output ofrank
to the yes condition in theifelse
– Croote
Mar 27 at 6:05
Excellent. Thankyou for clarifying and explaining
– e_conomics
Mar 28 at 0:19
Thankyou Croote. That works perfectly. I have accepted your answer. Could you just clarify that rank(-x[cond,$pval) is indexing the rows of x in column pval and that whether the meet the cond criteria. Many thanks
– e_conomics
Mar 27 at 5:41
Thankyou Croote. That works perfectly. I have accepted your answer. Could you just clarify that rank(-x[cond,$pval) is indexing the rows of x in column pval and that whether the meet the cond criteria. Many thanks
– e_conomics
Mar 27 at 5:41
I see. Thinking on that question has shown me that there is another issue with the first solution and your
ifelse()
logic. It will not behave as desired because If there are multiple rows which meet the condition it will attempt to place a vector of ranks into a single row and simply take the first. The second solution is better and will fill the rows accordingly.– Croote
Mar 27 at 6:04
I see. Thinking on that question has shown me that there is another issue with the first solution and your
ifelse()
logic. It will not behave as desired because If there are multiple rows which meet the condition it will attempt to place a vector of ranks into a single row and simply take the first. The second solution is better and will fill the rows accordingly.– Croote
Mar 27 at 6:04
rank
function in your case is not indexing the rows to check if they meet the condition. It is simply trying to assign the output of rank
to the yes condition in the ifelse
– Croote
Mar 27 at 6:05
rank
function in your case is not indexing the rows to check if they meet the condition. It is simply trying to assign the output of rank
to the yes condition in the ifelse
– Croote
Mar 27 at 6:05
Excellent. Thankyou for clarifying and explaining
– e_conomics
Mar 28 at 0:19
Excellent. Thankyou for clarifying and explaining
– e_conomics
Mar 28 at 0:19
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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.
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%2f55368131%2fissue-with-conditionally-ranking-p-values%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
Your code may benefit from use of the
%in%
operator. To read about it, look at the?match
help page.– lmo
Mar 27 at 0:39
Thanks for the reply. I see that the %in% will retur a vector of TRUE/FALSE, will i still not have the ranking issue though, unless I i base the ranking on TRUE values only?
– e_conomics
Mar 27 at 0:44
You can use logical vectors to subset, removing the p-values that you don't want to consider in your ranking. See
?"["
if this sounds interesting.– lmo
Mar 27 at 0:50
If the 2 was instead a 1, would that be a desired output? Or would Easter and Christmas also have a ranking?
– Croote
Mar 27 at 4:20
Hi Croote, correct, 2 should be a 1. Eastern and Christmas should not have a ranking as their p-value is <0.2
– e_conomics
Mar 27 at 4:28