Domi wrote on 08/01/2012 Jul 29, 2012; 8:59am:
> 
> Hello erverybody, 
> 
> I have a problem with my second for-loop. 
> 
> 1. First i read the tables. 
> 
> datos.mx1 <- read.table('PETmx1.csv',head=TRUE,sep=';') 
> datos.min <- read.table('PETmin.csv',head=TRUE,sep=';')


You are most likely to get good help with your R problem if you provide 
code that allows someone else to recreate your problem by just copying and 
pasting R code.  You could use dput() to share the first 10 rows of your 
two data files, instead of attaching your csv files.

datos.mx1 <- structure(list(Fecha = c("01.01.2006", "02.01.2006", 
"03.01.2006", 
"04.01.2006", "05.01.2006", "06.01.2006", "07.01.2006", "08.01.2006", 
"09.01.2006", "10.01.2006"), Mes = c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L), Serra.da.Foladoira = c(4.1, 5.5, 9.9, 9.7, 10.2, 
4.2, 1, 9.4, 8.3, 11.8), Santiago = c(14.4, 9.8, 13, 13.3, 12.2, 
14.2, 6.9, 12.2, 8.7, 12.9), Sergude = c(9.3, 11, 12.7, 12.7, 
13.1, 10.2, 3.2, 11.7, 9.1, 8.6), Rio.Do.Sol = c(5.7, 7.6, 9.9, 
9.7, 8, 5.4, 3.2, 10.9, 8.2, 9.8)), .Names = c("Fecha", "Mes", 
"Serra.da.Foladoira", "Santiago", "Sergude", "Rio.Do.Sol"), row.names = 
c(NA, 
10L), class = "data.frame")

datos.min <- structure(list(Fecha = c("01.01.2006", "02.01.2006", 
"03.01.2006", 
"04.01.2006", "05.01.2006", "06.01.2006", "07.01.2006", "08.01.2006", 
"09.01.2006", "10.01.2006"), Mes = c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L), Serra.da.Foladoira = c(-3.7, -0.9, -2.1, -3.7, 
-1.8, -4, -5.2, -3.9, -4.4, -5), Santiago = c(1.5, 4.4, -0.7, 
-2.7, 2.7, 0.4, -1.3, -4, -2.2, -6.7), Sergude = c(-0.2, 1, -0.4, 
-4.6, 1.7, -1.4, -3.3, -4.5, -6.4, -8.3), Rio.Do.Sol = c(-2.7, 
-0.1, -2.7, -3.6, -2, -3.5, -5.4, -4.2, -5.2, -5.5)), .Names = c("Fecha", 
"Mes", "Serra.da.Foladoira", "Santiago", "Sergude", "Rio.Do.Sol"
), row.names = c(NA, 10L), class = "data.frame") 


> PETmx1.csvPETmin.csv 
> 
> names(datos.mx1) 
> 
>  "Fecha"              "Mes"                "Serra.da.Foladoira" 
> "Santiago"           "Sergude"            "Rio.Do.Sol" 
> 
> You find in the first column the date and in the second only the 
> month. The other columns contain the temperature of the respective 
> weather stations. 
> 
> 2.  My aim is to calculate thresholds for each weather station. 
> 
> superior <- NULL 
> inferior <- NULL 
> LC <- NULL 
> LF <- NULL 
> 
> 
> for (i in 3:6){ 
> superior[i] <- 23+(datos.mx1[i]-23)*0.33; 
> inferior[i] <- 18+(datos.min[i]-18)*0.33; 
> } 


# You don't need a loop to execute your first step
superior <- 23 + (datos.mx1[, 3:6] - 23)*0.33
inferior <- 18 + (datos.min[, 3:6] - 18)*0.33


> #Until here everything is ok, but the next loop issues an error. I 
> must multiply the results of each weather station with a constant. 
> 
> for (i in 3:6){ 
> 
> LF[i] <- 1.26086956521739*superior[[i]]; 
> LC[i] <- 0.722222222222222*inferior[[i]] 
> } 


# You don't need a loop to execute your second step either
LF <- 1.26086956521739*superior
LC <- 0.722222222222222*inferior


> The error is: "Number of items to replace is not a multiple of 
> replacement length". 
> 
> 
> I hope someone can help me. I thank you very much. 
> 
> Best regards, 
> 
> Domi 

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to