Save result of for loop in a vector

Posted by hendrik on Stack Overflow See other posts from Stack Overflow or by hendrik
Published on 2012-12-02T17:01:40Z Indexed on 2012/12/02 17:03 UTC
Read the original article Hit count: 267

Filed under:

i think I'm just too tired to see the mistake. i wrote a function to get the maximal value for two data sets from a for loop

plot_zu <- function(x) {for (i in 1:x){
    z=data_raw[grep(a[i], data_raw$Gene.names),]
    b=data_raw_ace[grep(a[i], data_raw_ace$Gene.names),]
    p<-vector("numeric", length(1:length(a)))
    p[i]<-max(z$t_test_diff)
    return(p)}

}

so picture: a is a vector of names and the data set (data_raw(_ace)) are filtered by it. In the end i would like to have all maxima values of column t_test_diff in a vector. After that i want to add the t_test_diff column values from data_raw_ace also.

So the problem is, that i get this:

[1] 1.210213 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

[8] 0.000000 0.000000

So there is a problem with brackets or something but i cannot see it ( first value fits). Sorry for no good example but i think it is understandable and an easy to solve question.

If im to dumb to explain my problem right, i will add an example. !! Thx a lot !! grateful Hendrik

© Stack Overflow or respective owner

Related posts about r