Re: [R] create a function with "subset" statement

2015-01-29 Thread JSHuang
Hi, The following is implemented with function named subsetAll. It calls the function subset1. The input to subset1 is the matrix A and a vector indicating the beginning and ending values for columns 1 and 2. Input to subsetAll is the matrix A and a matrix that is row bind from those vectors

Re: [R] Variables of a function called inside another one

2015-01-29 Thread JSHuang
Hi, Maybe I missed something. The following example works. It should not cause any problem with the same parameter names since their scopes are within the functions. > function2 <- function(a,b,c,d){ + a+b+c+d} > function2(1:2,2:3,3:4,4:5) [1] 10 14 > function1 <- function(a,b,c,d){ + newb <-

Re: [R] split rows by range

2015-01-28 Thread JSHuang
Hi, I define a function named starStop with three inputs: start, stop and increment. > startStop <- function(start, stop, increment) { + for (i in seq(start, stop, increment+1)) cat(i,"-",i+increment,"\n")} > startStop(12, 35, 5) 12 - 17 18 - 23 24 - 29 30 - 35 > startStop(42, 83, 5) 42 -

Re: [R] remove rows by a list of rownames

2015-01-28 Thread JSHuang
Hi, I think what you did is correct. The row name 'comp168081_c2_seq1' is not in the filter data frame. Neither is the row as the following small example shows. Actually the dim(datawithoutVF) 171417 12 is different from dim(data) 171471 12. Or 171417 is not the same as 171471 altho

Re: [R] problem with conditional column sums

2015-01-28 Thread JSHuang
Hi, I think you need quotation around I like the following: > status 2010 2011 2012 1 AAA 2 AII 3 AAA 4 UUU 5 AAA 6 III 7 UII 8 AUA 9 IAU 10III > apply(start,2,function(x)

Re: [R] Paste every two columns together

2015-01-28 Thread JSHuang
Hi, Here is my implementation: > combine <- function(x){ + odd <- x[1:length(x) %% 2 == 1] + even <- x[1:length(x) %%2 == 0] + paste0(odd,even)} > temp <- letters[1:24] > temp [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" > combine(temp)

Re: [R] Sum function and missing values --- need to mimic SAS sum function

2015-01-27 Thread JSHuang
Hi, Not sure if the following is what you look for: >x <- c(1:10, NA, 12:20) >sum(x[!is.na(x)]) -- View this message in context: http://r.789695.n4.nabble.com/Sum-function-and-missing-values-need-to-mimic-SAS-sum-function-tp4702344p4702392.html Sent from the R help mailing list archive at N