![](/img/trans.png)
[英]Convert 3 columns dataframe to a matrix - Change the names of similar column
[英]How to convert dataframe to matrix without column names
我想將數據幀轉換為僅數字矩陣。 我的目標:
num [1:3,1:4] 1 2 3 1 2 3 1 2 3 1 ...
就這樣。
alpha <- beta <- gamma <- delta <- c(1,2,3)
df <- data.frame(alpha, beta, gamma, delta, stringsAsFactors = FALSE)
M1 <- as.matrix(df, ncol = ncol(df))
str(M1)
M2 <- data.matrix(df)
str(M2)
num [1:3,1:4] 1 2 3 1 2 3 1 2 3 1 ... - attr(*,“dimnames”)= 2的清單
.. $:NULL
.. $:chr [1:4]“alpha”“beta”“gamma”“delta”
我不能為我的生活弄清楚如何在沒有所有屬性的情況下做到這一點。 我需要純形式作為另一種方法的輸入。
@thelatemail是完全正確的。
unname(as.matrix(DF
訣竅。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.