如何重塑多个数据帧

时间:2016-08-12 21:56:29

标签: r for-loop dataframe reshape lapply

我有一个名为data

的数据框
head (data)

        Date Station variable  value
1 2004-06-10  Tushka       US 173.62
2 2004-06-11  Tushka       US 173.57
3 2004-06-12  Tushka       US 173.52
4 2004-06-13  Tushka       US 173.47
5 2004-06-14  Tushka       US 173.43
6 2004-06-15  Tushka       US 173.39

levels(as.factor(data$Station))

[1] "AbuSimbel" "AdinE"     "AdinW"     "Afia"      "ARQE"      "ARQW"      "Garf"      "Tushka"

levels(data$variable)

 [1] "US"  "PW1" "PW2" "PW3" "PW4" "W1"  "W4"  "PW7" "PW8" "PE1" "PE3" "PE4" "E1"  "PE2"

我使用了代码:

list_df <- split(data, data$Station)

我得到了8个数据框的列表(&#34; AbuSimbel&#34;,&#34; AdinE&#34;,&#34; AdinW&#34;,&#34; Afia&#34;&# 34; ARQE&#34;,&#34; ARQW&#34;,&#34; Garf&#34;,&#34; Tushka&#34;)

重塑8个数据帧从长到宽我不得不为每个站重复代码8次

Tushka <- reshape(Tushka, timevar = "variable",idvar = c("Date","Station"),direction = "wide")

我的问题是如何使用for_循环函数重复代码8次而无法使用list_df的重塑代码

0 个答案:

没有答案