turn a numeric dataframe to binary in r

# Assuming df is your numeric dataframe

# Step 1: Define a threshold for conversion
threshold <- 0.5

# Step 2: Apply a function to convert numeric values to binary
df_binary <- apply(df, MARGIN = 2, FUN = function(x) ifelse(x > threshold, 1, 0))