?sample里说得很清楚了
If x has length 1, is numeric (in the sense of is.numeric) and x >= 1, sampling via sample takes place from 1:x. Note that this convenience feature may lead to undesired behaviour when x is of varying length in calls such as sample(x). See the examples.
某些情况方便,某些情况奇怪。
如果你真的只对变量a抽一次,as.numeric(sample(as.character(a),1))应该可以满足你的要求,如果抽一次以上应该写上replace=T避免报错。