【发布时间】:2015-11-24 14:30:34
【问题描述】:
如何将 csv 文件转换为本机 hadoop 格式,以便可以将其与 plyrmr 包一起使用?
这个问题与我的另一个帖子有关:
How to read files in HDFS in R without loosing column and row names
我有 csv 格式的 mtcar,但是当我使用以下代码阅读它时它不起作用:
filename3 <- "/user/sgerony/mtcars.csv" #file uploaded manually on to the HDFS
input(filename3) ## DOES NOT WORK
当我使用以下代码阅读它时,它可以工作,但我丢失了列名:
input(filename3,format=make.input.format(format = "csv", sep=",")) ## works
结果:
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12
1 Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3 4
2 Fiat 128 32.4 4 78.7 66 4.08 2.2 19.47 1 1 4 1
3 Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
4 Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.9 1 1 4 1
考虑到 github 上的 plyrmr 教程显示的内容,这已经很奇怪了。
所以我受到以下代码的启发,该代码将 mtcars 写入 HDFS 并读回以查看列名是否保留:
output(
bind.cols(
input(mtcars),
carb.per.cyl = carb/cyl),
path="/user/sgerony/mtcars0.out")
结果:
mpg cyl disp hp drat wt qsec vs am gear carb carb.per.cyl
1 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 0.6666667
2 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 0.6666667
3 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 0.2500000
4 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 0.1666667
然后:
x=output(
bind.cols(
input(mtcars),
carb.per.cyl = carb/cyl),
path="/user/sgerony/mtcars0.out")
get.format(x)
结果:
"native"
有什么想法吗?
【问题讨论】: