length package:base R Documentation _L_e_n_g_t_h _o_f _a_n _O_b_j_e_c_t _D_e_s_c_r_i_p_t_i_o_n: Get or set the length of vectors (including lists) and factors, and of any other R object for which a method has been defined. _U_s_a_g_e: length(x) length(x) <- value _A_r_g_u_m_e_n_t_s: x: an R object. For replacement, a vector or factor. value: an integer. _D_e_t_a_i_l_s: Both functions are generic: you can write methods to handle specific classes of objects, see InternalMethods. 'length<-' has a '"factor"' method. The replacement form can be used to reset the length of a vector. If a vector is shortened, extra values are discarded and when a vector is lengthened, it is padded out to its new length with 'NA's ('nul' for raw vectors). These functions are primitive, so argument names are ignored (but this might not be true of their methods). _V_a_l_u_e: The default method currently returns an 'integer' of length 1. Since this may change in the future and may differ for other methods, programmers should not rely on it. (Should the length exceed the maximum representable integer, it is returned as 'NA'.) For vectors (including lists) and factors the length is the number of elements. For an environment it is the number of objects in the environment, and 'NULL' has length 0. For expressions and pairlists (including language objects and dotlists) it is the length of the pairlist chain. All other objects (including functions) have length one: note that for functions this differs from S. The replacement form removes all the attributes of 'x' except its names. _R_e_f_e_r_e_n_c_e_s: Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_. Wadsworth & Brooks/Cole. _S_e_e _A_l_s_o: 'nchar' for counting the number of characters in character vectors. _E_x_a_m_p_l_e_s: length(diag(4))# = 16 (4 x 4) length(options())# 12 or more length(y ~ x1 + x2 + x3)# 3 length(expression(x, {y <- x^2; y+2}, x^y)) # 3 ## from example(warpbreaks) require(stats) fm1 <- lm(breaks ~ wool * tension, data = warpbreaks) length(fm1$call) # 3, lm() and two arguments. length(formula(fm1)) # 3, ~ lhs rhs