I want to filter a dataframe using a field which is defined in a variable, to select a value that is also in a variable. Say I have
df <- data.frame(V=c(6
Here's an alternative with base R, which is maybe not very elegant, but it might have the benefit of being rather easily understandable:
R
df[df[colnames(df)==fld]==sval,] # V Unhappy #2 1 Y #3 5 Y #4 3 Y