can any one explain

i can understand rep("abcdef", 4)
even this also substr("abcdef", 2, 4)

but this one i know like 1:2 is to select from 1 to 2 index but i find it hard to relate with
substr(rep("abcdef", 4), 1:2,4:2)

?? substr

will pull up the help page for substr, which explains the role of the numeric arguments, which are the starting and ending index positions of the string to use. Then, work from the inside out to see how it works. 1:2 in the starting position means the first two characters, and 4:2 means the fourth through second characters, in that order.

rep("abcdef",4)
#> [1] "abcdef" "abcdef" "abcdef" "abcdef"
substr(rep("abcdef", 4),1,2)
#> [1] "ab" "ab" "ab" "ab"
substr(rep("abcdef", 4),1:2,3)
#> [1] "abc" "bc"  "abc" "bc"
substr(rep("abcdef", 4), 1:2,4:2)
#> [1] "abcd" "bc"   "ab"   "bcd"
1 Like

thnx like cross multiplication right

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.