Renaming columns after reshape in R -
i used line of code transpose dataset:
b2<-reshape(b1,timevar="species",idvar="pointid",direction="wide")
and ended this:
point final$count.tot.spec1 final$count.tot.spec2 ... final$count.tot.spec99 1 1 2 ... 0 2 3 0 ... 0
i want rename columns after "point" removing "final$count.tot." names, have:
point spec1 spec2 ... spec99 1 1 2 ... 0 2 3 0 ... 0
i have tried using this:
names(b2)<-gsub("final$count.tot.","",names(b2))
but gets hung on non-characters. i've searched stack overflow have not found solution works case. appreciated.
$
special character in regular expressions (determines line ending, see ?regexp
). have use \\$
or set fixed=true
(see ?gsub
):
x <- c("point", "final$count.tot.spec1", "final$count.tot.spec2") gsub("final$count.tot.", "", x=x, fixed=true) # [1] "point" "spec1" "spec2"
Comments
Post a Comment