Skip to content

Commit

Permalink
Merge pull request #6 from USFWS/Jonah_Dev
Browse files Browse the repository at this point in the history
Jonah dev
  • Loading branch information
JonahWithers-USFWS authored Oct 29, 2024
2 parents b428158 + 4b79fb1 commit ded48b3
Show file tree
Hide file tree
Showing 26 changed files with 832 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/R/intro_errors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Create function that introduces errors into dataframe with numeric columns
intro_errors <- function(df,
neg_count = 5,
neg_min = -100,
non_numeric_count = 5,
non_numeric_value = "none",
large_count = 2,
large_mutliplier = 10) {



# introduce negative values
for (i in 1:neg_count) {
row <- sample(1:nrow(df), 1)
col <- sample(1:ncol(df), 1)
if (is.numeric(df[[col]])) {
df[row, col] <- runif(1, min = neg_min, max = 0) # Random negative value
}
}



# introduce non-numeric values
for (j in 1:non_numeric_count) {
row <- sample(1:nrow(df), 1)
col <- sample(1:ncol(df), 1)
if (is.integer(df[[col]])) {
df[row, col] <- non_numeric_value # Setting a string value
}

return(df)
}


# introduce large numbers
for (k in 1:large_count) {
row <- sample(1:nrow(df), 1)
col <- sample(1:ncol(df), 1)
if (is.numeric(df[[col]])) {
df[row, col] <- max(col) * large_mutliplier # Setting value to maximum value of column times multiplier
}

return(df)
}
}
Loading

0 comments on commit ded48b3

Please sign in to comment.