D. Shin
D. Shin

Reputation: 335

R : how to call colnames inside r function

Let me demonstrate: (u is a df)

u %>% fill(colnames(u)[2],colnames(u)[3], .direction = "downup")

Would there be any alternative of doing so? I would like to simplify code.

Thank you very much

Upvotes: 0

Views: 38

Answers (1)

AEF
AEF

Reputation: 5650

If you want to fill the second and third column, you can just use fill(2, 3, .direction = "downup").

To reference the input to a pipe, you can use . as in u %>% colnames(.). But this will not work here, since fill expects the column names as name, not as string.

Upvotes: 1

Related Questions