Created
May 24, 2023 22:55
-
-
Save opplatek/e4f80b4530f8c6d161d0d1fe7e77829a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Convert apply() result to data.frame | |
# | |
# Sample data frame | |
df <- data.frame(A = c(1, 2, 3), | |
B = c(4, 5, 6)) | |
# Sample function | |
calculate_sum <- function(row) { | |
sum(row) | |
} | |
# Apply function | |
result <- apply(df, 1, calculate_sum) | |
# Convert to data.frame | |
result_df <- do.call(rbind, lapply(result, as.data.frame)) | |
print(result_df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment