Unable to resolve error in seq.default(which(text == "")[1] + 1, length(text), 1): wrong sign in 'by' argument I am trying to run this code get.msg <- function(path) { con <- file(path, open = "rt", encoding = "latin1") text <- readLines(con) # The message always begins after the first full line break msg <- text[seq(which(text == "")[1] + 1,length(text),1)] close(con) return(paste(msg, collapse = "\n")) Kindly help [[alternative HTML version deleted]]
This is discussed in the help of seq(). See the details section of ?sec Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -----Oorspronkelijk bericht----- Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens Neeraj Kohli Verzonden: vrijdag 20 januari 2012 7:19 Aan: r-help at r-project.org Onderwerp: [R] error Unable to resolve error in seq.default(which(text == "")[1] + 1, length(text), 1): wrong sign in 'by' argument I am trying to run this code get.msg <- function(path) { con <- file(path, open = "rt", encoding = "latin1") text <- readLines(con) # The message always begins after the first full line break msg <- text[seq(which(text == "")[1] + 1,length(text),1)] close(con) return(paste(msg, collapse = "\n")) Kindly help [[alternative HTML version deleted]] ______________________________________________ R-help at 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.
Dear All, I have a function that it works in all of data. dim(data) 24(sample) 2600(variable) data [1] [2] [3] [4] ... [2600] [1] 10.73140 9.89450 9.12233 8.33994 9.43412 [2] 10.58010 10.02023 8.69257 8.46640 9.05038 [3] 10.80644 9.59991 8.71311 8.64168 9.08396 [4] 10.85874 9.16161 9.27786 9.10818 9.70617 [5] 10.89607 10.02847 8.81274 8.77573 9.12501 ... [24] 10.71652 9.71979 9.23088 8.87465 9.49099 Now I want that the function works on 100 subgroups of data. I determined this subgroups by subgroup matrix dim(subgroup) 100(subgroup) 2600(variable) Subgroup [1] [2] [3] [4]... [2600] [1] 1 0 0 0 0 [2] 1 0 0 0 0 [3] 1 0 0 0 0 [4] 0 1 0 0 0 [5] 0 0 1 0 0 ... [100] 0 0 1 0 0 the elements of subgroup are 1 ( show us the variable belongs the subgroup) or 0 (show us the variable does not belong the subgroup) result <- apply(subgroup , 1, function(z) func_LL(data[which(z==1),])) but I saw this error Error in ncol(data) : subscript out of bounds while our dimensions are correct, I think:( Thanks a lot for your guide. Best Regards, Soheila [[alternative HTML version deleted]]
On Wed, Feb 15, 2012 at 02:13:28PM +0100, Soheila Khodakarim wrote:> Dear All, > I have a function that it works in all of data. > > dim(data) > 24(sample) 2600(variable) > data > > > [1] [2] [3] [4] ... [2600] > > [1] 10.73140 9.89450 9.12233 8.33994 9.43412 [2] 10.58010 10.02023 8.69257 > 8.46640 9.05038 [3] 10.80644 9.59991 8.71311 8.64168 9.08396 [4] 10.85874 > 9.16161 9.27786 9.10818 9.70617 [5] 10.89607 10.02847 8.81274 8.77573 > 9.12501 > > ... > [24] 10.71652 9.71979 9.23088 8.87465 9.49099 > > Now I want that the function works on 100 subgroups of data. > > I determined this subgroups by subgroup matrix > > dim(subgroup) > > 100(subgroup) 2600(variable) > > Subgroup > > [1] [2] [3] [4]... [2600] > [1] 1 0 0 0 0 > [2] 1 0 0 0 0 > [3] 1 0 0 0 0 > [4] 0 1 0 0 0 > [5] 0 0 1 0 0 > ... > [100] 0 0 1 0 0 > > > > the elements of subgroup are 1 ( show us the variable belongs the subgroup) > or 0 (show us the variable does not belong the subgroup) > > > > result <- apply(subgroup , 1, function(z) func_LL(data[which(z==1),])) > > but I saw this error > > Error in ncol(data) : subscript out of bounds > while our dimensions are correct, I think:(Hi. The vector z is a row of matrix subgroup, so its length is the number of columns in data. So, i think, you mean result <- apply(subgroup , 1, function(z) func_LL(data[, which(z==1)])) where which(z==1) selects columns, not rows of data. Hope this helps. Petr Savicky.