Find max/mean/min of the a subset in R

A simple question but I can't seem to figure it out. I want to find the maximum value in a subset of my data frame.

To my knowledge, it would look something like:


but I get the error message of incorrect number of dimensions.

This text is then supposed to be used as a logical test in another subscript


Your indexing command is wrong. Try

 max( dataframe[ , "vector1" ] )                              ## all of vector1

for all, and

 max( dataframe[ dataframe[,"vector2"]==1 , "vector1" ] )     ## subset

which you can write in long form as

 sdfind <- dataframe[,"vector2"]==1
 max( dataframe[sdfind, "vector1"])

You can also use the subset() function, or create a temporary variable, or even apply the summary() function at all values of vector2, or ..

Need Your Help

Difference between LLVM, GCC 4.2 and Apple LLVM compiler 3.1

ios compiler-construction llvm llvm-gcc

What are the major differences between LLVM GCC 4.2 and Apple LLVM compiler 3.1?

How can a user input an array of any length in java?

java arrays

I'm writing a program in java that requires the user to input a series of numbers, for example 1 2 3 4 .. until the user decides to stop and press enter. Normally what I would do is something like ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.