When piping in R, do you always have to set the variable to the data frame? i.e. variable <- variable %>%

Hi I am doing the R course and I am still confused on setting variables in data frames. The example I will use is with the US census project. my question is in each section (also for everyday R usage) do you always have to do ‘us_census ← us_census %>%’ and then the next operation such as colnames or mutate or select,etc…? or when do you simply do ‘us_census %>%’ and the the next operation such as colnames or mutate or select,etc…?

Hello, @java7225832738, welcome to the forums. I’m not sure I fully understand your question, but it seems to be more of a general programming question than one particular to R, if my understanding is correct. We can ask the computer to perform many operations. We can chain operations together in some languages, or pipe output from one operation straight into the next operation. Assigning a variable to the results of operations is what allows us to use those results later on. For example, if I do this:

     5 * 10

I’ll see this output:

I have the result of the equation, but I don’t have access to reuse that result further along in my code, because it has no variable assigned to it.

Let me know if I’ve completely misinterpreted your question.

Hi midlindner,

thanks for responding. yes my question was specifically for R. What I am trying to essentially ask is what the difference is between “variable or data frame ← variable or data frame %>% colnames()” and “variable or data frame %>% colnames()”? This is what has been confusing me during some of the practices for R and was not sure what the difference was between them and if applicable, when to choose one over the other.