Hi Gabor, Richard, and Thierry,
Thanks very much for your replies. Turns out I had already hit on Gabor's idea
of "factor out" in writing an initial draft of the code converting from SAS to
R. Below is the link Gabor sent describing this and other approaches.
https://stackoverflow.com/questio
There is some discussion of approaches to this here:
https://stackoverflow.com/questions/34096162/dplyr-mutate-replace-on-a-subset-of-rows/34096575#34096575
On Mon, Dec 17, 2018 at 10:30 AM Paul Miller via R-help
wrote:
>
> Hello All,
>
> Season's greetings!
>
> Am trying to replicate some SAS
I got another 10% savings with this example by using only one
subscripting adjustment.
I also fixed a typo in my previous posting (which didn't affect the timing).
microbenchmark(
rmh={
d3 <-data.frame(ID=rownames(d1),
d1,
test1=0,
test2=0,
this can be dome even faster, and I think more easily read, using only base R
d1 <- data.frame(workshop=rep(1:2,4),
gender=rep(c("f","m"),each=4))
## needed by vector and rowbased, not needed by rmh
library(tibble)
library(plyr)
library(magrittr)
microbenchmark(
vector = {d1 %>
Dear Paul,
R's power is that is works vectorised. Unlike SAS which is rowbased. Using
R in a SAS way will lead to very slow code.
Your examples can be written vectorised
d1 %>%
rownames_to_column("ID") %>%
mutate(
test1 = ifelse(gender == "f" & workshop == 1, 7, 0),
test2 = ifelse(ge
Hello All,
Season's greetings!
Am trying to replicate some SAS code in R. The SAS code uses if-then-do code
blocks. I've been trying to do likewise in R as that seems to be the most
reliable way to get the same result.
Below is some toy data and some code that does work. There are some thing
6 matches
Mail list logo