Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想逐行迭代一个csv。通常我会使用 read.csv,问题是,我没有典型的标题,名称不在第一行而是在第一列。
例如:
name1 1 2 3 name2 6 9 0 name3 8 7 0
...
有办法吗?
您可以将其读入read.csv()然后转置:
read.csv()
df = read.csv('row_csv.csv', sep=' ', header=FALSE, row.names=1) df_fixed = data.frame(t(df))
完成后,您可以删除行名以使其恢复正常:
rownames(df_fixed) = NULL df_fixed
结果:
name1 name2 name3 1 1 6 8 2 2 9 7 3 3 0 0