r - Function to Change "List" objects into "numerics" -
i have matrix containing several "list" vector. transform them numerics. have read should use as.numeric(x) - since have several values use function goes through matrix , checks each vector of matrix if list , returns numeric.
i have thought use like:
if typeof(matrix$vector1)=="list"
then as.numeric(matrix$vector1)
can me out how create such function? i'd appreciate kind of help!
kind regards,
try this:
if (is.list(matrix$vector1)) sapply(matrix$vector1,as.numeric)
is.list
check whether input list, if true sapply
'apply' function as.numeric every element of list
Comments
Post a Comment