R 使用不同的变量组成一个大的链接列表

R 使用不同的变量组成一个大的链接列表,r,R,我需要使用时间相关变量组成一个链接列表。到目前为止,我一直设法使用paste(),但结果并不令人满意。链接遵循以下结构: http://www.somesite/year/month/day/hour/minute.txt 我尝试为每个零件创建一个变量 link <-'http://www.somesite' year<-as.character(c("2010","2011","2012","2013","2014")) month<-as.character(c("01

我需要使用时间相关变量组成一个链接列表。到目前为止,我一直设法使用
paste()
,但结果并不令人满意。链接遵循以下结构:

http://www.somesite/year/month/day/hour/minute.txt
我尝试为每个零件创建一个变量

link <-'http://www.somesite'

year<-as.character(c("2010","2011","2012","2013","2014"))
month<-as.character(c("01","02","03","04","05","06","07","08","09","10","11","12"))
day<-as.character(c("01","02","03","04","05","06","07","08","09","10","11","12",
                    "13","14","15","16","17","18","19","20","21","22","23","24",
                    "25","26","27","28","29","30","31"))
hour<-as.character(c("01","02","03","04","05","06","07","08","09","10","11","12",
                     "13","14","15","15","16","17","18","19","20","21","22","23",
                     "24"))
min <-as.character(c("00","10","20","30","40","50"))
ext <-as.character("ext")
我明白了:

  [1]"http:/somesite/2010/01/01/01/10.ext"
    [2]"http:/somesite/2011/02/02/02/20.ext"
    [3]"http:/somesite/2012/03/03/03/30.ext"
    [4]"http:/somesite/2013/04/04/04/40.ext"
    ****************************************
我想得到这样的东西:

 [1]"http:/somesite/2010/01/01/01/10.ext"
    [2]"http:/somesite/2010/02/01/01/20.ext"
    [3]"http:/somesite/2010/03/01/01/30.ext"
    [4]"http:/somesite/2010/04/01/01/40.ext"
    ****************************************
有什么想法吗?我不想手动输入它。:)


谢谢。

展开。网格可以让您开始

dat  <- list(link  = 'http://www.somesite',
             year = as.character(c("2010","2011","2012","2013","2014")),
             month = as.character(c("01","02","03","04","05","06","07","08","09","10","11","12")),
             day = as.character(c("01","02","03","04","05","06","07","08","09","10","11","12",
                    "13","14","15","16","17","18","19","20","21","22","23","24",
                    "25","26","27","28","29","30","31")),
             hour = as.character(c("01","02","03","04","05","06","07","08","09","10","11","12",
                     "13","14","15","15","16","17","18","19","20","21","22","23",
                     "24")),
             min  = as.character(c("00","10","20","30","40","50")),
             ext  = as.character("ext"))

gr <- expand.grid(dat)

# sort results...
gr <- gr[order(gr$year, gr$month, gr$day, gr$hour, gr$min),]

head(gr)

#                       link year month day hour min ext
# 1      http://www.somesite 2010    01  01   01  00 ext
# 46501  http://www.somesite 2010    01  01   01  10 ext
# 93001  http://www.somesite 2010    01  01   01  20 ext
# 139501 http://www.somesite 2010    01  01   01  30 ext
# 186001 http://www.somesite 2010    01  01   01  40 ext
# 232501 http://www.somesite 2010    01  01   01  50 ext

dat我不确定我是否理解你的问题。预期的输出是按我想要的方式输入的,而不是paste()输出。你救了我一天。谢谢!如果要按所有列排序,完全不需要命名所有列名,只需执行
gr即可
dat  <- list(link  = 'http://www.somesite',
             year = as.character(c("2010","2011","2012","2013","2014")),
             month = as.character(c("01","02","03","04","05","06","07","08","09","10","11","12")),
             day = as.character(c("01","02","03","04","05","06","07","08","09","10","11","12",
                    "13","14","15","16","17","18","19","20","21","22","23","24",
                    "25","26","27","28","29","30","31")),
             hour = as.character(c("01","02","03","04","05","06","07","08","09","10","11","12",
                     "13","14","15","15","16","17","18","19","20","21","22","23",
                     "24")),
             min  = as.character(c("00","10","20","30","40","50")),
             ext  = as.character("ext"))

gr <- expand.grid(dat)

# sort results...
gr <- gr[order(gr$year, gr$month, gr$day, gr$hour, gr$min),]

head(gr)

#                       link year month day hour min ext
# 1      http://www.somesite 2010    01  01   01  00 ext
# 46501  http://www.somesite 2010    01  01   01  10 ext
# 93001  http://www.somesite 2010    01  01   01  20 ext
# 139501 http://www.somesite 2010    01  01   01  30 ext
# 186001 http://www.somesite 2010    01  01   01  40 ext
# 232501 http://www.somesite 2010    01  01   01  50 ext