我从链接Hearthstone Arena Card Pickup probability中获得了一个CSV文件
现在这只是向量列表,我想转换成9列数据框。因此可能看起来像:
我当前的代码如下,但是根本不起作用。
hsd <- read.csv("hearthstonedraw.csv", header = TRUE)
hsd1 <- as.data.frame(hsd,ncol = 9)
hsd1
答案 0 :(得分:0)
答案发给了莫里斯·埃弗斯(Maurits Evers)和亚当·桑普森(Adam Sampson)。
read.csv
可以从您指定的地址读取内容,并自动将character
列转换为因子(默认行为)以及计算列数。
hsd1 <- read.csv("https://bnetcmsus-a.akamaihd.net/cms/gallery/LN4X4GN4W59R1532566073433.csv", header = TRUE)
str(hsd1)
# 'data.frame': 3931 obs. of 9 variables:
# $ Draft.Class : Factor w/ 9 levels "Druid","Hunter",..: 1 1 1 1 1 1 1 1 1 1 ...
# $ Card.Name : Factor w/ 995 levels "Abominable Bowman",..: 716 813 646 500 263 964 549 186 509 984 ...
# $ Rarity : Factor w/ 5 levels "basic","common",..: 1 1 2 2 2 1 1 2 5 2 ...
# $ Type : Factor w/ 3 levels "Minion","Spell",..: 2 2 2 2 1 2 2 1 2 2 ...
# $ Card.Class : Factor w/ 10 levels "druid","hunter",..: 1 1 1 1 1 1 1 1 1 1 ...
# $ Average : num 1.47 1.45 1.44 1.17 1.03 ...
# $ P.1.or.more.: num 0.78 0.776 0.774 0.696 0.649 ...
# $ P.2.or.more.: num 0.436 0.431 0.428 0.327 0.273 ...
# $ P.3.or.more.: num 0.1784 0.1757 0.1724 0.1081 0.0819 ...
ncol(hsd1)
# [1] 9
# There are 9 columns in the data frame