Hello all,
I strongly believe, that my issue is quite easy to resolve. However, I have
no idea how to find/debug what is wrong and I would blame myself for
insufficient knowledge about data tables and some useful functions in R! as
apply, sapply, lapply.
My question is as follows:
I would like to display correlation coefficients in a table (ideally - with
p-value, but below there's only Pearson correlation coefficients). However,
my code produces exactly the same values for each period (so something is
obviously wrong). Could you give me any advice:
#first of all, I read my data table from CSV file:
imported <- read.table (file="/home/someone/data_for_R.csv",
header=TRUE, sep='\t', quote='"\'', dec=',',
fill=FALSE, comment.char="#",
na.strings = "NA", nrows = -1, skip = 0, check.names = TRUE,
strip.white FALSE, blank.lines.skip = TRUE)
# Typing: class(imported[["Period"]]) produces:
# [1] "factor"
#Typing: levels(imported[["Period"]]) produces:
# [1] "Summer 2010" "Summer 2011" "Winter
2010" "Winter 2011" "Winter
2012"
xx <-
imported[c("Period","Data1.MEAN","Data2.MEAN")]
result <- by(xx, xx$Period, function(x) {cor(xx$Data1.MEAN,
xx$Data2.MEAN)})
result.dataframe <- as.data.frame(as.matrix(result))
result.dataframe$C <- rownames(result)
Best regards,
Mateusz
[[alternative HTML version deleted]]