最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

R Analysing data with different time stamps - Stack Overflow

programmeradmin0浏览0评论

I have a huge dataset of several laboratory results for several patients. In the example dataset I have several Puls measurements at different examinations. Puls1 was determined at baseline visit and Puls 2 at the second visit, etc. What I already did was to evaluate the changes over time by using ggplot, however, due to the huge amount of data, the plots are inappropriate. What I want to do is to detect those patients who had changes +/- 5 regarding their Puls looking at all of the different examinations (in this example Puls1, Puls2, Puls3).

Here is a small example dataset:

ID <- c(1, 2, 3)
Puls1 <- c(55, 70, 65)
Puls2 <- c(55, 70, 80)
Puls3 <- c(80, 70, 75)

So in this case of changes between +/-5 I would detect patient 1 and patient 3. Could anyone help me out here?

I have a huge dataset of several laboratory results for several patients. In the example dataset I have several Puls measurements at different examinations. Puls1 was determined at baseline visit and Puls 2 at the second visit, etc. What I already did was to evaluate the changes over time by using ggplot, however, due to the huge amount of data, the plots are inappropriate. What I want to do is to detect those patients who had changes +/- 5 regarding their Puls looking at all of the different examinations (in this example Puls1, Puls2, Puls3).

Here is a small example dataset:

ID <- c(1, 2, 3)
Puls1 <- c(55, 70, 65)
Puls2 <- c(55, 70, 80)
Puls3 <- c(80, 70, 75)

So in this case of changes between +/-5 I would detect patient 1 and patient 3. Could anyone help me out here?

Share Improve this question asked Feb 6 at 12:54 USER12345USER12345 1036 bronze badges 2
  • 2 Make your data tidy by pivoting to long format. (Your data frame isn't tidy at the moment because information you need to do the analysis is contained in the column names rather than values.). The group by ID and calculate the maximum and minimum values, and the difference between them. The filter to obtain IDs whose absolute difference is greater than or equal to 5. This approach is simple and robust with respect to the number of time points considered. – Limey Commented Feb 6 at 13:08
  • Thanks a lot. That's a great idea. – USER12345 Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 1

You can solve this problem by computing the differences between consecutive pulse measurements for each patient and checking if any difference exceeds +/-5:

# Sample dataset
ID <- c(1, 2, 3)
Puls1 <- c(55, 70, 65)
Puls2 <- c(55, 70, 80)
Puls3 <- c(80, 70, 75)

# Create a dataframe
df <- data.frame(ID, Puls1, Puls2, Puls3)

# Detect patients with changes greater than ±5
df$flag <- apply(df[, -1], 1, function(x) any(diff(x) > 5 | diff(x) < -5))

# Filter patients who have significant pulse changes
patients_with_changes <- df[df$flag, "ID"]

# Output result
print(patients_with_changes)
发布评论

评论列表(0)

  1. 暂无评论