Length and subsetting by multiple conditions

1.2k Views Asked by At

So I have this data set in Excel (two column names are Col1 and Col2) Col1<-c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,4,4,5,6,6,6,6,7,7,7,8,9) (are numbers of different sellers (and must be duplicated) and Col2 which consist of names and this names are assigned to these numbers so

1=Mazda
2=BWM
3=Opel
4=Citroen
5=Fiat
6=Porsche
7=Audi
8=Dacia
9=Lexus

So now I would like to find out unique length of seller 1 by subsetting.

I have tried this

length(subset(data.set, Col2 == "Mazda")) 

but this gave me length of Mazda and I need to find out length of Col1 by Col2=Mazda

I am missing something here:

length(unique(subset(data.set, Col2 == "Mazda" & ......)))
1

There are 1 best solutions below

0
On

can't really figure out what you need but I'm sure filter from dplyr will suit your needs

filter(df, col2 == "Mazda", col1 == "10")