0

I am lost as to how to convert a specific column from a .csv file into a matrix. I was able to do it without using the matrix function, but how can I do it using the matrix function?

setwd("C:/Users/Owner/Folder/data/data")
getwd()
options(max.print=999999)
df=read.csv("C:/Users/Owner/Folder/data/data/file.csv",
        stringsAsFactors=FALSE,
        header=TRUE)
a = df[889:1248, 4]

dim(a) <- c(30, 12)
rowNames = c(1961:1990)
colNames = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
dimnames(a) = list(rowNames, colNames)
print(a)
  • 1
    Have you read `help("matrix")`? I'm confused by your question because doing it with the `matrix` function is easier than what you are doing now. – Roland Sep 15 '22 at 07:21
  • 1
    As an aside, changing the working directory is generally considered to be [poor practice](https://stackoverflow.com/questions/73489216/choose-working-directory-in-code-option-of-r-chunk#73489216). – Limey Sep 15 '22 at 07:34

0 Answers0