R:将多个布尔列折叠为单个属性列,并为每个组合添加新行

时间:2018-06-28 22:46:55

标签: r dataframe reshape2 melt

尝试将具有多个布尔列的数据框融化或折叠到包含id列和折叠值列的两列数据库中,但每个值都会导致新行。

示例开头:

API token

所需的输出:

      A S1 S2 S3 S4
1   ex1  1  0  0  0
2   ex2  0  1  0  0
3   ex3  0  0  1  0
4   ex4  1  1  0  0
5   ex5  0  1  0  1
6   ex6  0  1  0  0
7   ex7  1  1  1  0
8   ex8  0  1  1  0
9   ex9  0  0  1  0
10 ex10  1  0  0  0

谢谢!

1 个答案:

答案 0 :(得分:1)

在基数R中:

#include <vector>
#include <string>

using namespace std;
vector<string> vec1;
//vec1.  //completion does not work AND break the completion that used to work if left without semicolon.

int main(){

    vector<string> vec2;
    vec2.push_back("sometext"); //completion works
    vec1.push_back("sometext"); //works here too

    return 0;
}