Given the R code below, I was wondering how to create two columns such that the 16 largest values of LR and their corresponding xs when "x" is bounded between .4 and .8 be shown? (a column for x & a column for the corresponding LR)?
LR <- dbeta(x,h+1,n-h+1)/max(dbeta(x,h+1,n-h+1))
head(sort(LR[which(x<=.8 & x>=.4)], decreasing=TRUE), 16)
Here is a way using
library(dplyr) df <- data.frame(x, LR) df1 <- df %>% filter((x >= 0.4) & (x <= 0.8)) %>% arrange(desc(LR)) %>% head(16) # to save the data write.csv(df1, "abc.csv", row.names=FALSE)