This has got to be a simple answer. I want to subset my data for testing purposes. I have a data frame where I want to keep all columns of information, just simply reduce the number of observations PER individual. So, I have a unique Identifier and about 50 individuals. I want to select only 2 individuals AND and I want to select only 500 data points from those 2.
My data frame is called wloc08. There are 50 unique IDs. I am only taking 2 of those individuals but of those 2, I’d like only 500 data points from each.
subwloc08=subset(wloc08, subset = ID %in% c("F07001","F07005"))
somewhere in this statement can I use [?
reduced= subwloc08$ID[1:500,]
Doesn’t work.
You could use
lapply:Your command
reduced = subwloc08$ID[1:500,]didn’t work sincesubwloc08$IDis a vector. However,reduced = subwloc08$ID[1:500]would have worked but would have returned the first 500 values ofsubwloc08$ID(not the whole rows ofsubwloc08).If you want to run this command for the first 30 subjects, you could use
unique(wloc08$ID)[1:30]instead ofc("F07001", "F07005"):