2017-04-14 13 views
1

私はテキストファイルを読み込み、そのデータをテーブルに保存しています。私は列 "Vf2"から値を選びたいと思います。列 "Site"の値は2です。Rでどうやったらいいですか?Rの特定の列から値を取得する方法

Vf2 Site 
2.76 1 
2.32 2 
2.56 3 
2.45 2 
2.76 1 
2.98 3 
2.58 1 
2.42 2 

これは私がこれまで持っていたものです。

afile <- read.table("C:/blufiles/WFRHN205_700.blu", skip = 2, header = TRUE, sep="\t") 
afile["Vf2"] 

答えて

1

このような何か作業をする必要があります:

# Set up the dataframe 
Vf2 <- c(2.76, 2.32, 2.56, 2.45, 2.76, 2.98, 2.58, 2.42) 
Site <- c(1, 2, 3, 2, 1, 3, 1, 2) 
afile <- data.frame(Vf2, Site) 

# Select all values in the Vf2 column where the corresponding Site value is 2 
afile$Vf2[afile$Site == '2'] 

# if you want to select the entire row: 
afile[afile$Site == '2', ] 
関連する問題