"What is the best practice of applying the same function to vectors if they have different sizes? Suppose the data is on an SQL server, how to import it?"
As Shane suggested, here is your choice. Of course, you can use it with custom functions too - if you feel that the summary does not provide enough information.
For the SQL part: for most relational DBMSs there are packages: RPostgreSQL, RMySQL, ROracle, and RODBC - as a general one. If you are talking about MS SQL Server, I'm not sure if there is any specific package, but RODBC should do the job. I do not know if you are married to MS SQL Server material, but if you want to run your own local database for R-RMySQL, it is very easy to configure.
In general, using database packages, you use wrappers such as dbListTable or dbReadTable, which simply turn the table into R data.frame.
If you really want to import data that could use the .csv export of your database and use read.table or read.csv depending on what suits you. But I suggest connecting directly to the database - itβs not so difficult, even if you havenβt done it before, and it has become more fun.
EDIT: I don't use MS, but others did it before the mail list helps
source share