Alexandre Santos
2007-Nov-06 16:54 UTC
[R] Problem with a non-factor, non-numeric variable in a data.frame
Dear R list, I would like to perform an ANOVA in a set of measurements, but I have problems formatting the data. The data is a two dimensional array containing two columns: - "Stim" : the type of stimulation (string) - "Ratio" : a ratio of two numeric values Now, because some values are missing in the data (defaulting to zero), part of this array will be populated with NA ratios. Maybe this is important later. In order to make the ANOVA analysis, I need to turn my vector into a data.frame. I tried vector.table=as.data.frame(vector) But I realized that is.numeric(Ratio) gives FALSE is.factor(Ratio) gives TRUE After reading the documentation, I tried vector.table=as.data.frame(vector, stringsAsFactors = FALSE) This time is.numeric(Ratio) gives FALSE is.factor(Ratio) gives FALSE So I don't even know what is Ratio, but it's not yet numeric (is this due to the NA values?). How can I get R to understand that Ratio is numeric? Checking the documentation it seems you can do it with I(x), but the details are not explained. I also tried as.numeric(Ratio), and everything was turned into zeros. Any suggestions? Cheers, Alexandre Santos Neuro-MPI, Martinsread, Germany
John Kane
2007-Nov-06 20:09 UTC
[R] Problem with a non-factor, non-numeric variable in a data.frame
Have a look at the R-FAQ issue 7.10. It's a standard problem For more information about your variable try str(variable). --- Alexandre Santos <alexandre.santos at ochipepe.org> wrote:> Dear R list, > > I would like to perform an ANOVA in a set of > measurements, but I have > problems formatting the data. > > The data is a two dimensional array containing two > columns: > - "Stim" : the type of stimulation (string) > - "Ratio" : a ratio of two numeric values > > Now, because some values are missing in the data > (defaulting to zero), > part of this array will be populated with NA ratios. > Maybe this is > important later. > > In order to make the ANOVA analysis, I need to turn > my vector into a data.frame. > > I tried vector.table=as.data.frame(vector) > > But I realized that > is.numeric(Ratio) gives FALSE > is.factor(Ratio) gives TRUE > > After reading the documentation, I tried > > vector.table=as.data.frame(vector, stringsAsFactors > = FALSE) > > This time > > is.numeric(Ratio) gives FALSE > is.factor(Ratio) gives FALSE > > So I don't even know what is Ratio, but it's not yet > numeric (is this > due to the NA values?). > > How can I get R to understand that Ratio is numeric? > Checking the > documentation it seems you can do it with I(x), but > the details are > not explained. I also tried as.numeric(Ratio), and > everything was > turned into zeros. > > Any suggestions? > > Cheers, > > Alexandre Santos > > Neuro-MPI, Martinsread, Germany > > ______________________________________________ > 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. >