简体   繁体   English

从列获取信息

[英]Get info from a column

I have this column in a data frame of R Studio and I want to get the info inside. 我在R Studio的数据框中有此列,我想获取内部信息。 This is how one of the lines in the column looks like : 这是该列中的一行内容的样子:

<goal>
   <value>
      <comment>n</comment>
      <stats>
         <goals>1</goals>
         <shoton>1</shoton>
      </stats>
      <event_incident_typefk>71</event_incident_typefk>
      <elapsed>2</elapsed>
      <player1>43372</player1>
      <sortorder>0</sortorder>
      <team>8370</team>
      <id>2305454</id>
      <n>34</n>
      <type>goal</type>
      <goal_type>n</goal_type>
   </value>
   <value>
      <comment>n</comment>
      <stats>
         <goals>1</goals>
         <shoton>1</shoton>
      </stats>
      <event_incident_typefk>71</event_incident_typefk>
      <elapsed>4</elapsed>
      <player1>2983</player1>
      <sortorder>0</sortorder>
      <team>8603</team>
      <id>2305455</id>
      <n>30</n>
      <type>goal</type>
      <goal_type>n</goal_type>
   </value>
   <value>
      <comment>n</comment>
      <stats>
         <goals>1</goals>
         <shoton>1</shoton>
      </stats>
      <event_incident_typefk>71</event_incident_typefk>
      <elapsed>62</elapsed>
      <player1>358127</player1>
      <sortorder>0</sortorder>
      <team>8370</team>
      <id>2305677</id>
      <n>33</n>
      <type>goal</type>
      <goal_type>n</goal_type>
   </value>
</goal>

I want to see if there is a way in order to look like this: ex. 我想看看是否有一种方法可以像这样:例如。

Goal Goals Shoton 进球进球肖顿

..n.......1.........1 ..n ....... 1 ......... 1

and so on.. 等等..

What you have is an XML string. 您拥有的是一个XML字符串。 You can parse it to transform into a list and do everything you need from there. 您可以解析它以转换为列表,然后从那里执行所需的所有操作。 Just an example, following what you asked for: 只是一个例子,遵循您的要求:

test <- "<goal><value><comment>n</comment><stats><goals>1</goals><shoton>1</shoton></stats><event_incident_typefk>71</event_incident_typefk><elapsed>2</elapsed><player1>43372</player1><sortorder>0</sortorder><team>8370</team><id>2305454</id><n>34</n><type>goal</type><goal_type>n</goal_type></value><value><comment>n</comment><stats><goals>1</goals><shoton>1</shoton></stats><event_incident_typefk>71</event_incident_typefk><elapsed>4</elapsed><player1>2983</player1><sortorder>0</sortorder><team>8603</team><id>2305455</id><n>30</n><type>goal</type><goal_type>n</goal_type></value><value><comment>n</comment><stats><goals>1</goals><shoton>1</shoton></stats><event_incident_typefk>71</event_incident_typefk><elapsed>62</elapsed><player1>358127</player1><sortorder>0</sortorder><team>8370</team><id>2305677</id><n>33</n><type>goal</type><goal_type>n</goal_type></value></goal>"

vector <- unlist(xmlToList(test))
summary <- vector[c("value.goal_type", "value.stats.goals", "value.stats.shoton")]
names(summary) <- c("Goal", "Goals", "Shoton")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM