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.)\\.(..)"))
Which was based off an answer from hadley here.
But I get the error:
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.
thanks!