Example data:
Sales <- data.frame(Appliance = c("Laptop", "TV", "Fridge","TV", "TV", "TV","Laptop", "Laptop", "Radio"), ID=c( "1", "1", "1", "1", "2", "2", "2", "3", "3"))
IDLocation <-data.frame(ID=1, Location="UK")
I join the two tables using a inner join:
IDLocationSales<-merge(Sales, IDLocation, by.x="ID", by.y="ID")
I then create a table to show the count of IDs from the table created from the inner join.
CountofIDs<-table(IDLocationSales$ID, dnn=("CountOfIDs"))
View(CountofIDs)
The problem is that in the CountofIDs table it includes all the IDs (1-3) when in the actual table that I created as a result of the merge (IDLocationSales), there is only ID no. 1 present. It is only the sales table that has IDs 1-3 in there. How can I create the CountofIDs table that only references the data that is actually in the merged table?