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)}
}
Imagine: a is a vector of names and the data set (data_raw(_ace)) is 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 need be, I can add another example.
Thanks a lot!!
gratefully,
Hendrik
In the absence of data and even the call you make to this function, I’m going to offer an alternative based on what I think you are attempting. It appears you want to select only those rows of “data_raw” whose “Gene.names” column values are in the set defined by “a”. If so, that is just:
If you want to use grep or grepl inside “[” then use sapply:
When you do this, what is it that is desired?
If you want the maximum value for an identically named column in the two subset of data, then do this:
Based on you further comments above I (now) think maybe: