I'm working with a data set from a long-term where plants get re-measured every year. Occasionally a new record gets inserted for a plant that already occurs in the data. This can be identified with the duplicated() command.
I can get a list that tells me TRUE/FALSE which regarding which entries are duplciated.
duplicated(data$tag)
This is a long list, so I can screen that output just for what is true by nesting the duplicated() command within a which() command
which(duplicated(data$tag) == TRUE)
The unique() command can also be used for similar task
Showing posts with label which(). Show all posts
Showing posts with label which(). Show all posts
Friday, February 18, 2011
Thursday, February 17, 2011
Locating missing values with is.na()
When getting data ready for analysis, a very handy function is "is.na." It prints out a list of "TRUE" and "FALSE" responses for the status of every entry in a vector or column.
I have data from an experiment where I know the plot number is missing for a few entries. I can quickly identify these like this:
First, use is.na on the plot column and store the results (a LONG list of 2000 entries) to an object "na_plot"
na_plot<-is.na(reboot1$plot)
Second, use the which() function to query the list for the entries where the answer to the question "is.na" is "TRUE"
which(na_plot == TRUE)
This gives me the index number of the entries that are NA.
I have data from an experiment where I know the plot number is missing for a few entries. I can quickly identify these like this:
First, use is.na on the plot column and store the results (a LONG list of 2000 entries) to an object "na_plot"
na_plot<-is.na(reboot1$plot)
Second, use the which() function to query the list for the entries where the answer to the question "is.na" is "TRUE"
which(na_plot == TRUE)
This gives me the index number of the entries that are NA.
Subscribe to:
Posts (Atom)