I have a list (IPCs) containing multiple data frames.
here is a sample from my list:
$ 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"
I would like to select only the first and fifth elements (X1 and X5) from all data frames, to later construct a further dataset with only these two elements.
I have tried to grab X1 with this:
citations_IPC <- sapply(IPCs, function(x){
y<-x[,1]
return(y)
})
and X5 with:
citations_titles <- sapply(IPCs[[1]], function(z){
e<-z[,5]
return(e)
})
Then I convert citations_IPCs and citations_titles into a single data frame with:
citation_list <- data.frame(IPC = unlist(lapply(citations_IPC, paste)), title = unlist(lapply(citations_titles, paste)) )
1#problem
If I write the sapply function on an individual list (e.g. IPCs[[1]]) I get the result I want:
citations_IPC <- sapply(IPCs[[1]], function(x){
y<-x[,1]
return(y)
})
result:
> citations_IPC
[,1]
[1,] "3415985A"
[2,] "3916190A"
[3,] "4088895A"
[4,] "4633084A"
[5,] "4670651A"
[6,] "4860224A"
However, this function doesn't work for the whole lists (IPCs). The error I get is: "Error in x[, 1] : incorrect number of dimensions"
I am guessing the problem might be due to a few lists within my dataset with no data frame, no observations and no variables. In that case I would need a function which allows me to use the sapply() on the dataset despite the lines without data frame.
Please any suggestions would be really appreciated.
Many thanks
str(IPCs)
> 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" ...