Quantcast
Channel: R: Swap two variables without using a third - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by Ronak Shah for R: Swap two variables without using a third

$
0
0

For integers, you can use

a = a + bb = a - ba = a - b

and for strings, this would work

a <- "one"b <- "two"a <- paste(a,b, sep = "")b <- substr(a,0,nchar(a) - nchar(b))a <- substr(a,nchar(b) + 1, nchar(a))> a# two> b # one

Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>