[R] Subset error on atomic vectors why?

arun smartpink111 at yahoo.com
Thu Apr 3 00:59:37 CEST 2014


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 <james at crosb.ie> 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.

______________________________________________
R-help at 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.





More information about the R-help mailing list