我很想念這裏。我看了很多例子,但無法弄清楚以下問題。 df1 <- data.frame(
Rep = factor(rep(1:3, each = 4, times = 2)),
Gen = rep(paste0("T", 1:4), times = 6),
Env = rep(paste0("Loc", 1:2), each = 12),
Y = rnor
我的數據是這樣的: data.frame(name=c("city","village"),code=c(10322,10321),plz=c(7041,7043),plz1=c(7044,7044),plz2=c(7043,NA))
什麼是列plz1和列plz2轉換爲PLZ最聰明的辦法: name code plz
city 10322 7041
city 10322 7044
我目前正在使用正態分佈運行模擬,它模擬事件之間的時間並基於給定數據的分析(與問題無關)。仿真創建這樣的: SimProcess <- function(mu, sigma, T) {
ctimes <- c() # Array of arrival times, initially empty
t <- rnorm(1,mu, sqrt(sigma)) # Time of n
我想將具有n行和n列的數據幀轉換爲單行,並添加了列名和行名稱 例如,我想將下表轉換爲單行 Country Percentage
United States 97.89%
United Kingdom 0.65%
Switzerland 0.50%
Ireland 0.48%
Singapore 0.45%
Hong Kong
我運行下面R碼Rstudio,目的是寬的數據幀(稱爲「合併」)轉換成一個漫長的。 > merged
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2017 (A) 5980 5341 5890 5596 5753 5470 5589 5545 5749 5938 5844 5356
2017 (P) 5762 5275 5733