Reputation: 73
I am trying to write a function in R to subset data based on ID in a data frame like below, but the function I wrote does not work and it doesn't give me an error message either. Can someone let me know how to fix my function code?
subset1<-function(id){df2<-df[df$ID==id,]}
Upvotes: 2
Views: 2227
Reputation: 887901
We can use [[
inside a function
f1 <- function(id){
df[df[["ID"]] == id,]
}
f1(11)
# ID Item
#1 11 a
Upvotes: 3