создать data.frame на основе двух data.frames

Примечание. Я только что переписал этот ответ с 24-часовым появлением git-fu под моим поясом :) В моей истории оболочки весь shebang теперь три однострочных. Тем не менее, я не сдержал их для вашего удобства.

Таким образом, я надеюсь, вы сможете увидеть, как я это сделал, вместо того, чтобы просто слепо копировать / вставлять файлы.


Вот шаг за шагом.

Предположим, что источник находится в ~ / OLDREPO, содержащем stashes. Создайте клон TEST, который не содержит штампов:

cd ~/OLDREPO
git clone . /tmp/TEST

Нажмите все блокировки в виде ветвей temp:

git send-pack /tmp/TEST $(for sha in $(git rev-list -g stash); \
    do echo $sha:refs/heads/stash_$sha; done)

Петля на принимающей стороне, чтобы преобразовать обратно в штампы:

cd /tmp/TEST/
for a in $(git rev-list --no-walk --glob='refs/heads/stash_*'); 
do 
    git checkout $a && 
    git reset HEAD^ && 
    git stash save "$(git log --format='%s' -1 HEAD@{1})"
done

Очистите свои временные ветви, если вы

git branch -D $(git branch|cut -c3-|grep ^stash_)

Сделайте список записок git, и вы будете что-то вроде этого:

stash@{0}: On (no branch): On testing: openmp import
stash@{1}: On (no branch): On testing: zfsrc
stash@{2}: On (no branch): WIP on sehe: 7006283 fixed wrong path to binary in debianized init script (reported as part of issue
stash@{3}: On (no branch): WIP on debian-collab: c5c8037 zfs_pool_alert should be installed by default
stash@{4}: On (no branch): WIP on xattrs: 3972694 removed braindead leftover -O0 flag
stash@{5}: On (no branch): WIP on testing: 3972694 removed braindead leftover -O0 flag
stash@{6}: On (no branch): WIP on testing: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{7}: On (no branch): WIP on xattrs: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{8}: On (no branch): WIP on testing: 28716d4 fixed implicit declaration of stat64
stash@{9}: On (no branch): WIP on emmanuel: bee6660 avoid unrelated changes

В исходном репозитории , то же, что и

stash@{0}: WIP on emmanuel: bee6660 avoid unrelated changes
stash@{1}: WIP on testing: 28716d4 fixed implicit declaration of stat64
stash@{2}: WIP on xattrs: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{3}: WIP on testing: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{4}: WIP on testing: 3972694 removed braindead leftover -O0 flag
stash@{5}: WIP on xattrs: 3972694 removed braindead leftover -O0 flag
stash@{6}: WIP on debian-collab: c5c8037 zfs_pool_alert should be installed by default
stash@{7}: WIP on sehe: 7006283 fixed wrong path to binary in debianized init script (reported as part of issue #57)
stash@{8}: On testing: zfsrc
stash@{9}: On testing: openmp import
0
задан user2380782 13 July 2018 в 09:30
поделиться

2 ответа

Это мое решение:

dfA=data.frame(index=1:5, B=c(0,0,1,0,2), C=c(0,0,0,0,1))
dfB=data.frame(index=1:5, B=c(1,1,2,0,2), C=c(0,1,0,2,1))

dfC <- data.frame(ifelse(dfB[-1]>dfA[-1],1,0))

Результат:

  B C
1 1 0
2 1 1
3 1 0
4 0 1
5 0 0
0
ответ дан Riverarodrigoa 17 August 2018 в 13:16
поделиться

Если ваши data.frames приведены в примере, который вы могли бы сделать:

dfC <- dfA
dfC[-1] <- as.integer(dfB[-1] > dfA[-1])
dfC
  index B C
1     1 1 0
2     2 1 1
3     3 1 0
4     4 0 1
5     5 0 0

[-1] на data.frame выбирает весь файл данных, кроме первого столбца.

1
ответ дан snoram 17 August 2018 в 13:16
поделиться
Другие вопросы по тегам:

Похожие вопросы: