Skip to content

$ operator is invalid for atomic vectors

4 messages · agrins, Steve Lianoglou, mlell08 +1 more

#
HI all- 

I have used this .fun in S+ without a problem however, in R when I run this
code to generate multiple graphs:

trendplot<-function(datafr,dataf2, abbrev="", titlestr="",
devname="s",filen="",styr=1990,endyr=2012) {
if (!is.null(dev.list())) {dev.off()}

dataf<-datafr[datafr$abbrev==abbrev,]			#subset entire dataset with one
species at a time
dataf2sp<-dataf2[dataf2$abbrev==abbrev,]  etc... 

It returns  "Error in dataf2$abbrev : $ operator is invalid for atomic
vectors"

Is there an easy fix for this error?

Thanks for the help- 

Alexis




--
View this message in context: http://r.789695.n4.nabble.com/operator-is-invalid-for-atomic-vectors-tp4643189.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi,
On Fri, Sep 14, 2012 at 2:33 PM, agrins <agrinde at d.umn.edu> wrote:
I suspect you just have to ensure that the thing you are passing in to
the `dataf2` parameter is in fact a data.frame -- the error you are
getting suggests that it is currently not.

Also -- have no fear for the space bar, it is your friend ;-)
#
On 14.09.2012 22:16, Steve Lianoglou wrote:
Hello,

I had a similar problem and I found two solutions

1) Don't use the $ op on atomic vectors;-). Instead try:
       dataf2sp<-dataf2[dataf2["abbrev"]==abbrev,]

2) Make the vector a list. I don't know if there are side-Effects to
this, but perhaps it's just the anxiety of a Java-Programmer who isn't
used to the somewhat easy-going way R deals with classes:
       class(dataf2) <- "list"

Regards,
Moritz
#
Indeed, there are _many_ side effects to this and you really should
read up on the differences, but this really is a bad idea in general.
To make it _very_ short, (atomic = regular) vector is a regular array
while a list is an associative array.

Cheers,
Michael