Evgenij Reznik
Evgenij Reznik

Reputation: 18594

R: Average value of vector

I'm playing around with R and trying to get the average of a column. Just mean(V1) doesn't work.

enter image description here

Could anybody give me an advice?
Thank you!

Upvotes: 6

Views: 33249

Answers (2)

Ananta
Ananta

Reputation: 3711

if you just want mean(V1), you can attach dataframe with attach(D), but probably I don't want to recommend it as later you may have other dataframes with same variable names and a mess withattach and detach commands. So, mean(D$V1) is the best way.

Upvotes: -1

IRTFM
IRTFM

Reputation: 263362

A: mean(D$V1) ... column names are not first class objects. They are part of a data.frame with a name that needs to be used.

Q: es, thanks. So $ is like the dot-operator? – user1170330 4 mins ago

A: Perhaps (depending on which language is being compared.) it is possible to construct list objects with cascaded calls to $<- and then obj$V1$subV1 to extract. Review ?Extract very carefully.

Upvotes: 10

Related Questions