Note that there are some explanatory texts on larger screens.

plurals
  1. POR data.frame, group some inputs into "data$inputs"
    primarykey
    data
    text
    <p>I have a <code>dataframe</code>, loaded from file, such as</p> <pre><code>F[1] F[2] ... [F100000] &lt;Output&gt; 1 0 ... 1 6.25 1 1 ... 0 7.22 ...(5000 rows) </code></pre> <p>I want to represent this data as <code>data.frame</code> where <code>data$inputs</code> is inputs from <code>F[1]</code> to <code>F[100000]</code> and <code>data$output</code> is outputs to use this <code>dataframe</code> this way:</p> <p><code>randomForest(outputs~inputs,data=data)</code></p> <p>But I have no way how to group <code>F</code> inputs into <code>data$inputs</code></p> <p>I wrote some functions but it seems awful:</p> <pre><code>loadDescriptors &lt;-function(input){ rd = read.csv(input, sep = " ", header =TRUE) rd &lt;- rd[,colSums(is.na(rd))&lt;nrow(rd)] #Delete empty columns na.omit(rd) #Delete Empty rows } getDescriptors &lt;- function(data){ return(grep("F",colnames(data), value=TRUE)) } getFormula &lt;- function(input){ return(as.formula(paste("outputs ~ ", paste(getDescriptors(input), collapse="+")))) } </code></pre> <p><strong>Added</strong>: Sample of data:</p> <pre><code>&gt; d &lt;- loadDescriptors("Test.stg") &gt; str(d) 'data.frame': 4316 obs. of 325 variables: $ F.0. : int 2 1 0 0 0 0 0 0 0 0 ... $ F.1. : int 0 1 0 0 0 0 0 1 0 0 ... $ F.2. : int 0 0 1 0 0 0 0 0 0 0 ... $ F.3. : int 0 0 1 1 0 0 0 0 1 0 ... $ F.4. : int 0 0 1 0 0 0 0 0 0 0 ... $ F.5. : int 0 0 1 0 0 0 0 0 0 0 ... $ F.6. : int 0 0 1 0 0 0 0 0 0 0 ... $ F.7. : int 0 0 1 0 0 0 0 0 0 0 ... $ F.8. : int 0 0 1 0 0 0 0 0 0 0 ... $ F.9. : int 0 0 1 0 0 0 1 0 0 0 ... $ F.10. : int 0 0 0 1 0 0 0 0 0 0 ... ... $ F.98. : int 0 0 0 0 0 0 0 0 0 0 ... [list output truncated] </code></pre> <p>And the output is:</p> <pre><code>&gt; str(d$Activity) int [1:4316] 1 0 0 0 0 1 0 1 0 0 ... </code></pre> <p>I can refer to any field of <code>data.frame</code> for example: </p> <pre><code>&gt; str(d$F.2.) int [1:4316] 0 0 1 0 0 0 0 0 0 0 ... </code></pre> <p>But I want to group all inputs to refer to inputs, as <code>data$input</code>, how can i do it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload