'How can I distinguish results in ifelse
I want distinguish between $p-values$ for t-test and $p-values$ for Wilicoxon in this code, How can I do that?
replicate(1000, ifelse(shapiro.test(rnorm(4))$p.value>=0.05,t.test(rnorm(4), alternative = "two.sided")$p.value, wilcox.test(rnorm(4), mu = 0, alternative = "two.sided")$p.value))
from this code, I will get 1000 p-values for the t-test and Wilcoxon test, if the p-value for the Shapiro-Wilk test is greater than 0.05 we will get the p-value for the t-test and if it is less than 0.05 we will get a p-value for Wilcoxon test my Q is how can I get list or vector of p-values for t-test only from these 1000 p-values
Solution 1:[1]
Something like this?
library(data.table)
set.seed(1)
df <- data.table(data = rnorm(4000), sample=rep(1:1000, each=4))
result <- df[, .(s=shapiro.test(data)$p.value,
w=wilcox.test(data)$p.value,
t=t.test(data)$p.value),
by=.(sample)]
result[, final:=ifelse(s < 0.05, w, t)]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jlhoward |