In a problem, I have a set of vectors. Each vector has sensor readings but are of different lengths. I’d like to compute the same descriptive statistics on each of these vectors. My question is, how should I store them in R. Using c() concatenates the vectors. Using list() seems to cause functions like mean() to misbehave. Is a data frame the right object?
What is the best practice for applying the same function to vectors if different sizes? Supposing the data resides in a SQL server, how should it be imported?
Vectors of different sizes should be combined into a list: a data.frame expects each column to be the same length.
Use
lapplyto fetch your data. Then uselapplyagain to get the descriptive statistics.Where
sqlfunctionis some function you created to query your database. You can collapse thestatslist into a data.frame by callingdo.call(rbind, stats)or by usingplyr: