2
例データ値:予想通り、それは仕事に縫い目はありませんしかしバイナリ列は
library(data.table)
setDT(df_stock2)
df_stock3 <- dcast(melt(df_stock2 , url = 'url')[value != 'NA'],
url ~ value, fun.aggregate = length)
:私はhereからコードを再現してみ
df_stock2 <-data.frame(url= c("https://www.example.com/test","https://www.example2.com/test","https://www.example3.com/test"), stock_yes_01 = c("Google","Microsoft","Yahoo"), stock_yes_02 = c("Yahoo","Google",NA))
。
これがなぜ機能しないのか、何を変更する必要があるのでしょうか?
エラー私が受け取る:
> setDT(df_stock2)
Warning message:
In melt.data.table(df_stock2, url = "url") :
To be consistent with reshape2's melt, id.vars and measure.vars are internally guessed when both are 'NULL'. All non-numeric/integer/logical type columns are conisdered id.vars, which in this case are columns [url, stock_yes_01, stock_yes_02, stock_yes_03, ...]. Consider providing at least one of 'id' or 'measure' vars in future.
df_stock3 <- dcast(melt(df_stock2, url = 'url')[value != 'NA'],
+ url() ~ value, fun.aggregate = length)
Error in url() : argument "description" is missing, with no default
In addition: Warning message:
In melt.data.table(df_stock2, url = "url") :
To be consistent with reshape2's melt, id.vars and measure.vars are internally guessed when both are 'NULL'. All non-numeric/integer/logical type columns are conisdered id.vars, which in this case are columns [url, stock_yes_01, stock_yes_02, stock_yes_03, ...]. Consider providing at least one of 'id' or 'measure' vars in future.
私はマイナーな改善を提案したいと思います。 'melt()'は、溶融データから 'NA'値を取り除くために使用できるパラメータ' na.rm'を持っています。したがって、 '[value!= 'NA']'は 'df_stock3 < - dcast(melt(df_stock2、id = 'url'、na.rm = TRUE)、 url_value、fun.aggregate = lengthで保存できます) ' – Uwe