I'm trying to return a list of values given this function:
Pass_or_fail <- function(y){
x = round(runif(y, 0, 100), 1)
if(x>50){
print("Passed")
}else if(x < 50){
print("Failed")
}
}
When I pass a value into y
for example 20
this should return a list of either Passed
or Failed
characters. However, the function above only returns a single vector. I wish for it to return 20 values relative to the condition provided above, mainly in list format.
I was thinking of creating a variable likeso:
t_list <- list(1:20)
#then
Map(Pass_or_fail(20), t_list)
Output:
"Passed" "Failed" "Passed" "Failed" "Passed" "Failed" "Passed" "Failed" "Passed" "Failed" "Passed" "Failed" "Passed" "Failed" "Passed" "Failed" "Passed" "Failed" "Passed" "Failed"
I cannot seem to figure it out yet.
Aucun commentaire:
Enregistrer un commentaire