Hi all!
Quick question, and not sure if I need to provide reproducible example or not, but hoping not.
I am looking for the following values in a dataframe:
tomato_analyses[which(tomato_analyses$plot == "6-9" & tomato_analyses$harvest_year == "2001"),] #row 925 value
I get this:
plot plot_side analysis_date sample_type tomato_part tomato_analysis analysis_value units comments harvest_year
925 6-9 W 2001-08-24 ptab_samples fruit Color score - PTAB 25.000 2001
I want the value in the row 925, seventh column (analysis_value) to be changed to 27, not 25.
I do this:
tomato_analyses[925, 7] = 27
And when I go back to check again, I get the same thing; nothing changed.
plot plot_side analysis_date sample_type tomato_part tomato_analysis analysis_value units comments harvest_year
925 6-9 W 2001-08-24 ptab_samples fruit Color score - PTAB 25.000 2001
Oddly enough, this works FINE for other rows. What is happening? Any ideas?
Thanks!
--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
I can imagine it is an issue from my deleting and/or reordering, which I have been doing, but I have been checking each time for the new row number, and it doesn’t seem to consistently give me the updated row number as I go through and make multiple changes.
I can’t use the suggested first line because there are other rows that match that same call, and I don’t want to change ALL of them, only one of them.
How can I ensure that I am getting the right row number returned when I use which()?
It might make sense to add an index column that can resolve these ambiguities:
tomato_analyses[["index"]] <- 1:nrow(tomato_analyses)
Then you can use this value for future lookups. This will give you the rows, but now also show index
:
tomato_analyses[tomato_analyses$plot == "6-9" & tomato_analyses$harvest_year == "2001",]
(Note you don’t need which()
here - the bracket indexing can go on just the TRUE/FALSE values)
Now, replace values using the index:
tomato_analyses[tomato_analyses$index==INDEX_PROBABLY_NOT_925,] <- 27