PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 7, 2022

[FIXED] How do I Divide Values in a Column by the Value in the Last Cell?

 October 07, 2022     dataframe, r, statistics     No comments   

Issue

So I am working in R, and I am trying to write a function. But I reached a roadblock.

I have the following df:

Number Freq CumFreq
00.1 2 2
00.5 1 3

...so on and so forth.

I'd like to have it so the numbers in df$CumFreq are divided by the last cell in the df$CumFreq, and create a new column. For instance:

Number Freq CumFreq CF/n
00.1 2 2 0.667
00.5 1 3 1

Any advice on how to write this out?


Solution

You can try

df$CFn <- with(df,CumFreq/sum(Freq))

or

df$CFn <- with(df,CumFreq/tail(CumFreq,1))


Answered By - ThomasIsCoding
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing