我有一個數據幀:過濾數據幀閃亮
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
現在我想使搜索例如100和顯示40,如果我SEACH 102的輸出將是58。
我有以下幾點:
df %>%
filter(height == input$counter) %>%
select(weight)
這是工作,但舉例來說,如果5鍵入任何其他數字,是不是在DF $高度,然後我得到這個:
> df %>%
filter(height == input$counter) %>%
select(weight)
[1] weight
<0 rows> (or 0-length row.names)
input$counter
是ui.R
輸入。結果在閃亮的作品中,但如果在高度df中找不到輸入,則會顯示numeric(0)
。我怎樣才能使它的輸出是0
而不是numeric(0)
?