for循环中S4对象的输出错误

时间:2019-07-09 10:51:04

标签: r for-loop s4

使用for循环从S4对象获取特定于类的输出。 S4对象称为数据,是一个大对象。

for循环包含5类,即:“脂肪”,“炎症”,“肌肉”,“腺体”,“内腔”

tissues = c("fat","inflammation","muscle","glands","lumen")
tissues
for (i in tissues) {
    print(i)
    print(data$i)
}

输出:

'fat' 'inflammation' 'muscle' 'glands' 'lumen' 

[1] "fat"
$`m424_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 169 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m424_inflammation_tic-normalization
    raster dimensions: 507 x 164 x 1
    coord(3): x = 1..507, y = 1..164, z = 1..1
    mass range:  599.9313 to 3200.0906 
    centroided: FALSE 

$`m80_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 149 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m80_inflammation_tic-normalization
    raster dimensions: 400 x 212 x 1
    coord(3): x = 1..400, y = 1..212, z = 1..1
    mass range:  599.6025 to 3200.7207 
    centroided: FALSE 

[1] "inflammation"
$`m424_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 169 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m424_inflammation_tic-normalization
    raster dimensions: 507 x 164 x 1
    coord(3): x = 1..507, y = 1..164, z = 1..1
    mass range:  599.9313 to 3200.0906 
    centroided: FALSE 

$`m80_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 149 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m80_inflammation_tic-normalization
    raster dimensions: 400 x 212 x 1
    coord(3): x = 1..400, y = 1..212, z = 1..1
    mass range:  599.6025 to 3200.7207 
    centroided: FALSE 

[1] "muscle"
$`m424_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 169 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m424_inflammation_tic-normalization
    raster dimensions: 507 x 164 x 1
    coord(3): x = 1..507, y = 1..164, z = 1..1
    mass range:  599.9313 to 3200.0906 
    centroided: FALSE 

$`m80_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 149 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m80_inflammation_tic-normalization
    raster dimensions: 400 x 212 x 1
    coord(3): x = 1..400, y = 1..212, z = 1..1
    mass range:  599.6025 to 3200.7207 
    centroided: FALSE 

[1] "glands"
$`m424_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 169 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m424_inflammation_tic-normalization
    raster dimensions: 507 x 164 x 1
    coord(3): x = 1..507, y = 1..164, z = 1..1
    mass range:  599.9313 to 3200.0906 
    centroided: FALSE 

$`m80_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 149 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m80_inflammation_tic-normalization
    raster dimensions: 400 x 212 x 1
    coord(3): x = 1..400, y = 1..212, z = 1..1
    mass range:  599.6025 to 3200.7207 
    centroided: FALSE 

[1] "lumen"
$`m424_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 169 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m424_inflammation_tic-normalization
    raster dimensions: 507 x 164 x 1
    coord(3): x = 1..507, y = 1..164, z = 1..1
    mass range:  599.9313 to 3200.0906 
    centroided: FALSE 

$`m80_inflammation_tic-normalization`
An object of class 'MSContinuousImagingExperiment'
  <53400 feature, 149 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(0):
    metadata(11): ibd binary type universally unique identifier ...
        files name
    run(1): m80_inflammation_tic-normalization
    raster dimensions: 400 x 212 x 1
    coord(3): x = 1..400, y = 1..212, z = 1..1
    mass range:  599.6025 to 3200.7207 
    centroided: FALSE 


代码应输出data $ fat,然后输出data $ inflammation,data $ muscle,data $ gland,data $ lumen。

但是它只输出数据$ inflammation

1 个答案:

答案 0 :(得分:0)

data $ i是问题。请改用data [[i]]。 data $ i搜索列表中的元素“ i”,因为没有这样的元素,它会自动完成data $ i到data $ inflammation的操作。