Related questions
Select the first row by group
From a dataframe like this
test <- data.frame('id'= rep(1:5,2), 'string'= LETTERS[1:10])
test <- test[order(test$id), ]
rownames(test) <- 1:10
> test
id string
1 1 A
2 1 F
3 2 B
4 2 G
5 3 C
6 3 H
7 4 D
8 4 I
9 5 E
10 5 J
I …
Summarize with conditions in dplyr
I'll illustrate my question with an example.
Sample data:
df <- data.frame(ID = c(1, 1, 2, 2, 3, 5), A = c("foo", "bar", "foo", "foo", "bar", "bar"), B = c(1, 5, 7, 23, 54, 202))
df
ID A B
1 1 foo 1
2 1 bar 5
3 2 foo 7
4 2 foo 23
5 3 bar 54
6 5 bar 202
What I want to …
SQLDF Left Join in R
My goal is to take 'matr', sort it by column c1, and keep unique(c1) where c2 = 1. For example, from this code...
c1 = c("a",'a','a','b','b','b','b','c','c')
c2 = c(1,1,0,1,1,0,1,0,0)
matr = as.data.frame(cbind(…