[R] How to import data from teradata
Marc Schwartz
marc_schwartz at me.com
Tue Apr 6 23:57:00 CEST 2010
On Apr 6, 2010, at 4:26 PM, sumit gupta wrote:
> Hello All,
>
> I am very new to the R and i want to know how to connect to the teradata in
> R and import data from there.
> Currently I am using SAS to import data and i use the following syntax to
> connect to teradata.
>
>
> *Proc Sql;
> connect to odbc (dsn=teradata username = '**********' password =
> '*********');
> create table dorm.bkg_tables
> as select * from connection to odbc*
>
> Could you please tell me what is the syntax for connecting to teradata
> through R and import data in R.
>
> Also could you tell me what all packages do i have to install in order to
> perform above tasks.
>
> Thanks.
>
>
> Sumit
Presuming that based upon the above, you have an ODBC driver for Teradata installed on your system, you can use the RODBC package on CRAN. Once installed, use:
vignette("RODBC")
to review a more detailed document on the package.
Presuming that the above SAS statements connect to the server and then create a SAS data object from a table on the server, you can use something like:
library(RODBC)
db <- odbcConnect("teradata", uid = "*****", pwd = "*****")
DF <- sqlQuery(db, "select * from TableName")
odbcClose(db)
DF will be an R data frame containing the results of the query.
See the help pages for the above functions for additional information.
If you have not yet, be sure to read "An Introduction to R", which will be available with your R installation and/or online at:
http://cran.r-project.org/manuals.html
HTH,
Marc Schwartz
More information about the R-help
mailing list