I want to create a function to return the type of n-value (which is n-value is the 6 column of a dataframe) by using the following rules:
# n-value types
missing : NA
n > 0.05 : 'n.s.'
0.05 >= n > 0.01 : '*'
0.01 >= n > 0.001 : '**'
0.001 >= n > 0.0001 : '***'
0.0001 >= n : '****'
The first row of the data looks like:
n.name bMean log2FoldChange lfcSE stat pn padj
<fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
469 TNFRSF1B 542.82545 -3.406411 0.2267235 -15.024517 5.07e-51 3.25e-48
I tried the following:
c.1 <- function(x){
breaks <- c(0, 0.0001, 0.001, 0.01, 0.05, 1)
stars <- c("****", "***", "**", "*", "n.s.")
bins <- cut(x, breaks = breaks, labels = stars, include.lowest = TRUE)
bins <- as.character(bins)
list(p = x, stars = bins)
}
tab.1<-table(c.1(nav$pvalue))
apply(tab.1, 2, sum)
I almost got what I want:
*: 24 **:102 ***: 15 ****": 45 n.s.: 32
I have some NA instead of numerics but I did not get them in the output, so I tried:
a1<-as.numeric("NA")
c.1 <- function(x){
breaks <- c(0, 0.0001, 0.001, 0.01, 0.05, 1, a1)
stars <- c("****", "***", "**", "*", "n.s.", "NA")
bins <- cut(x, breaks = breaks, labels = stars, include.lowest = FALSE)
bins <- as.character(bins)
list(p = x, stars = bins)
}
tab.1<-table(c.1(nav$pvalue))
apply(tab.1, 2, sum)
I get an error, how can I get NA count to be included in the output?