R语言中如何将列表转为Schema对象?Arrow包11.0.0.2报错求助
解决Arrow包中列表转Schema对象的问题
在Arrow 11.0.0.2版本中,确实可以将你生成的列表转换为Schema对象,有两种可行方式:
方式一:直接创建Schema对象(推荐)
不用先生成列表,直接用Schema$create()方法定义Schema,能直接得到Schema类对象:
schema <- Schema$create( `Key` = int64(), Sex = string(), `Age` = int64(), `Date of Birth` = date32(), `Institution` = string(), `Admission Date` = date32(), `Discharge Date` = date32(), `Elderly Home` = string(), `Paycode` = string() ) class(schema) # 输出:[1] "Schema"
方式二:将已有的列表转换为Schema对象
如果已经得到了那个列表,用as_schema()函数或者Schema$create()传入列表即可完成转换:
# 假设你已经有了这个列表 schema_list <- list( `Key`=int64(), Sex = string(), `Age` = int64(), `Date of Birth` = date32(), `Institution` = string(), `Admission Date` = date32(), `Discharge Date` = date32(), `Elderly Home` = string(), `Paycode` = string() ) # 方法1:用as_schema转换 schema <- as_schema(schema_list) # 方法2:用Schema$create传入列表 schema <- Schema$create(schema_list) class(schema) # 输出:[1] "Schema"
你之前用schema(...)得到列表,是因为该版本中这个调用方式返回的是字段列表而非Schema实例,改用上面的方法就能解决报错问题。
内容的提问来源于stack exchange,提问作者doraemon
相关产品推荐
相关产品推荐

