Search code examples
rvariablesabbreviation

What does 'as' mean in R?


what does as mean in

as.numeric(T)

or

variable <- as.data.frame('midwest')`

P.S. explaining abbreviation would be much better if you please...


Solution

  • It means that you want an object to be converted to another one of a given type.

    If I have x <- 1 it is an numeric and thus, it has numeric properties (e.g. can be summed to 1 an become 2 as in x + 1). When you use as.character(x), you basically transform that 1 (numeric) in a "1", which is an object of type "string". And so on. You can transform matrices to data frames with as.data.frame() and the opposite with as.matrix(), for example.

    Hope this helps.