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

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

$
0
0

You can temporary store values in a list and also make an assignment inside it. But I don't recommend this way, just to show another possibility.

a <- 1b <- 2b <- list(a, a <- b)[[1]]a#[1] 2b#[1] 1

Using a temporary variable might be easier to read and might be more performant.

a <- 1b <- 2. <- aa <- bb <- .rm(.)a#[1] 2b#[1] 1

Viewing all articles
Browse latest Browse all 9

Trending Articles



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