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

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -