我有一個CSV文件這樣遍歷數據幀,並追加到一個新的空單
a b c
1 2 'some string1'
1 54 'some string2'
2 87 'some string3'
3 18 'some string4'
我需要遍歷每個數據和複製數據彼此的數據幀。所以我需要這樣的東西
df <- read.csv("example.csv", sep='\t', header=TRUE)
new_df <- data.frame(a=NA, b=NA, c=NA)
for (row in df){
#some calculation here then
append(row to new_df)
}
save the new_df to a new csv.
我該怎麼做?我找到了很多解決方案,但都讓我感到困惑。
'DF = rbind(DF,the.new.row.to.append)' – Onyambu
我認爲OP想追加到一個新的空白數據框,而不是原始數據框。 – neilfws