r - Subtract minimum of the column based on other column -


I have a dataframe as follows:

  D Year Total file 1999 3, 9 31 12000 A 2002 4,273.71,020 In 2005 a 4601.414 9 3 a 2008 4101.32100 a 1999 346.82000 B. 2002 134.30882b 2005 130.43038 B 2008 88.27546 B  

I want to minimize the total and reduce it to every group defined by the file.
I can consider getting the lowest with:

  tapply (d $ total, d $ file, min)  

but I can not think of the wise, the way the minimum amount of vector gets reduced.

After

I would suggest that and avenue . Something like this: (mydf, {tot2 & lt; - avenue (total, file, fun = function (x) - minute (x))}) # years total file tot2 # 1 1999 3, 9 31.12,000 A 0.00,000 # 2 2002 4,273.71020 A 342.59, 020 # 3 2005 4,601.414 9 3 A 670.29, 493 # 4 2008 4,101 .32100 One 170.20,100 # 5 1999 346.82,000 b 258.54,454 # 6 2002 134.30,882 b 46.03,336 # 7 2005 130.43,038 b 42.15,4 9 2 # 8 2008 88.27,546 b 0.00,000


Or, with "data.table":

  library ( Data.table) DT & lt; - Data.table (mydf) DT [, tot2: = Total - Min (total), = from file] []  

Or, with "dplyr":

  Library (dplyr) Mydf% & gt;% group_by (file)%>% mutate (tot2 = Total - Min (total))  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -