2
votes

I have data.table with data that looks like this:

 9:                                                   FIXED ASSETS
10:                c("Tangible assets", "2", "726,809", "729,029")
11:                c("Investments", "3", "2,020,888", "2,020,888")

I would like to extract the whole row of the data.table given the searching parameter:

search <- quote(ColName=="Tangible assets")
WholeRow <- subset(DT, eval(search))

or else, I have tried this:

DT[ColName=="Tangible assets"]

Where DT is name of the data.frame and ColName is the column name. There is only 1 column named ColName, where are all the data as seen.

How to extract the whole row with only partial search parameter?

1
it seems your data is in a strange format. Any reason you want to preserve it as such, or is it better to clean it out first? - Ricardo Saporta
yes, strange format indeed!Long story.It is from scraping certain document. Certainly I would be open to cleaning etc. but that would bring me explaining the "Long story".No one wants this :) - Maximilian
It is possible that somewhere in your script, you have one two many calls to list something like: DT[i=.., j=list(list(..))]. It might be worth taking a look at. - Ricardo Saporta

1 Answers

4
votes

the way your data is currently stored, the best option is to use grepl as in:

 DT[grepl("Tangible assets", V1)]
 # where V1 is the name of the column you are searching through