search for: pipeop

Displaying 2 results from an estimated 2 matches for "pipeop".

Did you mean: pipe
2024 Jul 21
2
[External] Using the pipe, |>, syntax with "names<-"
...t; z |> names() |> elt(2) <- "foo" > z a foo 1 1 a 2 2 b 3 3 c You could actually also do (using a similar function already defined in methods) z |> names() |> el(2) <- "bar" Iris's _ trick is of course a nice alternative; and this example in ?pipeOp already covers it: # using the placeholder as the head of an extraction chain: mtcars |> subset(cyl == 4) |> lm(formula = mpg ~ disp) |> _$coef[[2]] While the replacement question is a nice exercise, I am not sure about the value of emphasizing that you can use pipes to do complex assign...
2024 Jul 20
1
[External] Using the pipe, |>, syntax with "names<-"
I second Rich's excellent suggestion. As with all elegant solutions, Iris's clicked on the wee light bulb in my brain, and I realized that a slightly more verbose, but perhaps more enlightening, alternative may be: z |> attr("names") |> _[2] <- "foo" However, I would add this as an example *only with* Iris's solution. Hers should be shown whether or not