Closed utterances-bot closed 3 years ago
Dear Antoine,
Thank you very much for all the insights you add here to help inexperienced people like me. I have one question regarding the manipulation of the variables. Is it possible to sign values to qualitative (Ordinal and Nominal) variables in R? For example; I have a variable named "Confidence in Vaccination" with three options: absolutely confident, absolutely sceptical, refrain to respond. In addition to this, there are plenty of such qualitative variables in my excel sheet. Therefore, my question is, after uploading excel data in R, is it possible to give values to these variables' options? If yes, can you please guide or share the link, in case I missed this information in your posts?
Thank you very much in the advance.
Dear Antoine,
Thank you very much for all the insights you add here to help inexperienced people like me. I have one question regarding the manipulation of the variables. Is it possible to sign values to qualitative (Ordinal and Nominal) variables in R? For example; I have a variable named "Confidence in Vaccination" with three options: absolutely confident, absolutely sceptical, refrain to respond. In addition to this, there are plenty of such qualitative variables in my excel sheet. Therefore, my question is, after uploading excel data in R, is it possible to give values to these variables' options? If yes, can you please guide or share the link, in case I missed this information in your posts?
Thank you very much in the advance.
Dear Gill,
Thanks for your question.
Let me try to be as clear as possible. So when importing an Excel file into R, if you have qualitative variables in your dataset, you can add the argument stringsAsFactors = TRUE
in the read.csv()
function.
With this argument R will consider your qualitative variables as factor variables, so R will assign a value for each level (in alphabetical order). This means that for your variable Confidence in Vaccination
, R will assign (in the "backend") the value 1
to the level absolutely confident
, 2
to the level absolutely sceptical
and 3
for the level refrain to respond
.
That being said, it will still be considered as a factor variable. Therefore, you won't be able to do computations on these levels (even if in the backend the levels are assigned to a numeric value), as computations (e.g., sum, mean, etc.) are not meaningful for factors/qualitative variables.
If your question was how to assign numeric values to these levels in order to do computations on it, you can transform your qualitative variable into a quantitative variable with the as.numeric()
function (note that it does not mean I recommend doing it, it's is just if, for some reasons, you need to).
Hope that helps.
Regards, Antoine
Variable types and examples - Stats and R
Learn the differences between a quantitative continuous, quantitative discrete, qualitative ordinal and qualitative nominal variable via concrete examples
https://statsandr.com/blog/variable-types-and-examples/