通过分隔符对数据帧中的所有值进行子集化

时间:2016-10-14 23:00:15

标签: r dataframe substr

数据看起来像

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div style="text-align: center;">
    <asp:UpdateProgress ID="updateProgress" runat="server">
        <ProgressTemplate>
            <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                <asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="Content/img/loader.gif" AlternateText="Loading ..." ToolTip="Loading ..." Style="padding: 10px; position: fixed; top: 45%; left: 50%;" />
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
</div>

<asp:UpdatePanel ID="updpnlContentDetail" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:HiddenField runat="server" ID="hdnEnvironmentType" />
        <asp:HiddenField runat="server" ID="hdnID" />
        <asp:HiddenField runat="server" ID="hdnGvSelectedIndex" Value="0" />
        <asp:HiddenField runat="server" ID="hdnButtonPermission" Value="0" />
        <asp:HiddenField runat="server" ID="hdnSelectedTab" Value="0" />
        <asp:HiddenField runat="server" ID="hdnButtonStatus" Value="Active" /> 
        <div class="row">
            <div class="col-md-3">
                    <h5>Manage Detail</h5>
                    <div class="filterWrapper relative" id="dvLeftcontentdetail">
                    <div class="clearfix whiteBg">
                        <div class="pull-left">
                            <label>Bucket Type</label>
                        </div>
                        <div class="pull-right">
                            <span class="addBtn">Add
                                <asp:Button ID="lnkbtnAdd" runat="server" OnClick="lnkbtnAdd_Click" CssClass="btn btn-add pull-right"></asp:Button>
                            </span>

                        </div>
                    </div>
                    <div class="input-group clearfix col-sm-12">
                        <asp:TextBox CssClass="form-control height26" ID="txtSearchName" runat="server"></asp:TextBox>
                        <span class="input-group-btn">
                            <asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" CssClass="btn btn-black glyphicons filter btn-icon white input-group-btnbtnmargin"></asp:Button>
                            <i></i>
                        </span>
                    </div>
                    <div id="divgv">
                        <div id="" class="gridview2 relative" style="height: 424px;">
                            <asp:GridView CssClass="gridview" ID="gv" runat="server" DataKeyNames="ID" PageSize="13" OnPageIndexChanging="gv_PageIndexChanging" ShowHeader="False" 
                                AutoGenerateColumns="false" AllowPaging="true">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:Label ID="lblID" runat="server" Visible="false" Text='<%#Eval("ID") %>' />
                                        <asp:LinkButton ID="lnkBtnShowContentDetail" runat="server" Text='<%#Eval("Name") %>' CommandName="Select" OnClick="lnkBtnName_Click" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <PagerStyle CssClass="gridview-pager"></PagerStyle>
                            <SelectedRowStyle CssClass="gvSelectedRow" />
                        </asp:GridView>
                            <div id="content"></div>
                            <div class="filterResults relative btnGroup">
                                <div class="btn-groupSpecial">
                                    <asp:Button ID="lnkbtnActive" runat="server" Text="Active" OnClick="lnkbtnActive_Click" OnClientClick="return ConfirmMessage(4); " CssClass="results-control col-xs-4 active"></asp:Button>
                                    <asp:Button ID="lnkbtnInActive" runat="server" Text="InActive" OnClick="lnkbtnInActive_Click" OnClientClick="return ConfirmMessage(5);" CssClass="results-control col-xs-4"></asp:Button>
                                    <asp:Button ID="lnkbtnAll" runat="server" Text="All" OnClick="lnkbtnAll_Click" CssClass="results-control col-xs-4" OnClientClick="return ConfirmMessage(6);"></asp:Button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
          <div class="col-sm-9">
            <h5>Details</h5>
            <div  id="dvRightContent" class="row clearfix relative btnGroup btnGroup3" style="height: 492px;">
                <div class="tabControls">
                            <ul class="nav nav-tabs">
                            <li class="col-xsm-100 nav-tabs-content active"><span class="linkDisabledsp">&nbsp;</span><a data-toggle="tab" href="#manageDetailTab" onclick="SetSelectedTab('contentTab')">Bucket Details</a></li>
                        </ul>
                <div class="row">
                      <div class="col-md-12">
                          <div class="col-md-4">
                              <label for="iconName">Name</label>
                              <asp:TextBox CssClass="form-control" ID="txtName" MaxLength="250" runat="server"></asp:TextBox>
                          </div>
                      </div>
                  </div>
                  <div class="row">
                      <div class="col-md-12">
                          <div class="col-md-4">
                              <label for="iconName">Display Name</label>
                              <asp:TextBox CssClass="form-control" ID="txtDisplayName" MaxLength="250" runat="server"></asp:TextBox>
                          </div>
                      </div>
                   </div>
                <div class="row">
                      <div class="col-md-12">

                      </div>
                   </div>
                <div class="col-md-12 btnGroup2 row navbar-fixed-bottom">
                  <div class="btn-groupSpecial clearfix">
                                <asp:Button ID="lnkbtnSave" OnClientClick="return FormValidation();" runat="server" Text="Save" OnClick="lnkbtnSave_Click" CssClass="results-control col-xsm-32"></asp:Button>
                                <asp:Button ID="lnkbtnCancel" runat="server" OnClientClick=" return ConfirmMessage(2);" Text="Cancel" OnClick="lnkbtnCancel_Click" CssClass="results-control col-xsm-32"></asp:Button>
                                <asp:Button ID="lnkbtnDelete" runat="server" OnClientClick="return ConfirmMessage(3);" Text="Delete" OnClick="lnkbtnDelete_Click" CssClass="results-control col-xsm-32"></asp:Button>

                            </div>
                    </div>
               </div>
          </div>
        </div>

        <div id="AlertBox" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                        <h4 class="modal-title">Alert</h4>
                    </div>
                    <div class="modal-body">
                        <p id="alertMessage" runat="server"></p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn" id="btnOK" data-dismiss="modal">OK</button>
                    </div>
                </div>
            </div>
        </div>


        <!-- Modal Dialog -->
        <div id="ConfirmBox" class="modal fade" role="dialog" aria-labelledby="confirmDeleteLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                        <h4 class="modal-title">Confirm?</h4>
                    </div>
                    <div class="modal-body">
                        <p id="ConfirmBoxMessage"></p>
                    </div>
                    <div class="modal-footer">
                        <asp:Button ID="btnConfirmedSave" CssClass="btn btn-danger" runat="server" Text="OK" UseSubmitBehavior="false" data-dismiss="modal" OnClick="lnkbtnSave_Click" Style="display: none;"></asp:Button>
                        <asp:Button ID="btnConfirmedCancel" CssClass="btn btn-danger" runat="server" Text="OK" UseSubmitBehavior="false" data-dismiss="modal" OnClick="lnkbtnCancel_Click" Style="display: none;"></asp:Button>
                        <asp:Button ID="btnConfirmedDelete" CssClass="btn btn-danger" runat="server" Text="OK" UseSubmitBehavior="false" data-dismiss="modal" OnClick="lnkbtnDelete_Click" Style="display: none;"></asp:Button>
                    </div>
                </div>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

我一直在尝试

> loc.dat[1:2,1:3]
              imageNumber.1             imageNumber.2             imageNumber.3
1         latitude=34.73388         latitude=34.73393    latitude=34.7339966667
2 longitude=-106.7133033333 longitude=-106.7128583333 longitude=-106.7123566667

但由于

,这不起作用
df <- unlist(strsplit(loc.dat, '=', fixed=TRUE))[2]

我尝试了lapply和for循环,但它不起作用。我确信它很简单,但我以前没遇到过这个问题。

有没有人有更好的解决方案?

1 个答案:

答案 0 :(得分:1)

strsplit无法直接应用于数据框。您可以使用lapply循环遍历列。以下是来自lapply的{​​{1}}和tstrsplit的方法,假设所有列都是字符类而不是因子:

data.table