Matching Data from Different columns / dataframes - Working in R -
here sample data
dataset id name reasonforlogin 123 tom work 246 timmy work 789 mark play dataset b id name reasonforlogin 789 mark work 313 sasha interview 000 meryl interview 987 dara play 789 mark play 246 timmy work
two datasets. same columns. uneven number of rows.
i want able
1)"i want of id numbers appear in both dataseta , datasetb"
or
2)"i want know how many times 1 id logs in on day, day 2."
so answer
1) list
[246, 789]
2) data.frame "header" of ids, , "row" of login numhbers.
123, 246, 789, 313, 000, 987 0, 1, 2, 1, 1, 1
it seems easy, think non-trivial large data. planned on doing loops-in-loops, i'm sure there has term these kind of comparisons , packages similar things.
if have a
first data set , b
second, , id
character column in both keep 000
being printed 0
, can ...
id
common both data sets:
intersect(a$id, b$id) # [1] "246" "789"
times id
logged in on second day (b
), including not logged in @ all:
table(factor(b$id, levels = unique(c(a$id, b$id)))) # 123 246 789 313 000 987 # 0 1 2 1 1 1
Comments
Post a Comment