I'm trying to create a function has work like INDEX in Excel using select and filter in function.
Here is my code but it seem like not working when I tested with one data frame.
index_matching <- function(data = NULL, row_matching, col_matching){
if(!missing(data)) {
#Variable create
col <- quo(col_matching)
row <- row_matching
matching <- data %>%
as.data.frame() %>%
filter(!!col == row) #This row has problem
select(!!col) %>%
return(matching)
} else {
message("You must specify data frame to matching!")
}
}
I want to search the row "B" and column length to have needed data, in this example is 4.9.
reprex::reprex({
raw_input_data <- data.frame(
length = c(5.1, 4.9, 4.7, 4.6, 5),
width = c(3.5, 3, 3.2, 3.1, 3.6)
text = c("A", "B", "C", "D", "E")
)
})
But when I use the function, there has been a error that they return data frame with 0 rows and
reprex::reprex({
index_matching(raw_input_data, row_matching = "B", col_matching = "length")
})
Here is the error
[1] component_type
<0 rows> (or 0-length row.names)
I think it's a issue but I want to ask in R community first. Glad to hear comment.