Hi, I've been working through lesson one in the r-inflammation lesson. It includes the following passage:
> ## Forcing Conversion > > The code above may give you an error in some R installations, > since R does not automatically convert a sliced row of a `data.frame` to a > vector. > (Confusingly, sliced columns are automatically converted.) > If this happens, you can use the `as.numeric` command to convert the row of > data to a numeric vector: > > `patient_1 <- as.numeric(dat[1, ])` The example data is entirely numeric, with no missing values, and no non-numeric columns. In that case, type coercion should work as you expect. If it doesn't, I would be very surprised if the results depend on a particular R *installation*. It may be the case that older R *versions* did different things. But I'm not sure about that. Can someone confirm which R versions require the explicit conversion of data to numeric in this example? coercion in R does have some ugly corner cases. If this is in fact one of them, I think it would be a good idea to rework the example so that it doesn't require this kind of fix. Incidentally, columns always work because a column by definition is composed of a single vector (which therefore has a single type). Rows can include data from different columns, and thus may have different types that need to be coerced into the lowest common denominator before we can use them. This isn't really confusing when you understand how a dataframe is constructed, but it's perhaps an issue that we don't need to throw at students in lesson 1. Best, Tyler -- plantarum.ca _______________________________________________ Discuss mailing list [email protected] http://lists.software-carpentry.org/listinfo/discuss
