R 我有一个列为c的数据集(国家、元素、1961年、1961年、1962年、1962年)

R 我有一个列为c的数据集(国家、元素、1961年、1961年、1962年、1962年),r,R,这将持续到2011年。我知道1961:2011将分配所有年份,但有没有办法容纳单独的国旗栏 更具体地说,它是一个csv文件。我把数据读作 data <-read.csv("file", col.names=(country, element, *would be 1961:2011 if there were no flag columns*), header=True) data您可以使用paste0生成名称 col.names = c(country,

这将持续到2011年。我知道1961:2011将分配所有年份,但有没有办法容纳单独的国旗栏

更具体地说,它是一个csv文件。我把数据读作

data <-read.csv("file", 
           col.names=(country, element, *would be 1961:2011 if there were no flag columns*),     header=True)

data您可以使用
paste0
生成名称

col.names = c(country, element, paste0(rep(1961:2011, each=2), c("", "flags")))
rep
调用将生成:

  [1] 1961 1961 1962 1962 1963 1963 1964 1964 1965 1965 1966 1966 1967 1967 1968
 [16] 1968 1969 1969 1970 1970 1971 1971 1972 1972 1973 1973 1974 1974 1975 1975
 [31] 1976 1976 1977 1977 1978 1978 1979 1979 1980 1980 1981 1981 1982 1982 1983
 [46] 1983 1984 1984 1985 1985 1986 1986 1987 1987 1988 1988 1989 1989 1990 1990
 [61] 1991 1991 1992 1992 1993 1993 1994 1994 1995 1995 1996 1996 1997 1997 1998
 [76] 1998 1999 1999 2000 2000 2001 2001 2002 2002 2003 2003 2004 2004 2005 2005
 [91] 2006 2006 2007 2007 2008 2008 2009 2009 2010 2010 2011 2011

请注意,我使用的是
每个
,而不是
时间
,这将导致添加两次1961:2011序列。

能否显示数据集的几行?我假设您没有
标志
列。。