[R] How to avoid "$ operator is invalid for atomic vectors"

Erik Iverson iverson at biostat.wisc.edu
Thu Nov 6 17:36:06 CET 2008


Hello -

cruz wrote:
> Hi,
> 
> I am writing this in a wrong way, can someone please correct me?
> 
>> A <- matrix()
>> length(A) <- 6
>> dim(A) <- c(3,2)
>> colnames(A) <- c("X","Y")
>> A
>       X  Y
> [1,] NA NA
> [2,] NA NA
> [3,] NA NA
>> A$X
> Error in A$X : $ operator is invalid for atomic vectors

A[, "X"] may be what you want?

See the details of ?Extract about how '$' only works on recursive 
(list-like) objects, of which your matrix A is not one of.

> 
> Thanks,
> cruz
> 
> ______________________________________________
> 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