I have this matrix and following code:
# Remove NA-observations from dataset "lus" and removing row "totalsum"
lus2 <- na.omit(lus)
lus3 <- lus2[-c(10),]
# The problem now is that "laksepris" has months in the columns, while "lus" has months in the rows
laksepris2 <- laksepris %>%
spread (Month, Pris)
test <- rbind(setDT(lus3), setDT(laksepris2), fill=TRUE)
test[10,1] <- "Pris pr.kilo"
test_round <- test %>%
mutate_if(is.numeric, round, digits = 2)
#-------------------------------------------
rearranget_lus <- as.data.frame(t(test_round))
rearranget_lus
# Removing first row, and renaming the columns:
lus_1 <- rearranget_lus[-c(1),]
names (lus_1) [1] <- "Finmark"
names (lus_1) [2] <- "Troms"
names (lus_1) [3] <- "Nordland"
names (lus_1) [4] <- "Nord-Trondelag"
names (lus_1) [5] <- "Sor-Trondelag"
names (lus_1) [6] <- "More og Romsdal"
names (lus_1) [7] <- "Sogn og Fjordane"
names (lus_1) [8] <- "Hordaland"
names (lus_1) [9] <- "Rogaland og Agder"
names (lus_1) [10] <- "Pris pr.kilo"
I just started using R, and I am therefore wondering how I can run a correlation between the values in "pris pr.kilo" against the values in column "Finmark". Following I would also like to loop this, so that the loop runs the correlation between "pris.pr.kilo" and all the other columns as well.
Does anyone have a suggestion to how this is done?