0

Trying to create a function that if a != b then it return b else returns a null value then cbind this to the original dataframe.

However getting the following errors: "argument is of length zero"

Would appreciate any help - similar function in python works fine.

DataFrame is pretty simple

colid col1 col2. expected output

  1.      Blue  Blue
    
  2. Blue Blue Null
  3. Red Blue Blue
  4.            Null
    
library(readr)
library(tidyverse)
library(purrr)

df <- read_csv('/Users/david/Downloads/trustdata.csv')
df_dups <- df[!duplicated(df), ]

wins = function(a,b) {
  if(NULL) return(NULL)
  else if(a != b) {return (b)}
  else {return ("NULL")}
}


df_wins <- apply(df, 1, function(x) wins(x["col1"],x["col2"])) ```

0 Answers0