Can I refer to variables by the number of the column they reside in?
Here's why I want to know: for each observation, I have three vectors in Euclidean space, so my columns are
obsID | v1b1 v1b2 v2b1...v5b4 | tv1b1 tv1b2 tv2b1...tv5b4 | nv1b1 nv1b2 nv2b1...nv5b4
where the |
are included simply for readability. My variable names look like those above, but I don't know the naming pattern ahead of time. I can get the length of each vector as ng = (c(k) - 1)/3
, so if I could refer to variables by column, it would be straightforward to write a loop to find Euclidean distances, e.g., from v
to nv
.
I know there are other ways to go about calculating the Euclidean distance (like reshaping the data; or extracting the varnames from 2/(ng+1)
and doing a foreach
loop on them), but if there is a way to reference variables by column number, I would like to know it.