2017-01-30 132 views
-1

我想在下面的數據框中的「Delta = delta」和「Card = vars」之間插入一個空白欄。我還想在數據框中對列「Model_Avg_Error」的輸出進行排序。在數據框中插入空白欄

df = data.frame(Card = vars, Model_Avg_Error = model_error, Forecast = forecasts, Delta = delta, ,Card = vars, Model_Avg_Error = model_error, 
       Forecast = forecasts, Delta = delta) 

# save 
write.csv(df, file = file.path(proj_path, "output.csv"), row.names = F) 

這是從上面接收到的錯誤:在data.frame

錯誤(卡= VARS,Model_Avg_Error = model_error,預測=預測,: 參數丟失,沒有默認值

+0

是否有一些具體的事情你已經嘗試過,沒有工作 – joran

+0

請嘗試創建一個[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。發佈您的數據樣本或創建[示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 –

+0

是的,我只用一個空格,用逗號Delta = delta,Card = vars, – ZJAY

回答

1

您可以添加空白列,重新排序,排序和使用下面的代碼:

df$blankVar <- NA #blank column 
df[c("Card", "blankVar", "Model_Avg_Error", "Forecast", "Delta")] #re-ordering columns by name 
df[order(df$Model_Avg_Error),] #sorting by Model_Avg_Error