Differences between length and nchar in R

length(x) will give how many elements are there in a vector.
nchar(x) will give how many letters in each element of x.

Examples:

Create Two Vectors:

> x< -c(5:15) --X Vector with integer type > x [1] 5 6 7 8 9 10 11 12 13 14 15 > y< -c(9:19,"Hello World") --y vector with string data type > y [1] "9" "10" "11" "12" "13" "14" "15" "16" [9] "17" "18" "19" "Hello World" > length(x) [1] 11 --x vector contains 11 elements > length(y) [1] 12 --y vector contains 12 elements > nchar(x) --This will give each element length of vector x [1] 1 1 1 1 1 2 2 2 2 2 2 > nchar(y) --This will give each element length of vector y [1] 1 2 2 2 2 2 2 2 2 2 2 11

Related Posts

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools