Hello all R gurus,
I have a following problem which I hope someone will help me to solve.
I have a data.frame in form similar to below. >
testframe<-data.frame("Name"=c("aa","aa","aa","aa","aa","bb","bb","bb","bb","bb"),"Value"=c(1,100,1,1,1,100,100,100,100,1))
Name Value
1 aa 1
2 aa 100
3 aa 1
4 aa 1
5 aa 1
6 bb 100
7 bb 100
8 bb 100
9 bb 100
10 bb 1 My aim is to find extreme upper whisker of boxplot
(boxplot.stats$stats[5]) of Values for each unique Name.I wrote the folowing
function for this upex<-function(x){boxplot.stats(subset(testframe, Name==x,
select=Value))$stats[5]} When I test with different strings it works correctly
> upex("bb")
[1] 100 > upex("aa")
[1] 1 But the problem is, how to apply this function to the whole dataframe at
once, so I would get list of values as an output. As an output I want to to get
values (1,1,1,1,1,100,100,100,100,100).I tried diffrent things such as>
upex(testframe$Name)
[1] 100> lapply(testframe, upex)
$Name
[1] 100
$Value
[1] NA> for (x in testframe["Name"]) print(upex(x))
[1] 100 As you can see, I get only one value as an output, so I assume these
calls apply the function to the whole set of values in the datframe. Is there a
way to make it work as I want it to? I hope my question is understandable
enough..
[[alternative HTML version deleted]]