Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何添加一个观察值为常量的列和另一个R中带有字符的连续数字的变量_R_Variables_Dataframe - Fatal编程技术网

如何添加一个观察值为常量的列和另一个R中带有字符的连续数字的变量

如何添加一个观察值为常量的列和另一个R中带有字符的连续数字的变量,r,variables,dataframe,R,Variables,Dataframe,我想在现有数据帧中添加第一列,其中包含连续的数字和字符 我使用以下代码。它不起作用 df$VARNAME_ <- paste0('COL', 1:5)(df) 提前谢谢 很抱歉我问了一个愚蠢的问题。现在我明白了。 解决方案如下 actual_df<-data.frame(df)#transfer matrix a to data frame actual_df<-cbind(VARNAME_=paste0('COL', 1:5),actual_df) #add COL1~

我想在现有数据帧中添加第一列,其中包含连续的数字和字符

我使用以下代码。它不起作用

df$VARNAME_ <- paste0('COL', 1:5)(df) 
提前谢谢


很抱歉我问了一个愚蠢的问题。现在我明白了。 解决方案如下

actual_df<-data.frame(df)#transfer matrix a to data frame
actual_df<-cbind(VARNAME_=paste0('COL', 1:5),actual_df) #add COL1~COL5 in the first column
actual_df<-cbind(ROWTYPE_ = 'PROX', actual_df) #Add a variable with constant observations in first column. Now the previous column become second one.
实际值

将起作用

df$VARNAME_u它在$VARNAME_u中显示“我没有任何问题。不确定。哦!!它起作用了!!谢谢。我需要先将我的矩阵传输到数据帧。然后,我使用您提到的“cbind”将VARNAME_u移动到第一列。非常感谢。
actual_df<-data.frame(df)#transfer matrix a to data frame
actual_df<-cbind(VARNAME_=paste0('COL', 1:5),actual_df) #add COL1~COL5 in the first column
actual_df<-cbind(ROWTYPE_ = 'PROX', actual_df) #Add a variable with constant observations in first column. Now the previous column become second one.
df$VARNAME_ = paste0('COL', 1:5)