如果您需要获得“ y”的订单,无论是数字还是字符:x[order(ordered(x, levels = y))]4 4 4 2 2 1 3 3 3步骤:a <- ordered(x, levels = y) # Create ordered factor from "x" upon order in "y".[1] 2 2 3 4 1 4 4 3 3Levels: 4 < 2 < 1 < 3b <- order(a) # Define "x" order that match to order in "y".[1] 4 6 7 1 2 5 3 8 9x[b] # Reorder "x" according to order in "y".[1] 4 4 4 2 2 1 3 3 3