On Apr 1, 2014 8:04 PM, "Sandip Nandi" <sanna...@umail.iu.edu> wrote: > > Hi , > > I am concerned about the return value of typeof in character column in a dataframe. I expect it to be of character ,it returns integer instead . > Of course typeof returns integer; typeof returns the internal storage type of an object. Factors are integer vectors with a levels attribute. See ?typeof and ?factor.
As I said, it's not a character column. data.frame coerced it to factor. > Thanks > > > > > On Tue, Apr 1, 2014 at 5:56 PM, Joshua Ulrich <josh.m.ulr...@gmail.com> wrote: >> >> >> On Apr 1, 2014 7:48 PM, "Sandip Nandi" <sanna...@umail.iu.edu> wrote: >> > >> > Hi , >> > >> > I want to know is this behavior expected and why is that ? Need some help >> > >> > gender <- c("F", "M", "M", "F", "F", "M", "F", "F") >> > > age <- c(23, 25, 27, 29, 31, 33, 35, 37) >> > > df<- data.frame(gender,age) >> > > typeof(df[[1]]) >> > [1] "integer" >>>>>>>>>>>>> Why is this integer . *Should not it be >> > character ?* >> > > typeof(df[[2]]) >> > [1] "double" >> > >> > > typeof(gender) >> > [1] "character" >> > > typeof(age) >> > [1] "double" >> > > >> > >> > In my code i am trying to do some thing based on typeof and the type for >> > character column is strange. >> > >> The first column is coerced to factor when stringsAsFactors=TRUE, which is the default for data.frame. See ?data.frame. >> >> > Thanks, >> > Sandip >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-devel@r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-devel > > [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel