R: string vector, finding values of indeices smaller than a certain number -
could kindly me error message below?
list <- c("apple","bee","cat","dog","egg","frog","goat","hippo","iguana") list[1:5] # [1] "apple" "bee" "cat" "dog" "egg" however,
list[<5] # error: unexpected '<' in "list[<" thank you.
we need either numeric index (in op's first example) or logical index subset 'list'. create logical index, can compare sequence of 'list' elements index 5.
seq_along(list)<5 #[1] true true true true false false false false false and using index, can elements corresponds true values
list[seq_along(list)<5] #[1] "apple" "bee" "cat" "dog" regarding error message, if type
<5 on console
error: unexpected '<' in "<"
so, needs value on lhs of <
Comments
Post a Comment