Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I create a function that also considers these three other trios of data and run the 'if' function for the ten lines of the dataframe?

I ultimately want to have an output of ten lines and four columns (za, zc, ze, zg) with the information: TRUE or NULL.

What I have tried:

I have this function:

xa <- 9
xb <- 6
za <- 20

a1 <- xa / za
b1 <- xb / za

Validation <- function (a1, b1)
  
if (a1 / b1 >= .85 && a1 / b1 <= 1.15) {print(TRUE)}

result <- Validation (a1, b1)

result

The value of xa, xb, and za change ten times and there are also three other trios of data that change ten times:

c1 <- xc / zc
d1 <- xd / zc

e1 <- xe / ze
f1 <- xf / ze

g1 <- xg / zg
h1 <- xh / zg

as you can see in the dataframe below:

mat <- data.frame(xa = sample(0:10,  10, replace = TRUE),
                  xb = sample(0:10,  10, replace = TRUE),
                  za = sample(10:20, 10, replace = TRUE),
                  xc = sample(0:10,  10, replace = TRUE),
                  xd = sample(0:10,  10, replace = TRUE),
                  zc = sample(10:20, 10, replace = TRUE),
                  xe = sample(0:10,  10, replace = TRUE),
                  xf = sample(0:10,  10, replace = TRUE),
                  ze = sample(10:20, 10, replace = TRUE),
                  xg = sample(0:10,  10, replace = TRUE),
                  xh = sample(0:10,  10, replace = TRUE),
                  zg = sample(10:20, 10, replace = TRUE))
                  
mat

So, my question is: How can I create a function that also considers these three other trios of data and run the 'if' function for the ten lines of the dataframe?

I ultimately want to have an output of ten lines and four columns (za, zc, ze, zg) with the information: TRUE or NULL.

Thanks,
Posted
Updated 6-Mar-17 12:35pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900