For a given dataframe where the windows are specified by a column in the dataframe, evaluate whether all observations in each window share the same values for specified columns.

GetHomogeneousWindows(
  inputted.data,
  window.ID.col.name,
  observation.vals.to.compare
)

Arguments

inputted.data

A dataframe that needs a column that labels which window each observation belongs to.

window.ID.col.name

A string that specifies the column name of the column that provides the window name.

observation.vals.to.compare

A vector of strings with each string being the name of a column in the datafarame to look at.

Value

List where each object is a homogeneous window (dataframe) that has observations sharing the same values for the observation.vals.to.compare column(s).

Details

Function takes a single dataframe with each row as observations. This dataframe needs a column that specifies which window each observation belongs to. For each window, the observations within the window is evaluated to see if all observations share the same values for specified columns of the dataframe. Windows where the specified columns have the same values across all observations are labeled as "homogeneous" windows and are captured and outputted in a list, where each element is a window (dataframe). This function uses the FindHomogeneousWindows() function to determine whether each window is homogeneous. As the code executes, it outputs number indicating how many homogeneous windows have been found so far in the inputted.data.

Examples

#Example using a dataframe with 3 windows. #Windows 20 and 30 are homogeneous if looking at col.two and col.three values. window.name.column <- c(10, 10, 10, 20, 20, 20, 30, 30, 30, 30) col.two <- c("a", "a", "a", "a", "a", "a", "a", "a", "a", "a") col.three <- c(1, 1, 0, 1, 1, 1, 2, 2, 2, 2) multi.window.data <- data.frame(window.name.column, col.two, col.three) result <- GetHomogeneousWindows(multi.window.data, "window.name.column", c("col.two", "col.three")) #As expected, it looks like two windows are homogeneous. str(result)
#> List of 2 #> $ :'data.frame': 3 obs. of 3 variables: #> ..$ window.name.column: num [1:3] 20 20 20 #> ..$ col.two : chr [1:3] "a" "a" "a" #> ..$ col.three : num [1:3] 1 1 1 #> $ :'data.frame': 4 obs. of 3 variables: #> ..$ window.name.column: num [1:4] 30 30 30 30 #> ..$ col.two : chr [1:4] "a" "a" "a" "a" #> ..$ col.three : num [1:4] 2 2 2 2
#Output the two windows that are homogeneous: result[[1]]
#> window.name.column col.two col.three #> 4 20 a 1 #> 5 20 a 1 #> 6 20 a 1
result[[2]]
#> window.name.column col.two col.three #> 7 30 a 2 #> 8 30 a 2 #> 9 30 a 2 #> 10 30 a 2