I have a dataframe:
height <- c('100', '101','102')
weight <- c('40 ', '45', '58')
df <- data.frame(height, weight)
df
height weight
1 100 40
2 101 45
3 102 58
Now I want to make to search for example 100 and be shown 40, and if I seach 102 the output would be 58.
I have the following:
df %>%
filter(height == input$counter) %>%
select(weight)
Which is working, but If type in for example 5 any other number that isn't in the df$height then I get this:
> df %>%
filter(height == input$counter) %>%
select(weight)
[1] weight
<0 rows> (or 0-length row.names)
The input$counter is a ui.R input. The result in shiny works, but if the input is not found in the height df then it will show numeric(0). How can I make it that the output is 0 instead of numeric(0)?