我对LendingClub的历史数据感兴趣,LendingClub是最大的P2P借贷公司。
这是一个非标准化的压缩CSB文件,但在Excel中打开时可以通过删除第1行,第39789-39791号和第42543-42544行轻松修复,如何在R中自动执行? (如果您想提供帮助,但担心这可能是恶意链接,请先将Google这家公司联系起来)
我尝试了以下内容:
data <- read.csv(url("https://resources.lendingclub.com/LoanStats3a.csv.zip"))
但它会引发错误:
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
duplicate 'row.names' are not allowed
答案 0 :(得分:2)
你可以使用skip
来越过第一个“垃圾”行,但是你需要处理导入后的末尾有~4个“垃圾”行:
dat <- read.csv("LoanStats3a.csv", skip=1, header=TRUE, stringsAsFactors=FALSE)
str(dat)
## 'data.frame': 42538 obs. of 96 variables:
## $ id : chr "1077501" "1077430" "1077175" "1076863" ...
## $ member_id : int 1296599 1314167 1313524 1277178 1311748 1311441 1304742 1288686 1306957 1306721 ...
## $ loan_amnt : int 5000 2500 2400 10000 3000 5000 7000 3000 5600 5375 ...
## $ funded_amnt : int 5000 2500 2400 10000 3000 5000 7000 3000 5600 5375 ...
## $ funded_amnt_inv : num 4975 2500 2400 10000 3000 ...
## $ term : chr " 36 months" " 60 months" " 36 months" " 36 months" ...
## $ int_rate : chr " 10.65%" " 15.27%" " 15.96%" " 13.49%" ...
## $ installment : num 162.9 59.8 84.3 339.3 67.8 ...
## $ grade : chr "B" "C" "C" "C" ...
## $ sub_grade : chr "B2" "C4" "C5" "C1" ...
## $ emp_title : chr "" "Ryder" "" "AIR RESOURCES BOARD" ...
## $ emp_length : chr "10+ years" "< 1 year" "10+ years" "10+ years" ...
## ... (a bunch more variables, some are all NA)