熔化数据框的子集
Subset of a melt dataframe
我的数据框
a<-c(2, 4, 6, 6, 8, 10, 12, 13, 14)
c<-c(2, 2, 2, 2, 2, 2, 4, 4,4)
d<-c(10, 10, 10, 30, 30, 30, 50, 50, 50)
ID<-rep(c("no","bo", "fo"), each=3)
mydata<-data.frame(ID, a, c, d)
gg.df <- melt(mydata, id="ID", variable.name="variable")
我只想对变量 "no" 进行子集化,我试过:
gg.df[,"variable"=="no"]
哪个returns
data frame with 0 columns and 27 rows
请参考子集函数:
no.df <- subset( x = gg.df
, subset = ID == "no"
)
ID variable value
1 no a 2
2 no a 4
3 no a 6
10 no c 2
11 no c 2
12 no c 2
19 no d 10
20 no d 10
21 no d 10
或者:
gg.df[ ID == "no", ]
ID variable value
1 no a 2
2 no a 4
3 no a 6
10 no c 2
11 no c 2
12 no c 2
19 no d 10
20 no d 10
21 no d 10
我的数据框
a<-c(2, 4, 6, 6, 8, 10, 12, 13, 14)
c<-c(2, 2, 2, 2, 2, 2, 4, 4,4)
d<-c(10, 10, 10, 30, 30, 30, 50, 50, 50)
ID<-rep(c("no","bo", "fo"), each=3)
mydata<-data.frame(ID, a, c, d)
gg.df <- melt(mydata, id="ID", variable.name="variable")
我只想对变量 "no" 进行子集化,我试过:
gg.df[,"variable"=="no"]
哪个returns
data frame with 0 columns and 27 rows
请参考子集函数:
no.df <- subset( x = gg.df
, subset = ID == "no"
)
ID variable value
1 no a 2
2 no a 4
3 no a 6
10 no c 2
11 no c 2
12 no c 2
19 no d 10
20 no d 10
21 no d 10
或者:
gg.df[ ID == "no", ]
ID variable value
1 no a 2
2 no a 4
3 no a 6
10 no c 2
11 no c 2
12 no c 2
19 no d 10
20 no d 10
21 no d 10