use table instead of sapply