用于在R中生成向量的多行的函数 [英] Function to generate multiple rows of vectors in R

查看:92
本文介绍了用于在R中生成向量的多行的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NOAA天气数据来构建数据框.我有一天的最高和最低温度,我正在尝试创建一个看起来像这样的表,其中:

I'm trying to build a dataframe using NOAA weather data. I have the max and min temps by day and I'm trying to create a table which looks like this where:

  • 第1行是日期(本质上是从我的数据集中转置的日期)
  • 第2行是每天的高温
  • 第3-85行是高于该温度的单元格的温度减去间隔(该间隔定义为(高温-低温)/84.84是映射的行数.

我正在像这样完成第1行和第2行(最大F是最大温度的向量):

I'm accomplishing rows 1 and 2 like this (max.F is a vector of the max temps):

rbind(as.character(data$Date),max.F)

其余的行我都在苦苦挣扎.通过这样做,我能够获得第3行,然后rbind到上面的行:

What I'm struggling with are the rest of the rows. I was able to get row 3 by doing this, and then rbind to the rows above:

vector <- numeric(length=nrow(data))
for(i in seq_along(max.F)){vector[i] <- max.F[i] - interval[i]}

我正在努力解决的问题是如何创建一个可以遍历并创建其余82行的函数.我对R(和一般而言的编程)还是很陌生,我尝试在一个函数内使用上面的代码片段,但运气不佳(它返回与第3行相同的值,并且只执行一行).我想我必须告诉它重复一遍,但是我不确定如何在其中进行操作:

What I'm struggling with is how to create a function that will loop through and create the rest of the 82 rows. I'm still fairly new to R (and programming in general) and I've tried using the code snippet above within a function without much luck (it returns the same value as row 3 and only does one row). I imagine I have to tell it to repeat, but I'm not sure how to work that in:

mapping <- function(x){
  bin <- rbind()
  vector <- for(i in seq_along(max.F)){vector[i] <- max.F[i] - interval[i]}
  for(i in vector){
    vector[i] <- vector[i] - interval[i]
    bin <- rbind(bin, vector)}
  return(bin)}

这里是dput(请让我知道我是否做得不好,这是我第一次使用此功能):

Here's the dput (please let me know if I haven't done this properly, it's my first time using this function):

structure(list(Date = structure(c(17897,17898,17899,17900, 17901、17902、17903、17904、17905、17906、17907、17908、17909, 17910、17911、17912、17913、17914、17915、17916、17917、17918, 17919、17920、17921、17922、17923、17924、17925、17926、17927, 17928、17929、17930、17931、17932、17933、17934、17935、17936, 17937、17938、17939、17940、17941、17942、17943、17944、17945, 17946、17947、17948、17949、17950、17951、17952、17953、17954, 17955、17956、17957、17958、17959、17960、17961、17962、17963, 17964、17965、17966、17967、17968、17969、17970、17971、17972, 17973、17974、17975、17976、17977、17978、17979、17980、17981, 17982、17983、17984、17985、17986、17987、17988、17989、17990, 17991、17992、17993、17994、17995、17996、17997、17998、17999, 18000,18001,18002,18003,18004,18005,18006,18007,18008, 18009、18010、18011、18012、18013、18014、18015、18016、18017, 18018、18019、18020、18021、18022、18023、18024、18025、18026, 18027、18028、18029、18030、18031、18032、18033、18034、18035, 18036、18037、18038、18039、18040、18041、18042、18043、18044, 18045、18046、18047、18048、18049、18050、18051、18052、18053, 18054、18055、18056、18057、18058、18059、18060、18061、18062, 18063、18064、18065、18066、18067、18068、18069、18070、18071, 18072、18073、18074、18075、18076、18077、18078、18079、18080, 18081、18082、18083、18084、18085、18086、18087、18088、18089, 18090,18091,18092,18093,18094,18095,18096,18097,18098, 18099、18100、18101、18102、18103),类=日期"),最大值= c(39, 30、29、40、47、52、48、53、45、21、25、29、30、32、26、33、36, 34、30、30、14、17、34、31、22、5、10、28、34、5,-14、6、20, 41、46、49、49、35、42、13、24、28、32、32、36、45、19、29、28, 29、34、35、31、43、45、33、19、25、28、26、38、32、20、13、21, 31、28、41、42、38、40、48、58、64、41、40、42、44、50、45、46, 50、53、49、45、51、58、65、59、45、39、49、53、58、46、53、68, 68、74、66、40、59、50、53、36、51、75、76、53、55、66、77、78, 63、62、69、63、44、53、51、52、59、48、58、66、73、68、54、73, 62、59、50、51、64、69、73、74、56、79、73、56、54、78、72、74, 81,76,73,67,75,78,81,84,73,71,82,83,81,82,79,77, 74、79、70、68、79、69、66、72、80、76、72、74、80、81、77、85, 89、90、90、91、90、87、90、91、89、89、85、80,NA,87、93、84, 87,92,91,88,83,91,87,92,94,79,77,79,81,83),Min = c(30, 26、23、23、29、30、32、32、18、14、14、17、27、15、23、25、28, 29,26,5,2,1,1,17,7,-7,-9,-11,-9,-3,-24,-25,-24,6, 17,39,24,24,32,3,3,3,23,28,11,11,9,9,8,14,21,10, 10、24、20、20、33、6、6、15、12、12、24、18,-4,-4、7、8、17 25、31、27、23、22、37、36、28、26、27、27、27、36、35、25、25, 33、26、27、31、40、37、22、22、27、34、34、41、39、39、48、45, 34、34、38、33、33、26、27、47、49、42、40、40、45、49、42、43 43、42、30、30、42、40、43、40、39、41、43、45、44、47、43、40, 37、39、39、39、51、55、45、42、45、45、45、54、54、54、65、53 57、53、56、59、61、54、49、53、59、59、56、59、63、60、53、57, 53、48、53、57、56、55、55、56、53、56、62、65、61、63、68、70, 69、69、68、69、70、70、73、73、67、62,NA,63、69、61、62、69, 69,70,71,74,70,77,71,65,60,61,60,62),间隔= c(0.107142857142857, 0.0476190476190476、0.0714285714285714、0.202380952380952、0.214285714285714, 0.261904761904762、0.19047619047619、0.25、0.321428571428571, 0.0833333333333333、0.130952380952381、0.142857142857143、0.0357142857142857, 0.202380952380952、0.0357142857142857、0.0952380952380952、0.0952380952380952, 0.0595238095238095、0.0476190476190476、0.297619047619048、0.142857142857143, 0.19047619047619、0.202380952380952、0.285714285714286、0.345238095238095, 0.166666666666667、0.25、0.44047619047619、0.44047619047619, 0.345238095238095、0.130952380952381、0.357142857142857、0.166666666666667, 0.285714285714286、0.0833333333333333、0.297619047619048、0.297619047619048, 0.0357142857142857、0.464285714285714、0.119047619047619、0.25, 0.0595238095238095、0.0476190476190476、0.25、0.297619047619048, 0.428571428571429、0.130952380952381、0.178571428571429、0.0833333333333333, 0.226190476190476、0.285714285714286、0.130952380952381、0.130952380952381, 0.273809523809524、0.142857142857143、0.321428571428571、0.154761904761905, 0.119047619047619、0.19047619047619、0.166666666666667、0.166666666666667, 0.166666666666667、0.285714285714286、0.202380952380952、0.166666666666667, 0.273809523809524、0.130952380952381、0.19047619047619、0.130952380952381, 0.130952380952381、0.202380952380952、0.30952380952381、0.25, 0.333333333333333、0.154761904761905、0.166666666666667、0.178571428571429, 0.202380952380952、0.273809523809524、0.107142857142857、0.130952380952381, 0.297619047619048、0.333333333333333、0.19047619047619、0.226190476190476, 0.285714285714286、0.321428571428571、0.297619047619048、0.261904761904762, 0.273809523809524、0.202380952380952、0.261904761904762、0.226190476190476, 0.285714285714286、0.0595238095238095、0.166666666666667、0.345238095238095, 0.238095238095238、0.345238095238095、0.380952380952381、0.0714285714285714, 0.25、0.202380952380952、0.238095238095238、0.119047619047619, 0.285714285714286、0.333333333333333、0.321428571428571、0.130952380952381, 0.178571428571429、0.30952380952381、0.380952380952381、0.345238095238095, 0.25、0.226190476190476、0.30952380952381、0.25、0.166666666666667, 0.273809523809524、0.107142857142857、0.142857142857143、0.19047619047619, 0.0952380952380952、0.226190476190476、0.297619047619048、0.357142857142857, 0.273809523809524、0.119047619047619、0.30952380952381、0.226190476190476, 0.226190476190476、0.154761904761905、0.142857142857143、0.297619047619048, 0.357142857142857、0.261904761904762、0.226190476190476、0.130952380952381, 0.44047619047619、0.333333333333333、0.130952380952381、0.107142857142857, 0.285714285714286、0.214285714285714、0.238095238095238、0.19047619047619, 0.273809523809524、0.19047619047619、0.166666666666667、0.226190476190476, 0.226190476190476、0.238095238095238、0.357142857142857、0.285714285714286, 0.214285714285714、0.273809523809524、0.285714285714286、0.297619047619048, 0.273809523809524、0.19047619047619、0.202380952380952、0.25, 0.261904761904762、0.202380952380952、0.238095238095238、0.30952380952381, 0.142857142857143、0.119047619047619、0.202380952380952、0.297619047619048, 0.238095238095238、0.226190476190476、0.214285714285714、0.214285714285714, 0.19047619047619、0.19047619047619、0.261904761904762、0.25, 0.238095238095238、0.25、0.261904761904762、0.261904761904762, 0.214285714285714、0.238095238095238、0.25、0.19047619047619, 0.19047619047619、0.214285714285714、0.214285714285714,NA,0.285714285714286, 0.285714285714286、0.273809523809524、0.297619047619048、0.273809523809524, 0.261904761904762、0.214285714285714、0.142857142857143、0.202380952380952, 0.202380952380952、0.178571428571429、0.273809523809524、0.166666666666667, 0.202380952380952,0.214285714285714,0.25,0.25)),类="data.frame",row.names = c(NA, -207L))

structure(list(Date = structure(c(17897, 17898, 17899, 17900, 17901, 17902, 17903, 17904, 17905, 17906, 17907, 17908, 17909, 17910, 17911, 17912, 17913, 17914, 17915, 17916, 17917, 17918, 17919, 17920, 17921, 17922, 17923, 17924, 17925, 17926, 17927, 17928, 17929, 17930, 17931, 17932, 17933, 17934, 17935, 17936, 17937, 17938, 17939, 17940, 17941, 17942, 17943, 17944, 17945, 17946, 17947, 17948, 17949, 17950, 17951, 17952, 17953, 17954, 17955, 17956, 17957, 17958, 17959, 17960, 17961, 17962, 17963, 17964, 17965, 17966, 17967, 17968, 17969, 17970, 17971, 17972, 17973, 17974, 17975, 17976, 17977, 17978, 17979, 17980, 17981, 17982, 17983, 17984, 17985, 17986, 17987, 17988, 17989, 17990, 17991, 17992, 17993, 17994, 17995, 17996, 17997, 17998, 17999, 18000, 18001, 18002, 18003, 18004, 18005, 18006, 18007, 18008, 18009, 18010, 18011, 18012, 18013, 18014, 18015, 18016, 18017, 18018, 18019, 18020, 18021, 18022, 18023, 18024, 18025, 18026, 18027, 18028, 18029, 18030, 18031, 18032, 18033, 18034, 18035, 18036, 18037, 18038, 18039, 18040, 18041, 18042, 18043, 18044, 18045, 18046, 18047, 18048, 18049, 18050, 18051, 18052, 18053, 18054, 18055, 18056, 18057, 18058, 18059, 18060, 18061, 18062, 18063, 18064, 18065, 18066, 18067, 18068, 18069, 18070, 18071, 18072, 18073, 18074, 18075, 18076, 18077, 18078, 18079, 18080, 18081, 18082, 18083, 18084, 18085, 18086, 18087, 18088, 18089, 18090, 18091, 18092, 18093, 18094, 18095, 18096, 18097, 18098, 18099, 18100, 18101, 18102, 18103), class = "Date"), Max = c(39, 30, 29, 40, 47, 52, 48, 53, 45, 21, 25, 29, 30, 32, 26, 33, 36, 34, 30, 30, 14, 17, 34, 31, 22, 5, 10, 28, 34, 5, -14, 6, 20, 41, 46, 49, 49, 35, 42, 13, 24, 28, 32, 32, 36, 45, 19, 29, 28, 29, 34, 35, 31, 43, 45, 33, 19, 25, 28, 26, 38, 32, 20, 13, 21, 31, 28, 41, 42, 38, 40, 48, 58, 64, 41, 40, 42, 44, 50, 45, 46, 50, 53, 49, 45, 51, 58, 65, 59, 45, 39, 49, 53, 58, 46, 53, 68, 68, 74, 66, 40, 59, 50, 53, 36, 51, 75, 76, 53, 55, 66, 77, 78, 63, 62, 69, 63, 44, 53, 51, 52, 59, 48, 58, 66, 73, 68, 54, 73, 62, 59, 50, 51, 64, 69, 73, 74, 56, 79, 73, 56, 54, 78, 72, 74, 81, 76, 73, 67, 75, 78, 81, 84, 73, 71, 82, 83, 81, 82, 79, 77, 74, 79, 70, 68, 79, 69, 66, 72, 80, 76, 72, 74, 80, 81, 77, 85, 89, 90, 90, 91, 90, 87, 90, 91, 89, 89, 85, 80, NA, 87, 93, 84, 87, 92, 91, 88, 83, 91, 87, 92, 94, 79, 77, 79, 81, 83), Min = c(30, 26, 23, 23, 29, 30, 32, 32, 18, 14, 14, 17, 27, 15, 23, 25, 28, 29, 26, 5, 2, 1, 17, 7, -7, -9, -11, -9, -3, -24, -25, -24, 6, 17, 39, 24, 24, 32, 3, 3, 3, 23, 28, 11, 11, 9, 8, 14, 21, 10, 10, 24, 20, 20, 33, 6, 6, 15, 12, 12, 24, 18, -4, -4, 7, 8, 17, 25, 31, 27, 23, 22, 37, 36, 28, 26, 27, 27, 27, 36, 35, 25, 25, 33, 26, 27, 31, 40, 37, 22, 22, 27, 34, 34, 41, 39, 39, 48, 45, 34, 34, 38, 33, 33, 26, 27, 47, 49, 42, 40, 40, 45, 49, 42, 43, 43, 42, 30, 30, 42, 40, 43, 40, 39, 41, 43, 45, 44, 47, 43, 40, 37, 39, 39, 39, 51, 55, 45, 42, 45, 45, 45, 54, 54, 54, 65, 53, 57, 53, 56, 59, 61, 54, 49, 53, 59, 59, 56, 59, 63, 60, 53, 57, 53, 48, 53, 57, 56, 55, 55, 56, 53, 56, 62, 65, 61, 63, 68, 70, 69, 69, 68, 69, 70, 70, 73, 73, 67, 62, NA, 63, 69, 61, 62, 69, 69, 70, 71, 74, 70, 77, 71, 65, 60, 61, 60, 62), Interval = c(0.107142857142857, 0.0476190476190476, 0.0714285714285714, 0.202380952380952, 0.214285714285714, 0.261904761904762, 0.19047619047619, 0.25, 0.321428571428571, 0.0833333333333333, 0.130952380952381, 0.142857142857143, 0.0357142857142857, 0.202380952380952, 0.0357142857142857, 0.0952380952380952, 0.0952380952380952, 0.0595238095238095, 0.0476190476190476, 0.297619047619048, 0.142857142857143, 0.19047619047619, 0.202380952380952, 0.285714285714286, 0.345238095238095, 0.166666666666667, 0.25, 0.44047619047619, 0.44047619047619, 0.345238095238095, 0.130952380952381, 0.357142857142857, 0.166666666666667, 0.285714285714286, 0.0833333333333333, 0.297619047619048, 0.297619047619048, 0.0357142857142857, 0.464285714285714, 0.119047619047619, 0.25, 0.0595238095238095, 0.0476190476190476, 0.25, 0.297619047619048, 0.428571428571429, 0.130952380952381, 0.178571428571429, 0.0833333333333333, 0.226190476190476, 0.285714285714286, 0.130952380952381, 0.130952380952381, 0.273809523809524, 0.142857142857143, 0.321428571428571, 0.154761904761905, 0.119047619047619, 0.19047619047619, 0.166666666666667, 0.166666666666667, 0.166666666666667, 0.285714285714286, 0.202380952380952, 0.166666666666667, 0.273809523809524, 0.130952380952381, 0.19047619047619, 0.130952380952381, 0.130952380952381, 0.202380952380952, 0.30952380952381, 0.25, 0.333333333333333, 0.154761904761905, 0.166666666666667, 0.178571428571429, 0.202380952380952, 0.273809523809524, 0.107142857142857, 0.130952380952381, 0.297619047619048, 0.333333333333333, 0.19047619047619, 0.226190476190476, 0.285714285714286, 0.321428571428571, 0.297619047619048, 0.261904761904762, 0.273809523809524, 0.202380952380952, 0.261904761904762, 0.226190476190476, 0.285714285714286, 0.0595238095238095, 0.166666666666667, 0.345238095238095, 0.238095238095238, 0.345238095238095, 0.380952380952381, 0.0714285714285714, 0.25, 0.202380952380952, 0.238095238095238, 0.119047619047619, 0.285714285714286, 0.333333333333333, 0.321428571428571, 0.130952380952381, 0.178571428571429, 0.30952380952381, 0.380952380952381, 0.345238095238095, 0.25, 0.226190476190476, 0.30952380952381, 0.25, 0.166666666666667, 0.273809523809524, 0.107142857142857, 0.142857142857143, 0.19047619047619, 0.0952380952380952, 0.226190476190476, 0.297619047619048, 0.357142857142857, 0.273809523809524, 0.119047619047619, 0.30952380952381, 0.226190476190476, 0.226190476190476, 0.154761904761905, 0.142857142857143, 0.297619047619048, 0.357142857142857, 0.261904761904762, 0.226190476190476, 0.130952380952381, 0.44047619047619, 0.333333333333333, 0.130952380952381, 0.107142857142857, 0.285714285714286, 0.214285714285714, 0.238095238095238, 0.19047619047619, 0.273809523809524, 0.19047619047619, 0.166666666666667, 0.226190476190476, 0.226190476190476, 0.238095238095238, 0.357142857142857, 0.285714285714286, 0.214285714285714, 0.273809523809524, 0.285714285714286, 0.297619047619048, 0.273809523809524, 0.19047619047619, 0.202380952380952, 0.25, 0.261904761904762, 0.202380952380952, 0.238095238095238, 0.30952380952381, 0.142857142857143, 0.119047619047619, 0.202380952380952, 0.297619047619048, 0.238095238095238, 0.226190476190476, 0.214285714285714, 0.214285714285714, 0.19047619047619, 0.19047619047619, 0.261904761904762, 0.25, 0.238095238095238, 0.25, 0.261904761904762, 0.261904761904762, 0.214285714285714, 0.238095238095238, 0.25, 0.19047619047619, 0.19047619047619, 0.214285714285714, 0.214285714285714, NA, 0.285714285714286, 0.285714285714286, 0.273809523809524, 0.297619047619048, 0.273809523809524, 0.261904761904762, 0.214285714285714, 0.142857142857143, 0.202380952380952, 0.202380952380952, 0.178571428571429, 0.273809523809524, 0.166666666666667, 0.202380952380952, 0.214285714285714, 0.25, 0.25)), class = "data.frame", row.names = c(NA, -207L))

推荐答案

这是我的解决方案.有一个警告.由于您的日期在粘贴的DF中的格式为整数,因此要将其转换回日期,您需要一个原点.我选择了"1970-01-01",其开始日期为"2019-01-01".如果此值低或高,则相应地调整原点以使其匹配.其余代码如下.

Here is my solution. There is one caveat. Since your Date is formatted as integer in the DF that you pasted, to convert it back to Date, you need an origin. I have choosen "1970-01-01" which gives me the starting date as "2019-01-01". If this is low or high, accordingly adjust the origin to match it. Rest of the code is as below.

Date  <- as.Date(c(17897, 17898, 17899, 17900, 17901, 17902, 17903, 17904, 17905, 17906, 17907, 17908, 17909, 17910, 17911, 17912, 17913, 17914, 17915, 17916, 17917, 17918, 17919, 17920, 17921, 17922, 17923, 17924, 17925, 17926, 17927, 17928, 17929, 17930, 17931, 17932, 17933, 17934, 17935, 17936, 17937, 17938, 17939, 17940, 17941, 17942, 17943, 17944, 17945, 17946, 17947, 17948, 17949, 17950, 17951, 17952, 17953, 17954, 17955, 17956, 17957, 17958, 17959, 17960, 17961, 17962, 17963, 17964, 17965, 17966, 17967, 17968, 17969, 17970, 17971, 17972, 17973, 17974, 17975, 17976, 17977, 17978, 17979, 17980, 17981, 17982, 17983, 17984, 17985, 17986, 17987, 17988, 17989, 17990, 17991, 17992, 17993, 17994, 17995, 17996, 17997, 17998, 17999, 18000, 18001, 18002, 18003, 18004, 18005, 18006, 18007, 18008, 18009, 18010, 18011, 18012, 18013, 18014, 18015, 18016, 18017, 18018, 18019, 18020, 18021, 18022, 18023, 18024, 18025, 18026, 18027, 18028, 18029, 18030, 18031, 18032, 18033, 18034, 18035, 18036, 18037, 18038, 18039, 18040, 18041, 18042, 18043, 18044, 18045, 18046, 18047, 18048, 18049, 18050, 18051, 18052, 18053, 18054, 18055, 18056, 18057, 18058, 18059, 18060, 18061, 18062, 18063, 18064, 18065, 18066, 18067, 18068, 18069, 18070, 18071, 18072, 18073, 18074, 18075, 18076, 18077, 18078, 18079, 18080, 18081, 18082, 18083, 18084, 18085, 18086, 18087, 18088, 18089, 18090, 18091, 18092, 18093, 18094, 18095, 18096, 18097, 18098, 18099, 18100, 18101, 18102, 18103),format="%Y-%m-%d",origin="1970-01-01")
Max <- c(39, 30, 29, 40, 47, 52, 48, 53, 45, 21, 25, 29, 30, 32, 26, 33, 36, 34, 30, 30, 14, 17, 34, 31, 22, 5, 10, 28, 34, 5, -14, 6, 20, 41, 46, 49, 49, 35, 42, 13, 24, 28, 32, 32, 36, 45, 19, 29, 28, 29, 34, 35, 31, 43, 45, 33, 19, 25, 28, 26, 38, 32, 20, 13, 21, 31, 28, 41, 42, 38, 40, 48, 58, 64, 41, 40, 42, 44, 50, 45, 46, 50, 53, 49, 45, 51, 58, 65, 59, 45, 39, 49, 53, 58, 46, 53, 68, 68, 74, 66, 40, 59, 50, 53, 36, 51, 75, 76, 53, 55, 66, 77, 78, 63, 62, 69, 63, 44, 53, 51, 52, 59, 48, 58, 66, 73, 68, 54, 73, 62, 59, 50, 51, 64, 69, 73, 74, 56, 79, 73, 56, 54, 78, 72, 74, 81, 76, 73, 67, 75, 78, 81, 84, 73, 71, 82, 83, 81, 82, 79, 77, 74, 79, 70, 68, 79, 69, 66, 72, 80, 76, 72, 74, 80, 81, 77, 85, 89, 90, 90, 91, 90, 87, 90, 91, 89, 89, 85, 80, NA, 87, 93, 84, 87, 92, 91, 88, 83, 91, 87, 92, 94, 79, 77, 79, 81, 83)
Min <- c(30, 26, 23, 23, 29, 30, 32, 32, 18, 14, 14, 17, 27, 15, 23, 25, 28, 29, 26, 5, 2, 1, 17, 7, -7, -9, -11, -9, -3, -24, -25, -24, 6, 17, 39, 24, 24, 32, 3, 3, 3, 23, 28, 11, 11, 9, 8, 14, 21, 10, 10, 24, 20, 20, 33, 6, 6, 15, 12, 12, 24, 18, -4, -4, 7, 8, 17, 25, 31, 27, 23, 22, 37, 36, 28, 26, 27, 27, 27, 36, 35, 25, 25, 33, 26, 27, 31, 40, 37, 22, 22, 27, 34, 34, 41, 39, 39, 48, 45, 34, 34, 38, 33, 33, 26, 27, 47, 49, 42, 40, 40, 45, 49, 42, 43, 43, 42, 30, 30, 42, 40, 43, 40, 39, 41, 43, 45, 44, 47, 43, 40, 37, 39, 39, 39, 51, 55, 45, 42, 45, 45, 45, 54, 54, 54, 65, 53, 57, 53, 56, 59, 61, 54, 49, 53, 59, 59, 56, 59, 63, 60, 53, 57, 53, 48, 53, 57, 56, 55, 55, 56, 53, 56, 62, 65, 61, 63, 68, 70, 69, 69, 68, 69, 70, 70, 73, 73, 67, 62, NA, 63, 69, 61, 62, 69, 69, 70, 71, 74, 70, 77, 71, 65, 60, 61, 60, 62)
Interval <- c(0.107142857142857, 0.0476190476190476, 0.0714285714285714, 0.202380952380952, 0.214285714285714, 0.261904761904762, 0.19047619047619, 0.25, 0.321428571428571, 0.0833333333333333, 0.130952380952381, 0.142857142857143, 0.0357142857142857, 0.202380952380952, 0.0357142857142857, 0.0952380952380952, 0.0952380952380952, 0.0595238095238095, 0.0476190476190476, 0.297619047619048, 0.142857142857143, 0.19047619047619, 0.202380952380952, 0.285714285714286, 0.345238095238095, 0.166666666666667, 0.25, 0.44047619047619, 0.44047619047619, 0.345238095238095, 0.130952380952381, 0.357142857142857, 0.166666666666667, 0.285714285714286, 0.0833333333333333, 0.297619047619048, 0.297619047619048, 0.0357142857142857, 0.464285714285714, 0.119047619047619, 0.25, 0.0595238095238095, 0.0476190476190476, 0.25, 0.297619047619048, 0.428571428571429, 0.130952380952381, 0.178571428571429, 0.0833333333333333, 0.226190476190476, 0.285714285714286, 0.130952380952381, 0.130952380952381, 0.273809523809524, 0.142857142857143, 0.321428571428571, 0.154761904761905, 0.119047619047619, 0.19047619047619, 0.166666666666667, 0.166666666666667, 0.166666666666667, 0.285714285714286, 0.202380952380952, 0.166666666666667, 0.273809523809524, 0.130952380952381, 0.19047619047619, 0.130952380952381, 0.130952380952381, 0.202380952380952, 0.30952380952381, 0.25, 0.333333333333333, 0.154761904761905, 0.166666666666667, 0.178571428571429, 0.202380952380952, 0.273809523809524, 0.107142857142857, 0.130952380952381, 0.297619047619048, 0.333333333333333, 0.19047619047619, 0.226190476190476, 0.285714285714286, 0.321428571428571, 0.297619047619048, 0.261904761904762, 0.273809523809524, 0.202380952380952, 0.261904761904762, 0.226190476190476, 0.285714285714286, 0.0595238095238095, 0.166666666666667, 0.345238095238095, 0.238095238095238, 0.345238095238095, 0.380952380952381, 0.0714285714285714, 0.25, 0.202380952380952, 0.238095238095238, 0.119047619047619, 0.285714285714286, 0.333333333333333, 0.321428571428571, 0.130952380952381, 0.178571428571429, 0.30952380952381, 0.380952380952381, 0.345238095238095, 0.25, 0.226190476190476, 0.30952380952381, 0.25, 0.166666666666667, 0.273809523809524, 0.107142857142857, 0.142857142857143, 0.19047619047619, 0.0952380952380952, 0.226190476190476, 0.297619047619048, 0.357142857142857, 0.273809523809524, 0.119047619047619, 0.30952380952381, 0.226190476190476, 0.226190476190476, 0.154761904761905, 0.142857142857143, 0.297619047619048, 0.357142857142857, 0.261904761904762, 0.226190476190476, 0.130952380952381, 0.44047619047619, 0.333333333333333, 0.130952380952381, 0.107142857142857, 0.285714285714286, 0.214285714285714, 0.238095238095238, 0.19047619047619, 0.273809523809524, 0.19047619047619, 0.166666666666667, 0.226190476190476, 0.226190476190476, 0.238095238095238, 0.357142857142857, 0.285714285714286, 0.214285714285714, 0.273809523809524, 0.285714285714286, 0.297619047619048, 0.273809523809524, 0.19047619047619, 0.202380952380952, 0.25, 0.261904761904762, 0.202380952380952, 0.238095238095238, 0.30952380952381, 0.142857142857143, 0.119047619047619, 0.202380952380952, 0.297619047619048, 0.238095238095238, 0.226190476190476, 0.214285714285714, 0.214285714285714, 0.19047619047619, 0.19047619047619, 0.261904761904762, 0.25, 0.238095238095238, 0.25, 0.261904761904762, 0.261904761904762, 0.214285714285714, 0.238095238095238, 0.25, 0.19047619047619, 0.19047619047619, 0.214285714285714, 0.214285714285714, NA, 0.285714285714286, 0.285714285714286, 0.273809523809524, 0.297619047619048, 0.273809523809524, 0.261904761904762, 0.214285714285714, 0.142857142857143, 0.202380952380952, 0.202380952380952, 0.178571428571429, 0.273809523809524, 0.166666666666667, 0.202380952380952, 0.214285714285714, 0.25, 0.25)
My_DF <- NULL
My_DF <- data.frame()
My_DF <- data.frame(rbind(My_DF,Max))
for(i in c(1:83))
{
  Computed_Vec <- Max - (i-0)*Interval
  My_DF <- rbind(My_DF,Computed_Vec)
}
My_DF <- rbind(My_DF,Min)
Column_Names <- c()
for (i in length(Date)){Column_Names <- c(Column_Names, paste("Column_",i))}
colnames(My_DF) <- Date
Row_Names <- c("Max")
for (i in c(1:83)){Row_Names <- c(Row_Names, paste("Max - Interval*",(i)))}
Row_Names <- c(Row_Names,"Min")
rownames(My_DF) <- Row_Names
View(My_DF)

这给了我以下输出.图片中随附的代码段.我不确定这是否是您想要的.请让我知道.

This gives me the following output. Snippet attached in the image. I am not sure if this is what you wanted. Please let me know.

这篇关于用于在R中生成向量的多行的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆