Replacement Behaviors By Function In R