michael watson (IAH-C)
2004-Dec-17 15:41 UTC
[R] If it's not a data.frame, matrix or vector, what is it?
Hi Forgive my ignorance. I am selecting a column of a data.frame using the column name, and I want to know what the resulting column "is". My data frame is called "submin" and the column name is held in a variable called "display.gname" Eg:> is.data.frame(submin)[1] TRUE> is.data.frame(submin[,display.gname])[1] FALSE> is.matrix(submin[,display.gname])[1] FALSE> is.vector(submin[,display.gname])[1] FALSE> length(submin[,display.gname])[1] 4622 So if it's not a data.frame, a matrix or a vector, what is "it"? Thanks (and sorry if this is in the FAQ) Mick
Liaw, Andy
2004-Dec-17 15:54 UTC
[R] If it's not a data.frame, matrix or vector, what is it?
What does str(submin$display.gname) say? Andy> From: michael watson (IAH-C) > > Hi > > Forgive my ignorance. I am selecting a column of a > data.frame using the > column name, and I want to know what the resulting column > "is". My data > frame is called "submin" and the column name is held in a variable > called "display.gname" Eg: > > > is.data.frame(submin) > [1] TRUE > > is.data.frame(submin[,display.gname]) > [1] FALSE > > is.matrix(submin[,display.gname]) > [1] FALSE > > is.vector(submin[,display.gname]) > [1] FALSE > > length(submin[,display.gname]) > [1] 4622 > > So if it's not a data.frame, a matrix or a vector, what is "it"? > > Thanks (and sorry if this is in the FAQ) > > Mick > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
michael watson (IAH-C)
2004-Dec-17 16:13 UTC
[R] If it's not a data.frame, matrix or vector, what is it?
OK I'm definitely being a bit ignorant (so please accept my apologies) of R and it's internal data storage. When I created the data.frame, I did use I() with this column - the original data being a vector created simply with "vector()". It's clear now that I didn't realise exactly what this was doing (all I wanted was for it to NOT be converted to a factor).> str(submin[,display.gname])Class 'AsIs' chr [1:4622] "" "" "" "" ...> is.array(submin[,display.gname])[1] FALSE> class(submin[,display.gname])[1] "AsIs" But I am still confused; I program mainly in perl and java, and this "thing" - it's not a vector, an array, a matrix or a data.frame - so what is "it"? :-S Thanks Mick -----Original Message----- From: Liaw, Andy [mailto:andy_liaw at merck.com] Sent: 17 December 2004 15:55 To: michael watson (IAH-C); r-help at stat.math.ethz.ch Subject: RE: [R] If it's not a data.frame, matrix or vector, what is it? What does str(submin$display.gname) say? Andy> From: michael watson (IAH-C) > > Hi > > Forgive my ignorance. I am selecting a column of a > data.frame using the > column name, and I want to know what the resulting column > "is". My data > frame is called "submin" and the column name is held in a variable > called "display.gname" Eg: > > > is.data.frame(submin) > [1] TRUE > > is.data.frame(submin[,display.gname]) > [1] FALSE > > is.matrix(submin[,display.gname]) > [1] FALSE > > is.vector(submin[,display.gname]) > [1] FALSE > > length(submin[,display.gname]) > [1] 4622 > > So if it's not a data.frame, a matrix or a vector, what is "it"? > > Thanks (and sorry if this is in the FAQ) > > Mick > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------ ------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Liaw, Andy
2004-Dec-17 16:26 UTC
[R] If it's not a data.frame, matrix or vector, what is it?
It may be educational to read the help pages of functions that you're using, namely ?I (or even ?AsIs) and ?as.vector. ?I says it simply prepend "AsIs" to the class attribute of the object. ?as.vector says it returns FALSE if the object has any attributes except names (which it does in this case: the class). Note that str() does tell you that it's `chr', or character. You can unclass() it to see what it actually is. HTH, Andy> From: michael watson (IAH-C) > > > OK I'm definitely being a bit ignorant (so please accept my apologies) > of R and it's internal data storage. > > When I created the data.frame, I did use I() with this column - the > original data being a vector created simply with "vector()". > It's clear > now that I didn't realise exactly what this was doing (all I > wanted was > for it to NOT be converted to a factor). > > > str(submin[,display.gname]) > Class 'AsIs' chr [1:4622] "" "" "" "" ... > > is.array(submin[,display.gname]) > [1] FALSE > > class(submin[,display.gname]) > [1] "AsIs" > > But I am still confused; I program mainly in perl and java, and this > "thing" - it's not a vector, an array, a matrix or a data.frame - so > what is "it"? :-S > > Thanks > > Mick > > > -----Original Message----- > From: Liaw, Andy [mailto:andy_liaw at merck.com] > Sent: 17 December 2004 15:55 > To: michael watson (IAH-C); r-help at stat.math.ethz.ch > Subject: RE: [R] If it's not a data.frame, matrix or vector, > what is it? > > > What does str(submin$display.gname) say? > > Andy > > > From: michael watson (IAH-C) > > > > Hi > > > > Forgive my ignorance. I am selecting a column of a > > data.frame using the > > column name, and I want to know what the resulting column > > "is". My data > > frame is called "submin" and the column name is held in a variable > > called "display.gname" Eg: > > > > > is.data.frame(submin) > > [1] TRUE > > > is.data.frame(submin[,display.gname]) > > [1] FALSE > > > is.matrix(submin[,display.gname]) > > [1] FALSE > > > is.vector(submin[,display.gname]) > > [1] FALSE > > > length(submin[,display.gname]) > > [1] 4622 > > > > So if it's not a data.frame, a matrix or a vector, what is "it"? > > > > Thanks (and sorry if this is in the FAQ) > > > > Mick > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > -------------------------------------------------------------- > ---------- > ------ > Notice: This e-mail message, together with any attachment...{{dropped}}