I have a data frame, imported with excel with library(readxl). It contains long columns of data each with its own column title. Now I need to store specific values in new variables. I stored the column titles in the vector "titles" and want to extract certain values from a specific row e.g 151 and store it in a new variable.
I tried with the code below. I am really new to R and tried a lot and failed...
example <- data.frame(c('N 1','N 2'), c(50, 60), c(70, 80))
titles <- c('N 1', 'N 2')
for (i in titles) {
(paste("nkorrigiert",i)) <- as.numeric(example[[paste(i)]][3])
}
dput(head(example))
and get this
Fehler in (paste("nkorrigiert", i)) <- as.numeric(example[[paste(i)]][3]) : Ziel der Zuweisung expandiert zu keinem Sprachobjekt
> dput(head(example))
structure(list(c..N.1....N.2.. = structure(1:2, .Label = c("N 1",
"N 2"), class = "factor"), c.50..60. = c(50, 60), c.70..80. = c(70,
80)), .Names = c("c..N.1....N.2..", "c.50..60.", "c.70..80."),
row.names = 1:2, class = "data.frame")
What am I doing wrong?