Re: [R] How to avoid $ operator is invalid for atomic vectors
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@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-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] How to avoid $ operator is invalid for atomic vectors
Hi Cruz you don't need to assign dimension or classes to your objects. It's easier if you do like this a=c(0,1,2,4,1,1) length(a) [1] 6 b=matrix(a,3,2,byrow=T) b [,1] [,2] [1,]01 [2,]24 [3,]11 of course you can change the colnames and assign what you prefer colnames(b)=c(x,y) but if you try to recall x with b$x is not going to work like that, you have two option: 1. switch form matrix to a dataframe: c=as.data.frame(b) c x y 1 0 1 2 2 4 3 1 1 c$x [1] 0 2 1 no problems. 2. Can get the column x on the matrix b as b[,1] [1] 0 2 1 just giving the position. Hope that this helps. Best Regards Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: cruz [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Giovedì 6 novembre 2008, 17:22:42 Oggetto: [R] How to avoid $ operator is invalid for atomic vectors 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 Thanks, cruz __ 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. Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport: [[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] How to avoid $ operator is invalid for atomic vectors
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of anna freni sterrantino Sent: Thursday, November 06, 2008 10:00 AM To: cruz; r-help@r-project.org Subject: Re: [R] How to avoid $ operator is invalid for atomic vectors Hi Cruz you don't need to assign dimension or classes to your objects. It's easier if you do like this a=c(0,1,2,4,1,1) length(a) [1] 6 b=matrix(a,3,2,byrow=T) b [,1] [,2] [1,]01 [2,]24 [3,]11 of course you can change the colnames and assign what you prefer colnames(b)=c(x,y) but if you try to recall x with b$x is not going to work like that, you have two option: 1. switch form matrix to a dataframe: c=as.data.frame(b) c x y 1 0 1 2 2 4 3 1 1 c$x [1] 0 2 1 no problems. 2. Can get the column x on the matrix b as b[,1] [1] 0 2 1 just giving the position. Hope that this helps. Best Regards Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: cruz [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Giovedì 6 novembre 2008, 17:22:42 Oggetto: [R] How to avoid $ operator is invalid for atomic vectors 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 Thanks, cruz You can also use the column name with the matrix A[,'X'] Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] How to avoid $ operator is invalid for atomic vectors
Thanks for all the responses, they are all very helpful:) you don't need to assign dimension or classes to your objects. It's easier if you do like this this is something that really bothers me, when I need to define an object which i will later fill with data, the dimension of this object should not be fixed because it will grow... so in MATLAB, i.e. we define x = [ ], what about in R? Thanks, cruz __ 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] How to avoid $ operator is invalid for atomic vectors
Does that answer your question? Thanks:) I received one from Erin: x - NULL __ 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] How to avoid $ operator is invalid for atomic vectors
cruz wrote on 11/06/2008 12:16 PM: Thanks for all the responses, they are all very helpful:) you don't need to assign dimension or classes to your objects. It's easier if you do like this this is something that really bothers me, when I need to define an object which i will later fill with data, the dimension of this object should not be fixed because it will grow... so in MATLAB, i.e. we define x = [ ], what about in R? ?numeric, ?character, others probably... x - numeric() x[10] - 42 print(x) [1] NA NA NA NA NA NA NA NA NA 42 Does that answer your question? Jeff Thanks, cruz __ 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. -- http://biostat.mc.vanderbilt.edu/JeffreyHorner __ 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] How to avoid $ operator is invalid for atomic vectors
Does this help (mylist - list(NULL)) (mylist[[3]] - data.frame(a=1:4, b=letters[1:4])) mylist (mylist[[2]] - matrix(1:12, nrow=4)) mylist --- On Thu, 11/6/08, cruz [EMAIL PROTECTED] wrote: From: cruz [EMAIL PROTECTED] Subject: Re: [R] How to avoid $ operator is invalid for atomic vectors To: r-help@r-project.org Received: Thursday, November 6, 2008, 1:16 PM Thanks for all the responses, they are all very helpful:) you don't need to assign dimension or classes to your objects. It's easier if you do like this this is something that really bothers me, when I need to define an object which i will later fill with data, the dimension of this object should not be fixed because it will grow... so in MATLAB, i.e. we define x = [ ], what about in R? Thanks, cruz __ 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. __ [[elided Yahoo spam]] __ 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] How to avoid $ operator is invalid for atomic vectors
cruz wrote: Thanks for all the responses, they are all very helpful:) you don't need to assign dimension or classes to your objects. It's easier if you do like this this is something that really bothers me, when I need to define an object which i will later fill with data, the dimension of this object should not be fixed because it will grow... so in MATLAB, i.e. we define x = [ ], what about in R? It is generally best in R to create an object as the size it will end up being and then make assignments into the object. But using the theory of giving you enough rope to hang yourself, you can do things like: x - numeric(0) or x - NULL Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Thanks, cruz __ 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-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.