Hi,
I want to write a function in R which assigns a new object to a list item.
I have:
RM_and_CM_list <- vector(mode='list', length=2)
names(RM_and_CM_list) <- c('RM', 'CM')
GLM_Frequency <- 1
Set_RM_and_CM <- function(model){
if (!is.null(RM_and_CM_list[["CM"]])){
RM_and_CM_list[["RM"]] <- RM_and_CM_list[["CM"]]
RM_and_CM_list[["CM"]] <- model
}
if (is.null(RM_and_CM_list[["CM"]])){
RM_and_CM_list[["CM"]] <- model
}
return(RM_and_CM_list)
}
Set_RM_and_CM(model = GLM_Frequency)
My last line calls the functions. It should assign a GLM_Frequency object to a an item of the list. However it doesnt. If the same thing is written outside function, it works.
I cant understand why my function doesnt work. Anyone can help?
Thanks
p.s. Anyone knows a good source for functional writing in R?