r - Merging two data frames with different sizes and missing values -
i'm having problem merging 2 data frames in r.
the first 1 consists of 103731 obs of 6 variables. variable have use merge has 77111 unique values , rest na
s value of 0. second 1 contains frequency of variables plus frequency of na
s frame of 77112 obs 2 variables.
the resulting frame need first 1 joined frequency merging variable, df of 103731 obs frequency each value of merging variable (so duplicates if freq > 1 , each na
(or 0)).
can me?
the result i'm getting contains data frame of 1 894 919 obs , used:
tot = merge(df1, df2, = "mergingvar", all= f, sort = f);
also played lot 'all=
' , none of variations gave right df.
why don't take frequency table of first table?
a <- data.frame(a = c(na, na, 2,2,3,3,3)) data.frame(table(a, usena = 'ifany')) freq 1 2 2 2 3 3 3 <na> 2
or mutate
plyr
ddply(a, .(a), mutate, freq = length(a)) freq 1 2 2 2 2 2 3 3 3 4 3 3 5 3 3 6 na 2 7 na 2
Comments
Post a Comment