-2

So I need to create a vector V and fill them with the values based on the vector temp if temp[I] > 100 then fill vi with the string hot else fill with normal

my code is like that

for (I in temp) {
if (temp[I] > 100) {
V[I]="Hot"}
else {
V[I] = "Normal 
}

but I cannot get the answer what is wrong w my code?

max
  • 79
  • 7

1 Answers1

1

A tidyverse solution:

library(tidyverse)

temp %>% 
  mutate(v = case_when(i > 100 ~ "hot",
                       TRUE ~ "normal"))

Desmond
  • 1,047
  • 7
  • 14