Compare two vector in R -


i have 2 vectors:a = c(1,2,3), b = c(1,2,3)

i want test whether a same b. know result can given sum(a == b) == length(a), there elegant way?

we can use identical

identical(a,b) #[1] true 

or if there difference in attributes need avoid in comparison, use all.equal

all.equal(a,b, check.attributes=false) #[1] true 

or using similar approach in op's post, can make compact all

all(a==b) #[1] true 

the number of characters in above approach less...

nchar("identical(a,b)") #[1] 14 nchar("all(a==b)") #[1] 9 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo