I can subset a column named A from a data frame x_data
using x_data$A
.
But if I do
some_string<-'A'
x_data$some_string
I get NULL. Can someone please explain why is it so. Thanks.
I can subset a column named A from a data frame x_data
using x_data$A
.
But if I do
some_string<-'A'
x_data$some_string
I get NULL. Can someone please explain why is it so. Thanks.
You can reference a data frame with the $
operator using a string literal, only a column. If you want to subset using a string, use the list syntax:
sub_df <- x_data[[some_string]]