如何在R中指定guid为row.names?

时间:2016-10-07 06:59:23

标签: r guid

给定一个数据集(剥离问题)

id  activated   jobtitle    organisation    
11CE0982-B213-4140-B7FA-0000632D9B49    2013-05-30 06:40:00.000 NULL    Apple   
DFC75899-2335-48AC-BF30-00010AF58424    2014-05-29 23:47:55.807 Acting CIO  Care Connect
BC45E973-4AE4-4405-A62C-000373D2755C    2013-09-05 22:29:00.000 NULL        NULL    

我可以导入数据文件并使用

将其转换为数据框
users_for_dashboard_view <- read.delim("/source/dashboard/users_for_dashboard_view.txt", na.strings="NULL")
users_for_dashboard_dataframe <- data.frame( users_for_dashboard_view, stringsAsFactors = default.stringsAsFactors())

但我希望将id字段用作row.names 当我这样做时

users_for_dashboard_dataframe <- data.frame( users_for_dashboard_view, row.names = id, stringsAsFactors = default.stringsAsFactors())

它以

失败
Error in data.frame(users_for_dashboard_view, row.names = id, stringsAsFactors = default.stringsAsFactors()) : 
  row names supplied are of the wrong length

每行都有一个guid。

使用guid指定id列的正确方法是什么?row.names?

1 个答案:

答案 0 :(得分:1)

首次尝试读取数据(无row.names = F)

users_for_dashboard_view <- read.delim("Neues Textdokument.txt", na.strings="NULL")
rownames(users_for_dashboard_view)<-users_for_dashboard_view$id
users_for_dashboard_view$id <- NULL