0
私は大きなデータフレームの形を変える方法を探していましたが、私はいくつかの困難を抱えています。私はsrciptを実行し、出力データフレームは次のようになります(下記参照):データフレームの形を変えるには?
ここには、スクリプトとサンプルデータベースとのリンクがあります。
names(dataexample)
#To summary the categorical variables
str(dataexample)
# Transform
dataexample$Days<-as.numeric(as.character(dataexample$Days))
str(dataexample)
# Create a new column (polyname) combining treatment and block, separated by ","
dataexample$polyname <- paste(dataexample$Treatment, dataexample$Block, sep=",")
#Split the database and run approx function with the new column polyname
modelresult<-lapply(split(dataexample, dataexample$polyname), function(d) approx(d$Days, d$Variable, method="linear", xout=7:155, yleft=0, yright=0, rule = 1, f = 0, ties = mean))
#Create a new table
Tableresult<-as.data.frame(modelresult)
This is the resulting table:
A.1.x A.1.y B.1.x B.1.y C.1.x C.1.y
7 0.00 7 0.00 7 0.00
8 0.02 8 0.02 8 0.02
9 0.04 9 0.04 9 0.04
10 0.06 10 0.06 10 0.06
. . . . . .
145 0.33 139 0.16 117 0.63
146 0.22 140 0.15 118 0.61
147 0.11 141 0.13 119 0.58
以下、私が実行したいデータフレームがある:
A.1.x A.1.y 7 0.00
A.1.x A.1.y 8 0.02
A.1.x A.1.y 9 0.04
A.1.x A.1.y 10 0.06
A.1.x A.1.y . .
A.1.x A.1.y 145 0.33
A.1.x A.1.y 146 0.22
A.1.x A.1.y 147 0.11
B.1.x A.1.y 7 0.00
B.1.x B.1.y 8 0.02
B.1.x B.1.y 9 0.04
B.1.x B.1.y 10 0.06
B.1.x B.1.y . .
B.1.x B.1.y 139 0.16
B.1.x B.1.y 140 0.15
B.1.x B.1.y 141 0.13
C.1.x C.1.y 7 0.00
C.1.x C.1.y 8 0.02
C.1.x C.1.y 9 0.04
C.1.x C.1.y 10 0.06
C.1.x C.1.y . .
C.1.x C.1.y 117 0.63
C.1.x C.1.y 118 0.61
C.1.x C.1.y 119 0.58
データ
Tableresult <- read.table(header = TRUE, text = "A.1.x A.1.y B.1.x B.1.y C.1.x C.1.y
7 0.00 7 0.00 7 0.00
8 0.02 8 0.02 8 0.02
9 0.04 9 0.04 9 0.04
10 0.06 10 0.06 10 0.06
. . . . . .
145 0.33 139 0.16 117 0.63
146 0.22 140 0.15 118 0.61
147 0.11 141 0.13 119 0.58", na.strings = '.')
完全に機能しました。どうもありがとうございました。よろしく。 Matías。 –