Extract Function In R