Created
March 31, 2016 02:22
-
-
Save lcomm/c91a30170a4b0a84cb6efcd69b88ef03 to your computer and use it in GitHub Desktop.
Quick example of how you could extract ID variable from LME formula
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Function to extract the cluster ID variable from a formula | |
get_id <- function(formula){ | |
#Extract the thing between the | and the ) in the last part of formula | |
#This is the clustering variable | |
idvar <- gsub('.*[|](.*?)).*','\\1',formula[-c(1:2)]) | |
#Remove white space | |
idvar <- gsub("^\\s+|\\s+$", "", idvar) | |
#Return | |
return(idvar) | |
} | |
#Example use | |
get_id(formula = y ~ (x + z | id) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment