With a data frame df1
like below
+-----------------------------------------+
|reg |make |model |year|abs |gears|fm|
+-----------------------------------------+
|ax1234|Toyota|Corolla|1999|true |6 |0 |
|ax1235|Toyota|Corolla|1999|false|5 |0 |
|ax1236|Toyota|Corolla|1992|false|4 |NA|
|ax1237|Toyota|Camry |2001|true |7 |1 |
|ax1238|Honda |Civic |1994|true |5 |NA|
|ax1239|Honda |Civic |2000|false|6 |0 |
|ax1240|Honda |Accord |1992|false|4 |NA|
|ax1241|Nissan|Sunny |2001|true |6 |0 |
|ax1242| | |1998|false|6 |0 |
|ax1243|NA |NA |1992|false|4 |NA|
+-----------------------------------------+
On aggregation like below, I want to preserve make
s with NA
- how to achieve this ? It is fine to have the make
and NA
are combined together.
> aggregate(reg ~ make, df1, length)
make reg
1 1
2 Honda 3
3 Nissan 1
4 Toyota 4