How to use variable labels in R?
问题 I have a function that takes input as the column name of dataframe as columnname~1 . The dataframe consists of about 50 columns in which I want to repeat the process, I can use a for loop to generate column name as a character which unfortunately the function does not recognize. The difference is just M1~1 (works) vs "M1"~1 Any suggestions are welcome 回答1: Try: as.formula(paste("M1","1",sep="~")) 回答2: Use the "[[ function? datafrm[[M1]] ~ 1 That function will interpret the character value and