1

I'm trying to extract info from my data, one row of my data frame is look like this :

str(data[[1]][143,3:10])
'data.frame':   1 obs. of  8 variables:
 $ NA..1: Factor w/ 86 levels "[Hz]","[m/s]",..: 73
 $ NA..2: Factor w/ 22 levels " ","[dB(A)]",..: 1
 $ NA..3: Factor w/ 18 levels " ","[-]","[kg/m³]",..: 1
 $ NA..4: Factor w/ 29 levels " ","[-]","[kg/m³]",..: 1
 $ NA..5: Factor w/ 19 levels "-"," ","[-]",..: 2
 $ NA..6: Factor w/ 14 levels "-"," ","[kg/m³]",..: 2
 $ NA..7: Factor w/ 14 levels " ","***=project specific tower heights applicable",..: NA
 $ NA..8: Factor w/ 20 levels " ","[kg/m³]",..: NA

When I do the following :

as.character(data[[2]][143,3])
[1] "Hub height"

as.character(data[[2]][143,4])
[1] "80 m"

as.character(data[[2]][143,5])
[1] "90 m"

as.character(data[[2]][143,6])
[1] " "

The results are fine and return what I want but when I put all together like :

as.character(data[[2]][143,3:6])
[1] "88" "30" "81" "1"

It does not work any more ?!!! I don't have any explanation for this ! How could I correct this behavior ?

Sotos
  • 51,121
  • 6
  • 32
  • 66
Ali Hadjihoseini
  • 941
  • 1
  • 11
  • 31
  • 3
    You need to loop. For example, something like `lapply(data[, 3:6], as.character)` – Sotos Oct 02 '17 at 07:35
  • 1
    In addition to above comment, you have a list of dataframes, so we will need `lapply(data[[1]][, 3:6], as.character)`, meaning: take 1st dataframe from the list, loop through columns 3 to 6 and convert to character. If we need to do this for each dataframe in a list, then: `lapply(data, function(i) lapply(i[, 3:6], as.character))`. – zx8754 Oct 02 '17 at 07:53
  • 1
    you could just do `as.matrix(data[[2]])[143, 3:6]` – rawr Oct 02 '17 at 08:05

0 Answers0