I’m trying to set the default value for a function parameter to a named numeric. Is there a way to create one in a single statement? I checked ?numeric and ?vector but it doesn’t seem so. Perhaps I can convert/coerce a matrix or data.frame and achieve the same result in one statement? To be clear, I’m trying to do the following in one shot:
test = c( 1 , 2 )
names( test ) = c( "A" , "B" )
The convention for naming vector elements is the same as with lists:
If instead you wanted this to be a parameter that was a named vector (the sort of function that would handle arguments supplied by
apply):If instead you wanted this to be a parameter that was a named list: