【发布时间】:2019-12-29 00:13:22
【问题描述】:
我正在处理看起来像这样的数据:
AF: AU:
1 MIT Duflo, Esther
2 NBER; NBER Freeman, Richard B.; Gelber, Alexander M.
3 U MI; Cornell U; U VA Bound, John; Lovenheim, Michael F.; Turner, Sarah
4 Harvard U; U Chicago Fryer, Roland G., Jr.; Levitt, Steven D.
5 U OR; U CA, Davis; U British Columbia Lindo, Jason M.; Sanders, Nicholas J.; Oreopoulos, Philip
我有两个变量,AF:代表隶属关系,AU:代表作者。不同的作者和隶属关系用分号分隔,我想使用separate_rows-command 并创建这样的东西:
AF: AU:
MIT Duflo, Esther
NBER Freeman, Richard B.
NBER Gelber, Alexander M.
U MI Bound, John
Cornell U Lovenheim, Michael F.
U VA Turner, Sarah
Harvard U; Fryer, Roland G., Jr.
U Chicago Levitt, Steven D.
U OR Lindo, Jason M.
U CA, Davis Sanders, Nicholas J.
U British ColumbiaOreopoulos, Philip
separate_rows() 的标准版本会生成错误消息,可能是因为我的数据包含 NA:
authaf_spread<-separate_rows(authaf, 1:2, sep=";")
Error: All nested columns must have the same number of elements.
我下载并安装了开发版,这只是给了我另一个错误消息:
authaf_spread<-separate_rows(authaf, 1:2, sep=";")
Error: No common size for `AF:`, size 3, and `AU:`, size 4.
Call `rlang::last_error()` to see a backtrace
这是什么意思,我该如何规避这个错误?
如果有人感兴趣,我附上整个文件的链接:
https://www.dropbox.com/s/z456w7ll7v7o79z/authors_affiliations.csv?dl=0
【问题讨论】:
标签: r tidyr data-cleaning