粘贴数据框的列然后 "View" 然后

Paste colums of a dataframe and then "View" them

我正在尝试粘贴数据框的两列,然后使用 "View" 函数查看生成的字符向量,但出现此错误:

"Error in View : 'names' attribute [2] must be the same length as the vector [1]"

这是我的可重现示例:

name1 <- c("A2015169","A2015177","A2015185","A2015193","A2015201","A2015209","A2015217","A2015225",
           "A2015233","A2015241","A2015249","A2000049","A2000057","A2000065","A2000073","A2000081",
           "A2000089","A2000097","A2000105","A2000113","A2000121","A2000129","A2000137","A2000145",
           "A2000153","A2000161","A2000169")

name2 <- c("h07v06","h07v06","h07v06","h07v06","h07v06","h07v06","h07v06","h07v06","h07v06","h07v06",
           "h07v06","h08v06","h08v06","h08v06","h08v06","h08v06","h08v06","h08v06","h08v06","h08v06",
           "h08v06","h08v06","h08v06","h08v06","h08v06","h08v06","h08v06")

df <- data.frame(name1,name2)

names <- paste(df$name1,df$name2,sep=".")

View(names)

非常感谢您的建议。我在 R-3.2.2 中使用 RStudio 版本 0.99.485。弗兰克,我在没有 RStudio 的情况下使用了相同的 R 版本 (3.2.2),这次它成功了。 Honey Dipped Badger,谢谢你的建议,我更改了变量的名称"names",但在 RStudio 0.99.485 中仍然不起作用。 Alexey Ferapontov,我使用了相同版本的 R 和 RStudio 0.98.1103,这次成功了!这就是说,问题似乎出在 RStudio 版本上。我相信这回答了问题,但我不想把答案归功于我,我认为 Frank 和 Alexey Ferapontov 应得的。

我觉得没有R版本的问题

您在代码中提到的结果是一种 list 我们无法使用 View() 查看列表类型数据。

View() 仅用于数据框。

例如

x = letters
y = seq(1:26)
z = data.frame(x,y)
View(z)