CopyPastor

Detecting plagiarism made easy.

Score: 0.8103902339935303; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-07-05
by MHammer

Original Post

Original - Posted on 2012-03-11
by 2mia



            
Present in both answers; Present only in the new answer; Present only in the old answer;

While there may be more elegant solutions, using `dplyr::case_when()` gives you the flexibility to code things however you want:
library(dplyr)
df %>% dplyr::mutate( no_stars = dplyr::case_when( no_stars1 == 1 ~ 1, no_stars2 == 1 ~ 2, no_stars3 == 1 ~ 3) , satisfactory = dplyr::case_when( average == 1 ~ 2, satisfied == 1 ~ 3, bad == 1 ~ 1) ) # items no_stars1 no_stars2 no_stars3 average satisfied bad no_stars satisfactory # 1 A 1 0 0 0 0 1 1 1 # 2 B 0 1 0 1 0 0 2 2 # 3 C 0 0 1 0 1 0 3 3 # 4 D 0 1 0 0 1 0 2 3 # 5 E 0 0 1 1 0 0 3 2 # 6 F 0 0 1 0 1 0 3 3 # 7 G 1 0 0 0 0 1 1 1
Just out of curiosity I've taken a look at what happens under the hood, and I've used [dtruss/strace][1] on each test.
C++
./a.out < in Saw 6512403 lines in 8 seconds. Crunch speed: 814050
syscalls `sudo dtruss -c ./a.out < in`
CALL COUNT __mac_syscall 1 <snip> open 6 pread 8 mprotect 17 mmap 22 stat64 30 read_nocancel 25958

Python
./a.py < in Read 6512402 lines in 1 seconds. LPS: 6512402
syscalls `sudo dtruss -c ./a.py < in`
CALL COUNT __mac_syscall 1 <snip> open 5 pread 8 mprotect 17 mmap 21 stat64 29
[1]: http://en.wikipedia.org/wiki/Strace

        
Present in both answers; Present only in the new answer; Present only in the old answer;