I am reading data from UCI repository into table.
forestfire <- read.table(file = "http://archive.ics.uci.edu/ml/machine-learning-databases/forest-fires/forestfires.csv", header = TRUE, sep = ',')
How can I convert month and day column to corresponding numbers? I also want to divide this table to 2 matrices.
Best How To :
How can I convert month
R has a built in vector for the abbreviated days of the month, and we can use the match function to convert them:
forestfire$month = match(forestfire$month,tolower(month.abb))
and day column
To my knowledge, there isn't a similar vector for days, but we can create one:
day.abb = c("Mon","Tue","Wed","Thu","Fri","Sat","Sun")
forestfire$day = match(forestfire$day,tolower(day.abb))
I'm don't know what day you want the week to start with, but the
day.abb can be changed to your liking. This one has Monday = 1, Tuesday = 2, etc.
I also want to divide this table to 2 matrices
You'd have to be more specific on how you want them separated, but you can use
mySplit1 = as.matrix(forestfire[,1:5)
mySplit2 = as.matrix(forestfire[,6:13])
for instance if you wanted to divide it at the first five columns and last 8 columns. The 1:5 and 6:13 can be exchanged for vectors containing the column numbers of forestfire you want in each matrix.