Create New Variables in R Based on Existing Variable Values
To create new variables in R that are equal to the values of existing variables, you can use the assignment operator (<- or =) to assign the values of the existing variables to the new variables. Here's an example:
# Example data
var1 <- 5
var2 <- 10
var3 <- 15
# Create new variables equal to the value of existing variables
new_var1 <- var1
new_var2 <- var2
new_var3 <- var3
# Print the values of the new variables
new_var1
new_var2
new_var3
In this example, three new variables (new_var1, new_var2, and new_var3) are created with values equal to the existing variables var1, var2, and var3, respectively. The values of the new variables are then printed, which will display 5, 10, and 15 respectively.
原文地址: https://www.cveoy.top/t/topic/o9Mi 著作权归作者所有。请勿转载和采集!