读取或扫描功能,用于快速存储excel中的参数转储

时间:2017-05-24 17:34:35

标签: r regex strsplit read.csv

我有一个excel文件,在使用普通read.csv(filename)阅读之后,其摘录如下所示。复制粘贴导入数据的一列的前16行。

 [1] UserName, UserPassword, AppVersion, UserId, UUID, AppId, Latitude, Longitude        
 [2] UserId, UUID                                                                        
 [3] UserId, UUID                                                                        
 [4] UserId, UUID                                                                        
 [5] UserId, UUID                                                                        
 [6] UserId, UUID                                                                        
 [7] SessionId, StatusId, UserId, UUID                                                   
 [8] RoomId, Rows, Columns, SeatsRemoved, UserId, UUID                                   
 [9] SessionId, UserId, UUID                                                             
[10] QueryId, UserId, UUID                                                               
[11] SessionId, SeatIdList, StudentIdList, StatusId, UserId, UUID                        
[12] RoomId, UserId, UUID                                                                
[13] SessionId, UserId, UUID                                                             
[14] SessionId, UserId, UUID                                                             
[15] SessionId, UserId, UUID                                                             
[16] MessageType, MessageContent, SenderId, ReceiverId 

注意:我使用noquote()删除了引号。

我需要的是将所有参数值(上面列表中以逗号分隔的单个单词)拉入一个向量(char向量)。我需要一个干净而优雅的方式来做到这一点。通过使用与数据混淆的函数str_split,我知道混乱的方式。见下文。

str_split(y,",")

[[1]] [1] "UserName"      " UserPassword" " AppVersion"   " UserId"    " UUID"         " AppId"        [7] " Latitude"     " Longitude"   

[[2]] [1] "UserId" " UUID" 

[[3]] [1] "UserId" " UUID" 

[[4]] [1] "UserId" " UUID" 

[[5]] [1] "UserId" " UUID" 

[[6]] [1] "UserId" " UUID" 

[[7]] [1] "SessionId" " StatusId" " UserId"   " UUID"    

[[8]] [1] "RoomId"        " Rows"         " Columns"      " SeatsRemoved" " UserId"       " UUID"

.....

一个整齐的字符向量中需要所有单词。我相信有一种直截了当的方法可以做到这一点。如果您能提供一些提示,请欣赏。

1 个答案:

答案 0 :(得分:1)

我认为你在寻找:

unlist(strsplit(y,","))