m******t 发帖数: 273 | 1 【 以下文字转载自 Quant 讨论区 】
发信人: myregmit (myregmit), 信区: Quant
标 题: load data to a dictionary in R
发信站: BBS 未名空间站 (Sun Mar 16 20:45:51 2014, 美东)
I need to load data from a .csv file and then save it in a dictionary in R.
The data format:
country,region,value
Each row may have different country and region.
I need to save the value with the same country and region together.
Any help would be appreciated. | O*********h 发帖数: 140 | 2 你说的dictionary是python的dict吗?R中相对应的data structure是list。
如果是的话,你的需求可以通过两步实现:
1. temp.data.frame <- read.csv("your_name.csv")
2. result.list <- split(x = temp.data.frame, f = "split_factor")
如果country间region不重名,region可以直接用作split_factor。否
则,你需要在temp.data.frame中加入个新的 “country * region”
split_factor。 | C******y 发帖数: 2007 | 3 有hash package,可以实现hashmap功能,不过我用过,速度很慢。最好自己写一个 |
|