You want to change the last two lines highlighted in your function to:
object[, new] <- tmp[, 4]
object
Then, when you call the function specify the new
argument as a character string:
> df <- grouptest(df, GroupId, IndId, PropertyType, "ValidGroup")
> df
GroupId IndId IndGroupProperty PropertyType ValidGroupC ValidGroup
1 1 1 1 1 1 1
2 1 1 2 2 1 1
3 1 2 1 1 1 1
4 1 2 2 2 1 1
5 2 3 3 2 0 0
6 2 4 3 2 0 0
7 2 4 4 1 0 0
8 3 5 5 2 0 0
9 3 5 6 2 0 0