I have a data.frame shaped like:
c <- data.frame(name=c("a", "a", "b", "b", "c", "c","d","d"), value=c(1,3,2,4,5,3,4,5), address=c("rrrr","rrrr","zzzz","aaaa","ssss","jjjj","qqqq","qqqq"))
> c
name value address
1 a 1 rrrr
2 a 3 rrrr
3 b 2 zzzz
4 b 4 aaaa
5 c 5 ssss
6 c 3 jjjj
7 d 4 qqqq
8 d 5 qqqq
I am trying to split this data frame into two separate data frames according to one simple rule: group together people who didn't change address and group together people that changed address. Any hint on how to accomplish the task?
So far I am playing, with no avail, with:
for(i in seq(1,8, by=2)){
print(i)
print(unlist(c[which(c[i,3]==c[(i+1),3]),]))
}
This counts the number of addresses and splits on that basis. There is a hurdle to get over and it related to always getting
<NA>
fromave
until usingas.character
. There was a warning message from which I'm copying the beginning, so searchers might be able to find this:The successful version (using a data-object named
cc
):If you really wanted a bipartite split then convert to logical with
> 1
:I don't understand the comment. This is what I get as
str(dat)
: