Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get reverse of a TRUE/FALSE vector?

Tags:

r

I have a vector like :

> good.genes
    A     B     C     D     E 
FALSE FALSE FALSE  TRUE FALSE 

I want to get it's reverse which would be:

    A     B     C     D     E 
 TRUE  TRUE  TRUE FALSE  TRUE 

Would someone help me do this conversion in R?

like image 212
user2806363 Avatar asked Aug 06 '14 06:08

user2806363


People also ask

How do I reverse the order of a vector in R?

To reverse a vector in R programming, call rev() function and pass given vector as argument to it. rev() function returns returns a new vector with the contents of given vector in reversed order.

How do you reverse a Boolean list in Python?

Use the invert() Function From the NumPy Library to Negate a Boolean Value in Python. The invert() function helps in the bitwise inversion of an element or an array of elements.

How do you change true to false in Python?

Convert bool to string: str() You can convert True and False to strings 'True' and 'False' with str() . Non-empty strings are considered True , so if you convert False to strings with str() and then back to bool type with bool() , it will be True .


1 Answers

Just prepend the ! operator. As Richard Scriven pointed out, this operation is called negation.

!good.genes
    A     B     C     D     E 
    TRUE TRUE TRUE  FALSE  TRUE
like image 200
merlin2011 Avatar answered Oct 18 '22 21:10

merlin2011