2017-04-03 13 views
0

我想了解過去5年中在PLOS Medicine雜誌上發表的8000位作者的名字。我只有他們的姓氏和他們的首字母縮寫。我也需要每個作者的名字!我試圖用「rplos」包來做到這一點。但是,每當我嘗試匹配用戶時,我都會遇到錯誤。我是R的新手,我可能做錯了什麼。使用Rplos軟件包在R中指定作者的姓氏

這裏是我的代碼:

library('rplos') 

#This is the procedure for a single author's last name 

t <- plosauthor(q='Wood', fl=c('id','author'), limit=2) 

t <- data.frame(t) 

#I wanna match 8.000 author's last names and tried this: 

a <-read.csv("PLOSAuthors_List.csv", header= TRUE) 

all_authors <- a$Last_Name 

all_authors <- data.frame(all_authors) 

#Then I try to iterate over all authors 

    for (i in all_authors) { 

b <- plosauthor(q=all_authors, fl=c('id', 'author'), limit=2) 

} 

但不幸的是,我得到以下錯誤:

"Error in curl::curl_fetch_memory(url, handle = handle) : Failure when receiving data from the peer"

我不知道這意味着什麼,以及如何處理這個錯誤。

+0

[爲什麼要接受一個答案?](HTTPS: //meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。接受答案可以幫助其他有相同問題的人。 – Masoud

回答

0

試圖修改這樣的:

b <- matrix(data=NA,nrow=nrow(all_authors),ncol=1) 

for (i in 1:nrow(all_authors)) { 

    b[i,x] <- plosauthor(q=all_authors[i,1], fl=c('id', 'author'), limit=2) 
    #x is the size of the output (i.e. ncol) of the function. 

} 
+0

你好@Masoud非常感謝,但不幸的是它並沒有幫助我得到以下錯誤:「錯誤在b [i,1] < - plosauthor(q = test_set [i,1],fl = c(」id「 ,「作者」): 要替換的項目數不是替換長度的倍數「 –

+0

@MarciaFerreira您需要將b設置爲與plosauthor函數的輸出相同的大小。因爲我無法獲得此函數然後通過看到我可以將它們更改爲相同大小 – Masoud

+0

Hello @Masoud。所以函數是:plosauthors(q ='Riley',fl = c('id','author'),limit = 2) 。這個函數返回兩個匹配作者的任何姓氏,在這種情況下,我想查找的姓氏是「Riley」。輸出如下:$ meta numFound start maxScore 1 1359 0 NA $ data 作者 1 Steven Riley 2 Steven Riley –

0

我也試過如下:

all_authors <- as.vector(a$Last_Name) 

list_results <- NULL 

for (i in all_authors) { 

    b <- plosauthor(q=i, fl=c('id, author'), limit=2) 
    b <- as.data.frame(b) 
    list_results <- rbind(list_results, b) 
    b <- NULL 
    list_results 
} 

但它只返回部分結果

+0

您無法將整個結果存儲到數據框中。這與線性迴歸的結果是一樣的。您可以存儲係數,但不能存儲程度自由度和其他列出的結果。 – Masoud