문제

I have a data.frame called series_to_plot.df which I created by combining a number of other data.frames together (shown below). I now want to pull out just the .mm column from each of these, so I can plot them. So I want to pull out the 3rd column of each data.frame (e.g. p3c3.mm, p3c4.mm etc...), but I can't see how to do this for all data.frames in the object without looping through the name. Is this possible?

I can pull out just one set: e.g. series_to_plot.df[[3]] and another by series_to_plot.df[[10]] (so it is just a list of vectors..) and I can reference directly with series_to_plot.df$p3c3.mm, but is there a command to get a vector containing all mm's from each data.frame? I was expecting an index something like this to work: series_to_plot.df[,3[3]] but it returns Error in [.data.frame(series_to_plot.df, , 3[3]) : undefined columns selected

series_to_plot.df
          p3c3.rd         p3c3.day    p3c3.mm      p3c3.sd                 p3c3.n p3c3.noo p3c3.no_NAs
    1     2010-01-04             0    0.1702531    0.04003364              7                1           0
    2     2010-01-06             2    0.1790594    0.04696674              7                1           0
    3     2010-01-09             5    0.1720404    0.03801756              8                0           0

          p3c4.rd         p3c4.day    p3c4.mm      p3c4.sd                 p3c4.n p3c4.noo p3c4.no_NAs
    1     2010-01-04             0    0.1076581   0.006542157              6                2           0
    2     2010-01-06             2    0.1393447   0.066758781              7                1           0
    3     2010-01-09             5    0.2056846   0.047722862              7                1           0

          p3c5.rd         p3c5.day    p3c5.mm      p3c5.sd                 p3c5.n p3c5.noo p3c5.no_NAs
    1     2010-01-04             0   0.07987147   0.006508766              7                1           0
    2     2010-01-06             2   0.11496167   0.046478767              8                0           0
    3     2010-01-09             5   0.40326471   0.210217097              7                1           0
도움이 되었습니까?

해결책

To add to the other answers, I don't think it is a good idea to have useful information encoded in variable names. Much better to rearrange your data so that all useful information is in the value of some variable. I don't know enough about your data set to suggest the right format, but it might be something like

p c         rd day date mm sd ...
3 3 2010-10-04 ...

Once you have done this the answer to your question becomes the simple df$mm.

If you are getting the data in a less useful form from an external source, you can rearrange it in a more useful form like the above within R using the reshape function or functions from the reshape package.

다른 팁

.webpart 파일 리소스는 14 개 하이브에만 존재할 수 있으며이 이유가 있으며 실제로는 실제로 파일 시스템으로 실행중인 것과 관련이 있습니다.

캠프 프로비저닝 프레임 워크 (공식 이름 아님)에서 아무 것도 사용할 때마다, 사이트 eRIGING, 기능 활성화, 파일을 추진하는 모듈 (웹 파트와 같은)이 있는지 여부는 레이아웃을 찾는 스레드에 의해 처리됩니다. 가상 리소스를 위해 직접 직접.

페이지 렌더링 시간 (페이지에 추가 된 웹 파트 내에서, 페이지 컨트롤에서 또는 마스터 페이지에서)에서 리소스를 사용할 때 마다이 작업을 처리하는 스레드는 IIS 디렉토리에서 직접 App_GlobalResources를보고 있습니다. < / P>

왜 이것이 내가 전혀 모르겠지만, 나는 그것이 역사적으로 데이트하는 방식으로 wssv2로 되돌아 가고있다.

불행히도, 이는 소스 파일을 복제해야합니다. 플러스 측면은 실제로 Visual Studio를 App_GlobalResource에 파일을 배포하고 솔루션에서 파일을 선택하고 등록 정보 (F4)로 이동하여 app_globalresources를 선택하고 배포 유형을 선택하십시오. 파일이 적어도 빈 요소 폴더 또는 모듈 요소 폴더 내에 있음이 있습니다.

The R Language Definition has some good info on indexing (sec 3.4.1), which is pretty helpful.

You can then pull the names matching a sequence with the grep() command. Then string it all together like this:

 dataWithMM <- series_to_plot.df[,grep("[P]", names(series_to_plot.df))]

to deconstruct it a little, this gets the number of the columns that match the "mm" pattern:

 namesThatMatch <- grep("[mm]", names(series_to_plot.df)

Then we use that list to call the columns we want:

  dataWithMM <- series_to_plot.df[, namesThatMatch ]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top