mapply返回列表中的函数调用不是数据帧

时间:2018-10-14 00:53:06

标签: r

我有一个自定义功能。当我手动运行该函数时,它将返回一个数据帧:

if answer == "Circle" or answer == "C" or answer == "c" or answer == "circle":

但是,我想多次运行,因此我在数据帧的每一行上使用> create_sentiment_df('taggreason', 'republican', 'lost') Joining, by = "word" Joining, by = "word" sentiment prop.sentiment twitter.name party election.result 1 anger 0.04721931 taggreason republican lost 2 anticipation 0.14375656 taggreason republican lost 3 disgust 0.01259182 taggreason republican lost 4 fear 0.06190976 taggreason republican lost 5 joy 0.09024134 taggreason republican lost 6 negative 0.10073452 taggreason republican lost 7 positive 0.26862539 taggreason republican lost 8 sadness 0.03777545 taggreason republican lost 9 surprise 0.03882476 taggreason republican lost 10 trust 0.19832109 taggreason republican lost 。这是数据,数据帧只有1行(用于测试):

mapply

然后调用函数:

> datt1
# A tibble: 1 x 4
  twtr_handle party      result district_flipped
  <chr>       <chr>      <chr>  <chr>           
1 taggreason  republican lost   flipped    

哪个返回:

rslt <- mapply(create_sentiment_df, datt1$twtr_handle, datt1$party, datt1$result)

或:

enter image description here

下面是函数。它需要Twitter授权,所以我不确定如何轻松地重新运行它。函数本身是否有任何事情会使> rslt taggreason sentiment Character,10 prop.sentiment Numeric,10 twitter.name Character,10 party Character,10 election.result Character,10 返回列表而不是数据帧?

mapply

1 个答案:

答案 0 :(得分:1)

您的SES Home > Domains函数返回一个data.frame,而create_sentiment_df在默认情况下对其进行了简化。

如果需要data.frames列表,可以执行以下操作:

mapply

如果您的所有data.frame输出都需要一个data.frame,请使用:

mapply(create_sentiment_df, datt1$twtr_handle, datt1$party, datt1$result, SIMPLIFY = FALSE)