Skip to content
Prev 13555 / 398502 Next

row-wise dataframe calculation

Dear Ken,
At 05:51 PM 13/09/2001 -0400, kestickler at netscape.net wrote:
The size of the dataset may prove to be a problem, but in principle this 
kind of calculation can be done with the apply function: apply(df, 1, var), 
where df is the data frame containing your data.
You can simply create a new variable in the data frame, e.g., df$var <- 
apply(df, 1, var) .

When you sort a variable in a data frame, usually the row names don't show 
in the result. But something like the following should work (again, if the 
size of the problem isn't too large for your resources):

   names(df$var) <- rownames(df); sort(df$var)

I hope that this helps,
  John

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._