I am trying to write my first loop in R. I have a database loaded in the global environment in R-studio containing a set of tables. Here is an example of one table.
I would like to make the first column in each file the row name like this:
I have tried a couple of ideas but I am having no luck. First code:
tables = ls(envir=.GlobalEnv)[sapply(ls(envir=.GlobalEnv),
for (i in 1:length(tables)){
df=read.table(tables[[i]], sep="\t", header=T); rownames(df) = df[,1]}
}
Second code:
tables = ls(envir=.GlobalEnv)[sapply(ls(envir=.GlobalEnv),
for(i in 1:length(tables)){
tables[[i]] <- tables[[i]][,-1]
rownames(tables[[i]]) <- tables[[i]][,1]}
}
I'm sure it's an easy solution, I am still a novice at R though. Any thoughts on how to get this to work?