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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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