[R] How to avoid "$ operator is invalid for atomic vectors"
iverson at biostat.wisc.edu
Thu Nov 6 17:36:06 CET 2008
> 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")
> X Y
> [1,] NA NA
> [2,] NA NA
> [3,] NA NA
> 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.
> R-help at r-project.org mailing list
> 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