我有一个小时的矢量.例如:
vec.hours <- c("15:52:00", "15:56:00", "12:10:00", "15:12:00", "11:49:00" ,"13:35:00", "14:53:00")
Run Code Online (Sandbox Code Playgroud)
我想花几个小时来获得最接近整整5分钟的新时间,就像这样.
round.hours <- c("15:50:00", "16:00:00", "12:10:00", "15:10:00", "11:50:00" ,"13:35:00", "14:55:00" )
Run Code Online (Sandbox Code Playgroud)
我试过这个
hour <- strptime(vec.hours , "%H:%M:%S")
round.hour <- round(hour , "mins")
Run Code Online (Sandbox Code Playgroud)
但它没有用.
每个round.ours后我想做+/-一小时,例如:
hour.rd <- strptime(round.hours[1] , "%H:%M:%S")
hourM <- hour.rd - 3600
hourP <- hour.rd + 3600
l.tm <- timeSequence(from = hourM, to = hourP,format = "%H-%S-%M",by="5 min",FinCenter = "Europe/Zurich")
Run Code Online (Sandbox Code Playgroud)
所以,15:50:00我有一个从14:50到16:50的向量.
我不知道如何从vec.hours获得round.hour.
非常感谢
我正在尝试geom_bar从2个独立的data.frames中叠加2个条形图.
dEQ
lab perc
1 lmP 55.9
2 lmN 21.8
3 Nt 0.6
4 expG 5.6
5 expD 0.0
6 prbN 11.2
7 prbP 5.0
Run Code Online (Sandbox Code Playgroud)
和
LMD
lab perc
1 lmP 16.8
2 lmN 8.9
3 Nt 0.0
4 expG 0.0
5 expD 0.0
6 prbN 0.0
7 prbP 0.0
Run Code Online (Sandbox Code Playgroud)
第一个情节是:
p <- ggplot(dEQ, aes(lab, perc)) +
xlab(xlabel) + ylab(ylabel) +
geom_bar(stat="identity", colour="blue", fill="darkblue") +
geom_text(aes(vecX, vecYEQ+1.5, label=vecYlbEQ), data=dEQ, size=8.5) +
theme_bw() +
opts(axis.text.x = theme_text(size = 20, …Run Code Online (Sandbox Code Playgroud) 我不明白为什么我不能拥有这些数据的nls函数.我尝试了很多不同的起始值,我总是有同样的错误.
这是我一直在做的事情:
expFct2 = function (x, a, b,c)
{
a*(1-exp(-x/b)) + c
}
vec_x <- c(77.87,87.76,68.6,66.29)
vec_y <- c(1,1,0.8,0.6)
dt <- data.frame(vec_x=vec_x,vec_y=vec_y)
ggplot(data = dt,aes(x = vec_x, y = vec_y)) + geom_point() +
geom_smooth(data=dt, method="nls", formula=y~expFct2(x, a, b, c),
se=F, start=list(a=1, b=75, c=-5)
Run Code Online (Sandbox Code Playgroud)
我总是有这个错误:
Error in method(formula, data = data, weights = weight, ...) :
singular gradient
Run Code Online (Sandbox Code Playgroud) 关于应用函数,我有一个小问题.例如,我有:
l <- list(a = data.frame(A1=rep(10,5),B1=c(1,1,1,2,2),C1=c(5,10,20,7,30)),
b = data.frame(A1=rep(20,5),B1=c(3,3,4,4,4),C1=c(3,5,10,20,30)))
Run Code Online (Sandbox Code Playgroud)
我想为每个B1找到最小C1.结果应该是
$a
A1 B1 C1
10 1 5
10 2 7
$b
A1 B1 C1
20 3 3
20 4 10
Run Code Online (Sandbox Code Playgroud)
我知道如何使用'for'来实现它,但它必须是'lapply'更简单的方法,但我无法使它工作.
请帮忙
我正在用ggplot做直方图.
p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) +
xlab(xlabel) + ylab(ylabel) +
geom_histogram(colour = "darkblue", fill = "white", binwidth=500)
Run Code Online (Sandbox Code Playgroud)
我的x在2到6580之间,我有2600个数据.
我想绘制一个不同的直方图binwidth.可能吗?
例如,我想要8个条形,宽度如下:
c(180,100,110,160,200,250,1000,3000)
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我的结构有问题.这是我正在做的事情的例子.
x <- c(211.50, 200.50, 148.60, 144.20, 132.20, 159.80, 107.70, 91.40, 63.10, 62.10, 55.70, 74.60, 224.90, 208.001, 45.80, 133.50, 122.70, 161.70, 160.00, 136.80, 92.20, 91.20, 79.20, 109.90, 244.60, 212.20, 147.20, 129.30, 118.50, 165.80, 120.60, 97.90, 69.30, 65.50, 59.10, 81.90, 94.15, 114.20, 131.03, 133.89, 132.25, 153.51)
y <- x
Ref <- c(rep("ref1",36), rep("ref2",6))
ID <- c(rep("id1",6), rep("id2",6),rep("id3",6),rep("id4",6),rep("id5",6),rep("id6",6),rep("id7",6))
data.split <- data.frame(Ref,ID,x,y)
l.ref <- ddply(data.split, .(Ref), "nrow")
vec1 <- c(rep(1,l.ref$nrow[1]))
for (i in 2:length(l.ref$Ref)) {
vec2 <- c(rep(i,l.ref$nrow[i]))
vec3 <- append(vec1,vec2, after =length(vec1)) …Run Code Online (Sandbox Code Playgroud)