mercredi 13 février 2019

Checking the value in the dataframe in R

The following are my r code. I am trying to check whether the true value a = 10 is included or in the dataframe. If its included in the dataframe, then I need to compute the length of that data frame otherwise I want to assign the length 0 .

Assume the value I am checking is 10

k1 = c(1,2,3,5,6) 
k2 = c(10,12,13,15,16,18)  

For example, for the k1 set i want to get the length 0 whereas for k2 the length must be 6

I trying to use the following code to do this work

library(tidyverse)
map_lgl(k, `%in%`, x = 10) %>% length

Why it is not working for the k1 dataset?

Thank you very much.

Aucun commentaire:

Enregistrer un commentaire