在R Studio中修改列

我在R studio中有一个传感器数据。每个列值的末尾都有半冒号。 我应该怎么写才能从每个值中删除分号。我要附上图片。 这个数据集非常大,大约有5300个条目。 我想删除分号,因此可以使用ggplot()轻松绘制它们 Sensor Data

这是我的代码:

库(ggplot2) T

排量1

ggplot(传感器,aes(x = T,y =位移1))+ geom_point()

imaginechina 回答:在R Studio中修改列

我已经将Sensor数据集重新创建为简化的CSV文件(我称为“ iStack2.csv”),该文件读取

enter image description here

您不需要处理该文件,将其清理并替换即可得到这样的数据框

    ID      T Displacement1
1 0002 18.628       -0.0345
2 0003  17.28       -0.0245
3 0004 18.328       -0.0145
4 0005 19.628       -0.1245
5 0006  1.628        -0.345
6 0007 28.628       -0.2345 

这是ggplot的全部代码

rm(list=ls())
library(ggplot2) 

filenames <- "iStack2.csv"

delim = ","
DF <- read.csv(filenames,header = F,sep=delim)
print(DF)
print(is.data.frame(DF))

DF2 <- data.frame(lapply(DF,function(x) gsub("13:00:","",x)))
DF3 <- data.frame(lapply(DF2,function(x) gsub("=",x)))
DF4 <- data.frame(lapply(DF3,function(x) gsub(";",x)))
colnames(DF4) <- c("ID","T","Displacement1")


p1 <- ggplot(DF4,aes(x=T,y=Displacement1)) +
  geom_point()

print(p1)

你得到的情节 enter image description here

希望这会有所帮助,显然,如果您可以生成一个干净的数据集更好,那么它将节省大量时间。

本文链接:https://www.f2er.com/3124385.html

大家都在问