从数据框中删除字符

时间:2018-06-13 00:14:33

标签: r

我有这个简单的代码,它生成一个数据框。我想从中间列中删除import os from werkzeug.contrib.fixers import ProxyFix from flask import Flask, redirect, url_for from flask_dance.contrib.google import make_google_blueprint, google from raven.contrib.flask import Sentry app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app) sentry = Sentry(app) app.secret_key = os.environ.get("FLASK_SECRET_KEY", "supersekrit") app.config["GOOGLE_OAUTH_CLIENT_ID"] = os.environ.get("GOOGLE_OAUTH_CLIENT_ID") app.config["GOOGLE_OAUTH_CLIENT_SECRET"] = os.environ.get("GOOGLE_OAUTH_CLIENT_SECRET") google_bp = make_google_blueprint(scope=["profile", "email"]) app.register_blueprint(google_bp, url_prefix="/login") @app.route("/") def index(): if not google.authorized: return redirect(url_for("google.login")) resp = google.get("/plus/v1/people/me") assert resp.ok, resp.text return "You are {email} on Google".format(email=resp.json()["emails"][0]["value"]) if __name__ == "__main__": app.run() 字符。有没有简单的方法呢?

这是一个测试代码(实际代码非常长),与实际代码非常相似。

V

这是数据框:

mat1=matrix(c(1,2,3,4,5,"V1","V2","V3","V4","V5",1,2,3,4,5), ncol=3)
mat=as.data.frame(mat1)
colnames(mat)=c("x","row","y")
mat

我只想删除 x row y 1 1 V1 1 2 2 V2 2 3 3 V3 3 4 4 V4 4 5 5 V5 5 这样的内容:

V

1 个答案:

答案 0 :(得分:3)

我们可以使用str_replace

中的stringr
library(stringr)
mat$row <- str_replace(mat$row, "V", "")