Re: [R] $ operator is invalid for atomic vectors

2015-02-11 Thread JS Huang
Hi, 

  If x is a data frame, then x$getmean will try to get the vector named
getmean in x.  You put "()" after x$getmean.  I think r is confused about
it.  It appears that you want to call a function named getmean().



--
View this message in context: 
http://r.789695.n4.nabble.com/operator-is-invalid-for-atomic-vectors-tp4703112p4703114.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors

2012-09-15 Thread R. Michael Weylandt
> 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"

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors

2012-09-15 Thread mlell08
On 14.09.2012 22:16, Steve Lianoglou wrote:
> Hi,
> 
> On Fri, Sep 14, 2012 at 2:33 PM, agrins  wrote:
>> 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?
> 
> 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 ;-)
> 

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

-- 
GnuPG Key: 0x7340821E

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors

2012-09-14 Thread Steve Lianoglou
Hi,

On Fri, Sep 14, 2012 at 2:33 PM, agrins  wrote:
> 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?

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 ;-)

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] $ operator is invalid for atomic vectors

2012-09-14 Thread agrins
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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors

2012-04-19 Thread Milan Bouchet-Valat
Le jeudi 19 avril 2012 à 09:34 +0300, Ana-Maria Dobre a écrit :
> I have got the following statement:
> 
> *> overview.domains$sample.var <- aggregate(migr$amigo.migr,
> by=list(siruta=amigo$siruta), var)[,-1]/overview.domains$n.i.*
> *Error in migr$amigo.migr : $ operator is invalid for atomic vectors*
> 
> 
> What should i do to solve this error?
Well, the error says it all: migr is a not a list, so you cannot use $
on it. The object is probably not what you think it is.


Hope this helps

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] $ operator is invalid for atomic vectors

2012-04-19 Thread Ana-Maria Dobre
I have got the following statement:

*> overview.domains$sample.var <- aggregate(migr$amigo.migr,
by=list(siruta=amigo$siruta), var)[,-1]/overview.domains$n.i.*
*Error in migr$amigo.migr : $ operator is invalid for atomic vectors*


What should i do to solve this error?


Thank you.

Kind regards,
Ana Maria Dobre

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors

2011-01-18 Thread Pete Brecknock

Amy

It would have been helpful if you had sent your R code of how you
constructed the sab object.

If you have a data.frame, the subset command you are having trouble with
should work fine. See below.

# Working Example 
sab = data.frame(group=c('Group A', 'Group A', 'Group C', 'Group B', 'Group
C'), gender=c(1,1,1,2,2))
subset(sab, sab$group=='Group A') 

Perhaps your data is stored as a matrix? If so, the following code will fail
with the error message you experienced.

# Non Working Example
sab2 = matrix(c('Group A', 'Group A', 'Group C', 'Group B', 'Group
C',1,1,1,2,2),5,2)
subset(sab2, sab2$group=='Group A') 

HTH

Pete
-- 
View this message in context: 
http://r.789695.n4.nabble.com/operator-is-invalid-for-atomic-vectors-tp3224224p3224318.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors, returning NULL - what is the right thing to do then?

2007-12-06 Thread Duncan Murdoch
On 12/6/2007 7:04 AM, Søren Højsgaard wrote:
> Dear all,
> Starting from a recent version of R, the $ became "unusable" on atomic 
> vectors, e.g.
>> x <- c(a=1,b=2)
>> x$a
> NULL
> Warning message:
> In x$a : $ operator is invalid for atomic vectors, returning NULL
>  
> I can of course do
>> x['a']
> - but that requires more typing (5 characters rather than 2). 
>  
> Apologies if I've missed a an announcement regarding this, but
> 1) Is there an alternative to the ['a'] and
> 2) Why was this change made?

There's an announcement in the NEWS file for 2.6.0

DEPRECATED & DEFUNCT

 o  $ on an atomic vector now gives a warning that it is 'invalid'.
It remains deprecated, but may be removed in R >= 2.7.0.

and an update in R-devel saying that in fact it has been made defunct there.

In answer to your questions:

1) I don't think so, other than x[1].
2) I don't remember the details, other than it was to avoid confusion. 
Maybe someone else can summarize the discussion?

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors, returning NULL

2007-12-06 Thread Ted Harding
On 06-Dec-07 12:04:56, Søren Højsgaard wrote:
> Dear all,
> Starting from a recent version of R, the $ became "unusable"
> on atomic vectors, e.g.
>> x <- c(a=1,b=2)
>> x$a
> NULL
> Warning message:
> In x$a : $ operator is invalid for atomic vectors, returning NULL
>  
> I can of course do
>> x['a']
> - but that requires more typing (5 characters rather than 2). 
>  
> Apologies if I've missed a an announcement regarding this, but
> 1) Is there an alternative to the ['a'] and
> 2) Why was this change made?

While Brian has answered your query from a more technical
point of view, there's an implication you should consider.

x$a always (as far as I know)[*] has been "unusable", in that
it returns NULL, and not what you expected to get. The only
thing that's (relatively) new is that you now get a warning.

[*] Certainly as early as R-1.6.2 (Jan 2003), as I've just checked.

Previously, you were not getting a warning.

So, if you were using the likes of x$a in code, and getting
no warnings, possibly your code was generating results
derived from NULL values rather than from the values you
expected it to be using. Perhaps you should check back!

Best wishes,
Ted.


E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 06-Dec-07   Time: 12:39:49
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] $ operator is invalid for atomic vectors, returning NULL - what is the right thing to do then?

2007-12-06 Thread Prof Brian Ripley

On Thu, 6 Dec 2007, Søren Højsgaard wrote:


Dear all,
Starting from a recent version of R,



From R 2.5.0, not so recent.



the $ became "unusable" on atomic vectors, e.g.

x <- c(a=1,b=2)
x$a

NULL
Warning message:
In x$a : $ operator is invalid for atomic vectors, returning NULL
I can of course do

x['a']

- but that requires more typing (5 characters rather than 2).

Apologies if I've missed a an announcement regarding this, but
1) Is there an alternative to the ['a'] and
2) Why was this change made?


It has always returned NULL on atomic vectors: see the help page.
E.g. in R 2.0.0 from 2004:


x <- c(a=1,b=2)
x$a

NULL

x['a']

a
1

The warning was added three versions of R ago: the announcement is in the 
NEWS file for 2.5.0.


USER-VISIBLE CHANGES

o   Using $ on an atomic vector now raises a warning, as does use
on an S4 class for which a method has not been defined.

I think you have exemplified the answer to your question '2)': because 
users misunderstood what it did.


In R 2.7.0 this will be an error, since package programmers did not seem 
to be heeding the warnings.


--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] $ operator is invalid for atomic vectors, returning NULL - what is the right thing to do then?

2007-12-06 Thread Søren Højsgaard
Dear all,
Starting from a recent version of R, the $ became "unusable" on atomic vectors, 
e.g.
> x <- c(a=1,b=2)
> x$a
NULL
Warning message:
In x$a : $ operator is invalid for atomic vectors, returning NULL
 
I can of course do
> x['a']
- but that requires more typing (5 characters rather than 2). 
 
Apologies if I've missed a an announcement regarding this, but
1) Is there an alternative to the ['a'] and
2) Why was this change made?
 
Regards
Søren
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.