R中提取函数中的Regex参数

时间:2017-05-08 18:39:49

标签: r regex

根据Gather multiple sets of columns中的解决方案,我试图收集多组列。我想收集的所有专栏都有一年的结束。 column.name.2010, column.name.2011, column.name.2012, column.name2.2010, column.name2.2011, column.name2.2012 etc.

我试过

db %>%
  gather(key, value, -c(1:6)) %>%
  extract(key, c("question", "Year"), "([^\d{4}]+)") %>%
  spread(question, value)

我想做到这一点:

Id Index.number Country.Name World.Rank.by.Assets Year  column.name. column.name2.
1    a            3              6                 2010    xxxx          xxy
2    b            4              6                 2011    xxyx          xyy
3    c            5              8                 2012    xxxs          sada

db负责人

     Id Index.number Country.Name World.Rank.by.Assets Total.Assets.th.EUR.2010 Total.Assets.th.EUR.2011
1 10931        10931            9                    6                     n.a.            1,965,283,000
2 10696        10696            9                    9                     n.a.            1,879,536,000
3 11948        11948            9                   13                     n.a.            1,723,608,000
4 11150        11150            9                   19                     n.a.            1,181,372,000
5 10708        10708            9                   NA                     n.a.            1,138,395,000
  Total.Assets.th.EUR.2012 Total.Assets.th.EUR.2013 Total.Assets.th.EUR.2014 Total.Assets.th.EUR.2015
1            1,907,200,000            1,810,522,000            2,077,759,000            1,994,193,000
2            1,783,220,000            1,688,264,000            1,762,714,000            1,698,859,000
3            1,617,429,000            1,518,811,000            1,589,044,000            1,529,294,000
4            1,250,889,000            1,214,193,000            1,308,138,000            1,334,391,000
5            1,147,521,000            1,123,520,000            1,223,298,000            1,166,535,000
  Total.Assets.th.EUR.2016 Deposits...Short.term.funding.th.EUR.2010
1            2,076,959,000                                      n.a.
2            1,722,849,000                                      n.a.
3            1,524,232,000                                      n.a.
4            1,382,241,000                                      n.a.
5            1,235,240,000                                      n.a.
  Deposits...Short.term.funding.th.EUR.2011 Deposits...Short.term.funding.th.EUR.2012
1                               947,516,000                               942,644,000
2                               917,933,000                               928,045,000
3                               808,028,000                               805,504,000
4                               452,417,000                               540,628,000
5                               604,912,000                               661,297,000
  Deposits...Short.term.funding.th.EUR.2013 Deposits...Short.term.funding.th.EUR.2015
1                               942,387,000                             1,032,100,000
2                               911,884,000                               891,035,000
3                               789,353,000                               796,777,000
4                               523,624,000                               673,520,000
5                               692,997,000                               707,185,000
  Deposits...Short.term.funding.th.EUR.2014 Deposits...Short.term.funding.th.EUR.2016
1                             1,031,624,000                             1,111,246,000
2                               890,072,000                               903,317,000
3                               773,094,000                               759,184,000
4                               587,177,000                               687,328,000
5                               740,298,000                               761,140,000
  Loan.loss.res...Gross.loans...2010 Loan.loss.res...Gross.loans...2011 Loan.loss.res...Gross.loans...2012
1                               n.a.                               4,04                               4,05
2                               n.a.                               3,55                               3,16
3                               n.a.                               4,53                               3,77
4                               n.a.                               4,21                               4,26
5                               n.a.                               1,96                               2,03

0 个答案:

没有答案