Recognizing several IDs in a complicated String with R

I have a data frame with a lot of character strings and a value like this ID String Value 1 LocationID=123,321,345&TimeID=456,321,789&TypeID=12,32 100 2 LocationID=123,345&TimeID=456,321 50 3 LocationID=123,321,345&TypeID=32 120 ... As you may see in the example, the "," means "or". So locationID=123,321,345 refers to those elements that have location ID 123, 321, or 345. and the "value" can be thought as the numbers of entries that satisfied the String. I want to write a program to calculate the number of occurrences of each ID using R. i.e. the output of the program should be: ID Occurrence LocationID = 123 270 #(100+50+120) LocationID = 321 220 #(100+120) ... TypeID = 12 100 ... Can anyone give me some suggestion on how to do this task? I found it is very difficult to deal with the "," and the IDs. Otherwise I can use for loop, though I hate for loop..... A further problem, the ID should allow empty or character, like this: ID String Value 1 LocationID=123,321,345&TimeID=456,321,789&TypeID= 100 2 LocationID=123,345&TimeID=&TypeID=A 50 3 LocationID=123,321,345&TypeID=32 120

以上就是Recognizing several IDs in a complicated String with R的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏