我可以将数据作为一个篮子列表而不是像这样的URL中的数据框读取:
url <- "http://www.salemmarafi.com/wp-content/uploads/2014/03/groceries.csv"
baskets <- strsplit(readLines(url), ",", fixed=TRUE)
> head(baskets,2)
[[1]]
[1] "citrus fruit" "semi-finished bread" "margarine" "ready soups"
[[2]]
[1] "tropical fruit" "yogurt" "coffee"
但是当我尝试通过从文件加载数据来完成相同的操作时,结果是:
baskets2 <- strsplit(readLines("groceries.csv"), ",", fixed=TRUE)
> head(baskets2,2)
[[1]]
[1] "citrus fruit;semi-finished bread;margarine;ready soups;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
[[2]]
[1] "tropical fruit;yogurt;coffee;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
用“;”它是:
> baskets2 <- strsplit(readLines("groceries.csv"), ";", fixed=TRUE)
> head(baskets2,2)
[[1]]
[1] "citrus fruit" "semi-finished bread" "margarine" "ready soups"
[5] "" "" "" ""
[9] "" "" "" ""
etc
如何从我的计算机上的文件中加载数据(即C:/mathath/groceries.csv),因为它是从URL加载的,即没有空项“;;;;”?
*编辑:这只是一个csv,我试图避免将其加载到数据框中。