• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How can I perform different operations in the same column of data frame?

Resolved: How can I perform different operations in the same column of data frame?

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m using R to analyze data. I have an ordered grouped time series that shows the brightness of a sample at different times, starting at 0
Group Time Brightness Retention
A 0 100 NA
A 50 70 = 70 /100
A 100 20 = 20/100
B 0 90 NA
B 50 80 = 80 /90
B 100 50 = 50/90

To calculate retention, I have to divide by the brightness at time 0 for that group. But there are multiple time zeros throughout the table. I tried using a for loop, but due to the length of the data, this takes about 15 seconds to run; I’m looking for more efficient ways.
Thanks for helping ๐Ÿ™‚

Answer:

You can use ifelse to calculate Retention on Time not equal to 0.

Data


df <- structure(list(Group = c("A", "A", "A", "B", "B", "B"), Time = c(0L, 50L, 100L, 0L, 50L, 100L), Brightness = c(100L, 70L, 20L, 90L, 80L, 50L)), class = "data.frame", row.names = c(NA, -6L)) [/code]

If you have better answer, please add a comment about this, thank you!

dataframe r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: When converting markdown to latex with pandoc, how can I end a block before the next heading?

26/03/2023

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.