-1
我有一個包含100列(名稱爲Col_1,Col_2 ... Col_100)的數據集,其結果如下:「A」,「B」,「C」...我不知道所有數據集中都有很多不同的字符。我想每個值轉換爲一個列有這樣一個矩陣:將多項式轉換爲二項式 - 數千列
A B C D
0 1 0 1
1 1 0 1
我這個嘗試:
library(reshape2)
train <- read.csv("train.csv",head=TRUE,sep=",")
train
recast(train, id ~ value, id.var = 1, fun.aggregate = function(x) (length(x) > 0) + 0L)
但我發現了以下錯誤:
Error in eval(substitute(expr), envir, enclos) :
n must be a positive integer
In addition: Warning messages:
1: attributes are not identical across measure variables; they will be dropped
2: In split_indices(.group, .n) :
NAs introduced by coercion to integer range
我能做些什麼來返回我想要的表格?
@Imo感謝您的答覆。我將所有值都設爲N/A,是正常的嗎? –
用我提供的例子,或者你的原始數據集?如果使用原始數據集,那麼至少應該提供'str(df)'的前10行,其中df是data.frame的名稱。 – lmo
我該怎麼做?對不起,我在R –