[Solved] Very new in R, subsetting columns


#columns 4 to the last one
myselec<-mydata[ 1, 4 : ncol(mydata)]

#put the columns you want to keep in a vector
columnsIWantToKeep <- c(4, 5, 6, 10, 12)
#subset your DFusing this vector
myselec<-mydata[1, columnsIWantToKeep]

The same applies to rows…

myselec<-mydata[ 4:nrow(mydata),] #get from row 4 to the end
myselec<-mydata[ c(1,3,5,7),] #get rows 1,3,5,7

You can even work by exclusion: tell the rows you don’t want and R will give you all others.

DontWant <- c(1,3,5)
myselec<-mydata[ -DontWant ,]  #note the 'minus' symbol to denote that you wish to exclude these

solved Very new in R, subsetting columns