在 tidyr 中使用正则表达式的问题 [英] Issue with using regular expressions in tidyr

查看:24
本文介绍了在 tidyr 中使用正则表达式的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数据是刚刚问的问题这里,我想使用 extract() 使用 tidyr 传播数据.

Using data is a question just asked here, I wanted to spread the data using tidyr using extract().

df<-read.table(header=T,text=
                "id m1      m2     m3
 P001.st   60.00   2.0     1
 P003.nd   14.30   2.077   1
 P003.rt   29.60   2.077   1
 P006.st   10.30   2.077   1
 P006.nd   79.30   2.077   1
 P008.nd    9.16   2.077   1")

df %>% 
  extract(id, c("id2", "var"), c("(P00.)\\.(..)"))

这是基于 hadley 此处的回答.

Which was based off an answer from hadley here.

但我收到错误:

Error in drop && length(x) == 1L : invalid 'x' type in 'x && y'

我通常不使用正则表达式,但想开始使用,所以如果有人能帮助我理解我失败的地方,我将不胜感激.

I don't normally use regular expressions, but would like to start to, so if someone could help me understand where I'm failing, it'd be much appreciated.

谢谢!

推荐答案

可能你的脚本也在加载 magrittr after loading tidyr 但你忘了提.

Probably your script is loading also magrittr after loading tidyr but you forgot to mention.

所以你实际上是在引用 magrittr::extract 而不是 tidyr::extract.

So you are actually referencing magrittr::extract instead of tidyr::extract.

你可以

  1. 加载 magrittr before 加载 tidyr;或
  2. 明确引用tidyr::extract.
  1. Load magrittr before loading tidyr; or
  2. Reference tidyr::extract explicitly.

两者都必须有效.

这篇关于在 tidyr 中使用正则表达式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆