Subset error on atomic vectors why?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Subset error on atomic vectors why?

jcrosbie
I'm getting this error: "Error in MOPrice$Date : $ operator is invalid for atomic vectors"

The cost is: subset(MOPrice, as.Date(MOPrice$Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))

The date column looks like:
"2013-12-31" "2013-12-31" "2013-12-31" "2013-12-31" "2013-12-31"



Reply | Threaded
Open this post in threaded view
|

Re: Subset error on atomic vectors why?

arun kirshna
Hi,
It is not mentioned whether your dataset is a matrix of data.frame.  Also, please use ?dput() to show the dataset.  I get similar errors with matrix.

MOPrice <- data.frame(Date=c("2013-12-31","2013-12-31","2013-12-31","2013-11-28"),stringsAsFactors=FALSE)
subset(MOPrice, as.Date(Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))
#        Date
#4 2013-11-28
MOPrice1 <- data.frame(Date=c("2013-12-31","2013-12-31","2013-12-31"),stringsAsFactors=FALSE)
subset(MOPrice1, as.Date(Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))
#[1] Date

#<0 rows> (or 0-length row.names)

MOPrice2 <- data.frame(Date=c("2013-12-31","2013-12-31","2013-12-31"))
subset(MOPrice2, as.Date(MOPrice2$Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))
#[1] Date
#<0 rows> (or 0-length row.names)
subset(MOPrice1, as.Date(MOPrice1$Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))
#[1] Date
#<0 rows> (or 0-length row.names)
MOPrice3 <- as.matrix(MOPrice1)
subset(MOPrice3, as.Date(MOPrice3$Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))
#Error in MOPrice3$Date : $ operator is invalid for atomic vectors


A.K.


On Wednesday, April 2, 2014 6:49 PM, jcrosbie <[hidden email]> wrote:
I'm getting this error: "Error in MOPrice$Date : $ operator is invalid for
atomic vectors"

The cost is: subset(MOPrice,
as.Date(MOPrice$Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))

The date column looks like:
"2013-12-31" "2013-12-31" "2013-12-31" "2013-12-31" "2013-12-31"







--
View this message in context: http://r.789695.n4.nabble.com/Subset-error-on-atomic-vectors-why-tp4688051.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Subset error on atomic vectors why?

David Winsemius
In reply to this post by jcrosbie

On Apr 2, 2014, at 3:35 PM, jcrosbie wrote:

> I'm getting this error: "Error in MOPrice$Date : $ operator is invalid for
> atomic vectors"
>
> The cost is: subset(MOPrice,
> as.Date(MOPrice$Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d"))
>
> The date column looks like:
> "2013-12-31" "2013-12-31" "2013-12-31" "2013-12-31" "2013-12-31"
>

What does str(MOPrice) return?


> View this message in context: http://r.789695.n4.nabble.com/Subset-error-on-atomic-vectors-why-tp4688051.html
> Sent from the R help mailing list archive at Nabble.com.
>
>

> [hidden email] 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.

David Winsemius
Alameda, CA, USA

______________________________________________
[hidden email] 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.