Me gustaría mostrar los coeficientes de correlación en una tabla (idealmente - con valor de p). Sin embargo, mi código produce exactamente los mismos valores para cada periodo (así que algo está claramente mal). ¿Podrías darme algún consejo?
#En primer lugar, leo mi tabla de datos desde un archivo CSV:
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)
# Escribir: class(imported[["Period"]]) produce:
# [1] "factor"
#Escribir: levels(imported[["Period"]]) produce:
# [1] "Verano 2010" "Verano 2011" "Invierno 2010" "Invierno 2011" "Invierno 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)
EDITAR:
Código que lee el archivo desde Github:
library(RCurl)
x <- getURL("https://raw.githubusercontent.com/kedziorm/testowe/master/data_for_R.csv")
imported <- read.csv (text=x, 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)
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)
EDITAR: Esto debería funcionar finalmente:
x <- "Period\tDate\tData1.MEAN\tData1.MEDIAN\tData2.MEAN\tData2.MEDIAN\tData3.MEAN\tData3.MEDIAN\nInvierno 2010\t26-03-2010\t0,3580917\t0,307479\t0,551191\t0,612853\t0,3476462\t0,3996462\nInvierno 2010\t26-04-2010\t0,3016958\t0,2643808\t0,417791\t0,393714\t0,2811050286\t0,3061050286\nVerano 2010\t03-07-2010\t0,1916181\t0,1816603\t0,390925\t0,37385\t0,2183438286\t0,2923438286\nVerano 2010\t04-07-2010\t0,2548711\t0,1738567\t0,4349834\t0,4957131\t0,2467746286\t0,3437746286\nInvierno 2011\t01-11-2010\t0,3393042\t0,2870481\t0,497295\t0,538132\t0,3210420857\t0,3690420857\nVerano 2011\t04-06-2011\t0,222748\t0,2218226\t0,363823\t0,275725\t0,2309696\t0,2809696\nVerano 2011\t05-06-2011\t0,241889\t0,1918457\t0,373566\t0,292997\t0,2306573429\t0,2966573429\nInvierno 2012\t07-11-2011\t0,2264874\t0,2601413\t0,373048\t0,274139\t0,2456219143\t0,2756219143\nInvierno 2012\t08-11-2011\t0,2414665\t0,2662565\t0,314382\t0,279857\t0,2348871429\t0,2598871429\nInvierno 2012\t09-11-2011\t0,2817838\t0,2325952\t0,376063\t0,468148\t0,254412\t0,287412\nInvierno 2012\t10-11-2011\t0,2476841\t0,2667485\t0,406902\t0,476582\t0,2632384571\t0,3632384571\n"
imported <- read.csv (text=x, 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)
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)