Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

r - 减去一列中的值并更改另一个(Subtracting value in a column and change another one)

I have a data frame which looks like this:

(我有一个数据框架,看起来像这样:)
"22:36:59", "22:37:00", "22:37:01", "22:37:02", "22:37:03", "23:47:39", "23:47:40", "23:47:41", "23:47:42", "23:47:43", "23:47:44", "23:47:45", "23:47:46", "23:47:47", "23:47:48", "23:59:49", "23:59:50", "23:59:51", "23:59:52", "23:59:53", "23:59:54", "23:59:55", "23:59:56", "23:59:57", "23:59:58", "23:59:59"), class = "factor"), V5 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "CEST", class = "factor"), V6 = c(2019L, 2019L, 2019L, 2019L, 2019L, 2019L, 2019L, 2019L, 2019L, 2019L)), row.names = c(NA, 10L), class = "data.frame") I want to change the hours in column V4 by subtracting 07:00:00.

(“ 22:36:59”,“ 22:37:00”,“ 22:37:01”,“ 22:37:02”,“ 22:37:03”,“ 23:47:39”,“ 23 :47:40“,” 23:47:41“,” 23:47:42“,” 23:47:43“,” 23:47:44“,” 23:47:45“,” 23:47 :46“,” 23:47:47“,” 23:47:48“,” 23:59:49“,” 23:59:50“,” 23:59:51“,” 23:59:52 “,” 23:59:53“,” 23:59:54“,” 23:59:55“,” 23:59:56“,” 23:59:57“,” 23:59:58“, “ 23:59:59”),类=“因子”),V5 =结构(c(1L,1L,1L,1L,1L,1L,1L,1L,1L,1L),.Label =“ CEST”, class =“ factor”),V6 = c(2019L,2019L,2019L,2019L,2019L,2019L,2019L,2019L,2019L,2019L)),row.names = c(NA,10L),class =“ data.frame “)我想通过减去07:00:00来更改V4列中的小时。)

If the hours in column V4 is smaller than 07:00:00 then it should as well change the day in column V3 and in case the day goes to the month before then it should change the month in column V2.

(如果V4列中的小时数小于07:00:00,则还应更改V3列中的日期,并且如果该日期到达前一个月,则应更改V2列中的月份。)

The final aim of this is to count how many rows are there for each day, for which I can use: count(entertainment_one, c("V2", "V3")) but before I need to reorganise my data frame.

(这样做的最终目的是计算每天可以使用多少行:count(entertainment_one,c(“ V2”,“ V3”))但在我需要重新组织数据框之前。)

I am new to R and do not know where to start.

(我是R新手,不知道从哪里开始。)

Any help would be really appreciated, thank you very much!

(任何帮助将不胜感激,非常感谢!)

  ask by Sofia Olivieri translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...