I want to check if numerical values in column A are present in the range between 2 numerical values in columns B and C in r.
Here is the starting dataset:
# dataset with values
numerical_values_dataset <-
data.frame(
A = c("0.798963315", "0.160710819", "0.247170125", "-0.910092611", "0.42959469", "0.710921651", "0.160710819"),
B = c("0.321418973", "0.710921651", "0.910092611", "0.42959469", "0.42959469", "0.42959469", "0.160710819"),
C = c("0.812661261", "0.146377668", "0.42959469", "0.710921651", "0.710921651", "0.710921651", "0.160710819")
)
> numerical_values_dataset
A B C
1 0.798963315 0.321418973 0.812661261
2 0.160710819 0.710921651 0.146377668
3 0.247170125 0.910092611 0.42959469
4 -0.910092611 0.42959469 0.710921651
5 0.42959469 0.42959469 0.710921651
6 0.710921651 0.42959469 0.710921651
7 0.160710819 0.160710819 0.160710819
I would at least like to get at least results that correspond to Ranges_status_yes_no
, and it would be nice to get "Ranges_status_specific".
# result Ranges_status_yes_no
Ranges_status_yes_no <- data.frame(Ranges_status_yes_no = c("yes", "yes", "no", "no", "yes", "yes", "yes"))
# result Ranges_status_specific
numerical_values_dataset$Ranges_status_specific <- c("A is between B and C", "A is between B and C", "A is less than B", "A is less than B", "A is equal to B", "A is equal to C", "A is equal to B and C")
> numerical_values_dataset
A B C Ranges_status_yes_no Ranges_status_specific
1 0.798963315 0.321418973 0.812661261 yes A is between B and C
2 0.160710819 0.710921651 0.146377668 yes A is between B and C
3 0.247170125 0.910092611 0.42959469 no A is less than B
4 -0.910092611 0.42959469 0.710921651 no A is less than B
5 0.42959469 0.42959469 0.710921651 yes A is equal to B
6 0.710921651 0.42959469 0.710921651 yes A is equal to C
7 0.160710819 0.160710819 0.160710819 yes A is equal to B and C
I suppose one could generate these results using long ifelse()
statements. But is there a way to do this in some other manner?
Any help, even partial answers, are greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire