'R for loops and if statements, can't save output as vector
Trying to replace output vector with string value of small, medium or large.
I am able to print out a string of 200 (1by1) vectors containing small/medium/large but not save that as a vector. What am I missing in the for loop?
output<- rep(NA, 200)
size <- sample(1:5000, 200)
myfun<- function(){
for (i in size) { if (i < 300) { print(output[i] <- "small") }
else if (i >= 300 & i<3000) { print(output[i] <- "medium") }
else if (i>= 3000) { print(output[i]<- "large") } } }
output<- myfun()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
