Appending Spatial Points Attributes to Spatial Lines Data Frame by Line ID - r
question for GIS fans out there. I have two sp objects. A spatial lines data frame (Taken as a clipped version of the OS Roads Vector) and a spatial points data frame (Data taken from the Police UK Data website). I used the snapPointsToLines function to create a third spatial point data frame with the new attribute for nearest_line_id.
How can I append the third dataframe back to my spatial lines data frame so I can use it as a color attribute in leaflet?
What I am trying to do overall is snap points to lines as a count. Then colour the lines based on the quantity of points in leaflet. So if there is another solution other than the one above to achieve that I am all ears.
Because I am using leaflet I am using a specific CRS
crs <- sp::CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')
However to do the snapPointsToLines function I need to temporally convert the crs to cartesian coordinates and then back (I know, its a pain).
temp_crs <- sp::CRS("+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
The structure is what is getting me for the two data sets. The Spatial Points Dataframe looks like this:
> str(Points)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
..# data :'data.frame': 191 obs. of 16 variables:
.. ..$ Crime type : chr [1:191] "Anti-social behaviour" "Anti-social behaviour" "Anti-social behaviour" "Anti-social behaviour" ...
.. ..$ Longitude : num [1:191] 1.3 1.31 1.34 1.35 1.37 ...
.. ..$ Latitude : num [1:191] 51.4 51.3 51.4 51.4 51.3 ...
.. ..$ n : int [1:191] 1 1 1 1 1 3 1 3 4 1 ...
.. ..$ objectid : Factor w/ 380 levels "1","10","100",..: 50 50 50 50 50 50 50 50 50 50 ...
.. ..$ lad17cd : Factor w/ 380 levels "E06000001","E06000002",..: 143 143 143 143 143 143 143 143 143 143 ...
.. ..$ lad17nm : Factor w/ 380 levels "Aberdeen City",..: 329 329 329 329 329 329 329 329 329 329 ...
.. ..$ lad17nmw : Factor w/ 22 levels "Abertawe","Blaenau Gwent",..: NA NA NA NA NA NA NA NA NA NA ...
.. ..$ bng_e : Factor w/ 380 levels "126473","199821",..: 376 376 376 376 376 376 376 376 376 376 ...
.. ..$ bng_n : Factor w/ 379 levels "1006584","101094",..: 63 63 63 63 63 63 63 63 63 63 ...
.. ..$ long : num [1:191] 1.33 1.33 1.33 1.33 1.33 ...
.. ..$ lat : num [1:191] 51.4 51.4 51.4 51.4 51.4 ...
.. ..$ st_areasha : num [1:191] 1.03e+08 1.03e+08 1.03e+08 1.03e+08 1.03e+08 ...
.. ..$ st_lengths : num [1:191] 56839 56839 56839 56839 56839 ...
.. ..$ nearest_line_id: Factor w/ 98 levels "1043","1107",..: 48 94 31 80 90 11 61 50 68 4 ...
.. ..$ snap_dist : num [1:191] 0.0317 0.0386 0.0317 0.0964 0.0826 ...
..# coords.nrs : num(0)
..# coords : num [1:191, 1:2] -35712 -35265 -32984 -31745 -31519 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:191] "142.4" "142.10" "142.17" "142.26" ...
.. .. ..$ : chr [1:2] "X" "Y"
..# bbox : num [1:2, 1:2] -38985 5714081 -25310 5720875
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "X" "Y"
.. .. ..$ : chr [1:2] "min" "max"
..# proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..# projargs: chr "+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0"
And the Spatial Lines DataFrame looks like this (had to cut it for size in this post):
> str(Clipped_Street)
Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
..# data :'data.frame': 6271 obs. of 29 variables:
.. ..$ fictitious: Factor w/ 1 level "false": 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ identifier: Factor w/ 33642 levels "0002D55A-A91E-41D7-B8ED-973F7562D903",..: 6313 22851 21972 20186 15807 23558 25474 25983 26498 25490 ...
.. ..$ class : Factor w/ 7 levels "A Road","B Road",..: 2 3 2 6 3 6 3 3 6 6 ...
.. ..$ roadNumber: Factor w/ 52 levels "A2","A20","A2033",..: 32 NA 36 NA NA NA NA NA NA NA ...
.. ..$ name1 : Factor w/ 6320 levels "Abbey Close",..: 5586 2955 5720 1695 2955 99 2955 2955 2082 5720 ...
.. ..$ name1_lang: Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
.. ..$ name2 : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
.. ..$ name2_lang: Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
.. ..$ formOfWay : Factor w/ 6 levels "Collapsed Dual Carriageway",..: 5 5 5 5 5 5 5 5 5 5 ...
.. ..$ length : int [1:6271] 111 86 66 63 19 41 8 46 45 23 ...
.. ..$ primary : Factor w/ 2 levels "false","true": 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ trunkRoad : Factor w/ 2 levels "false","true": 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ loop : Factor w/ 2 levels "false","true": 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ startNode : Factor w/ 21676 levels "00010DB2-DF39-455B-AA62-C3404539F18A",..: 1194 3350 8606 17475 6530 6530 5161 11442 3186 6852 ...
.. ..$ endNode : Factor w/ 24871 levels "00010DB2-DF39-455B-AA62-C3404539F18A",..: 5437 7429 10034 15538 5848 4003 13102 20036 13102 9098 ...
.. ..$ structure : Factor w/ 1 level "Road In Tunnel": NA NA NA NA NA NA NA NA NA NA ...
.. ..$ nameTOID : Factor w/ 7826 levels "osgb4000000029278481",..: 4067 4079 4071 6680 4079 7623 4079 4079 4084 4071 ...
.. ..$ numberTOID: Factor w/ 52 levels "osgb4000000030880859",..: 29 NA 43 NA NA NA NA NA NA NA ...
.. ..$ function. : Factor w/ 8 levels "A Road","B Road",..: 2 5 2 4 5 4 5 5 4 5 ...
.. ..$ objectid : Factor w/ 380 levels "1","10","100",..: 50 50 50 50 50 50 50 50 50 50 ...
.. ..$ lad17cd : Factor w/ 380 levels "E06000001","E06000002",..: 143 143 143 143 143 143 143 143 143 143 ...
.. ..$ lad17nm : Factor w/ 380 levels "Aberdeen City",..: 329 329 329 329 329 329 329 329 329 329 ...
.. ..$ lad17nmw : Factor w/ 22 levels "Abertawe","Blaenau Gwent",..: NA NA NA NA NA NA NA NA NA NA ...
.. ..$ bng_e : Factor w/ 380 levels "126473","199821",..: 376 376 376 376 376 376 376 376 376 376 ...
.. ..$ bng_n : Factor w/ 379 levels "1006584","101094",..: 63 63 63 63 63 63 63 63 63 63 ...
.. ..$ long : num [1:6271] 1.33 1.33 1.33 1.33 1.33 ...
.. ..$ lat : num [1:6271] 51.4 51.4 51.4 51.4 51.4 ...
.. ..$ st_areasha: num [1:6271] 1.03e+08 1.03e+08 1.03e+08 1.03e+08 1.03e+08 ...
.. ..$ st_lengths: num [1:6271] 56839 56839 56839 56839 56839 ...
..# lines :List of 6271
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:8, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "1"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "2"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "3"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "4"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "5"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "6"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "7"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "8"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "9"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "10"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "11"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "12"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "13"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "14"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "15"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:4, 1:2] 1.38 1.38 1.38 1.38 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "16"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "17"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:7, 1:2] 1.39 1.39 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "18"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:4, 1:2] 1.38 1.38 1.38 1.38 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "19"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:6, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "20"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "21"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "22"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:6, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "23"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:4, 1:2] 1.38 1.38 1.38 1.38 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "24"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "25"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:9, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "26"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:7, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "27"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.39 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "28"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "29"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:2, 1:2] 1.38 1.38 51.39 51.39
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "30"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:8, 1:2] 1.39 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "31"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "32"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:14, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "33"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "34"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "35"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..# Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..# coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..# ID : chr "36"
.. .. [list output truncated]
..# bbox : num [1:2, 1:2] 1.21 51.31 1.45 51.39
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..# proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..# projargs: chr "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
How do I merge Points$nearest_line_id with Clipped_Streets#Lines. When one is a column and the other is a list within an object? Is there any way I can put the attributes in #data instead? Very grateful for any direction. Happy to provide more detail if necessary.
I think I cracked it. The key is to use sp::merge to ensure that attributes get written back to points. Then invoke the #data element. then it is just like a regular merge.
Points<-snapPointsToLines(Clipped_Points, Clipped_Street, maxDist=0.1, withAttrs = TRUE, idField="identifier")
Points_agg<-Points#data %>% group_by( nearest_line_id) %>% tally()
Clipped_Street#data<-sp::merge(Clipped_Street#data,Points_agg,by.x="identifier",by.y="nearest_line_id", all.x=TRUE )
The next problem is merging and splitting the dataset before or after a merge and keeping the spatial attributes, but I may put that in a new question.
Related
R how to get association rules (LHS, RHS, support, confidence, lift) from recommenderlab object?
i'm current construct product recommendation using R recommenderlab, after compute AR recommender, i'm hoping to understand the association rules, but i couldn't found any why to extract the complete association rules from the recommender object. Below is the sample dataset m <- matrix(sample(c(0,1), 50, replace=TRUE), nrow=5, ncol=10, dimnames=list(users=paste("u", 1:5, sep=''), items=paste("i", 1:10, sep=''))) Convert matrix into binaryRatingMatrix b <- as(m, "binaryRatingMatrix") create a user-based CF recommender using training data r <- Recommender(getData(scheme, "train"), "AR") Looking into the AR recommender object r#model$rule_base i found "rule_base" Formal class 'Recommender' [package "recommenderlab"] with 5 slots ..# method : chr "AR" ..# dataType: chr "binaryRatingMatrix" ..# ntrain : int 5 ..# model :List of 9 .. ..$ description : chr "AR: rule base" .. ..$ rule_base :Formal class 'rules' [package "arules"] with 4 slots .. .. .. ..# lhs :Formal class 'itemMatrix' [package "arules"] with 3 slots .. .. .. .. .. ..# data :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots .. .. .. .. .. .. .. ..# i : int [1:145] 1 1 1 1 2 0 0 0 5 5 ... .. .. .. .. .. .. .. ..# p : int [1:80] 0 1 2 3 4 5 6 7 8 9 ... .. .. .. .. .. .. .. ..# Dim : int [1:2] 10 79 .. .. .. .. .. .. .. ..# Dimnames:List of 2 .. .. .. .. .. .. .. .. ..$ : NULL .. .. .. .. .. .. .. .. ..$ : NULL .. .. .. .. .. .. .. ..# factors : list() .. .. .. .. .. ..# itemInfo :'data.frame': 10 obs. of 1 variable: .. .. .. .. .. .. ..$ labels: chr [1:10] "i1" "i2" "i3" "i4" ... .. .. .. .. .. ..# itemsetInfo:'data.frame': 0 obs. of 0 variables .. .. .. ..# rhs :Formal class 'itemMatrix' [package "arules"] with 3 slots .. .. .. .. .. ..# data :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots .. .. .. .. .. .. .. ..# i : int [1:79] 6 4 9 3 8 4 9 3 6 3 ... .. .. .. .. .. .. .. ..# p : int [1:80] 0 1 2 3 4 5 6 7 8 9 ... .. .. .. .. .. .. .. ..# Dim : int [1:2] 10 79 .. .. .. .. .. .. .. ..# Dimnames:List of 2 .. .. .. .. .. .. .. .. ..$ : NULL .. .. .. .. .. .. .. .. ..$ : NULL .. .. .. .. .. .. .. ..# factors : list() .. .. .. .. .. ..# itemInfo :'data.frame': 10 obs. of 1 variable: .. .. .. .. .. .. ..$ labels: chr [1:10] "i1" "i2" "i3" "i4" ... .. .. .. .. .. ..# itemsetInfo:'data.frame': 0 obs. of 0 variables .. .. .. ..# quality:'data.frame': 79 obs. of 4 variables: .. .. .. .. ..$ support : num [1:79] 0.2 0.2 0.2 0.2 0.4 0.4 0.4 0.4 0.4 0.4 ... .. .. .. .. ..$ confidence: num [1:79] 1 1 1 1 1 1 1 1 1 1 ... .. .. .. .. ..$ lift : num [1:79] 1.67 1.25 1.25 1.25 1.67 ... .. .. .. .. ..$ count : num [1:79] 1 1 1 1 2 2 2 2 2 2 ... .. .. .. ..# info :List of 4 .. .. .. .. ..$ data : symbol data .. .. .. .. ..$ ntransactions: int 5 .. .. .. .. ..$ support : num 0.1 .. .. .. .. ..$ confidence : num 0.8 .. ..$ support : num 0.1 .. ..$ confidence : num 0.8 .. ..$ maxlen : num 3 .. ..$ sort_measure : chr "confidence" .. ..$ sort_decreasing: logi TRUE .. ..$ apriori_control:List of 1 .. .. ..$ verbose: logi FALSE .. ..$ verbose : logi FALSE ..# predict :function (model, newdata, n = 10, data = NULL, type = c("topNList", "ratings", "ratingMatrix"), ...) Question: how can i extract the association rules from recommender object as data frame? Get association rules dataframe with columns (LHS, RHS, support, confidence, lift, count)
you can use #Convert rules into data frame rules3 = as(rules, "data.frame")
error while assigning value to list of list
I have an R code that looks like this: r <- rowData(sce_list[[1]]) c <- colData(sce_list[[1]]) t <- sce_list[[1]][r$use,c$use] Till here all runs smoothly. However, when I try to assign the value of t to another object like the following I run into error. sce_list[[1]]$qc = t Error in `[[<-`(`*tmp*`, name, value = <S4 object of class "SingleCellExperiment">) : 1842 elements in value to replace 5586 elements where sce_list is a list of sce. EDIT: output of str(t) Formal class 'SingleCellExperiment' [package "SingleCellExperiment"] with 10 slots ..# int_elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. ..# rownames : NULL .. .. ..# nrows : int 1842 .. .. ..# listData :List of 2 .. .. .. ..$ is_spike_MT: logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. ..$ is_spike : logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. ..# elementType : chr "ANY" .. .. ..# elementMetadata: NULL .. .. ..# metadata : list() ..# int_colData :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. ..# rownames : NULL .. .. ..# nrows : int 3973 .. .. ..# listData : Named list() .. .. ..# elementType : chr "ANY" .. .. ..# elementMetadata: NULL .. .. ..# metadata : list() ..# int_metadata :List of 2 .. ..$ version :Classes 'package_version', 'numeric_version' hidden list of 1 .. .. ..$ : int [1:3] 1 0 0 .. ..$ spike_names: chr "MT" ..# reducedDims :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots .. .. ..# listData : Named list() .. .. ..# elementType : chr "ANY" .. .. ..# elementMetadata: NULL .. .. ..# metadata : list() ..# rowRanges :Formal class 'GRangesList' [package "GenomicRanges"] with 5 slots .. .. ..# unlistData :Formal class 'GRanges' [package "GenomicRanges"] with 6 slots .. .. .. .. ..# seqnames :Formal class 'Rle' [package "S4Vectors"] with 4 slots .. .. .. .. .. .. ..# values : Factor w/ 0 levels: .. .. .. .. .. .. ..# lengths : int(0) .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. ..# metadata : list() .. .. .. .. ..# ranges :Formal class 'IRanges' [package "IRanges"] with 6 slots .. .. .. .. .. .. ..# start : int(0) .. .. .. .. .. .. ..# width : int(0) .. .. .. .. .. .. ..# NAMES : NULL .. .. .. .. .. .. ..# elementType : chr "integer" .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. ..# metadata : list() .. .. .. .. ..# strand :Formal class 'Rle' [package "S4Vectors"] with 4 slots .. .. .. .. .. .. ..# values : Factor w/ 3 levels "+","-","*": .. .. .. .. .. .. ..# lengths : int(0) .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. ..# metadata : list() .. .. .. .. ..# elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. .. .. .. ..# rownames : NULL .. .. .. .. .. .. ..# nrows : int 0 .. .. .. .. .. .. ..# listData : Named list() .. .. .. .. .. .. ..# elementType : chr "ANY" .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. ..# metadata : list() .. .. .. .. ..# seqinfo :Formal class 'Seqinfo' [package "GenomeInfoDb"] with 4 slots .. .. .. .. .. .. ..# seqnames : chr(0) .. .. .. .. .. .. ..# seqlengths : int(0) .. .. .. .. .. .. ..# is_circular: logi(0) .. .. .. .. .. .. ..# genome : chr(0) .. .. .. .. ..# metadata : list() .. .. ..# elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. .. ..# rownames : NULL .. .. .. .. ..# nrows : int 1842 .. .. .. .. ..# listData :List of 12 .. .. .. .. .. ..$ id : chr [1:1842] "ENSG00000187608" "ENSG00000186891" "ENSG00000186827" "ENSG00000175756" ... .. .. .. .. .. ..$ symbol : chr [1:1842] "ISG15" "TNFRSF18" "TNFRSF4" "AURKAIP1" ... .. .. .. .. .. ..$ is_feature_control : logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. .. .. ..$ is_feature_control_MT: logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. .. .. ..$ mean_counts : num [1:1842] 5.067 0.166 0.162 0.639 0.719 ... .. .. .. .. .. ..$ log10_mean_counts : num [1:1842] 0.783 0.0669 0.0651 0.2146 0.2353 ... .. .. .. .. .. ..$ rank_counts : num [1:1842] 33536 30766 30710 32857 32945 ... .. .. .. .. .. ..$ n_cells_counts : int [1:1842] 4580 516 458 2376 2578 2153 2277 5388 3604 4131 ... .. .. .. .. .. ..$ pct_dropout_counts : num [1:1842] 18 90.8 91.8 57.5 53.8 ... .. .. .. .. .. ..$ total_counts : num [1:1842] 28305 930 904 3569 4017 ... .. .. .. .. .. ..$ log10_total_counts : num [1:1842] 4.45 2.97 2.96 3.55 3.6 ... .. .. .. .. .. ..$ use : Named logi [1:1842] TRUE TRUE TRUE TRUE TRUE TRUE ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:1842] "ENSG00000187608" "ENSG00000186891" "ENSG00000186827" "ENSG00000175756" ... .. .. .. .. ..# elementType : chr "ANY" .. .. .. .. ..# elementMetadata: NULL .. .. .. .. ..# metadata : list() .. .. ..# partitioning :Formal class 'PartitioningByEnd' [package "IRanges"] with 5 slots .. .. .. .. ..# end : int [1:1842] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..# NAMES : chr [1:1842] "ENSG00000187608" "ENSG00000186891" "ENSG00000186827" "ENSG00000175756" ... .. .. .. .. ..# elementType : chr "integer" .. .. .. .. ..# elementMetadata: NULL .. .. .. .. ..# metadata : list() .. .. ..# elementType : chr "GRanges" .. .. ..# metadata : list() ..# colData :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. ..# rownames : chr [1:3973] "AAACCTGAGAAGGTTT-1" "AAACCTGAGCGTTCCG-1" "AAACCTGAGTACGTAA-1" "AAACCTGGTCCATGAT-1" ... .. .. ..# nrows : int 3973 .. .. ..# listData :List of 32 .. .. .. ..$ dataset : int [1:3973] 1 1 1 1 1 1 1 1 1 1 ... .. .. .. ..$ barcode : chr [1:3973] "AAACCTGAGAAGGTTT-1" "AAACCTGAGCGTTCCG-1" "AAACCTGAGTACGTAA-1" "AAACCTGGTCCATGAT-1" ... .. .. .. ..$ total_features : int [1:3973] 1373 1837 2259 2601 1967 1236 1642 1153 1078 2682 ... .. .. .. ..$ log10_total_features : num [1:3973] 3.14 3.26 3.35 3.42 3.29 ... .. .. .. ..$ total_counts : num [1:3973] 3380 7332 10099 12184 7352 ... .. .. .. ..$ log10_total_counts : num [1:3973] 3.53 3.87 4 4.09 3.87 ... .. .. .. ..$ pct_counts_top_50_features : num [1:3973] 33.1 38.9 42.5 42.2 42.8 ... .. .. .. ..$ pct_counts_top_100_features : num [1:3973] 45 54.8 59.2 53.5 52.4 ... .. .. .. ..$ pct_counts_top_200_features : num [1:3973] 57.5 66.9 69 64.7 63.5 ... .. .. .. ..$ pct_counts_top_500_features : num [1:3973] 74.2 79.2 79.4 76.8 76.6 ... .. .. .. ..$ total_features_endogenous : int [1:3973] 1373 1837 2259 2601 1967 1236 1642 1153 1078 2682 ... .. .. .. ..$ log10_total_features_endogenous : num [1:3973] 3.14 3.26 3.35 3.42 3.29 ... .. .. .. ..$ total_counts_endogenous : num [1:3973] 3380 7332 10099 12184 7352 ... .. .. .. ..$ log10_total_counts_endogenous : num [1:3973] 3.53 3.87 4 4.09 3.87 ... .. .. .. ..$ pct_counts_endogenous : num [1:3973] 100 100 100 100 100 100 100 100 100 100 ... .. .. .. ..$ pct_counts_top_50_features_endogenous : num [1:3973] 33.1 38.9 42.5 42.2 42.8 ... .. .. .. ..$ pct_counts_top_100_features_endogenous: num [1:3973] 45 54.8 59.2 53.5 52.4 ... .. .. .. ..$ pct_counts_top_200_features_endogenous: num [1:3973] 57.5 66.9 69 64.7 63.5 ... .. .. .. ..$ pct_counts_top_500_features_endogenous: num [1:3973] 74.2 79.2 79.4 76.8 76.6 ... .. .. .. ..$ total_features_feature_control : int [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ log10_total_features_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ total_counts_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ log10_total_counts_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ pct_counts_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ total_features_MT : int [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ log10_total_features_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ total_counts_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ log10_total_counts_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ pct_counts_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. ..$ is_cell_control : logi [1:3973] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. ..$ use : logi [1:3973] TRUE TRUE TRUE TRUE TRUE TRUE ... .. .. .. ..$ outlier : logi [1:3973] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. ..# elementType : chr "ANY" .. .. ..# elementMetadata: NULL .. .. ..# metadata : list() ..# assays :Reference class 'ShallowSimpleListAssays' [package "SummarizedExperiment"] with 1 field .. ..$ data: NULL .. ..and 14 methods. ..# NAMES : NULL ..# elementMetadata :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. ..# rownames : NULL .. .. ..# nrows : int 1842 .. .. ..# listData : Named list() .. .. ..# elementType : chr "ANY" .. .. ..# elementMetadata: NULL .. .. ..# metadata : list() ..# metadata :List of 1 .. ..$ name: chr "iMates-1" and of class(sce_list[[1]]) [1] "SingleCellExperiment" attr(,"package") [1] "SingleCellExperiment" Could anyone of the R gurus here help me in solving this problem.
I figured out a way around to solve this problem. It is not the most elegant answer but it does solve the problem.So here it is: for (i in seq_along(sce_list)) { r <- rowData(sce_list[[i]])$use c <- colData(sce_list[[i]])$use tt=(sce_list[[i]])[r,c] assign(paste0("sce_",i,".qc"),tt) } Yes, I have put this in a loop as I want this to run in a loop. :) If someone has an elegant way of doing this please post it and I will try it out.
to get rid of warning and error: non-language object in R
I am coding in R and I have a small chunk that I need to loop it over. the part of the code looks like this: sc_1$ue <- cF(sc_1, 2500, 1000, 5) sc_2$ue <- cF(sc_2, 2500, 1000, 5) sc_3$ue <- cF(sc_3, 2500, 1000, 5) sc_4$ue <- cF(sc_4, 3000, 1000, 5) where cF is a function I am calling. This code in its present form works without any error. However, when I try to loop it like the following: sc_list=mget(sc) for (i in 1:5) sc_list[i]$ue <- cF(sc_list[i], 2500, 1000, 5) where sc contains sc_1 to sc_n objects. The output is not an immediate error but a warning. ## Warning in sc_list[i] <- `*vtmp*`: number of items to replace is not a ## multiple of replacement length ## Warning in sc_list[i] <- `*vtmp*`: number of items to replace is not a ## multiple of replacement length ## Warning in sc_list[i] <- `*vtmp*`: number of items to replace is not a ## multiple of replacement length ## Warning in sc_list[i] <- `*vtmp*`: number of items to replace is not a ## multiple of replacement length because of this following code in the program gives me an error. How can I fix this? What I have tried is: sc_list=mget(sc) for (i in 1:length(paths)) paste0("sc_",i)$ue <- cF(sc_list[i], 2500, 1000, 5) This throws up an error. Quitting from lines 209-217 (prototype.Rmd) Error in paste0("sc_", i)$use <- cF(sc_list[i], 2500, 1000, : target of assignment expands to non-language object Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval Execution halted Edit: output of > str(sc_list) List of 4 $ sc_1:Formal class 'SingleCellExperiment' [package "SingleCellExperiment"] with 10 slots .. ..# int_elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. ..# rownames : NULL .. .. .. ..# nrows : int 33694 .. .. .. ..# listData :List of 2 .. .. .. .. ..$ is_spike_MT: logi [1:33694] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. .. ..$ is_spike : logi [1:33694] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. ..# elementType : chr "ANY" .. .. .. ..# elementMetadata: NULL .. .. .. ..# metadata : list() .. ..# int_colData :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. ..# rownames : NULL .. .. .. ..# nrows : int 5586 .. .. .. ..# listData : Named list() .. .. .. ..# elementType : chr "ANY" .. .. .. ..# elementMetadata: NULL .. .. .. ..# metadata : list() .. ..# int_metadata :List of 2 .. .. ..$ version :Classes 'package_version', 'numeric_version' hidden list of 1 .. .. .. ..$ : int [1:3] 1 0 0 .. .. ..$ spike_names: chr "MT" .. ..# reducedDims :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots .. .. .. ..# listData : list() .. .. .. ..# elementType : chr "ANY" .. .. .. ..# elementMetadata: NULL .. .. .. ..# metadata : list() .. ..# rowRanges :Formal class 'GRangesList' [package "GenomicRanges"] with 5 slots .. .. .. ..# unlistData :Formal class 'GRanges' [package "GenomicRanges"] with 6 slots .. .. .. .. .. ..# seqnames :Formal class 'Rle' [package "S4Vectors"] with 4 slots .. .. .. .. .. .. .. ..# values : Factor w/ 0 levels: .. .. .. .. .. .. .. ..# lengths : int(0) .. .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. .. ..# metadata : list() .. .. .. .. .. ..# ranges :Formal class 'IRanges' [package "IRanges"] with 6 slots .. .. .. .. .. .. .. ..# start : int(0) .. .. .. .. .. .. .. ..# width : int(0) .. .. .. .. .. .. .. ..# NAMES : NULL .. .. .. .. .. .. .. ..# elementType : chr "integer" .. .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. .. ..# metadata : list() .. .. .. .. .. ..# strand :Formal class 'Rle' [package "S4Vectors"] with 4 slots .. .. .. .. .. .. .. ..# values : Factor w/ 3 levels "+","-","*": .. .. .. .. .. .. .. ..# lengths : int(0) .. .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. .. ..# metadata : list() .. .. .. .. .. ..# elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. .. .. .. .. ..# rownames : NULL .. .. .. .. .. .. .. ..# nrows : int 0 .. .. .. .. .. .. .. ..# listData : Named list() .. .. .. .. .. .. .. ..# elementType : chr "ANY" .. .. .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. .. .. ..# metadata : list() .. .. .. .. .. ..# seqinfo :Formal class 'Seqinfo' [package "GenomeInfoDb"] with 4 slots .. .. .. .. .. .. .. ..# seqnames : chr(0) .. .. .. .. .. .. .. ..# seqlengths : int(0) .. .. .. .. .. .. .. ..# is_circular: logi(0) .. .. .. .. .. .. .. ..# genome : chr(0) .. .. .. .. .. ..# metadata : list() .. .. .. ..# elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. .. .. ..# rownames : NULL .. .. .. .. .. ..# nrows : int 33694 .. .. .. .. .. ..# listData :List of 11 .. .. .. .. .. .. ..$ id : chr [1:33694] "ENSG00000243485" "ENSG00000237613" "ENSG00000186092" "ENSG00000238009" ... .. .. .. .. .. .. ..$ symbol : chr [1:33694] "RP11-34P13.3" "FAM138A" "OR4F5" "RP11-34P13.7" ... .. .. .. .. .. .. ..$ is_feature_control : logi [1:33694] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. .. .. .. ..$ is_feature_control_MT: logi [1:33694] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. .. .. .. ..$ mean_counts : num [1:33694] 0 0 0 0.000895 0.000179 ... .. .. .. .. .. .. ..$ log10_mean_counts : num [1:33694] 0.00 0.00 0.00 3.89e-04 7.77e-05 ... .. .. .. .. .. .. ..$ rank_counts : num [1:33694] 6741 6741 6741 18054 14520 ... .. .. .. .. .. .. ..$ n_cells_counts : int [1:33694] 0 0 0 5 1 0 0 0 611 542 ... .. .. .. .. .. .. ..$ pct_dropout_counts : num [1:33694] 100 100 100 99.9 100 ... .. .. .. .. .. .. ..$ total_counts : num [1:33694] 0 0 0 5 1 0 0 0 661 617 ... .. .. .. .. .. .. ..$ log10_total_counts : num [1:33694] 0 0 0 0.778 0.301 ... .. .. .. .. .. ..# elementType : chr "ANY" .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. ..# metadata : list() .. .. .. ..# partitioning :Formal class 'PartitioningByEnd' [package "IRanges"] with 5 slots .. .. .. .. .. ..# end : int [1:33694] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. .. ..# NAMES : chr [1:33694] "ENSG00000243485" "ENSG00000237613" "ENSG00000186092" "ENSG00000238009" ... .. .. .. .. .. ..# elementType : chr "integer" .. .. .. .. .. ..# elementMetadata: NULL .. .. .. .. .. ..# metadata : list() .. .. .. ..# elementType : chr "GRanges" .. .. .. ..# metadata : list() .. ..# colData :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. ..# rownames : chr [1:5586] "AAACCTGAGAAGGTTT-1" "AAACCTGAGCGTTCCG-1" "AAACCTGAGTACGTAA-1" "AAACCTGGTAAACACA-1" ... .. .. .. ..# nrows : int 5586 .. .. .. ..# listData :List of 30 .. .. .. .. ..$ dataset : int [1:5586] 1 1 1 1 1 1 1 1 1 1 ... .. .. .. .. ..$ barcode : chr [1:5586] "AAACCTGAGAAGGTTT-1" "AAACCTGAGCGTTCCG-1" "AAACCTGAGTACGTAA-1" "AAACCTGGTAAACACA-1" ... .. .. .. .. ..$ total_features : int [1:5586] 1373 1837 2259 802 2601 1967 1236 1642 1153 1078 ... .. .. .. .. ..$ log10_total_features : num [1:5586] 3.14 3.26 3.35 2.9 3.42 ... .. .. .. .. ..$ total_counts : num [1:5586] 3380 7332 10099 1833 12184 ... .. .. .. .. ..$ log10_total_counts : num [1:5586] 3.53 3.87 4 3.26 4.09 ... .. .. .. .. ..$ pct_counts_top_50_features : num [1:5586] 33.1 38.9 42.5 40.9 42.2 ... .. .. .. .. ..$ pct_counts_top_100_features : num [1:5586] 45 54.8 59.2 53.7 53.5 ... .. .. .. .. ..$ pct_counts_top_200_features : num [1:5586] 57.5 66.9 69 66.4 64.7 ... .. .. .. .. ..$ pct_counts_top_500_features : num [1:5586] 74.2 79.2 79.4 83.5 76.8 ... .. .. .. .. ..$ total_features_endogenous : int [1:5586] 1373 1837 2259 802 2601 1967 1236 1642 1153 1078 ... .. .. .. .. ..$ log10_total_features_endogenous : num [1:5586] 3.14 3.26 3.35 2.9 3.42 ... .. .. .. .. ..$ total_counts_endogenous : num [1:5586] 3380 7332 10099 1833 12184 ... .. .. .. .. ..$ log10_total_counts_endogenous : num [1:5586] 3.53 3.87 4 3.26 4.09 ... .. .. .. .. ..$ pct_counts_endogenous : num [1:5586] 100 100 100 100 100 100 100 100 100 100 ... .. .. .. .. ..$ pct_counts_top_50_features_endogenous : num [1:5586] 33.1 38.9 42.5 40.9 42.2 ... .. .. .. .. ..$ pct_counts_top_100_features_endogenous: num [1:5586] 45 54.8 59.2 53.7 53.5 ... .. .. .. .. ..$ pct_counts_top_200_features_endogenous: num [1:5586] 57.5 66.9 69 66.4 64.7 ... .. .. .. .. ..$ pct_counts_top_500_features_endogenous: num [1:5586] 74.2 79.2 79.4 83.5 76.8 ... .. .. .. .. ..$ total_features_feature_control : int [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ log10_total_features_feature_control : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ total_counts_feature_control : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ log10_total_counts_feature_control : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ pct_counts_feature_control : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ total_features_MT : int [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ log10_total_features_MT : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ total_counts_MT : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ log10_total_counts_MT : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ pct_counts_MT : num [1:5586] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. ..$ is_cell_control : logi [1:5586] FALSE FALSE FALSE FALSE FALSE FALSE ... .. .. .. ..# elementType : chr "ANY" .. .. .. ..# elementMetadata: NULL .. .. .. ..# metadata : list() .. ..# assays :Reference class 'ShallowSimpleListAssays' [package "SummarizedExperiment"] with 1 field .. .. ..$ data: NULL .. .. ..and 14 methods. .. ..# NAMES : NULL .. ..# elementMetadata :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots .. .. .. ..# rownames : NULL .. .. .. ..# nrows : int 33694 .. .. .. ..# listData : Named list() .. .. .. ..# elementType : chr "ANY" .. .. .. ..# elementMetadata: NULL .. .. .. ..# metadata : list() .. ..# metadata :List of 1 .. .. ..$ name: chr "iMates-1" Here is one of the four objects. Could anyone of you help me. Thank you
I'm assuming sc_list is a list of lists, right? If so, can you check if the following code works? sc_list=mget(sc) for (i in 1:5) sc_list[[i]]$ue <- cF(sc_list[[i]], 2500, 1000, 5)
access the data inside the slots of S4 objects
basically I am using a package that gives me a S4 object with many slots. these objects are easily accessible with s4obj#portfolio but then I need to extract FROM this slot a vector. more specifically, the package is fPortfolio and the function is portfolioFrontier(). in the pdf associated is at page 19. (http://postimg.org/image/62oa8z7dv/) in the pdf attached to the package it is specfied that such slot is "a list, containing parameter specifications for the portfolio: weights a numeric vector specifying the portfolio weights, targetReturn a numeric value specifying the target return, " I want to carve out "weights" but nothing worked so far (errors include that object is not subsettable, $ doens't work [meaning s4obj#portfolio$weights doesn't work], etc) code at work: frontier=portfolioFrontier(as.timeSeries(elements)) frontier#portfolio frontier#portfolio$weights Error in frontier#portfolio$weights : $ operator not defined for this S4 class p.s.: i hope this isn't already answered elsewhere but I found nothing on this forum or the web for that matter p.s.2 : str() yields > str(frontier#portfolio) Formal class 'fPFOLIOVAL' [package "fPortfolio"] with 2 slots ..# portfolio:List of 7 .. ..$ weights : num [1:49, 1:14] 0.0805 0.161 0.2415 0.322 0.4025 ... .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. ..$ covRiskBudgets : num [1:49, 1:14] -3.54e-05 -7.73e-05 -1.28e-04 -1.90e-04 -2.67e-04 ... .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. ..$ targetReturn : num [1:49, 1:2] -0.00171 -0.00154 -0.00136 -0.00119 -0.00101 ... .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : chr [1:2] "mean" "mu" .. ..$ targetRisk : num [1:49, 1:4] 0.0394 0.0359 0.0325 0.029 0.0256 ... .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : chr [1:4] "Cov" "Sigma" "CVaR" "VaR" .. ..$ targetAlpha : num 0.05 .. ..$ minriskPortfolio:Formal class 'fPORTFOLIO' [package "fPortfolio"] with 7 slots .. .. .. ..# call : language minriskPortfolio(data = data, spec = spec, constraints = constraints) .. .. .. ..# data :Formal class 'fPFOLIODATA' [package "fPortfolio"] with 3 slots .. .. .. .. .. ..# data :List of 3 .. .. .. .. .. .. ..$ series :Time Series: Name: object Data Matrix: Dimension: 240 14 Column Names: MNEU OBGVEUBR OBGVEUML OBCPEU OBGVIN OBCPNOEU OBGLHGYD OBPSEM AZEU AZUS AZPC AZEM AZRE ATCOMM Row Names: ... Positions: Start: End: With: Format: counts FinCenter: Units: MNEU OBGVEUBR OBGVEUML OBCPEU OBGVIN OBCPNOEU OBGLHGYD OBPSEM AZEU AZUS AZPC AZEM AZRE ATCOMM Title: Signal Series Object Documentation: Wed Mar 18 12:18:11 2015 .. .. .. .. .. .. ..$ nAssets: int 14 .. .. .. .. .. .. ..$ names : chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# statistics:List of 5 .. .. .. .. .. .. ..$ mean : Named num [1:14] 0.000277 0.0011 0.003337 0.002433 0.001609 ... .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. .. ..$ Cov : num [1:14, 1:14] 2.57e-08 1.60e-07 1.39e-07 -7.50e-08 4.11e-07 ... .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. .. .. .. .. .. ..$ : chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. .. .. .. ..$ : chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. .. ..$ estimator: chr "covEstimator" .. .. .. .. .. .. ..$ mu : Named num [1:14] 0.000277 0.0011 0.003337 0.002433 0.001609 ... .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. .. ..$ Sigma : num [1:14, 1:14] 2.57e-08 1.60e-07 1.39e-07 -7.50e-08 4.11e-07 ... .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. .. .. .. .. .. ..$ : chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. .. .. .. ..$ : chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# tailRisk : list() .. .. .. ..# spec :Formal class 'fPFOLIOSPEC' [package "fPortfolio"] with 5 slots .. .. .. .. .. ..# model :List of 5 .. .. .. .. .. .. ..$ type : chr "MV" .. .. .. .. .. .. ..$ optimize : chr "minRisk" .. .. .. .. .. .. ..$ estimator: chr "covEstimator" .. .. .. .. .. .. ..$ tailRisk : list() .. .. .. .. .. .. ..$ params :List of 2 .. .. .. .. .. .. .. ..$ alpha: num 0.05 .. .. .. .. .. .. .. ..$ a : num 1 .. .. .. .. .. ..# portfolio:List of 6 .. .. .. .. .. .. ..$ weights : atomic [1:14] 0.999 0 0 0 0 ... .. .. .. .. .. .. .. ..- attr(*, "invest")= num 1 .. .. .. .. .. .. ..$ targetRisk : num 0.000155 .. .. .. .. .. .. ..$ riskFreeRate : num 0 .. .. .. .. .. .. ..$ nFrontierPoints: num 50 .. .. .. .. .. .. ..$ status : num 0 .. .. .. .. .. .. ..$ targetReturn : Named num -1 .. .. .. .. .. .. .. ..- attr(*, "names")= chr "" .. .. .. .. .. ..# optim :List of 5 .. .. .. .. .. .. ..$ solver : chr "solveRquadprog" .. .. .. .. .. .. ..$ objective: chr [1:3] "portfolioObjective" "portfolioReturn" "portfolioRisk" .. .. .. .. .. .. ..$ options :List of 1 .. .. .. .. .. .. .. ..$ meq: num 2 .. .. .. .. .. .. ..$ control : list() .. .. .. .. .. .. ..$ trace : logi FALSE .. .. .. .. .. ..# messages :List of 2 .. .. .. .. .. .. ..$ messages: logi FALSE .. .. .. .. .. .. ..$ note : chr "" .. .. .. .. .. ..# ampl :List of 5 .. .. .. .. .. .. ..$ ampl : logi FALSE .. .. .. .. .. .. ..$ project : chr "ampl" .. .. .. .. .. .. ..$ solver : chr "ipopt" .. .. .. .. .. .. ..$ protocol: logi FALSE .. .. .. .. .. .. ..$ trace : logi FALSE .. .. .. ..# constraints:Formal class 'fPFOLIOCON' [package "fPortfolio"] with 16 slots .. .. .. .. .. ..# stringConstraints : chr "LongOnly" .. .. .. .. .. ..# minWConstraints : Named num [1:14] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# maxWConstraints : Named num [1:14] 1 1 1 1 1 1 1 1 1 1 ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# eqsumWConstraints : num [1:2, 1:15] -1 -1 0.000277 -1 0.0011 ... .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. .. .. .. .. ..$ : chr [1:2] "Return" "Budget" .. .. .. .. .. .. .. ..$ : chr [1:15] "ceq" "MNEU" "OBGVEUBR" "OBGVEUML" ... .. .. .. .. .. ..# minsumWConstraints : logi [1, 1] NA .. .. .. .. .. ..# maxsumWConstraints : logi [1, 1] NA .. .. .. .. .. ..# minBConstraints : Named num [1:14] -Inf -Inf -Inf -Inf -Inf ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# maxBConstraints : Named num [1:14] 1 1 1 1 1 1 1 1 1 1 ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# listFConstraints : list() .. .. .. .. .. ..# minFConstraints : num(0) .. .. .. .. .. ..# maxFConstraints : num(0) .. .. .. .. .. ..# minBuyinConstraints: Named num [1:14] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# maxBuyinConstraints: Named num [1:14] 1 1 1 1 1 1 1 1 1 1 ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# nCardConstraints : int 14 .. .. .. .. .. ..# minCardConstraints : Named num [1:14] 0 0 0 0 0 0 0 0 0 0 ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. ..# maxCardConstraints : Named num [1:14] 1 1 1 1 1 1 1 1 1 1 ... .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. ..# portfolio :Formal class 'fPFOLIOVAL' [package "fPortfolio"] with 2 slots .. .. .. .. .. ..# portfolio:List of 6 .. .. .. .. .. .. ..$ weights : Named num [1:14] 0.999 0 0 0 0 ... .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. .. ..$ covRiskBudgets: Named num [1:14] 0.999 0 0 0 0 ... .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:14] "MNEU" "OBGVEUBR" "OBGVEUML" "OBCPEU" ... .. .. .. .. .. .. ..$ targetReturn : Named num [1:2] 0.000279 0.000279 .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:2] "mean" "mu" .. .. .. .. .. .. ..$ targetRisk : Named num [1:4] 1.55e-04 1.55e-04 -1.22e-05 -3.15e-05 .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:4] "Cov" "Sigma" "CVaR" "VaR" .. .. .. .. .. .. ..$ targetAlpha : num 0.05 .. .. .. .. .. .. ..$ status : num 0 .. .. .. .. .. ..# messages : list() .. .. .. ..# title : chr "Minimum Variance Portfolio" .. .. .. ..# description: chr "Wed Mar 18 12:18:11 2015 by user: dallaliberaf" .. ..$ status : num 0 ..# messages : list()
It really is just standard S4, so you need to pick element by element. Here is an example which I have actually wrapped in C++ as an RInside example: suppressMessages(library(fPortfolio)) lppData <- 100 * LPP2005.RET[, 1:6] ewSpec <- portfolioSpec() nAssets <- ncol(lppData) weightsvec <- c(0.5, rep(0.1, 5)) setWeights(ewSpec) <- weightsvec ewPf <- feasiblePortfolio(data=lppData, spec=ewSpec, constraints="LongOnly") print(ewPf) vec <- getCovRiskBudgets(ewPf#portfolio) Here, you simply read the str() output wrong and omitted a layer of #portfoio (Hint: you need two) when trying to get to weights: R> ewPf#portfolio#portfolio$weights SBI SPI SII LMI MPI ALT 0.5 0.1 0.1 0.1 0.1 0.1 R> which are of course the same six values I gave it earlier in the example. Edit: Your subsequent edits proves this. You have > str(frontier#portfolio) Formal class 'fPFOLIOVAL' [package "fPortfolio"] with 2 slots ..# portfolio:List of 7 .. ..$ weights : num [1:49, 1:14] 0.0805 0.161 0.2415 0.322 0.4025 .. which is precisely the frontier#portfolio#portfolio$weights I show in my code (albeit applied to the variable named the way it is in your example).
Create a list of Spatial Polygons based on a list of shapefiles
I have a list of Shapefiles list_shp_Tanzania with 61 shapefiles and each shapefiles contains several polygons. I want to create a Spatial Polygons list out of this shapefile list. Here is the structure of a polygon in a shapefile. .. .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots .. .. .. .. ..# Polygons :List of 1 .. .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots .. .. .. .. .. .. .. ..# labpt : num [1:2] 39 -11 .. .. .. .. .. .. .. ..# area : num 2.65e-05 .. .. .. .. .. .. .. ..# hole : logi FALSE .. .. .. .. .. .. .. ..# ringDir: int 1 .. .. .. .. .. .. .. ..# coords : num [1:67, 1:2] 39 39 39 39 39 .. Can somebody help me out with it?