I really like using the frame syntax in R. However, if I try to do this with apply, it gives me an error that the input is a vector, not a frame (which is correct). Is there a similar function to mapply which will let me keep using the frame syntax?
df = data.frame(x = 1:5, y = 1:5)
# This works, but is hard to read because you have to remember what's
# in column 1
apply(df, 1, function(row) row[1])
# I'd rather do this, but it gives me an error
apply(df, 1, function(row) row$x)
Youcab’t use the
$on an atomic vector, But I guess you want use it for readability. But you can use[subsetter.Here an example. Please provide a reproducible example next time. Question in R specially have no sense without data.
Note that with apply I need to convert to a numeric.
You can also use
plyrordata.tablefor a clean syntax , for example:is equivalent to