Lev
Lev

Reputation: 833

Data frame header in R

I am trying to make some calculations with data from oracle db using R. I connected to the DB and extracted the data correctly.

> y=dbGetQuery(con, "select distinct(fk_parametro) from t_datos")
> y

FK_PARAMETRO
1            30
2            42
3            43
4            83
5            87
6             1
7             6
8            44
9            20
10           14
11           86
12           88
13           85
14           81
15           35
16            8
17           80
18           89
19            7
20           12
21           82
22            9
23           10

The following command.. works:

> sum(y)
[1] 1042

But this one.. fails:

> mean(y)
[1] NA
Warning message:
In mean.default(y) : argument is not numeric or logical: returning NA

I think it happens because R is considering the header "FK_PARAMETRO" as an element. can someone help me to figure out?

Upvotes: 1

Views: 121

Answers (1)

Lev
Lev

Reputation: 833

As commented by @akrun, this works

mean(y[,1]) 

Or as suggested by @PierreLafortune, could also do

colMeans(y)

Upvotes: 1

Related Questions