Here is my toy dataset
df <- tribble(
~x, ~y, ~z,
7, NA, 4,
8, 2, NA,
NA, NA, NA,
NA, 4, 6)
I want to get a dataframe with a number of NA
s for each variable only between the first and the last occurrence of numbers in each column and number of NA
s between the first occurred number and last row. So, for this example, the desired solution is
desired_df <- tribble(~vars, ~na_count_between_1st_last_num, ~na_count_between_1st_num_last_row,
"x", 0, 2,
"y", 1, 1,
"z", 2, 2)
How can I get the desired output?
<NA>
<chr> <int> 1 NA 0 , not sure why. Is it because of the names_pattern = "^(.)_(.*)$" – Mada