I was wondering if there was a way to select specific columns via a sequence and create new variables from this.
So for example, if I had 8 columns with n observations, how could I create 4 variables that selects 2 rows sequentially? My dataset is much larger than this and I have 1416 variables with 62 observations each (I have pasted a link to the spreadsheet below, whereby the first column and row represent names). I would like to create new dataframes from this named as sites 1-12. So site 1 = df[,1:117]; site 2 = df [,119:237] etc.
I am planning on using this code for future datasets with even more variables so some form of loop or sequence function would be very effective if anyone could shed any light on how to achieve this?
Thank you in advance.
p.s @nrussell I have copied and pasted the output of the code you mentioned below, it follows on as a series of numbers like those displayed.
dput(z[ , 1:10])
structure(list(1
= c(0, 0, 0, 0, 0, 0, 0, 0, 0.0311410340342049,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.0207444023791158, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0312971643732546,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0376287494579976, 0, 0, 0, 0, 0,
0, 0),......... 10
= c(0, 0, 0, 0, 0.119280313679916,
0, 0, 0.301029995663981, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.715681882079494,
0.136831816210901, 0, 0, 0, 0.0273663632421801, 0, 0, 0, 0.0547327264843602,
0, 0, 0, 0, 0.0231561535126139, 0, 0, 0.0903089986991944, 0,
0, 0.0752574989159953, 0.159368821233872, 0.0272640716982664,
0.0177076468037636, 0, 0, 0.120411998265592, 0, 0, 0, 0, 0.0322532138211408,
0.0250858329719984, 0, 0, 0, 0.119280313679916, 0, 0.172922500085254,
0.225772496747986, 0, 0, 0, 0.0954242509439325, 0)), .Names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame", row.names = c(NA,
-62L))