0

Here is my code

nutrients<- read.csv("nutrients.csv", head = TRUE, sep = ",")
> plot(nutrients)
> head(nutrients)
         crop Nutrient.dens N..tons.acre. P2O5 K2O sum.nut
1    broccoli         340.0           210  245 100     555
2      carrot         458.0            70  250  50     370
3 cauliflower         315.0            25   35  80     140
4     letuce          318.5           165  150  90     405
5       onion         109.0           120   30 150     300
6      tomato         186.0           175   85 275     535
> df_nutrients<- as.data.frame(nutrients)
> df_nutrients<- df_nutrients[1,1=="broc"]

I am sure this is easy, and Ive tried searching anything i can find to get the answer but i cannot find it. I just need to change that one variable to "broc". is there a specific function i need or something?

spmoose
  • 63
  • 1
  • 12

1 Answers1

1

If crop is a character type, then a simple subset should work

nutrients$crop[nutrients$crop == "broccoli"] <- "broc"

If crop is a factor, then use this:

levels(nutrients$crop)[levels(nutrients$crop) == "broccoli"] <- "proc"
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360