数据框中的数字向量的字符值
从数据框中,我获得了列的字符向量: 按日期,时间和group_by日期安排
fall_hc %>% arrange(a_dat,AZeit) %>% group_by(a_dat) %>%
mutate(time_vec = str_c(snzeit,collapse= ",")) %>%
ungroup() %>%
filter(!is.na(time_vec))
此符号向量,例如:
x <- c("5, 31, 16, 64, 9, 10, 31")
我需要在dataframe中的x中的数字向量: 5 31 16 64 9 10 31.
因为我想计算diff(x)
:26 -15 48 -55 1 21.
并进一步处理这以计算否定差异的数量。
以下是一些数据:
tibble::tribble(
~a_dat, ~AZeit, ~snzeit,
"2019-01-02", "24180", 31,
"2019-01-02", "24360", 27,
"2019-01-02", "24480", 16,
"2019-01-02", "24780", 64,
"2019-01-02", "30420", 9,
"2019-01-02", "30840", 10,
"2019-01-02", "35280", 31,
"2019-01-03", "24120", 40,
"2019-01-03", "24120", 27,
"2019-01-03", "24480", 6,
"2019-01-03", "24480", 4,
"2019-01-03", "24780", 9,
"2019-01-03", "25380", 25,
"2019-01-03", "26460", 33,
"2019-01-04", "24000", 5,
"2019-01-04", "24360", 2,
"2019-01-04", "24900", 1,
"2019-01-04", "27180", 29,
"2019-01-04", "30600", 8,
"2019-01-07", "24780", 25,
"2019-01-07", "24840", 4,
"2019-01-07", "28920", 3,
"2019-01-07", "31620", 11,
"2019-01-08", "24060", 46,
"2019-01-08", "24480", 7,
"2019-01-08", "25260", 4,
"2019-01-08", "27900", 5,
"2019-01-08", "29820", 5,
"2019-01-08", "30060", 74,
"2019-01-08", "33360", 5,
"2019-01-08", "33600", 28,
"2019-01-08", "34200", 15,
"2019-01-08", "35520", 13,
"2019-01-08", "36000", 19,
"2019-01-08", "44100", 24
)
它们已经对其进行分类,因此您可以删除%&gt;%bepand(a_dat,azeit)。
为了澄清目的: 我需要知道如何对Snzeit进行分类,这是从切割到缝合线的时间。想确定从短到长时间分类的那些日子。
From a dataframe I get a character vector of a column by:
arrange by date, time and group_by date
fall_hc %>% arrange(a_dat,AZeit) %>% group_by(a_dat) %>%
mutate(time_vec = str_c(snzeit,collapse= ",")) %>%
ungroup() %>%
filter(!is.na(time_vec))
This results in character vectors like:
x <- c("5, 31, 16, 64, 9, 10, 31")
I need a numeric vector from this x within a dataframe:
5 31 16 64 9 10 31.
because I want to calculate diff(x)
: 26 -15 48 -55 1 21.
and further process this to calculate the number of negativ differences.
Here are some data:
tibble::tribble(
~a_dat, ~AZeit, ~snzeit,
"2019-01-02", "24180", 31,
"2019-01-02", "24360", 27,
"2019-01-02", "24480", 16,
"2019-01-02", "24780", 64,
"2019-01-02", "30420", 9,
"2019-01-02", "30840", 10,
"2019-01-02", "35280", 31,
"2019-01-03", "24120", 40,
"2019-01-03", "24120", 27,
"2019-01-03", "24480", 6,
"2019-01-03", "24480", 4,
"2019-01-03", "24780", 9,
"2019-01-03", "25380", 25,
"2019-01-03", "26460", 33,
"2019-01-04", "24000", 5,
"2019-01-04", "24360", 2,
"2019-01-04", "24900", 1,
"2019-01-04", "27180", 29,
"2019-01-04", "30600", 8,
"2019-01-07", "24780", 25,
"2019-01-07", "24840", 4,
"2019-01-07", "28920", 3,
"2019-01-07", "31620", 11,
"2019-01-08", "24060", 46,
"2019-01-08", "24480", 7,
"2019-01-08", "25260", 4,
"2019-01-08", "27900", 5,
"2019-01-08", "29820", 5,
"2019-01-08", "30060", 74,
"2019-01-08", "33360", 5,
"2019-01-08", "33600", 28,
"2019-01-08", "34200", 15,
"2019-01-08", "35520", 13,
"2019-01-08", "36000", 19,
"2019-01-08", "44100", 24
)
They are already sorted, so you can leave out %>% arrange(a_dat,AZeit).
To clarify the purpose:
I need to know how the operations are sorted with respect to snzeit, thats the time from cut to suture. Want to identify those days where they are sorted from short to long.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解了您的问题,您需要在第一名中创建该字符向量,您只需要列表柱子,然后在每个列表上应用diff并计算每个
a_dat
由 reprex软件包(v2.0.1)
If I have understood your problem correctly, you donot need to create that character vector in the 1st place, you just need list-column and then applying diff on each list and calculate the number of negative values for each
a_dat
Created on 2022-07-07 by the reprex package (v2.0.1)
在 list 中将数字保留为 n数字:
然后,我们可以在下面的数字列表中进行:
Keep numbers as numeric in a list:
Then we can do below on the list of numbers: