Barnaby
Barnaby

Reputation: 1480

eliminating 0s from objects in a vector which contain 0s

I have a vector of objects

A<-c(a,b,c,d,e,f,g,h,i,j,k,l,ll,m,n,o,p,q,r,s,t,x,y,z,aa,bb,cc,dd,ee)

All vector elements are 0 except the first (a)

A
[1] "s2" "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"    
"0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 

I would like to eliminate all 0s in the expression without indicating the possition and then eliminating, more an expression like

A<-names(which(A!=0))
A
NULL

However I get the error above. Would you happen to know how could I eliminate the zeros and obtain as a result of A "s2"

Upvotes: 0

Views: 51

Answers (1)

twin
twin

Reputation: 1669

Seems to me that

A[which (A != 0)]

would work

Upvotes: 1

Related Questions