我正在尝试将其转换2008-01-01为1/1/2008R 语言。我已经尝试过as.Date(abc,'%m/%d/%y'),但它不起作用......相反,我得到了一堆 NA。
有任何想法吗?
我有一个单元格数组{'W','L','D','D','W'}.我想将其转换为{-1,0,1}数组,其中'W'映射为1,'D'映射为0,'L'映射为-1.
没有编写循环,有没有快速的方法来做到这一点?
['2017-07-17', '2017-07-27', '2017-07-17;14', '2017-07-17;5', '2017-07-19;11', '2017-07-19;13', '2017-07-23;4', '2017-07-27;-1']
Run Code Online (Sandbox Code Playgroud)
我想提取与日期对应的分号右边的所有数字.例如,对于日期'2017-07-17',我想返回列表[14,5].到目前为止2017-07-23我只想回来[4].
我怎样才能做到这一点?我只知道迭代索引来提取数字,但这不会得到我对应于某些日期的数字列表.
for eventIndex in range(2,len(path)):
curr_date = path[eventIndex].split(';')[0]
只会得到我遍历的相应数字,但我根本不知道如何获得与每个日期对应的列表.
我很难理解为什么我的代码不起作用.问题的部分是当我将文本文件中的值传递到我的成绩变量时.我不明白为什么这是错的.我的代码中的其他所有内容都很好,除此之外,但无论如何我都把它包括在内.
string fileName;
cout << "Program that takes data from file and calculate\nmean and standard deviation and put it in file out.txt\n";
cout << "Enter the input file name ";
cin >> fileName;
double grade;
ifstream inData;
inData.open(fileName.c_str());
// Declare vector<double> vecx
vector<double> vecx;
// read data from input file to vector vecx,
while(inData >> grade)
{
vecx.push_back(grade);
}
inData.close();
// keep track how many elements you read from file
// When you done with reading from file, close stream …Run Code Online (Sandbox Code Playgroud)