I have the following string:
"Title\nToday 1,239 €\nYesterday 1,2 €\n17/04/2018 1,2 €\n14/04/2018 1,2 €\n13/04/2018 1,2 €\n12/04/2018 1,2 €\n11/04/2018 1,2 €\n09/04/2018 1,2 €\n08/04/2018 1,2 €\n07/04/2018 1,2 €"
But I don´t know if I can get a dataframe from it. I want to get a dataframe with two columns (Date and Price) with my string as follows (don't really need the Title
name):
Date Price
Today 1,239 €
Yesteday 1,2 €
17/04/2018 1,2 €
14/04/2018 1,2 €
13/04/2018 1,2 €
12/04/2018 1,2 €
11/04/2018 1,2 €
09/04/2018 1,2 €
08/04/2018 1,2 €
07/04/2018 1,2 €
This is almost the same that I can get with cat
function. But I think I can convert it to dataframe.
Any ideas?
Here a solution with read.table
:
> read.table(text=str, sep=' ', skip=1, col.names=c('Date', 'Price', 'Currency'))
Date Price Currency
1 Today 1,239 €
2 Yesterday 1,2 €
3 17/04/2018 1,2 €
4 14/04/2018 1,2 €
5 13/04/2018 1,2 €
6 12/04/2018 1,2 €
7 11/04/2018 1,2 €
8 09/04/2018 1,2 €
9 08/04/2018 1,2 €
10 07/04/2018 1,2 €
with str
being your data. Note the argument skip
is removing the 'Title'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With