I have a dataset like the generic dataset below and wish to join the three sitevariables into one.

```
 df <- data.frame(var1 = c("site1", NA, NA, NA, "site3", "site4"),
                  var2 = c(NA, NA, "NA", "site2", NA, "site4"),
                  var3 = c("site1", NA, "Site2", "site2", "site3", NA))

   var1  var2  var3
1 site1  <NA> site1
2  <NA>  <NA>  <NA>
3  <NA>    NA Site2
4  <NA> site2 site2
5 site3  <NA> site3
6 site4 site4  <NA>

```

The data frame I wish to obtain should thus be like this:

```
       var1  var2  var3  var4
1 site1  <NA> site1 site1
2  <NA>  <NA>  <NA>  <NA>
3  <NA>    NA Site2 site2
4  <NA> site2 site2 site2
5 site3  <NA> site3 site3
6 site4 site4  <NA> site4

```

I have tried using coalesce in the sqldf package, which gives the correct output, but str() reveals that the output is a data frame with one variable. and not a string of factors as I need.

```
library(sqldf)
df$var4 <-sqldf("select coalesce(var1, var2, var3) from df")
> df
   var1  var2  var3 coalesce(var1, var2, var3)
1 site1  <NA> site1                      site1
2  <NA>  <NA>  <NA>                       <NA>
3  <NA>    NA Site2                         NA
4  <NA> site2 site2                      site2
5 site3  <NA> site3                      site3
6 site4 site4  <NA>                      site4
> str(df)
'data.frame':   6 obs. of  4 variables:
 $ var1: Factor w/ 3 levels "site1","site3",..: 1 NA NA NA 2 3
 $ var2: Factor w/ 3 levels "NA","site2","site4": NA NA 1 2 NA 3
 $ var3: Factor w/ 4 levels "site1","site2",..: 1 NA 3 2 4 NA
 $ var4:'data.frame':   6 obs. of  1 variable:
  ..$ coalesce(var1, var2, var3): chr  "site1" NA "NA" "site2" ...
Warning message:

```