I had two data frames one with information about ProductId
, Price
, Location
and other data frame with ProductId
and Name
. So I merged them together using following command.
DF1$Name <- names$Name[match(DF1$ProductId,names$ProductId)];
And it worked fine. Then I took a subset of the DF1 based on certain Location like this
DF_London = subset(DF1, Location == "London")
In DF1
Names
had 100 Levels, In DF_London
it should have 25 Levels and by using unique
and length
I can see it. But in str(DF_London)
it shows 100 Levels of Names
and when i try to draw table like
with(DF_London,table(Names, Price)
It shows a table with 100 rows and many of these rows have all zero values because obviously those names don't exist in DF_London
data frame.
So how can I either fix the number of Level for Names in DF_London or delete the zero rows?
Sorry for not providing the reproducible example.