Extract.odbcDataset: Extracts Parts of an odbcDataset Object

Description Usage Arguments Details Value Author(s) See Also Examples

Description

These operators are used to extract subsets of rows and/or columns of an odbcDataset object.

Usage

1
2
3
4
5
6
## S3 method for class 'odbcDataset'
x$i
## S3 method for class 'odbcDataset'
x[[i]]
## S3 method for class 'odbcDataset'
x[i, j, drop = TRUE, ...]

Arguments

x

an odbcDataset object.

i

for $ or [[, the name of a column in the dataset, quoted in the case of [[. For [, a quoted SQL query to select a subset of rows; if missing, all rows are selected.

j

columns to select; may be column numbers, negative numbers, or names if missing, all columns are selected.

drop

is a single column is selected and drop = TRUE, then a vector, rather than a one-column data frame, is returned.

...

not used.

Details

Perhaps some more explanation here.

Value

These operators return a data frame or vector.

Author(s)

John Fox

See Also

odbcDataset, odbcDriverConnect, Prestige.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## These example presuppose that the data set prestige is stored as a table
## in the database attached via odbcDriverConnect().
## This data set is supplied as the data frame Prestige in the dfdb.RODBC
## package.
## Depending upon your OS/DBMS, the call to odbcDriverConnect() may have
## to be modified.

## Not run: 
channel <- odbcDriverConnect()
            
sqlTables(channel)

Prestige <- odbcDataset(channel, "prestige")  # create a pseudo-dataframe
Prestige

Prestige[,]   # retrieve the whole dataset as a data frame

Prestige$income

Prestige[["income"]]

Prestige["type = 'prof'",]    # perform an SQL fetch

Prestige["type = 'prof' order by income", c("education", "income")]

mod <- lm(prestige ~ income + education, 
    data=Prestige[,c("income", "education", "prestige")])
summary(mod)

remove(Duncan, mod, channel)

  
## End(Not run)

dfdb.RODBC documentation built on May 2, 2019, 5:18 p.m.