複数のデータフレームを含むリスト(IPC)があります。
これが私のリストからのサンプルです:
$ http://www.sumobrain.com/patents/us/Measured-object-support-mechanism-for-unbalance-measuring-apparatus/4981043.html
:List of 1
..$ :'data.frame': 3 obs. of 5 variables:
.. ..$ X1: chr [1:3] "2001826A" "2857764A" "3452604A"
.. ..$ X2: chr [1:3] "1935-05-21" "1958-10-28" "1969-07-01"
.. ..$ X3: chr [1:3] "Russell et al." "Frank" "Schaub"
.. ..$ X4: chr [1:3] "73/478" "73/477" "73/475"
.. ..$ X5: chr [1:3] "Machine for balancing heavy bodies" "Rotor balance testing machine" "BALANCE TESTING APPARATUS HEAD"
$ http://www.sumobrain.com/patents/us/Encoder-with-wide-index/4982189.html
:List of 1
..$ :'data.frame': 8 obs. of 5 variables:
.. ..$ X1: chr [1:8] "3500449A" "4212000A" "4233592A" "4524347A" ...
.. ..$ X2: chr [1:8] "1970-03-10" "1980-07-08" "1980-11-11" "1985-06-18" ...
.. ..$ X3: chr [1:8] "Lenz" "Yamada" "Leichle" "Rogers" ...
.. ..$ X4: chr [1:8] "341/6" "341/16" "341/6" "341/3" ...
.. ..$ X5: chr [1:8] "ELECTRONIC ENCODER INDEX" "Position-to-digital encoder" "Method for detection of the angular position of a part driven in rotation and instrumentation using it" "Position encoder" ...
$ http://www.sumobrain.com/patents/us/Device-for-detecting-at-least-one-variable-relating-to-the-movement-of-a-movable-body/4982106.html
:List of 1
..$ :'data.frame': 2 obs. of 5 variables:
.. ..$ X1: chr [1:2] "3956973A" "4797564A"
.. ..$ X2: chr [1:2] "1976-05-18" "1989-01-10"
.. ..$ X3: chr [1:2] "Pomplas" "Ramunas"
.. ..$ X4: chr [1:2] "92/5R" "307/119"
.. ..$ X5: chr [1:2] "Die casting machine with piston positioning control" "Robot overload detection mechanism"
すべてのデータフレームから最初と5番目の要素(X1とX5)のみを選択し、後でこれら2つの要素のみを使用してさらにデータセットを構築したいと思います。
私はこれでX1をつかもうとしました:
citations_IPC <- sapply(IPCs, function(x){
y<-x[,1]
return(y)
})
およびX5:
citations_titles <- sapply(IPCs[[1]], function(z){
e<-z[,5]
return(e)
})
次に、citations_IPCsとcitations_titlesを次の単一のデータフレームに変換します。
citation_list <- data.frame(IPC = unlist(lapply(citations_IPC, paste)), title = unlist(lapply(citations_titles, paste)) )
1#問題
個々のリスト(IPC [[1]]など)にsapply関数を書き込むと、次のような結果が得られます。
citations_IPC <- sapply(IPCs[[1]], function(x){
y<-x[,1]
return(y)
})
結果:
> citations_IPC
[,1]
[1,] "3415985A"
[2,] "3916190A"
[3,] "4088895A"
[4,] "4633084A"
[5,] "4670651A"
[6,] "4860224A"
ただし、この機能はリスト全体(IPC)では機能しません。私が得るエラーは次のとおりです:「x [、1]のエラー:次元の数が正しくありません」
この問題は、データセット内にデータフレーム、観測値、変数がないいくつかのリストが原因である可能性があると推測しています。その場合、データフレームのない行にもかかわらず、データセットでsapply()を使用できるようにする関数が必要になります。
何か提案をいただければ幸いです。
どうもありがとう
> str(IPCs)
List of 19
$ http://www.sumobrain.com/patents/us/Method-and-apparatus-for-the-quantitative,-depth-differential-analysis-of-solid-samples-with-the-use-of-two-ion-beams/4982090.html :List of 1
..$ :'data.frame': 6 obs. of 5 variables:
.. ..$ X1: chr [1:6] "3415985A" "3916190A" "4088895A" "4633084A" ...
.. ..$ X2: chr [1:6] "1968-12-10" "1975-10-28" "1978-05-09" "1986-12-30" ...
.. ..$ X3: chr [1:6] "Castaing et al." "Valentine et al." "Martin" "Gruen et al." ...
.. ..$ X4: chr [1:6] "250/309" "250/309" "250/309" "250/309" ...
.. ..$ X5: chr [1:6] "Ionic microanalyzer wherein secondary ions are emitted from a sample surface upon bombardment by neutral atoms" "Depth profile analysis apparatus" "Memory device utilizing ion beam readout" "High efficiency direct detection of ions from resonance ionization of sputtered atoms" ...
$ http://www.sumobrain.com/patents/us/Set-on-oscillator/4982165.html
:List of 1
..$ :'data.frame': 2 obs. of 5 variables:
.. ..$ X1: chr [1:2] "4437066A" "4558282A"
.. ..$ X2: chr [1:2] "1984-03-13" "1985-12-10"
.. ..$ X3: chr [1:2] "Gordon" "Lowenschuss"
.. ..$ X4: chr [1:2] "328/14" "307/523"
.. ..$ X5: chr [1:2] "Apparatus for synthesizing a signal by producing samples of such signal at a rate less than the Nyquist sampling rate" "Digital frequency synthesizer"
$ http://www.sumobrain.com/patents/us/Voltage-measuring-apparatus/4982151.html
:List of 1
..$ :'data.frame': 7 obs. of 5 variables:
.. ..$ X1: chr [1:7] "3419802A" "3419803A" "4446425A" "4603293A" ...
.. ..$ X2: chr [1:7] "1968-12-31" "1968-12-31" "1984-05-01" "1986-07-29" ...
.. ..$ X3: chr [1:7] "Pelenc et al." "Pelenc et al." "Valdmanis et al." "Mourou et al." ...
.. ..$ X4: chr [1:7] "324/96" "324/96" "" "" ...
.. ..$ X5: chr [1:7] "Apparatus for current measurement by means of the faraday effect" "Apparatus for current measurement by means of the faraday effect" "Measurement of electrical signals with picosecond resolution" "Measurement of electrical signals with subpicosecond resolution" ...
次に例を示します。
まず、いくつかのランダムな虹彩列を含むリストを作成しましょう。
data(iris)
lis = list(iris[1:3], iris[2:4])
使用lapply
列を抽出するカスタム関数と1
し、2
各データフレームから。それらに同じ名前が付けられていない場合は、次のステップのために列の名前を変更します。
b = lapply(lis, function(x){
z = x[,c(1,2)]
colnames(z) = c("z1", "z2")
return(z)
}
)
これb
が、必要な列のみのリストです。
rbind
bのデータフレーム:
do.call(rbind, b)
完了
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加