-1

I am new to coding and I received this code from a colleague for research purposes. The original data set for this code had 4 spectral variables, 12 texture variables and a combination of spectra and texture resulting in 16 variables in total. I am running the code only with texture variables but now I only have 6 texture variables in the new data set. I have attached the first part of the original code below where I have 12 texture variables..Please could someone assist me in changing my code using the new data set with 6 texture variables...I have attached an example of how my data is set up which is exactly the way the original data set is set up just with only 6 texture variables at the end.

Here is the image:

enter image description here

#change your work directory
#############################
setwd("C:/Texture")

############################

#output all resuls to a text file
#change apend to TRUE to record all analysis
#sink("Results.txt",append =F)

 source("plsrfsource.r")

    data<-read.csv("texture0ratios.csv",header=T, na.strings=c(".", "NA", "", "?"))

# Check the dataset

colnames(data)

#select response variable
#this example uses EnumAge

################
y <-data$EnumAge
################

#make sure that your explantory variables are in the same order as the example dataset

#######################
#texture variables only

x<-data[,16:27]

#spectral variables only
#x<-data[,12:15]

#using all the variables
#x<-data[,12:27]
######################


colnames(x)

#there must be 12 texture variables
#4 spectral variables
length (x)

#join the x and y 

dataset<-cbind(y,x)

# split into test and training datasets

set.seed(123)

inTrain <- createDataPartition(y, p = 0.7, list = F)
dataTrain<- dataset[inTrain[,1],]
dataTest <- dataset[-inTrain,]

trainY<-dataTrain$y
trainX<-as.matrix(dataTrain[-1])

testY<-dataTest$y
testX<-as.matrix(dataTest[-1])
989
  • 12,579
  • 5
  • 31
  • 53
  • It's not very clear what you're asking, from your title I was expecting to see an error in the question, but there isn't one. What exactly is the problem? Also, please include images in the body of the question, not as external links – Taegost Jun 22 '16 at 12:44
  • Looks like your data has column names. Why don't you use column names and subset the data rather than using numeric values. By which, you miss the count every time the column number changes. This should give you some direction. http://stackoverflow.com/questions/5234117/how-to-drop-columns-by-name-in-a-data-frame – user5249203 Jun 22 '16 at 15:41
  • When I changed the parameters from 27 to 21 because the new data set only has 6 texture variables I am getting an error saying "x not found" "error undefined columns selected" I want to know how to amend this code above so that I can run the code with 6 texture variables and not 12 texture variables as the original code above states. – Nickelz Jun 23 '16 at 08:48

1 Answers1

0

You only need to make a few minor adjustments:

#######################
#texture variables only

x<-data[,16:21]

#spectral variables only
#x<-data[,12:15]

#using all the variables
#x<-data[,12:21]
######################

Let me know if this does not solve your problem!

A. Stam
  • 2,148
  • 14
  • 29
  • Thanks for the responses. My initial thought was to make the change you suggested by using 21 instead of 27 because I only have 6 texture variables. When I made that change I got an error... It's said "x not found" "error undefined columns selected". I did not write this code and the colleague that wrote it is out of the country on conference and is unable to amend the code before this research is due. Your help will be very much appreciated. – Nickelz Jun 23 '16 at 08:46