如何删除数据框中的标题? [英] How do you delete the header in a dataframe?
问题描述
我想从我拥有的数据框中删除标题。我从csv文件读入数据,然后转换它,但它创建了一个新的头文件,它是文件的名称和数据来自文件的行。
以下是一个数据框df的示例:
a.csv.1 a.csv.2 a.csv。 3 ...
x 5 6 1 ... $ b $ 2 3 2 ...
我想删除a.csv.n行,但是当我尝试 df < - df [-1,]
时,它将删除行x而不是顶部。
如果你确实真的不喜欢列名,你可以将你的数据框转换为矩阵记住不同 class
的变量的可能强制),然后删除 dimnames
。
dd < - data.frame(x1 = 1:5,x2 = 11:15)
mm1< - as.matrix(dd )
mm2< - 矩阵(mm1,ncol = ncol(dd),dimnames = NULL)
我也在这里添加了我以前的评论:
?data.frame
:列名应该是非空的,并尝试使用空名称将产生不受支持的结果。
I want to delete the header from a dataframe that I have. I read in the data from a csv file then I transposed it, but it created a new header that is the name of the file and the row that the data is from in the file.
Here's an example for a dataframe df:
a.csv.1 a.csv.2 a.csv.3 ...
x 5 6 1 ...
y 2 3 2 ...
I want to delete the a.csv.n row, but when I try df <- df[-1,]
it deletes row x and not the top.
If you really, really, really don't like column names, you may convert your data frame to a matrix (keeping possible coercion of variables of different class
in mind), and then remove the dimnames
.
dd <- data.frame(x1 = 1:5, x2 = 11:15)
mm1 <- as.matrix(dd)
mm2 <- matrix(mm1, ncol = ncol(dd), dimnames = NULL)
I add my previous comment here as well:
?data.frame
: "The column names should be non-empty, and attempts to use empty names will have unsupported results.".
这篇关于如何删除数据框中的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!