[R] sub('^','var',1:3) produces unexpected results

David Forrest drf5n at maplepark.com
Tue Mar 22 22:02:20 CET 2005


Hi,

According to help(sub), the ^ should match the zero-length string at the
beginning of a string:

sub('^','var',1:3) # "1" "2" "3"
sub('$','var',1:3) # "1var" "2var" "3var"

# This generates what I expected from the first case:
sub('^.','var',11:13)  # "var1" "var2" "var3"

Dave
-- 
 Dr. David Forrest
 drf at vims.edu                                    (804)684-7900w
 drf5n at maplepark.com                             (804)642-0662h
                                   http://maplepark.com/~drf5n/




More information about the R-help mailing list