Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract columns that don't have a header or name in R

Tags:

r

I need to extract the columns from a dataset without header names.

I have a ~10000 x 3 data set and I need to plot the first column against the second two.

I know how to do it when the columns have names ~ plot(data$V1, data$V2) but in this case they do not. How do I access each column individually when they do not have names?

Thanks

like image 929
SwimBikeRun Avatar asked Dec 21 '22 04:12

SwimBikeRun


1 Answers

Why not give them sensible names?

names(data)=c("This","That","Other")
plot(data$This,data$That)

That's a better solution than using the column number, since names are meaningful and if your data changes to have a different number of columns your code may break in several places. Give your data the correct names and as long as you always refer to data$This then your code will work.

like image 183
Spacedman Avatar answered Jan 12 '23 00:01

Spacedman