I am new to R and have a problem. Any help would be really appreciated! When I use the for loop in the following (simplified) case, I get the error message: "replacement has 5 lines, data has 4"
Country <- c("Germany", "France", "Italy", "Spain") Unemploy <- c(2, 3, 4, 10) Growth <- c(2, 7, 6, 9) data <- data.frame(Country, Unemploy, Growth) for (i in data$Country) { if (identical(data$Country[i], "France")) { data$Growth[i] <- "5" } else { data$Growth[i] <- "2" } }
The following message is displayed:
Error in `$<-.data.frame`(`*tmp*`, "Growth", value = c("2", "2", "2", : replacement has 5 rows, data has 4
source share