Creating a new variable

Hi

Currently, I'm having trouble to in rstudio.The question as above, How to create a new variable with a value given.

Please have a look to our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

Hi, and welcome

This is actually two questions: (1) how to create a variable (more generally referred to as an object; and (2) how to assign a value to that variable based on a test.

The first is simple: use the <- operator. In your case, since you don't yet know what the value that the object will take before the test, you could simply assign a "not applicable" value to it and change it later

my_variable <- NA

but that's not the best way to start.

Create, instead two variables, one for percentage of students qualifying for lunch and one for those who are English learners. Then review your notes and text to see how to perform a test for the value of a variable.

Hi NUR,

Given the homework policy cited here by andresrcs, we can only give you hints.
It would probably be helpful for you to look at the help files for the dplyr functions
if_else
and
case_when
by doing

library(dplyr) help(if_else)

and

library(dplyr) help(case_when)

and Googling some examples or vignettes on how these are used

Best wishes in learning R!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.